or.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * Get research tasks.
  4. *
  5. * @param int $researchID
  6. * @param string $type
  7. * @param string $orderBy
  8. * @param object|null $pager
  9. * @access public
  10. * @return array
  11. */
  12. public function getResearchTasks($researchID = 0, $type = 'all', $orderBy = 'id_desc', $pager = null)
  13. {
  14. if(is_string($type)) $type = strtolower($type);
  15. $orderBy = str_replace('pri_', 'priOrder_', $orderBy);
  16. $fields = "DISTINCT t1.*, t2.realname AS assignedToRealName, IF(t1.`pri` = 0, {$this->config->maxPriValue}, t1.`pri`) as priOrder";
  17. $actionIDList = array();
  18. if($type == 'assignedbyme') $actionIDList = $this->dao->select('objectID')->from(TABLE_ACTION)->where('objectType')->eq('task')->andWhere('action')->eq('assigned')->andWhere('actor')->eq($this->app->user->account)->fetchPairs('objectID', 'objectID');
  19. $tasks = $this->dao->select($fields)
  20. ->from(TABLE_TASK)->alias('t1')
  21. ->leftJoin(TABLE_USER)->alias('t2')->on('t1.assignedTo = t2.account')
  22. ->leftJoin(TABLE_TASKTEAM)->alias('t3')->on('t3.task = t1.id')
  23. ->where('t1.project')->eq((int)$researchID)
  24. ->beginIF($type == 'myinvolved')
  25. ->andWhere("((t3.`account` = '{$this->app->user->account}') OR t1.`assignedTo` = '{$this->app->user->account}' OR t1.`finishedby` = '{$this->app->user->account}')")
  26. ->fi()
  27. ->beginIF($type == 'undone')->andWhere('t1.status')->notIN('done,closed')->fi()
  28. ->beginIF($type == 'assignedtome')->andWhere("(t1.assignedTo = '{$this->app->user->account}' or (t1.mode = 'multi' and t3.`account` = '{$this->app->user->account}' and t1.status != 'closed' and t3.status != 'done') )")->fi()
  29. ->beginIF($type == 'finishedbyme')
  30. ->andWhere('t1.finishedby', 1)->eq($this->app->user->account)
  31. ->orWhere('t3.status')->eq("done")
  32. ->markRight(1)
  33. ->fi()
  34. ->beginIF($type == 'delayed')->andWhere('t1.deadline')->gt('1970-1-1')->andWhere('t1.deadline')->lt(date(DT_DATE1))->andWhere('t1.status')->in('wait,doing')->fi()
  35. ->beginIF(is_array($type) or strpos(',all,undone,needconfirm,assignedtome,delayed,finishedbyme,myinvolved,assignedbyme,review,', ",$type,") === false)->andWhere('t1.status')->in($type)->fi()
  36. ->beginIF($type == 'assignedbyme')->andWhere('t1.id')->in($actionIDList)->andWhere('t1.status')->ne('closed')->fi()
  37. ->beginIF($type == 'review')
  38. ->andWhere("FIND_IN_SET('{$this->app->user->account}', t1.reviewers)")
  39. ->andWhere('t1.reviewStatus')->eq('doing')
  40. ->fi()
  41. ->andWhere('t1.deleted')->eq(0)
  42. ->orderBy($orderBy)
  43. ->page($pager, 't1.id')
  44. ->fetchAll('id');
  45. $this->loadModel('common')->saveQueryCondition($this->dao->get(), 'task', (in_array($type, array('myinvolved', 'needconfirm', 'assignedtome'))) ? false : true);
  46. $this->session->set('researchTaskTotal', count($tasks));
  47. if(empty($tasks)) return array();
  48. return $this->processTasks($tasks);
  49. }
  50. /**
  51. * Get tasks of a story.
  52. *
  53. * @param int $storyID
  54. * @access public
  55. * @return array
  56. */
  57. public function getStoryTasks($storyID)
  58. {
  59. return $this->loadExtension('or')->getStoryTasks($storyID);
  60. }