/** * Updates an existing Discipline model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); if ($model->load(Yii::$app->request->post()) && $model->save()) { DisciplineGroups::deleteAll('id_discipline = ' . $id); foreach ($model->mgroups as $group) { $dg = new DisciplineGroups(); $dg->id_discipline = $model->discipline_distribution_id; $dg->id_group = $group; $dg->insert(); } return $this->redirect(['view', 'id' => $model->discipline_distribution_id]); } else { $opt = DisciplineGroups::findAll(['id_discipline' => $_GET['id']]); foreach ($opt as $key) { $optArr[] = $key['id_group']; } $model->mgroups = $optArr; return $this->render('update', ['model' => $model]); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = DisciplineGroups::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'id_discipline' => $this->id_discipline, 'id_group' => $this->id_group]); return $dataProvider; }
/** * Finds the DisciplineGroups model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return DisciplineGroups the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = DisciplineGroups::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
use app\module\handbook\models\DisciplineList; use app\module\handbook\models\DisciplineGroups; use app\module\handbook\models\Groups; /* @var $this yii\web\View */ /* @var $model app\module\handbook\models\Discipline */ $d_name = DisciplineList::findOne([$model->id_discipline]); $this->title = $d_name['discipline_name']; $this->params['breadcrumbs'][] = ['label' => 'Дисципліни', 'url' => ['index']]; $this->params['breadcrumbs'][] = $this->title; function auditory($val) { $classes = ClassRooms::findOne(['classrooms_id' => $val]); $housing = Housing::findOne(['housing_id' => $classes['id_housing']]); return $classes['classrooms_number'] . ' - ' . $housing['name']; } $optionsId = DisciplineGroups::findAll(['id_discipline' => $model->discipline_distribution_id]); for ($i = 0; $i < count($optionsId); $i++) { $optionName[] = Groups::findAll(['group_id' => $optionsId[$i]['id_group']]); $optionsArray[] = $optionName[$i][0]['main_group_name'] . " "; } $optionsString = implode(' | ', $optionsArray); ?> <div class="discipline-view"> <h1><?php echo Html::encode($this->title); ?> </h1> <p> <?php