/**
  * 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]);
     }
 }
Beispiel #2
0
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