diff --git a/module/product/model.php b/module/product/model.php index 37612d6bab..ae59211dc9 100644 --- a/module/product/model.php +++ b/module/product/model.php @@ -261,14 +261,14 @@ class productModel extends model { if(defined('TUTORIAL')) return $this->loadModel('tutorial')->getProductPairs(); - $products = $this->dao->select('*, IF(INSTR(" closed", t1.status) < 2, 0, 1) AS isClosed, t1.id AS id, t1.name AS name') - ->from(TABLE_PRODUCT)->alias('t1') - ->leftJoin(TABLE_PROGRAM)->alias('t2')->on('t1.program = t2.id') - ->where('t1.deleted')->eq(0) - ->beginIF($programID)->andWhere('t1.program')->eq($programID)->fi() - ->beginIF(strpos($mode, 'noclosed') !== false)->andWhere('t1.status')->ne('closed')->fi() - ->beginIF(!$this->app->user->admin)->andWhere('t1.id')->in($this->app->user->view->products)->fi() - ->orderBy('t2.order_asc, t1.line_desc, t1.order_asc') + $orderBy = !empty($this->config->product->orderBy) ? $this->config->product->orderBy : 'isClosed'; + $products = $this->dao->select('*, IF(INSTR(" closed", status) < 2, 0, 1) AS isClosed') + ->from(TABLE_PRODUCT) + ->where('deleted')->eq(0) + ->beginIF($programID)->andWhere('program')->eq($programID)->fi() + ->beginIF(strpos($mode, 'noclosed') !== false)->andWhere('status')->ne('closed')->fi() + ->beginIF(!$this->app->user->admin)->andWhere('id')->in($this->app->user->view->products)->fi() + ->orderBy($orderBy) ->fetchPairs('id', 'name'); return $products; } diff --git a/module/story/control.php b/module/story/control.php index 9bdfe2f914..310c2efa6e 100644 --- a/module/story/control.php +++ b/module/story/control.php @@ -585,6 +585,18 @@ class story extends control $this->commonAction($storyID); + /* Sort products. */ + $myProducts = array(); + $othersProducts = array(); + $products = $this->loadModel('product')->getList(); + + foreach($products as $product) + { + if($product->status == 'normal' and $product->PO == $this->app->user->account) $myProducts[$product->id] = $product->name; + if($product->status == 'normal' and !($product->PO == $this->app->user->account)) $othersProducts[$product->id] = $product->name; + if($product->status == 'closed') continue; + } + /* Assign. */ $story = $this->story->getById($storyID, 0, true); $product = $this->product->getById($story->product); @@ -599,6 +611,7 @@ class story extends control $this->view->stories = $stories; $this->view->users = $this->user->getPairs('pofirst|nodeleted', "$story->assignedTo,$story->openedBy,$story->closedBy"); $this->view->product = $product; + $this->view->products = $myProducts + $othersProducts; $this->view->branches = $product->type == 'normal' ? array() : $this->loadModel('branch')->getPairs($story->product); $this->display(); }