public function actionGetTeacher($time, $form, $subject, $branch) { if (Yii::app()->request->isAjaxRequest) { $times = explode(',', $time); $tCount = count($times); $crTimes = $times; $schedule = []; $j = 0; $k = 0; $form = Form::model()->findByPk($form); for ($i = 0; $i < $tCount; $i++) { $times[$i] = substr($times[$i], strpos($times[$i], 'T') + 1); } for ($i = 0; $i < $form->number; $i++) { if ($j == $tCount) { $j = 0; $k++; } $schedule[$i] = str_replace(" ", "T", date('Y-m-d H:i:s', strtotime("+" . $k . "week", strtotime($crTimes[$j])))); $j++; } $condT = ''; $condition = ''; $first = 0; foreach ($times as $cr) { $condT .= " AND `t`.`start_time`<='{$cr}' AND SUBTIME(`t`.`end_time`,'01:00:00')>='{$cr}'"; } foreach ($schedule as $sch) { if ($first == 0) { $condition .= "`schedule`.`start_time` ='{$sch}'"; $first++; } else { $condition .= " OR `schedule`.`start_time` ='{$sch}'"; } } $models = Teacher::model()->with('user', 'schedule', 'subject')->findAllBySql("SELECT `t`.* FROM spbp_user_teacher `t` " . "WHERE `t`.`id` <> ALL(" . "SELECT `t`.`id` FROM spbp_user_teacher `t` JOIN spbp_listner_position `position` " . "ON `position`.`teacher_id` = `t`.`id` JOIN spbp_listner_schedule `schedule` " . "ON `schedule`.`position_id` = `position`.`id` WHERE {$condition}) {$condT}"); $arr = []; foreach ($models as $teacher) { $checks = TeacherToSubject::model()->find("teacher_id={$teacher->id} AND subject_id={$subject}"); if ($checks['teacher_id'] == $teacher->id) { array_push($arr, $teacher); } } $arr1 = []; foreach ($arr as $teacher) { $checks = Teacher::model()->with('user', 'schedule', 'subject')->findAll('user_id=' . $teacher->user_id); if (count($checks) >= 1) { foreach ($checks as $check) { if ($check->branch_id == $branch) { array_push($arr1, $check); } } } } echo CJSON::encode($this->convertModelToArray($arr1)); Yii::app()->end(); } else { throw new CHttpException(404, Yii::t('ListnerModule.listner', 'Запрошенная страница не найдена.')); } }
public function actionAddTeacher($i, $s) { if (Yii::app()->request->isAjaxRequest) { $model = TeacherToSubject::model()->find("teacher_id={$i} AND subject_id={$s}"); if (!$model) { $model = new \TeacherToSubject(); $model->teacher_id = $i; $model->subject_id = $s; $model->save(); Yii::app()->end(); } else { $model->delete(); } } else { throw new CHttpException(404, 'Невозможно обработать запрос'); } }