/** * Labels dor dropdown * @return array */ public static function getTypeLabels() { $labels = array(); $types = ProjectsType::find()->orderBy("sort")->all(); foreach ($types as $type) { $labels[$type->id] = $type->name; } return $labels; }
/** * Save or update project types * @param array $types * @return bool */ public function setTypes($types = array()) { if (empty($types)) { return true; } $_dbItemsIds = $_formItemsIds = array(); //Get all current menu items from database $_dbItemsData = ProjectsType::find()->all(); foreach ($_dbItemsData as $_dbItem) { $_dbItemsIds[] = $_dbItem->id; $_dbItems[$_dbItem->id] = $_dbItem; } foreach ($types['types'] as $type) { //Create new item if (empty($type['id'])) { $_newItem = new ProjectsType(); $_newItem->setAttributes($type, false); $_newItem->save(); $type['id'] = $_newItem->id; $_dbItems[$type['id']] = $_newItem; } $_dbItems[$type['id']]->updateAttributes($type); $_dbItems[$type['id']]->save(); $_formItemsIds[] = $type['id']; } //Check elements for deleting $_deleteItems = array_diff($_dbItemsIds, $_formItemsIds); if (sizeof($_deleteItems) > 0) { ProjectsType::deleteAll(['id' => $_deleteItems]); ProjectsTypeLang::deleteAll(['type_id' => $_deleteItems]); } }
/* @var $this yii\web\View * @var $form yii\bootstrap\ActiveForm * @TODO Multilanguage */ ?> <div class="project-create-form"> <?php $form = ActiveForm::begin(); ?> <?php echo \common\models\Languages::showSelectButtons(); ?> <hr/> <?php echo $form->field($model, 'title')->textInput(['maxlength' => 50, 'class' => 'form-control mlang']) ?> <?php echo $form->field($model, 'description')->textarea(['maxlength' => 1500, 'class' => 'mlang', 'id' => 'ckeditor']) ?> <?php $projectTypes = \common\models\ProjectsType::getTypeLabels(); if (sizeof($projectTypes) > 0) { ?> <div class="form-group col-md-6"> <?php echo $form->field($model, 'type_id')->dropDownList($projectTypes); ?> </div> <? } echo Html::a(Yii::t('backend', 'Edit type'), 'javascript: void(0);', ['class' => 'btn edit-children']); ?> <div class="form-group col-md-6 hidden edit-children-block"> <?php echo $form->field($model, 'types')->widget(MultipleInput::className(), [ 'columns' => [