|
@@ -4,360 +4,214 @@
|
|
|
{
|
|
|
private $db;
|
|
|
|
|
|
- private $id;
|
|
|
private $userId;
|
|
|
- private $date;
|
|
|
- private $inTime;
|
|
|
- private $outTime;
|
|
|
- private $lessTime;
|
|
|
- private $codeId;
|
|
|
-
|
|
|
- /**
|
|
|
- * @return mixed
|
|
|
- */
|
|
|
- public function getId()
|
|
|
- {
|
|
|
- return $this->id;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @param mixed $id
|
|
|
- */
|
|
|
- public function setId($id)
|
|
|
- {
|
|
|
- $this->id = $id;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @return mixed
|
|
|
- */
|
|
|
- public function getUserId()
|
|
|
- {
|
|
|
- return $this->userId;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @param mixed $userId
|
|
|
- */
|
|
|
- public function setUserId($userId)
|
|
|
- {
|
|
|
- $this->userId = $userId;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @return mixed
|
|
|
- */
|
|
|
- public function getDate()
|
|
|
- {
|
|
|
- return $this->date;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @param mixed $date
|
|
|
- */
|
|
|
- public function setDate($date)
|
|
|
- {
|
|
|
- $this->date = $date;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @return mixed
|
|
|
- */
|
|
|
- public function getInTime()
|
|
|
- {
|
|
|
- return $this->inTime;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @param mixed $inTime
|
|
|
- */
|
|
|
- public function setInTime($inTime)
|
|
|
- {
|
|
|
- $this->inTime = $inTime;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @return mixed
|
|
|
- */
|
|
|
- public function getOutTime()
|
|
|
- {
|
|
|
- return $this->outTime;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @param mixed $outTime
|
|
|
- */
|
|
|
- public function setOutTime($outTime)
|
|
|
- {
|
|
|
- $this->outTime = $outTime;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @return mixed
|
|
|
- */
|
|
|
- public function getLessTime()
|
|
|
- {
|
|
|
- return $this->lessTime;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @param mixed $lessTime
|
|
|
- */
|
|
|
- public function setLessTime($lessTime)
|
|
|
- {
|
|
|
- $this->lessTime = $lessTime;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @return mixed
|
|
|
- */
|
|
|
- public function getCodeId()
|
|
|
- {
|
|
|
- return $this->codeId;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @param mixed $codeId
|
|
|
- */
|
|
|
- public function setCodeId($codeId)
|
|
|
- {
|
|
|
- $this->codeId = $codeId;
|
|
|
- }
|
|
|
-
|
|
|
- function __construct()
|
|
|
+ private $startDate;
|
|
|
+ private $month;
|
|
|
+ private $nextMonth;
|
|
|
+ private $previousMonth;
|
|
|
+ private $nextYear;
|
|
|
+ private $previousYear;
|
|
|
+ private $year;
|
|
|
+ private $endDate;
|
|
|
+ private $entries;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ public function getUserId()
|
|
|
{
|
|
|
- $this->db = Staple_DB::get();
|
|
|
- }
|
|
|
-
|
|
|
- function load()
|
|
|
- {
|
|
|
- $authId = Staple_Auth::get()->getAuthId();
|
|
|
- //Get User ID.
|
|
|
-
|
|
|
- if(isset($authId))
|
|
|
- {
|
|
|
- $sql = "SELECT id FROM accounts WHERE username = '".$this->db->real_escape_string($authId)."'";
|
|
|
-
|
|
|
- if($this->db->query($sql)->fetch_row() > 0)
|
|
|
- {
|
|
|
- $query = $this->db->query($sql);
|
|
|
- $result = $query->fetch_assoc();
|
|
|
-
|
|
|
- $this->setUserId($result['id']);
|
|
|
- }
|
|
|
-
|
|
|
- if(isset($this->userId))
|
|
|
- {
|
|
|
- $sql = "SELECT * FROM timeEntries WHERE userId = '" . $this->db->real_escape_string($this->userId) . "' ORDER BY inTime ASC";
|
|
|
-
|
|
|
- if ($this->db->query($sql)->fetch_row() > 0)
|
|
|
- {
|
|
|
- $query = $this->db->query($sql);
|
|
|
- $data = array();
|
|
|
- while ($row = $query->fetch_assoc())
|
|
|
- {
|
|
|
- $data[] = $row;
|
|
|
- }
|
|
|
-
|
|
|
- foreach($data as $entry)
|
|
|
- {
|
|
|
- $code = new codeModel();
|
|
|
- $code->load($entry['codeId']);
|
|
|
- $codeName = $code->getName();
|
|
|
-
|
|
|
- $data2['id'] = $entry['id'];
|
|
|
-
|
|
|
- //Set Date Object
|
|
|
- $date = new DateTime();
|
|
|
- $date->setTimestamp($entry['inTime']);
|
|
|
-
|
|
|
- //Date
|
|
|
- $data2['date']['ymd'] = $date->format("Y-m-d");
|
|
|
-
|
|
|
- //Formatted Date
|
|
|
- $data2['date']['formatted'] = $date->format("F jS, Y");
|
|
|
-
|
|
|
- //Day
|
|
|
- $data2['date']['dayOfWeek'] = $date->format("l");
|
|
|
-
|
|
|
- //Day Abbreviated
|
|
|
- $data2['date']['dayShort'] = $date->format("D.");
|
|
|
-
|
|
|
- //MonthYear
|
|
|
- $data2['date']['my'] = $date->format("m/y");
|
|
|
-
|
|
|
- //MonthDay
|
|
|
- $data2['date']['md'] = $date->format("m/d");
|
|
|
-
|
|
|
- //DateMonthYear
|
|
|
- $data2['date']['mdy'] = $date->format("m/d/y");
|
|
|
-
|
|
|
- //In Time
|
|
|
- $data2['rawInTime'] = $date->format("g:i A");
|
|
|
- $data2['roundedInTime'] = $this->nearestQuarterHour($date->format("g:i A"));
|
|
|
-
|
|
|
- //Out Time
|
|
|
- $date->setTimestamp($entry['outTime']);
|
|
|
- $data2['rawOutTime'] = $date->format("g:i A");
|
|
|
- $data2['roundedOutTime'] = $this->nearestQuarterHour($date->format("g:i A"));
|
|
|
-
|
|
|
- //Less Time
|
|
|
- $data2['lessTime'] = $entry['lessTime'];
|
|
|
+ return $this->userId;
|
|
|
+ }
|
|
|
|
|
|
- switch($entry['lessTime'])
|
|
|
- {
|
|
|
- case 60:
|
|
|
- $lessTime = 1;
|
|
|
- break;
|
|
|
- case 30:
|
|
|
- $lessTime = 0.5;
|
|
|
- break;
|
|
|
- case 15:
|
|
|
- $lessTime = 0.25;
|
|
|
- break;
|
|
|
- default:
|
|
|
- $lessTime = 0;
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * @param mixed $userId
|
|
|
+ */
|
|
|
+ public function setUserId($userId)
|
|
|
+ {
|
|
|
+ $this->userId = $userId;
|
|
|
+ }
|
|
|
|
|
|
- //Total Worked Time
|
|
|
- $dateTime1 = new DateTime($data2['roundedInTime']);
|
|
|
- $dateTime2 = new DateTime($data2['roundedOutTime']);
|
|
|
- $interval = $dateTime1->diff($dateTime2);
|
|
|
+ /**
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ public function getStartDate()
|
|
|
+ {
|
|
|
+ return $this->startDate;
|
|
|
+ }
|
|
|
|
|
|
- $data2['timeWorked'] = $interval->h.":".$interval->i;
|
|
|
+ /**
|
|
|
+ * @param mixed $startDate
|
|
|
+ */
|
|
|
+ public function setStartDate($startDate)
|
|
|
+ {
|
|
|
+ $this->startDate = $startDate;
|
|
|
+ }
|
|
|
|
|
|
- $timeWorked = $this->timeToDecimal($interval->h.":".$interval->i)-$lessTime;
|
|
|
+ /**
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ public function getMonth()
|
|
|
+ {
|
|
|
+ return $this->month;
|
|
|
+ }
|
|
|
|
|
|
- if($timeWorked > 0)
|
|
|
- {
|
|
|
- $data2['timeWorkedDec'] = $timeWorked;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- $data2['timeWorkedDec'] = 0;
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * @param mixed $month
|
|
|
+ */
|
|
|
+ public function setMonth($month)
|
|
|
+ {
|
|
|
+ $this->month = $month;
|
|
|
+ }
|
|
|
|
|
|
- $data2['code'] = $codeName;
|
|
|
+ /**
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ public function getNextMonth()
|
|
|
+ {
|
|
|
+ return $this->nextMonth;
|
|
|
+ }
|
|
|
|
|
|
- $data3[] = $data2;
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * @param mixed $nextMonth
|
|
|
+ */
|
|
|
+ public function setNextMonth($nextMonth)
|
|
|
+ {
|
|
|
+ $this->nextMonth = $nextMonth;
|
|
|
+ }
|
|
|
|
|
|
- return $data3;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- return array();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ public function getPreviousMonth()
|
|
|
+ {
|
|
|
+ return $this->previousMonth;
|
|
|
}
|
|
|
|
|
|
- private function nearestQuarterHour($time)
|
|
|
+ /**
|
|
|
+ * @param mixed $previousMonth
|
|
|
+ */
|
|
|
+ public function setPreviousMonth($previousMonth)
|
|
|
{
|
|
|
- $time = strtotime($time);
|
|
|
- $round = 15*60;
|
|
|
- $rounded = round($time/$round)*$round;
|
|
|
+ $this->previousMonth = $previousMonth;
|
|
|
+ }
|
|
|
|
|
|
- return date("g:i A", $rounded);
|
|
|
+ /**
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ public function getNextYear()
|
|
|
+ {
|
|
|
+ return $this->nextYear;
|
|
|
}
|
|
|
|
|
|
- private function timeToDecimal($time)
|
|
|
+ /**
|
|
|
+ * @param mixed $nextYear
|
|
|
+ */
|
|
|
+ public function setNextYear($nextYear)
|
|
|
{
|
|
|
- $timeArr = explode(':', $time);
|
|
|
- $hours = $timeArr[0]*1;
|
|
|
- $minutes = $timeArr[1]/60;
|
|
|
- $dec = $hours + $minutes;
|
|
|
+ $this->nextYear = $nextYear;
|
|
|
+ }
|
|
|
|
|
|
- if($dec > 0)
|
|
|
- {
|
|
|
- return round($dec,2);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- return 0;
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ public function getPreviousYear()
|
|
|
+ {
|
|
|
+ return $this->previousYear;
|
|
|
}
|
|
|
|
|
|
- function exists($id)
|
|
|
- {
|
|
|
- $sql = "SELECT id FROM timeEntries WHERE id = '".$this->db->real_escape_string($id)."'";
|
|
|
+ /**
|
|
|
+ * @param mixed $previousYear
|
|
|
+ */
|
|
|
+ public function setPreviousYear($previousYear)
|
|
|
+ {
|
|
|
+ $this->previousYear = $previousYear;
|
|
|
+ }
|
|
|
|
|
|
- if($this->db->query($sql)->fetch_row() > 0)
|
|
|
- {
|
|
|
- return true;
|
|
|
- }
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ public function getYear()
|
|
|
+ {
|
|
|
+ return $this->year;
|
|
|
+ }
|
|
|
|
|
|
- function entry($id)
|
|
|
- {
|
|
|
- $sql = "SELECT * FROM timeEntries WHERE id = '".$this->db->real_escape_string($id)."'";
|
|
|
+ /**
|
|
|
+ * @param mixed $year
|
|
|
+ */
|
|
|
+ public function setYear($year)
|
|
|
+ {
|
|
|
+ $this->year = $year;
|
|
|
+ }
|
|
|
|
|
|
- if($this->db->query($sql)->fetch_row() > 0)
|
|
|
- {
|
|
|
- $query = $this->db->query($sql);
|
|
|
- $result = $query->fetch_assoc();
|
|
|
+ /**
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ public function getEndDate()
|
|
|
+ {
|
|
|
+ return $this->endDate;
|
|
|
+ }
|
|
|
|
|
|
- $data['date'] = date("m/d/Y",$result['inTime']);
|
|
|
- $data['inTime'] = date("h:i A",$result['inTime']);
|
|
|
- $data['outTime'] = date("h:i A",$result['outTime']);
|
|
|
- $data['lessTime'] = $result['lessTime'];
|
|
|
- $data['code'] = $result['codeId'];
|
|
|
+ /**
|
|
|
+ * @param mixed $endDate
|
|
|
+ */
|
|
|
+ public function setEndDate($endDate)
|
|
|
+ {
|
|
|
+ $this->endDate = $endDate;
|
|
|
+ }
|
|
|
|
|
|
- return $data;
|
|
|
+ /**
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ public function getEntries()
|
|
|
+ {
|
|
|
+ return $this->entries;
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- return array();
|
|
|
- }
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * @param mixed $entries
|
|
|
+ */
|
|
|
+ public function setEntries($entries)
|
|
|
+ {
|
|
|
+ $this->entries = $entries;
|
|
|
+ }
|
|
|
|
|
|
- function save($id = null)
|
|
|
+ function __construct($month = null,$year = null)
|
|
|
{
|
|
|
- $inTime = strtotime($this->getDate()." ".$this->getInTime());
|
|
|
- $outTime = strtotime($this->getDate()." ".$this->getOutTime());
|
|
|
+ $this->db = Staple_DB::get();
|
|
|
|
|
|
- if($id == null)
|
|
|
- {
|
|
|
- echo "Inserting";
|
|
|
- //Insert new item
|
|
|
- $sql = "INSERT INTO timeEntries (userId, inTime, outTime, lessTime, codeId)
|
|
|
- VALUES (
|
|
|
- '".$this->db->real_escape_string($this->getUserId())."',
|
|
|
- '".$this->db->real_escape_string($inTime)."',
|
|
|
- '".$this->db->real_escape_string($outTime)."',
|
|
|
- '".$this->db->real_escape_string($this->getLessTime())."',
|
|
|
- '".$this->db->real_escape_string($this->getCodeId())."'
|
|
|
- )";
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
+ //Get user ID from Auth
|
|
|
+ $user = new userModel();
|
|
|
+ $this->userId = $user->getId();
|
|
|
|
|
|
- echo "Updating";
|
|
|
- //Update item
|
|
|
- $sql = "UPDATE timeEntries SET
|
|
|
- userId='".$this->db->real_escape_string($this->getUserId())."',
|
|
|
- inTime='".$this->db->real_escape_string($inTime)."',
|
|
|
- outTime='".$this->db->real_escape_string($outTime)."',
|
|
|
- lessTime='".$this->db->real_escape_string($this->getLessTime())."',
|
|
|
- codeId='".$this->db->real_escape_string($this->getCodeId())."'
|
|
|
- WHERE id='".$this->db->real_escape_string($id)."'
|
|
|
- ";
|
|
|
+ if ($month == NULL) {
|
|
|
+ $month = new DateTime();
|
|
|
+ $month = $month->format('n');
|
|
|
}
|
|
|
-
|
|
|
- $query = $this->db->query($sql);
|
|
|
-
|
|
|
- if($query === true)
|
|
|
- {
|
|
|
- return true;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- return false;
|
|
|
+
|
|
|
+ if ($year == NULL) {
|
|
|
+ $year = new DateTime();
|
|
|
+ $year = $year->format('Y');
|
|
|
}
|
|
|
-
|
|
|
- }
|
|
|
|
|
|
+ $dateObj = new DateTime();
|
|
|
+ $dateObj->setDate($year, $month, 1);
|
|
|
+ $end = $dateObj->modify('+24 day');
|
|
|
+ $endTime = strtotime($end->format('Y-m-d'));
|
|
|
+ $endDate = $end->format('Y-m-d');
|
|
|
+ $this->setEndDate($endDate);
|
|
|
+ $this->setMonth($end->format('F'));
|
|
|
+ $this->setNextMonth($end->modify('+1 month')->format('m'));
|
|
|
+ $this->setPreviousMonth($end->modify('-1 month')->format('m'));
|
|
|
+
|
|
|
+ $this->setYear($end->format('Y'));
|
|
|
+ $this->setNextYear($end->modify('+1 year')->format('Y'));
|
|
|
+ $this->setPreviousYear($end->modify('-1 year')->format('Y'));
|
|
|
+
|
|
|
+ $start = $dateObj->modify('-1 month +1 day');
|
|
|
+ $startTime = strtotime($start->format('Y-m-d'));
|
|
|
+ $startDate = $start->format('Y-m-d');
|
|
|
+ $this->setStartDate($startDate);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
?>
|