コード例 #1
0
ファイル: actions.class.php プロジェクト: taryono/school
 public function executeUpdate()
 {
     $i18n = new sfI18N();
     $i18n->initialize($this->getContext());
     $i18n->setCulture($this->getUser()->getCulture());
     $action_i18n = $i18n->globalMessageFormat->format('save as new');
     $action_type = $this->getRequestParameter('action_type');
     if ($action_type == $action_i18n || !$this->getRequestParameter('id')) {
         $student_absence = new StudentAbsence();
         $class_agenda = ClassAgendaPeer::retrieveByPk($this->getRequestParameter('agenda_id'));
         $this->forward404Unless($class_agenda);
         $student_absence->setStudentId($this->getRequestParameter('student_id'));
         $student_absence->setAcademicCalendarId($class_agenda->getCourseSchedule()->getAcademicCalendarId());
         $student_absence->setClassGroupId($class_agenda->getClassGroupId());
         $student_absence->setStatus(5);
         $student_absence->setStart($class_agenda->getDate());
         $student_absence->setEnd($class_agenda->getDate());
         $student_absence->setDetail($this->getRequestParameter('detail'));
         $student_absence->setHoliday($this->getRequestParameter('holiday'));
         $start = strtotime($this->getRequestParameter('start'));
         $end = strtotime($this->getRequestParameter('end'));
         $count = 0;
         for ($i = $start; $i <= $end; $i + 86400) {
             $dn = strftime('%u', $i);
             $i += 86400;
             if ($dn < 6) {
                 ++$count;
             }
         }
         $count -= $student_absence->getHoliday();
         $student_absence->setTotalDays($count);
         $student_absence->save();
         $class_absence = new ClassAbsence();
         $class_absence->setClassAgendaId($class_agenda->getId());
         $class_absence->setStudentAbsence($student_absence);
         $class_absence->save();
     } else {
         $student_absence = StudentAbsencePeer::retrieveByPk($this->getRequestParameter('id'));
         $this->forward404Unless($student_absence);
         $class_agenda = ClassAgendaPeer::retrieveByPk($this->getRequestParameter('agenda_id'));
         $this->forward404Unless($class_agenda);
         $student_absence->setId($this->getRequestParameter('id'));
         $student_absence->setStudentId($this->getRequestParameter('student_id'));
         $student_absence->setAcademicCalendarId($class_agenda->getCourseSchedule()->getAcademicCalendarId());
         $student_absence->setClassGroupId($class_agenda->getClassGroupId());
         $student_absence->setStatus(5);
         $student_absence->setStart($class_agenda->getDate());
         $student_absence->setEnd($class_agenda->getDate());
         $student_absence->setDetail($this->getRequestParameter('detail'));
         $student_absence->setHoliday($this->getRequestParameter('holiday'));
         $start = strtotime($this->getRequestParameter('start'));
         $end = strtotime($this->getRequestParameter('end'));
         $count = 0;
         for ($i = $start; $i <= $end; $i + 86400) {
             $dn = strftime('%u', $i);
             $i += 86400;
             if ($dn < 6) {
                 ++$count;
             }
         }
         $count -= $student_absence->getHoliday();
         $student_absence->setTotalDays($count);
         $student_absence->save();
     }
     return $this->redirect('leave/listByEmployee?agenda_id=' . $this->getRequestParameter('agenda_id'));
 }