/**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  */
 public function loadModel()
 {
     if ($this->_model === null) {
         if (isset($_GET['id'])) {
             $this->_model = SchoolCalendar::model()->findbyPk($_GET['id']);
         }
         if ($this->_model === null) {
             throw new CHttpException(404, 'The requested page does not exist.');
         }
     }
     return $this->_model;
 }
 public function actionPopulate()
 {
     $model = $this->loadModel();
     foreach (KDateArray::createWeekdayRangeArray($model->start_date, $model->end_date) as $d) {
         $sc = new SchoolCalendar();
         $sc->school_day = $d;
         $sc->school_year_id = $model->id;
         // TODO: trap errors here somehow
         $sc->save();
     }
     $this->redirect(array('view', 'id' => $model->id));
 }
Example #3
0
 public function getDays_off()
 {
     return SchoolCalendar::model()->findAllBySql("select school_calendar.school_day\nfrom school_calendar\nleft join class_meeting \n     on school_calendar.school_day = class_meeting.meeting_date\n        and class_meeting.class_id = :cid\nwhere school_calendar.school_day > :start\n      and school_calendar.school_day < \n      (select max(class_meeting.meeting_date)\n             from class_meeting\n             where class_meeting.makeup < 1\n                   and class_meeting.class_id = :cid)\n      and dayofweek(school_calendar.school_day) = :wkday\n      and class_meeting.meeting_date is null", array('start' => $this->session->start_date, 'wkday' => $this->day_of_week, 'cid' => $this->id));
 }