<?php ActiveForm::end(); Pjax::end(); Modal::end(); } //End Authority Only. ?> <?php $form = ActiveForm::begin(['id' => 'menus-form', 'options' => ['class' => 'form-inline pull-right'], 'fieldConfig' => ['template' => "{label}{input} ", 'labelOptions' => ['class' => 'sr-only']]]); ?> <?php echo $form->field($model, 'langs')->dropDownList(\app\models\tblLangs::makeDropDown(), ['style' => 'width: 150px;', 'onchange' => 'form.submit();']); echo " "; echo $form->field($model, 'type')->dropDownList(TblMenutype::makeDropDown($model->langs), ['onchange' => 'form.submit();']); ?> <?php ActiveForm::end(); ?> </div> </div><br/> <?php Pjax::begin(); echo GridView::widget(['dataProvider' => $model->listCategory($model->langs), 'columns' => [['class' => 'yii\\grid\\SerialColumn', 'headerOptions' => ['width' => '5%']], ['headerOptions' => ['width' => '61%'], 'header' => 'หมวดหมู่', 'value' => function ($model) { return $model['names']; }], ['headerOptions' => ['width' => '7%', 'style' => 'text-align:center;'], 'contentOptions' => ['align' => 'center'], 'class' => 'yii\\grid\\CMSColumn', 'template' => '{published}'], ['headerOptions' => ['width' => '7%', 'style' => 'text-align:center;'], 'contentOptions' => ['align' => 'center'], 'class' => 'yii\\grid\\CMSColumn', 'template' => '{up} {down}'], ['headerOptions' => ['width' => '10%', 'style' => 'text-align:center;'], 'contentOptions' => ['align' => 'center'], 'class' => 'yii\\grid\\ActionColumn', 'header' => 'แก้ไข']]]); Pjax::end();
public function listCategory($langs = 'thai') { global $arr; $arr = array(); $parents = Menus::find()->where(['parent_id' => 0, 'langs' => $langs]); if ($this->type) { $parents = $parents->andWhere(['type' => $this->type]); } else { $menu = TblMenutype::makeDropDown($langs); foreach ($menu as $key => $value) { $mk = $key; break; } $parents = $parents->andWhere(['type' => $mk]); } $parents = $parents->orderBy('ordering')->all(); foreach ($parents as $parent) { $data = array(); $data['id'] = $parent->id; $data['names'] = $parent->names; $data['published'] = $parent->published; $data['ordering'] = $parent->ordering; $data['min'] = $this->orderMin($parent->langs, $parent->type, $parent->parent_id); $data['max'] = $this->orderMax($parent->langs, $parent->type, $parent->parent_id); $arr[] = $data; Menus::listCategorySub($parent->id); } return new ArrayDataProvider(['allModels' => $arr, 'key' => 'id', 'pagination' => ['pageSize' => 20]]); }
if ($type == 'article') { echo $form->field($model, 'urls')->widget(Select2::classname(), ['data' => array_merge(["" => ""], app\models\Article::makeLink($model->langs)), 'options' => ['placeholder' => 'เลือกเนื้อหาเว็บไซต์ หรือ บทความ', 'class' => 'form-control'], 'pluginOptions' => ['allowClear' => true]]); } else { if ($type == 'links') { echo $form->field($model, 'urls')->input('text', ['placeholder' => 'เช่น http://www.nongkhai.go.th']); } } ?> <?php echo $form->field($model, 'description')->textarea(); ?> </div> <div class="col-sm-4"> <?php echo $form->field($model, 'langs')->dropDownList(\app\models\tblLangs::makeDropDown(), ['style' => 'width: 150px;']); echo $form->field($model, 'type')->widget(Select2::classname(), ['data' => \app\models\TblMenutype::makeDropDown($model->langs), 'hideSearch' => true, 'options' => ['placeholder' => 'เลือก...', 'class' => 'form-control ', 'multiple' => false, 'style' => 'width: 98%;']]); echo $form->field($model, 'parent_id')->widget(DepDrop::classname(), ['type' => DepDrop::TYPE_SELECT2, 'data' => [$model->parent_id => ''], 'options' => ['style' => 'width: 98%;'], 'select2Options' => ['hideSearch' => true], 'pluginOptions' => ['depends' => [Html::getInputId($model, 'type')], 'placeholder' => 'เลือก...', 'url' => Url::to(["getsubmenu"]), 'initialize' => true]]); ?> <?php echo $form->field($model, 'published')->widget(SwitchInput::classname(), ['pluginOptions' => ['size' => 'normal'], 'inlineLabel' => false]); ?> <?php echo $form->field($model, 'target')->widget(SwitchInput::classname(), ['pluginOptions' => ['size' => 'normal', 'onText' => 'หน้าต่างใหม่', 'offText' => 'หน้าต่างเดิม'], 'inlineLabel' => false]); ?> </div> </div> <?php echo $form->field($model, 'id', ['options' => ['class' => 'sr-only']])->hiddenInput(); ?>