zentaomax.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. /**
  3. * @param string $begin
  4. * @param string $end
  5. */
  6. public function getWorkingDays($begin = '', $end = '')
  7. {
  8. $records = $this->dao->select('*')->from(TABLE_HOLIDAY)
  9. ->where('type')->eq('working')
  10. ->andWhere('begin')->le($end)
  11. ->andWhere('end')->ge($begin)
  12. ->fetchAll('id');
  13. $workingDays = array();
  14. foreach($records as $record)
  15. {
  16. $dates = $this->getDaysBetween($record->begin, $record->end);
  17. $workingDays = array_merge($workingDays, $dates);
  18. }
  19. return $workingDays;
  20. }
  21. /**
  22. * @param string $begin
  23. * @param string $end
  24. */
  25. public function getActualWorkingDays($begin, $end)
  26. {
  27. if(empty($begin) or empty($end) or $begin == '0000-00-00' or $end == '0000-00-00') return array();
  28. $this->app->loadConfig('execution');
  29. $actualDays = array();
  30. $currentDay = $begin;
  31. $holidays = $this->getHolidays($begin, $end);
  32. $workingDays = $this->getWorkingDays($begin, $end);
  33. $weekend = isset($this->config->execution->weekend) ? $this->config->execution->weekend : 2;
  34. /* When the start date and end date are the same. */
  35. if($begin == $end)
  36. {
  37. if(in_array($begin, $workingDays))
  38. {
  39. $actualDays[] = $begin;
  40. return $actualDays;
  41. }
  42. if(in_array($begin, $holidays)) return $actualDays;
  43. $w = date('w', strtotime($begin));
  44. if($weekend == 2)
  45. {
  46. if($w == 0 or $w == 6) return $actualDays;
  47. }
  48. else
  49. {
  50. if($w == 0) return $actualDays;
  51. }
  52. $actualDays[] = $begin;
  53. return $actualDays;
  54. }
  55. for($i = 0; $currentDay < $end; $i ++)
  56. {
  57. $currentDay = date('Y-m-d', strtotime("$begin + $i days"));
  58. $w = date('w', strtotime($currentDay));
  59. if(in_array($currentDay, $workingDays))
  60. {
  61. $actualDays[] = $currentDay;
  62. continue;
  63. }
  64. if(in_array($currentDay, $holidays)) continue;
  65. if($weekend == 2)
  66. {
  67. if($w == 0 or $w == 6) continue;
  68. }
  69. else
  70. {
  71. if($w == 0) continue;
  72. }
  73. $actualDays[] = $currentDay;
  74. }
  75. return $actualDays;
  76. }
  77. public function delete($id, $null = null)
  78. {
  79. $holidayInformation = $this->dao->select('begin,end')->from(TABLE_HOLIDAY)->where('id')->eq($id)->fetch();
  80. $result = parent::delete($id, $null = null);
  81. if($result)
  82. {
  83. /* Update project. */
  84. $this->updateProgramPlanDuration($holidayInformation->begin, $holidayInformation->end);
  85. $this->updateProjectRealDuration($holidayInformation->begin, $holidayInformation->end);
  86. /* Update task. */
  87. $this->updateTaskPlanDuration($holidayInformation->begin, $holidayInformation->end);
  88. $this->updateTaskRealDuration($holidayInformation->begin, $holidayInformation->end);
  89. }
  90. return $result;
  91. }