diff --git a/api/v1/entries/product.php b/api/v1/entries/product.php index a2b2294318..e22c2d34ba 100644 --- a/api/v1/entries/product.php +++ b/api/v1/entries/product.php @@ -43,7 +43,7 @@ class productEntry extends Entry if(!$fields) return $this->send(200, $product); /* Set other fields. */ - $fields = explode(',', $fields); + $fields = explode(',', strtolower($fields)); foreach($fields as $field) { switch($field) @@ -63,6 +63,23 @@ class productEntry extends Entry $actions = $data->data->actions; $product->actions = $this->loadModel('action')->processActionForAPI($actions, $users, $this->lang->product); break; + case 'lastexecution': + $execution = $this->dao->select('t2.id,t2.name')->from(TABLE_PROJECTPRODUCT)->alias('t1') + ->leftJoin(TABLE_PROJECT)->alias('t2')->on('t1.project = t2.id') + ->where('t2.deleted')->eq(0) + ->andWhere('t1.product')->eq($productID) + ->andWhere('t2.type')->in('sprint,stage') + ->orderBy('t2.id desc') + ->limit(1) + ->fetch(); + if($execution) + { + $workhour = $this->loadModel('project')->computerProgress(array($execution->id => $execution)); + if(isset($workhour[$execution->id])) $execution->progress = $workhour[$execution->id]->progress; + } + + $product->lastExecution = $execution; + break; } } diff --git a/module/product/model.php b/module/product/model.php index be7cdac0a8..59ab28e38f 100644 --- a/module/product/model.php +++ b/module/product/model.php @@ -1349,6 +1349,10 @@ class productModel extends model $product->bugs = $bugs ? $bugs->count : 0; $product->docs = $docs ? $docs->count : 0; + $closedTotal = $this->dao->select('count(id) AS count')->from(TABLE_STORY)->where('deleted')->eq(0)->andWhere('status')->eq('closed')->andWhere('product')->eq($productID)->fetch('count'); + $allTotal = $this->dao->select('count(id) AS count')->from(TABLE_STORY)->where('deleted')->eq(0)->andWhere('product')->eq($productID)->fetch('count'); + $product->progress = empty($closedTotal) ? 0 : round($closedTotal / $allTotal * 100, 1); + return $product; }