123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- <?php
- class reviewModel extends Staple_Model
- {
- private $db;
- private $accountId;
- private $payPeriodMonth;
- private $payPeriodYear;
- private $supervisorId;
- private $supervisorFirstName;
- private $supervisorLastName;
- private $reviewDate;
- /**
- * @return mixed
- */
- public function getAccountId()
- {
- return $this->accountId;
- }
- /**
- * @param mixed $accountId
- */
- public function setAccountId($accountId)
- {
- $this->accountId = $accountId;
- }
- /**
- * @return mixed
- */
- public function getPayPeriodMonth()
- {
- return $this->payPeriodMonth;
- }
- /**
- * @param mixed $payPeriodMonth
- */
- public function setPayPeriodMonth($payPeriodMonth)
- {
- $this->payPeriodMonth = $payPeriodMonth;
- }
- /**
- * @return mixed
- */
- public function getPayPeriodYear()
- {
- return $this->payPeriodYear;
- }
- /**
- * @param mixed $payPeriodYear
- */
- public function setPayPeriodYear($payPeriodYear)
- {
- $this->payPeriodYear = $payPeriodYear;
- }
- /**
- * @return mixed
- */
- public function getSupervisorId()
- {
- return $this->supervisorId;
- }
- /**
- * @param mixed $supervisorId
- */
- public function setSupervisorId($supervisorId)
- {
- $this->supervisorId = $supervisorId;
- }
- /**
- * @return mixed
- */
- public function getReviewDate()
- {
- return $this->reviewDate;
- }
- /**
- * @param mixed $reviewDate
- */
- public function setReviewDate($reviewDate)
- {
- $this->reviewDate = $reviewDate;
- }
- /**
- * @return mixed
- */
- public function getSupervisorFirstName()
- {
- return $this->supervisorFirstName;
- }
- /**
- * @param mixed $supervisorFirstName
- */
- public function setSupervisorFirstName($supervisorFirstName)
- {
- $this->supervisorFirstName = $supervisorFirstName;
- }
- /**
- * @return mixed
- */
- public function getSupervisorLastName()
- {
- return $this->supervisorLastName;
- }
- /**
- * @param mixed $supervisorLastName
- */
- public function setSupervisorLastName($supervisorLastName)
- {
- $this->supervisorLastName = $supervisorLastName;
- }
- function __construct()
- {
- $this->db = Staple_DB::get();
- }
- function load($year, $month)
- {
- $data = array();
- $sql = "SELECT * FROM timesheetReview WHERE payPeriodYear = '".$this->db->real_escape_string($year)."' AND payPeriodMonth = '".$this->db->real_escape_string($month)."'";
- $query = $this->db->query($sql);
- if($query->num_rows > 0)
- {
- while($result = $query->fetch_assoc())
- {
- $user = new userModel();
- $account = $user->userInfo($result['accountId']);
- $data[$account['lastName'].", ".$account['firstName']] = $result;
- $user2 = new userModel();
- $account2 = $user2->userInfo($result['supervisorId']);
- $date = new DateTime();
- $date->setTimestamp(strtotime($result['reviewDate']));
- $data[$account['lastName'].", ".$account['firstName']]['reviewDateFormatted'] = $date->format('F jS Y @ g:i A');
- $data[$account['lastName'].", ".$account['firstName']]['supervisor'] = $account2['firstName']." ".$account2['lastName'];
- }
- }
- return $data;
- }
- function save()
- {
- if(isset($this->accountId) && isset($this->payPeriodYear) && isset($this->payPeriodMonth))
- {
- //Get current users ID.
- $user = new userModel();
- $supervisorId = $user->getId();
- //Check if entry already exists
- $sql = "
- 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)."';
- ";
- $result = $this->db->query($sql)->num_rows;
- if($result == 0)
- {
- $sql = "
- 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)."')
- ";
- if($this->db->query($sql))
- {
- return true;
- }
- }
- }
- }
- function remove($userId, $year, $month)
- {
- $sql = "DELETE FROM timesheetReview WHERE accountId = '".$userId."' AND payPeriodMonth = '".$month."' AND payPeriodYear = '".$year."';";
- if($this->db->query($sql))
- {
- return true;
- }
- }
- }
|