control.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. * The control file of weekly of ZenTaoPMS.
  4. *
  5. * @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.cnezsoft.com)
  6. * @license ZPL (http://zpl.pub/page/zplv11.html)
  7. * @author Xiying Guan <guanxiying@xirangit.com>
  8. * @package weekly
  9. * @version $Id$
  10. * @link https://www.zentao.net
  11. */
  12. class weekly extends control
  13. {
  14. /**
  15. * The construct function, load users.
  16. *
  17. * @access public
  18. * @return void
  19. */
  20. public function __construct()
  21. {
  22. parent::__construct();
  23. $this->view->users = $this->loadModel('user')->getPairs('noletter');
  24. }
  25. /**
  26. * Common action.
  27. *
  28. * @param int $projectID
  29. * @access public
  30. * @return void
  31. */
  32. public function commonAction($projectID = 0)
  33. {
  34. $this->loadModel('project')->setMenu($projectID);
  35. }
  36. /**
  37. * Index
  38. *
  39. * @param int $projectID
  40. * @param string $date
  41. * @access public
  42. * @return void
  43. */
  44. public function index($projectID = 0, $date = '')
  45. {
  46. if(!common::hasPriv('weekly', 'view')) return $this->locate($this->createLink('user', 'deny', 'module=weekly&method=view'));
  47. $this->commonAction($projectID);
  48. if(!$date) $date = helper::today();
  49. $date = date('Y-m-d', strtotime($date));
  50. $this->weekly->save($projectID, $date);
  51. /* Get report data from module and assign data to view object. */
  52. $data = $this->weekly->getReportData($projectID, $date);
  53. foreach($data as $key => $val) $this->view->$key = $val;
  54. $this->view->title = $this->lang->weekly->common;
  55. $this->view->date = $date;
  56. $this->display();
  57. }
  58. /**
  59. * ComputeWeekly
  60. *
  61. * @access public
  62. * @return void
  63. */
  64. public function computeWeekly()
  65. {
  66. $projects = $this->dao->select('id, name')->from(TABLE_PROJECT)
  67. ->where('deleted')->eq(0)
  68. ->andWhere('type')->eq('project')
  69. ->andWhere('status')->ne('closed')
  70. ->fetchPairs();
  71. $date = helper::today();
  72. $weekStart = $this->weekly->getThisMonday($date);
  73. foreach($projects as $projectID => $project)
  74. {
  75. $this->dao->delete()->from(TABLE_WEEKLYREPORT)->where('project')->eq($projectID)->andWhere('weekStart')->eq($weekStart)->exec();
  76. $this->weekly->save($projectID, $date);
  77. }
  78. }
  79. /**
  80. * 定时创建报告。
  81. * Generate weekly report.
  82. *
  83. * @access public
  84. * @return void
  85. */
  86. public function createCycleReport()
  87. {
  88. if(in_array($this->config->edition, array('open', 'biz'))) return print('Support min edition is max');
  89. $errors = $this->loadModel('reporttemplate')->createCycleReport();
  90. if($errors) return print(json_encode($errors));
  91. return print('success');
  92. }
  93. }