public function saveThis($sch, $sch_id, $group_id) { foreach (Tch::model()->findAllByAttributes(array('group_id' => $group_id)) as $model) { $model->delete(); } foreach ($sch as $d => $day) { foreach ($day as $i => $nums) { foreach ($nums['rows'] as $row) { if (Yii::app()->sch->isRecordValid($nums, $row)) { foreach (Yii::app()->sch->parseWeek($row['week']) as $w) { $tch = new Tch(); $tch->day = $d; $tch->week = $w; $tch->sch_id = $sch_id; $tch->tch_id = $row['teacher']; $tch->number = $nums['number']; $tch->lesson_id = $nums['lesson']; $tch->group_id = $group_id; $tch->aud_id = $row['aud']; $tch->save(); } } } } } }