timesheetModel.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <?php
  2. class timesheetModel extends Staple_Model
  3. {
  4. private $db;
  5. private $userId;
  6. private $startDate;
  7. private $month;
  8. private $nextMonth;
  9. private $previousMonth;
  10. private $nextYear;
  11. private $previousYear;
  12. private $year;
  13. private $endDate;
  14. private $entries;
  15. /**
  16. * @return mixed
  17. */
  18. public function getUserId()
  19. {
  20. return $this->userId;
  21. }
  22. /**
  23. * @param mixed $userId
  24. */
  25. public function setUserId($userId)
  26. {
  27. $this->userId = $userId;
  28. }
  29. /**
  30. * @return mixed
  31. */
  32. public function getStartDate()
  33. {
  34. return $this->startDate;
  35. }
  36. /**
  37. * @param mixed $startDate
  38. */
  39. public function setStartDate($startDate)
  40. {
  41. $this->startDate = $startDate;
  42. }
  43. /**
  44. * @return mixed
  45. */
  46. public function getMonth()
  47. {
  48. return $this->month;
  49. }
  50. /**
  51. * @param mixed $month
  52. */
  53. public function setMonth($month)
  54. {
  55. $this->month = $month;
  56. }
  57. /**
  58. * @return mixed
  59. */
  60. public function getNextMonth()
  61. {
  62. return $this->nextMonth;
  63. }
  64. /**
  65. * @param mixed $nextMonth
  66. */
  67. public function setNextMonth($nextMonth)
  68. {
  69. $this->nextMonth = $nextMonth;
  70. }
  71. /**
  72. * @return mixed
  73. */
  74. public function getPreviousMonth()
  75. {
  76. return $this->previousMonth;
  77. }
  78. /**
  79. * @param mixed $previousMonth
  80. */
  81. public function setPreviousMonth($previousMonth)
  82. {
  83. $this->previousMonth = $previousMonth;
  84. }
  85. /**
  86. * @return mixed
  87. */
  88. public function getNextYear()
  89. {
  90. return $this->nextYear;
  91. }
  92. /**
  93. * @param mixed $nextYear
  94. */
  95. public function setNextYear($nextYear)
  96. {
  97. $this->nextYear = $nextYear;
  98. }
  99. /**
  100. * @return mixed
  101. */
  102. public function getPreviousYear()
  103. {
  104. return $this->previousYear;
  105. }
  106. /**
  107. * @param mixed $previousYear
  108. */
  109. public function setPreviousYear($previousYear)
  110. {
  111. $this->previousYear = $previousYear;
  112. }
  113. /**
  114. * @return mixed
  115. */
  116. public function getYear()
  117. {
  118. return $this->year;
  119. }
  120. /**
  121. * @param mixed $year
  122. */
  123. public function setYear($year)
  124. {
  125. $this->year = $year;
  126. }
  127. /**
  128. * @return mixed
  129. */
  130. public function getEndDate()
  131. {
  132. return $this->endDate;
  133. }
  134. /**
  135. * @param mixed $endDate
  136. */
  137. public function setEndDate($endDate)
  138. {
  139. $this->endDate = $endDate;
  140. }
  141. /**
  142. * @return mixed
  143. */
  144. public function getEntries()
  145. {
  146. return $this->entries;
  147. }
  148. /**
  149. * @param mixed $entries
  150. */
  151. public function setEntries($entries)
  152. {
  153. $this->entries = $entries;
  154. }
  155. function __construct($month = null,$year = null)
  156. {
  157. $this->db = Staple_DB::get();
  158. //Get user ID from Auth
  159. $user = new userModel();
  160. $this->userId = $user->getId();
  161. if ($month == NULL) {
  162. $month = new DateTime();
  163. $month = $month->format('n');
  164. }
  165. if ($year == NULL) {
  166. $year = new DateTime();
  167. $year = $year->format('Y');
  168. }
  169. $dateObj = new DateTime();
  170. $dateObj->setDate($year, $month, 1);
  171. $end = $dateObj->modify('+24 day');
  172. $endTime = strtotime($end->format('Y-m-d'));
  173. $endDate = $end->format('Y-m-d');
  174. $this->setEndDate($endDate);
  175. $this->setMonth($end->format('F'));
  176. $this->setNextMonth($end->modify('+1 month')->format('m'));
  177. $this->setPreviousMonth($end->modify('-1 month')->format('m'));
  178. $this->setYear($end->format('Y'));
  179. $this->setNextYear($end->modify('+1 year')->format('Y'));
  180. $this->setPreviousYear($end->modify('-1 year')->format('Y'));
  181. $start = $dateObj->modify('-1 month +1 day');
  182. $startTime = strtotime($start->format('Y-m-d'));
  183. $startDate = $start->format('Y-m-d');
  184. $this->setStartDate($startDate);
  185. }
  186. }
  187. ?>