control.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. /**
  3. * The control file of holiday module of ZenTaoPMS.
  4. *
  5. * @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.cnezsoft.com)
  6. * @license ZPL(http://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
  7. * @author Chunsheng Wang <chunsheng@cnezsoft.com>
  8. * @package holiday
  9. * @version $Id
  10. * @link https://www.zentao.net
  11. */
  12. class holiday extends control
  13. {
  14. /**
  15. * 节假日主页,跳转至列表。
  16. * Holiday list.
  17. *
  18. * @access public
  19. * @return void
  20. */
  21. public function index()
  22. {
  23. $this->locate(inlink('browse'));
  24. }
  25. /**
  26. * 节假日列表。
  27. * Holiday list.
  28. *
  29. * @param string $year
  30. * @access public
  31. * @return void
  32. */
  33. public function browse($year = '')
  34. {
  35. if(empty($year)) $year = date('Y');
  36. $holidays = $this->holiday->getList($year);
  37. $yearList = $this->holiday->getYearPairs();
  38. foreach($holidays as $holiday) $holiday->holiday = formatTime($holiday->begin, DT_DATE1) . ' ~ ' . formatTime($holiday->end, DT_DATE1);
  39. $yearAndNext = array(date('Y'), date('Y') + 1);
  40. foreach($yearAndNext as $date)
  41. {
  42. if(!in_array($date, $yearList)) $yearList[$date] = $date;
  43. }
  44. krsort($yearList);
  45. $this->view->title = $this->lang->holiday->browse;
  46. $this->view->holidays = $holidays;
  47. $this->view->yearList = $yearList;
  48. $this->view->currentYear = $year;
  49. $this->display();
  50. }
  51. /**
  52. * 创建一个节假日。
  53. * Create a holiday.
  54. *
  55. * @access public
  56. * @return void
  57. */
  58. public function create()
  59. {
  60. if($_POST)
  61. {
  62. $holiday = form::data($this->config->holiday->form->create)->get();
  63. $holiday->year = substr($holiday->begin, 0, 4);
  64. if($holiday->year && helper::isZeroDate($holiday->year)) dao::$errors['begin'][] = sprintf($this->lang->error->date, $this->lang->holiday->begin);
  65. if($holiday->end && helper::isZeroDate($holiday->end)) dao::$errors['end'][] = sprintf($this->lang->error->date, $this->lang->holiday->end);
  66. if($holiday->begin && $holiday->end && $holiday->begin > $holiday->end) dao::$errors['end'][] = sprintf($this->lang->error->ge, $this->lang->holiday->end, $this->lang->holiday->begin);
  67. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
  68. $holidayID = $this->holiday->create($holiday);
  69. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
  70. $this->loadModel('action')->create('holiday', $holidayID, 'created');
  71. return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'closeModal' => true, 'load' => true));
  72. }
  73. $this->view->title = $this->lang->holiday->create;
  74. $this->display();
  75. }
  76. /**
  77. * 编辑一个节假日。
  78. * Edit holiday.
  79. *
  80. * @param int $id
  81. * @access public
  82. * @return void
  83. */
  84. public function edit($id)
  85. {
  86. if($_POST)
  87. {
  88. $holiday = form::data($this->config->holiday->form->edit)->add('id', $id)->get();
  89. $holiday->year = substr($holiday->begin, 0, 4);
  90. if($holiday->year && helper::isZeroDate($holiday->year)) dao::$errors['begin'][] = sprintf($this->lang->error->date, $this->lang->holiday->begin);
  91. if($holiday->end && helper::isZeroDate($holiday->end)) dao::$errors['end'][] = sprintf($this->lang->error->date, $this->lang->holiday->end);
  92. if($holiday->begin && $holiday->end && $holiday->begin > $holiday->end) dao::$errors['end'][] = sprintf($this->lang->error->ge, $this->lang->holiday->end, $this->lang->holiday->begin);
  93. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
  94. $this->holiday->update($holiday);
  95. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
  96. return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'closeModal' => true, 'load' => true));
  97. }
  98. $this->view->title = $this->lang->holiday->edit;
  99. $this->view->holiday = $this->holiday->getById($id);
  100. $this->display();
  101. }
  102. /**
  103. * 删除一个节假日。
  104. * Delete a holiday.
  105. *
  106. * @param int $id
  107. * @access public
  108. * @return void
  109. */
  110. public function delete($id)
  111. {
  112. $holidayInformation = $this->dao->select('begin, end')->from(TABLE_HOLIDAY)->where('id')->eq($id)->fetch();
  113. $this->dao->delete()->from(TABLE_HOLIDAY)->where('id')->eq($id)->exec();
  114. /* Update project. */
  115. $this->holiday->updateProgramPlanDuration($holidayInformation->begin, $holidayInformation->end);
  116. $this->holiday->updateProjectRealDuration($holidayInformation->begin, $holidayInformation->end);
  117. /* Update task. */
  118. $this->holiday->updateTaskPlanDuration($holidayInformation->begin, $holidayInformation->end);
  119. $this->holiday->updateTaskRealDuration($holidayInformation->begin, $holidayInformation->end);
  120. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
  121. return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'closeModal' => true, 'load' => true));
  122. }
  123. /**
  124. * 导入节假日。
  125. * Import holiday.
  126. *
  127. * @param string $year
  128. * @access public
  129. * @return void
  130. */
  131. public function import($year = '')
  132. {
  133. if(empty($year)) $year = date('Y');
  134. $holidays = $this->holiday->getHolidayByAPI($year);
  135. if(!empty($_POST))
  136. {
  137. $this->holiday->batchCreate($holidays);
  138. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
  139. return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'closeModal' => true, 'load' => true));
  140. }
  141. foreach($holidays as $holiday) $holiday->holiday = formatTime($holiday->begin, DT_DATE1) . ' ~ ' . formatTime($holiday->end, DT_DATE1);
  142. $this->view->holidays = $holidays;
  143. $this->display();
  144. }
  145. }