public function actionEmployeeSchedulle() { header('Content-type: application/json'); $schedulles = AttendanceSchedulles::model()->findAllByAttributes(array('employee_id' => getUser()->id)); $data = array(); foreach ($schedulles as $schedulle) { for ($i = 1; $i <= 31; $i++) { if (strlen($i) == 1) { $date = 'date_0' . $i; } else { $date = 'date_' . $i; } $day = $schedulle->year . '-' . $schedulle->month . '-' . $i; $day = strtotime($day) + 2678400; $day = date('Y-m-d', $day); if ($schedulle->{$date} != '') { $shift = ReferenceAttendanceShifts::model()->findByPk($schedulle->{$date})->name; $data[] = array('title' => $shift, 'start' => $day, 'allDay' => true); } } } // $c = new CDbCriteria(); // $c->compare('employee_id', getUser()->id); // $schedulles = AttendanceSchedulle::model()->findAll($c); // $data = array(); // foreach($schedulles as $schedulle) // { // $data[] = array('title'=>$schedulle->shift->name, 'start'=>$schedulle->schedulle_date, 'allDay'=>true); // } echo CJSON::encode($data); }
public function getAttendanceSchedulles($employee_id, $department_id) { $AttendanceSchedulles = AttendanceSchedulles::model()->findByAttributes(array('employee_id' => $employee_id, 'department_id' => $department_id, 'year' => $this->year, 'month' => $this->month)); if (count($AttendanceSchedulles) == 0) { $AttendanceSchedulles = new AttendanceSchedulles(); $AttendanceSchedulles->employee_id = $employee_id; $AttendanceSchedulles->department_id = $department_id; $AttendanceSchedulles->year = $this->year; $AttendanceSchedulles->month = $this->month; } return $AttendanceSchedulles; }
public function getShift($date) { $date = strtotime($date); $year = date('Y', $date); $month = date('m', $date); $month = (int) $month - 1; $day = date('d', $date); $day = 'date_' . $day; $shift = 4; $schedulle = AttendanceSchedulles::model()->findByAttributes(array('employee_id' => $this->id, 'year' => $year, 'month' => $month)); if (count($schedulle) != 0) { if ($schedulle->{$day} != null) { $shift = $schedulle->{$day}; } } return $shift; }