* Fix API: get my info.
This commit is contained in:
@@ -1,22 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* 禅道API的my地盘资源类
|
||||
* 版本V1
|
||||
*
|
||||
* The bug entry point of zentaopms
|
||||
* Version 1
|
||||
*/
|
||||
class myEntry extends entry
|
||||
{
|
||||
public function get()
|
||||
{
|
||||
$info = $this->loadModel('my')->getInfo();
|
||||
$info->products = $this->loadModel('my')->getProducts();
|
||||
$info->projects = $this->loadModel('my')->getProjects();
|
||||
$info->joinProjectCount = count($info->projects);
|
||||
$info->dynamic = $this->loadModel('my')->getDynamic();
|
||||
|
||||
if(!$info) return $this->sendError(400, $info->message);
|
||||
$this->send(200, $info);
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,10 @@ class userEntry extends Entry
|
||||
{
|
||||
public function get($userID = 0)
|
||||
{
|
||||
/* Get my info defaultly. */
|
||||
if(!$userID) return $this->getInfo();
|
||||
|
||||
/* Get user by id. */
|
||||
$control = $this->loadController('user', 'profile');
|
||||
$control->profile($userID);
|
||||
|
||||
@@ -20,6 +24,25 @@ class userEntry extends Entry
|
||||
$this->send(200, $this->format($user, 'last:time,locked:time'));
|
||||
}
|
||||
|
||||
private function getInfo()
|
||||
{
|
||||
$info = $this->loadModel('my')->getInfo();
|
||||
|
||||
$products = $this->my->getProducts();
|
||||
$info->product = new stdclass();
|
||||
$info->product->total = count($products);
|
||||
$info->product->products = $products;
|
||||
|
||||
$projects = $this->my->getProjects();
|
||||
$info->project = new stdclass();
|
||||
$info->project->total = count($projects);
|
||||
$info->project->projects = $projects;
|
||||
|
||||
$info->actions = $this->my->getActions();
|
||||
|
||||
$this->send(200, $info);
|
||||
}
|
||||
|
||||
public function put($userID)
|
||||
{
|
||||
$oldUser = $this->loadModel('user')->getByID($userID, 'id');
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ $routes['/tasks/:id/finish'] = 'taskFinish';
|
||||
|
||||
$routes['/users'] = 'users';
|
||||
$routes['/users/:id'] = 'user';
|
||||
$routes['/my'] = 'my';
|
||||
$routes['/user'] = 'user';
|
||||
|
||||
$routes['/programs'] = 'programs';
|
||||
$routes['/programs/:id'] = 'program';
|
||||
|
||||
+61
-59
@@ -58,7 +58,7 @@ class myModel extends model
|
||||
}
|
||||
|
||||
/**
|
||||
* My charged products.
|
||||
* Get my charged products.
|
||||
*
|
||||
* @access public
|
||||
* @return array
|
||||
@@ -114,11 +114,12 @@ class myModel extends model
|
||||
if(isset($stories[$product->id])) $product->stories = $stories[$product->id];
|
||||
if(isset($executions[$product->id])) $product->executions = $executions[$product->id];
|
||||
}
|
||||
|
||||
return array_values($products);
|
||||
}
|
||||
|
||||
/**
|
||||
* All projects.
|
||||
* Get my projects.
|
||||
*
|
||||
* @access public
|
||||
* @return array
|
||||
@@ -130,21 +131,21 @@ class myModel extends model
|
||||
{
|
||||
if($project->status == 'doing')
|
||||
{
|
||||
$workhour = $this->loadModel('project')->getWorkhour($project->id);
|
||||
$workhour = $this->project->getWorkhour($project->id);
|
||||
$projects[$key]->progress = ($workhour->totalConsumed + $workhour->totalLeft) ? floor($workhour->totalConsumed / ($workhour->totalConsumed + $workhour->totalLeft) * 1000) / 1000 * 100 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
return array_values($projects);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamic.
|
||||
* Get latest actions.
|
||||
*
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getDynamic()
|
||||
public function getActions()
|
||||
{
|
||||
$actions = $this->loadModel('action')->getDynamic('all', 'today', 'date_desc');
|
||||
$users = $this->loadModel('user')->getPairs('noletter');
|
||||
@@ -174,12 +175,12 @@ class myModel extends model
|
||||
if(common::hasPriv('task', 'view'))
|
||||
{
|
||||
$tasks = $this->dao->select('*')->from(TABLE_TASK)
|
||||
->where('assignedTo')->eq($this->app->user->account)
|
||||
->andWhere('deleted')->eq('0')
|
||||
->andWhere('status')->ne('closed')
|
||||
->orderBy('id_desc')
|
||||
->limit(3)
|
||||
->fetchAll();
|
||||
->where('assignedTo')->eq($this->app->user->account)
|
||||
->andWhere('deleted')->eq('0')
|
||||
->andWhere('status')->ne('closed')
|
||||
->orderBy('id_desc')
|
||||
->limit(3)
|
||||
->fetchAll();
|
||||
$info->task->dynamic = $tasks;
|
||||
}
|
||||
|
||||
@@ -190,12 +191,12 @@ class myModel extends model
|
||||
if(common::hasPriv('story', 'view'))
|
||||
{
|
||||
$stories = $this->dao->select('*')->from(TABLE_STORY)
|
||||
->where('assignedTo')->eq($this->app->user->account)
|
||||
->andWhere('deleted')->eq('0')
|
||||
->andWhere('status')->ne('closed')
|
||||
->orderBy('id_desc')
|
||||
->limit(3)
|
||||
->fetchAll();
|
||||
->where('assignedTo')->eq($this->app->user->account)
|
||||
->andWhere('deleted')->eq('0')
|
||||
->andWhere('status')->ne('closed')
|
||||
->orderBy('id_desc')
|
||||
->limit(3)
|
||||
->fetchAll();
|
||||
$info->story->dynamic = $stories;
|
||||
}
|
||||
|
||||
@@ -207,30 +208,30 @@ class myModel extends model
|
||||
{
|
||||
$this->app->loadLang('bug');
|
||||
$bugs = $this->dao->select('*')->from(TABLE_BUG)
|
||||
->where('assignedTo')->eq($this->app->user->account)
|
||||
->andWhere('deleted')->eq('0')
|
||||
->andWhere('status')->ne('closed')
|
||||
->orderBy('id_desc')
|
||||
->limit(3)
|
||||
->fetchAll();
|
||||
->where('assignedTo')->eq($this->app->user->account)
|
||||
->andWhere('deleted')->eq('0')
|
||||
->andWhere('status')->ne('closed')
|
||||
->orderBy('id_desc')
|
||||
->limit(3)
|
||||
->fetchAll();
|
||||
$info->bug->dynamic = $bugs;
|
||||
}
|
||||
|
||||
/* My todos. */
|
||||
$info->todo = new stdclass();
|
||||
$info->todo->total = (int) $this->dao->select('count(*) AS count')->from(TABLE_TODO)->where('assignedTo')->eq($this->app->user->account)->andWhere('status')->ne('closed')->andWhere('deleted')->eq(0)->fetch('count');
|
||||
$info->todo->dynamic = new stdclass();
|
||||
$info->todo->dynamic = array();
|
||||
if(common::hasPriv('todo', 'view'))
|
||||
{
|
||||
$this->app->loadClass('date');
|
||||
$todos = $this->dao->select('*')->from(TABLE_TODO)
|
||||
->where('assignedTo')->eq($this->app->user->account)
|
||||
->andWhere('cycle')->eq(0)
|
||||
->andWhere('deleted')->eq(0)
|
||||
->andWhere('status')->eq('wait')
|
||||
->orderBy('`date` desc')
|
||||
->limit(3)
|
||||
->fetchAll();
|
||||
->where('assignedTo')->eq($this->app->user->account)
|
||||
->andWhere('cycle')->eq(0)
|
||||
->andWhere('deleted')->eq(0)
|
||||
->andWhere('status')->eq('wait')
|
||||
->orderBy('`date` desc')
|
||||
->limit(3)
|
||||
->fetchAll();
|
||||
foreach($todos as $key => $todo)
|
||||
{
|
||||
$todo->begin = date::formatTime($todo->begin);
|
||||
@@ -242,16 +243,16 @@ class myModel extends model
|
||||
/* My risks. */
|
||||
$info->risk = new stdclass();
|
||||
$info->risk->total = 0;
|
||||
$info->risk->dynamic = new stdclass();
|
||||
$info->risk->dynamic = array();
|
||||
if(common::hasPriv('risk', 'view') and isset($this->config->maxVersion))
|
||||
{
|
||||
$risks = $this->dao->select('*')->from(TABLE_RISK)
|
||||
->where('assignedTo')->eq($this->app->user->account)
|
||||
->andWhere('deleted')->eq('0')
|
||||
->andWhere('status')->ne('closed')
|
||||
->orderBy('id_desc')
|
||||
->limit(3)
|
||||
->fetchAll();
|
||||
->where('assignedTo')->eq($this->app->user->account)
|
||||
->andWhere('deleted')->eq('0')
|
||||
->andWhere('status')->ne('closed')
|
||||
->orderBy('id_desc')
|
||||
->limit(3)
|
||||
->fetchAll();
|
||||
$info->risk->total = (int) $this->dao->select('count(*) AS count')->from(TABLE_RISK)->where('assignedTo')->eq($this->app->user->account)->andWhere('status')->ne('closed')->andWhere('deleted')->eq(0)->fetch('count');
|
||||
$info->risk->dynamic = $risks;
|
||||
}
|
||||
@@ -259,23 +260,23 @@ class myModel extends model
|
||||
/* My meetings. */
|
||||
$info->meeting = new stdclass();
|
||||
$info->meeting->total = 0;
|
||||
$info->meeting->dynamic = new stdclass();
|
||||
$info->meeting->dynamic = array();
|
||||
if(common::hasPriv('meeting', 'view') and isset($this->config->maxVersion))
|
||||
{
|
||||
$today = helper::today();
|
||||
$now = date('H:i:s', strtotime(helper::now()));
|
||||
|
||||
$meetings = $this->dao->select('*')->from(TABLE_MEETING)
|
||||
->Where('deleted')->eq('0')
|
||||
->andWhere('(date')->gt($today)
|
||||
->orWhere('(begin')->gt($now)
|
||||
->andWhere('date')->eq($today)
|
||||
->markRight(2)
|
||||
->andwhere('(host')->eq($this->app->user->account)
|
||||
->orWhere('participant')->in($this->app->user->account)
|
||||
->markRight(1)
|
||||
->orderBy('id_desc')
|
||||
->fetchAll();
|
||||
->Where('deleted')->eq('0')
|
||||
->andWhere('(date')->gt($today)
|
||||
->orWhere('(begin')->gt($now)
|
||||
->andWhere('date')->eq($today)
|
||||
->markRight(2)
|
||||
->andwhere('(host')->eq($this->app->user->account)
|
||||
->orWhere('participant')->in($this->app->user->account)
|
||||
->markRight(1)
|
||||
->orderBy('id_desc')
|
||||
->fetchAll();
|
||||
$info->meeting->total = count($meetings);
|
||||
$info->meeting->dynamic = array_slice($meetings, 0, 3);
|
||||
}
|
||||
@@ -283,22 +284,23 @@ class myModel extends model
|
||||
/* My issues. */
|
||||
$info->issue = new stdclass();
|
||||
$info->issue->total = 0;
|
||||
$info->issue->dynamic = new stdclass();
|
||||
$info->issue->dynamic = array();
|
||||
if(common::hasPriv('issue', 'view') and isset($this->config->maxVersion))
|
||||
{
|
||||
$issues = $this->dao->select('*')->from(TABLE_ISSUE)
|
||||
->where('assignedTo')->eq($this->app->user->account)
|
||||
->andWhere('deleted')->eq('0')
|
||||
->andWhere('status')->ne('closed')
|
||||
->orderBy('id_desc')
|
||||
->limit(3)
|
||||
->fetchAll();
|
||||
->where('assignedTo')->eq($this->app->user->account)
|
||||
->andWhere('deleted')->eq('0')
|
||||
->andWhere('status')->ne('closed')
|
||||
->orderBy('id_desc')
|
||||
->limit(3)
|
||||
->fetchAll();
|
||||
$info->issue->total = (int) $this->dao->select('count(*) AS count')->from(TABLE_ISSUE)->where('assignedTo')->eq($this->app->user->account)->andWhere('status')->ne('closed')->andWhere('deleted')->eq(0)->fetch('count');
|
||||
$info->issue->dynamic = $issues;
|
||||
}
|
||||
|
||||
/* Some count. */
|
||||
$info->createdDocs = $this->dao->select('count(*) AS count')->from(TABLE_DOC)->where('addedBy')->eq($this->app->user->account)->andWhere('deleted')->eq('0')->fetch('count');
|
||||
/* Get count of docs created by me. */
|
||||
$info->doc = new stdclass();
|
||||
$info->doc->total = $this->dao->select('count(*) AS count')->from(TABLE_DOC)->where('addedBy')->eq($this->app->user->account)->andWhere('deleted')->eq('0')->fetch('count');
|
||||
|
||||
return $info;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user