partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

commit 0b1f509f95be76f3979c90b89ba016e0104f2686
parent c666d3754058d70a23b24343bb2604cf58ff9b64
Author: Felicitus <felicitus@felicitus.org>
Date:   Thu, 30 Jun 2011 03:10:39 +0200

Fixed part ordering

Diffstat:
Msrc/de/RaumZeitLabor/PartKeepr/Part/PartManager.php | 39++++++++++++++++++++++++---------------
Msrc/de/RaumZeitLabor/PartKeepr/Part/PartService.php | 12+-----------
2 files changed, 25 insertions(+), 26 deletions(-)

diff --git a/src/de/RaumZeitLabor/PartKeepr/Part/PartManager.php b/src/de/RaumZeitLabor/PartKeepr/Part/PartManager.php @@ -36,7 +36,7 @@ class PartManager extends Singleton { * * @todo The parameter list. We need to invent something so that we don't have like 20 parameters for this method. */ - public function getParts ($start = 0, $limit = 10, $sort = "name", $dir = "asc", $filter = "", $category = 0, $categoryScope = "all", $stockMode = "all", $withoutPrice = false, $storageLocation = "") { + public function getParts ($start = 0, $limit = 10, $sort = null, $filter = "", $category = 0, $categoryScope = "all", $stockMode = "all", $withoutPrice = false, $storageLocation = "") { $qb = PartKeepr::getEM()->createQueryBuilder(); $qb->select("COUNT(p.id)")->from("de\RaumZeitLabor\PartKeepr\Part\Part","p") @@ -55,19 +55,6 @@ class PartManager extends Singleton { $qb->andWhere("st.name = :storageLocation"); $qb->setParameter("storageLocation", $storageLocation); } - - switch ($sort) { - case "storageLocationName": - $orderBy = "st.name"; - break; - case "footprintName": - $orderBy = "f.name"; - break; - default; - $orderBy = "p.".$sort; - break; - } - $category = intval($category); @@ -109,7 +96,29 @@ class PartManager extends Singleton { $qb->select("p.averagePrice, p.name, p.needsReview, p.createDate, p.id, p.stockLevel, p.minStockLevel, p.comment, st.id AS storageLocation_id, p.categoryPath, st.name as storageLocationName, f.id AS footprint_id, f.name AS footprintName, c.id AS category_id, c.name AS categoryName, pu.id AS partUnit, pu.name AS partUnitName, pu.is_default AS partUnitDefault"); - $qb->orderBy($orderBy, $dir); + if ($sort === null) { + $qb->addOrderBy("p.name", "ASC"); + } else { + $sortArray = json_decode($sort, true); + + foreach ($sortArray as $sortParam) { + switch ($sortParam["property"]) { + case "storageLocationName": + $orderBy = "st.name"; + break; + case "footprintName": + $orderBy = "f.name"; + break; + default; + $orderBy = "p.".$sortParam["property"]; + break; + } + + $qb->addOrderBy($orderBy, $sortParam["direction"]); + } + } + + if ($limit > -1) { $qb->setMaxResults($limit); $qb->setFirstResult($start); diff --git a/src/de/RaumZeitLabor/PartKeepr/Part/PartService.php b/src/de/RaumZeitLabor/PartKeepr/Part/PartService.php @@ -18,20 +18,10 @@ class PartService extends Service implements RestfulService { if ($this->hasParameter("id")) { return array("data" => PartManager::getInstance()->getPart($this->getParameter("id"))->serialize()); } else { - if ($this->hasParameter("sort")) { - $tmp = json_decode($this->getParameter("sort"), true); - - $aSortParams = $tmp[0]; - } else { - $aSortParams = array( - "property" => "name", - "direction" => "ASC"); - } return PartManager::getInstance()->getParts( $this->getParameter("start", $this->getParameter("start", 0)), $this->getParameter("limit", $this->getParameter("limit", 25)), - $this->getParameter("sortby", $aSortParams["property"]), - $this->getParameter("dir", $aSortParams["direction"]), + $this->getParameter("sort", $this->getParameter("sort")), $this->getParameter("query", ""), $this->getParameter("category", 0), $this->getParameter("categoryScope", "all"),