reviewModel.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <?php
  2. class reviewModel extends Staple_Model
  3. {
  4. private $db;
  5. private $accountId;
  6. private $payPeriodMonth;
  7. private $payPeriodYear;
  8. private $supervisorId;
  9. private $supervisorFirstName;
  10. private $supervisorLastName;
  11. private $reviewDate;
  12. /**
  13. * @return mixed
  14. */
  15. public function getAccountId()
  16. {
  17. return $this->accountId;
  18. }
  19. /**
  20. * @param mixed $accountId
  21. */
  22. public function setAccountId($accountId)
  23. {
  24. $this->accountId = $accountId;
  25. }
  26. /**
  27. * @return mixed
  28. */
  29. public function getPayPeriodMonth()
  30. {
  31. return $this->payPeriodMonth;
  32. }
  33. /**
  34. * @param mixed $payPeriodMonth
  35. */
  36. public function setPayPeriodMonth($payPeriodMonth)
  37. {
  38. $this->payPeriodMonth = $payPeriodMonth;
  39. }
  40. /**
  41. * @return mixed
  42. */
  43. public function getPayPeriodYear()
  44. {
  45. return $this->payPeriodYear;
  46. }
  47. /**
  48. * @param mixed $payPeriodYear
  49. */
  50. public function setPayPeriodYear($payPeriodYear)
  51. {
  52. $this->payPeriodYear = $payPeriodYear;
  53. }
  54. /**
  55. * @return mixed
  56. */
  57. public function getSupervisorId()
  58. {
  59. return $this->supervisorId;
  60. }
  61. /**
  62. * @param mixed $supervisorId
  63. */
  64. public function setSupervisorId($supervisorId)
  65. {
  66. $this->supervisorId = $supervisorId;
  67. }
  68. /**
  69. * @return mixed
  70. */
  71. public function getReviewDate()
  72. {
  73. return $this->reviewDate;
  74. }
  75. /**
  76. * @param mixed $reviewDate
  77. */
  78. public function setReviewDate($reviewDate)
  79. {
  80. $this->reviewDate = $reviewDate;
  81. }
  82. /**
  83. * @return mixed
  84. */
  85. public function getSupervisorFirstName()
  86. {
  87. return $this->supervisorFirstName;
  88. }
  89. /**
  90. * @param mixed $supervisorFirstName
  91. */
  92. public function setSupervisorFirstName($supervisorFirstName)
  93. {
  94. $this->supervisorFirstName = $supervisorFirstName;
  95. }
  96. /**
  97. * @return mixed
  98. */
  99. public function getSupervisorLastName()
  100. {
  101. return $this->supervisorLastName;
  102. }
  103. /**
  104. * @param mixed $supervisorLastName
  105. */
  106. public function setSupervisorLastName($supervisorLastName)
  107. {
  108. $this->supervisorLastName = $supervisorLastName;
  109. }
  110. function __construct()
  111. {
  112. $this->db = Staple_DB::get();
  113. }
  114. function load($year, $month)
  115. {
  116. $data = array();
  117. $sql = "SELECT * FROM timesheetReview WHERE payPeriodYear = '".$this->db->real_escape_string($year)."' AND payPeriodMonth = '".$this->db->real_escape_string($month)."'";
  118. $query = $this->db->query($sql);
  119. if($query->num_rows > 0)
  120. {
  121. while($result = $query->fetch_assoc())
  122. {
  123. $user = new userModel();
  124. $account = $user->userInfo($result['accountId']);
  125. $data[$account['lastName'].", ".$account['firstName']] = $result;
  126. $user2 = new userModel();
  127. $account2 = $user2->userInfo($result['supervisorId']);
  128. $date = new DateTime();
  129. $date->setTimestamp(strtotime($result['reviewDate']));
  130. $data[$account['lastName'].", ".$account['firstName']]['reviewDateFormatted'] = $date->format('F jS Y @ g:i A');
  131. $data[$account['lastName'].", ".$account['firstName']]['supervisor'] = $account2['firstName']." ".$account2['lastName'];
  132. }
  133. }
  134. return $data;
  135. }
  136. function save()
  137. {
  138. if(isset($this->accountId) && isset($this->payPeriodYear) && isset($this->payPeriodMonth))
  139. {
  140. //Get current users ID.
  141. $user = new userModel();
  142. $supervisorId = $user->getId();
  143. //Check if entry already exists
  144. $sql = "
  145. SELECT id FROM timesheetReview WHERE accountId = '".$this->db->real_escape_string($this->accountId)."' AND payPeriodMonth = '".$this->db->real_escape_string($this->payPeriodMonth)."' AND payPeriodYear = '".$this->db->real_escape_string($this->payPeriodYear)."';
  146. ";
  147. $result = $this->db->query($sql)->num_rows;
  148. if($result == 0)
  149. {
  150. $sql = "
  151. INSERT INTO timesheetReview (accountId, payPeriodMonth, payPeriodYear, supervisorId) VALUES ('".$this->db->real_escape_string($this->accountId)."','".$this->db->real_escape_string($this->payPeriodMonth)."','".$this->db->real_escape_string($this->payPeriodYear)."','".$this->db->real_escape_string($supervisorId)."')
  152. ";
  153. if($this->db->query($sql))
  154. {
  155. return true;
  156. }
  157. }
  158. }
  159. }
  160. function remove($userId, $year, $month)
  161. {
  162. $sql = "DELETE FROM timesheetReview WHERE accountId = '".$userId."' AND payPeriodMonth = '".$month."' AND payPeriodYear = '".$year."';";
  163. if($this->db->query($sql))
  164. {
  165. return true;
  166. }
  167. }
  168. }