public function actionCreate() { $model = new Schedule(); $model2 = new ProfessorCourse(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Schedule'])) { $sql = ' select sem.end_Date from professor_course pc join courses co on pc.course_Id = co.course_Id join semesters sem on sem.semester_Id = co.semester_Id where professor_Course_Id = "' . $_POST['Schedule']['professor_Course_Id'] . '" ; '; $row1Class = Yii::app()->db->createCommand($sql)->queryRow(); $sql2 = ' select day from class_type where class_Type_Id = "' . $_POST['Schedule']['class_Type_Id'] . '" ; '; $row2Class = Yii::app()->db->createCommand($sql2)->queryRow(); $endDate = $row1Class['end_Date']; $dayNameEndDate = $row2Class['day']; $date = date('Y-m-d'); while ($date != $endDate) { $dayName = date('l', strtotime($date)); if ($dayName == $dayNameEndDate) { $model = new Schedule(); $model->date = $date; $model->attributes = $_POST['Schedule']; // other fileds if they are not getting assigned if (!$model->save()) { echo '<pre>'; print_r($model->getErrors()); echo '</pre>'; exit; } } $date = strtotime("+1 day", strtotime($date)); $date = date("Y-m-d", $date); } $this->redirect(array('index')); } $this->render('_Form2', array('model' => $model, 'model2' => $model2)); }
protected function afterSave() { parent::afterSave(); if ($this->isNewRecord) { $this->position->group_id = $this->id; $this->position->code = $this->code; $this->position->update(); $time = explode(',', $this->time); $tCount = count($time); $j = 0; $k = 0; for ($i = 0; $i < $this->number; $i++) { if ($j == $tCount) { $j = 0; $k++; } $schedule = new Schedule(); $schedule->group_id = $this->id; $schedule->number = $i + 1; $schedule->teacher_id = $this->teacher_id; $schedule->start_time = str_replace(" ", "T", date('Y-m-d H:i:s', strtotime("+" . $k . "week", strtotime($time[$j])))); if ($this->hui == "on") { $pizda = 30; } else { $pizda = 0; } $schedule->end_time = str_replace(" ", "T", date('Y-m-d H:i:s', strtotime("+" . $k . "week 1 hours " . $pizda . " minutes", strtotime($time[$j])))); //die(var_dump($this->branch_id)); $schedule->room_id = $this->findRoom($schedule->start_time, $this->branch_id, count($this->positions)); if (!$schedule->save()) { die(var_dump($schedule->getErrors())); } $j++; } } }