/**
  * Возвращает массив подкатегорий (forum_name) для переданной категории
  *
  * @param null|integer $id
  * @return array
  */
 public static function subsForCat($id = null)
 {
     $query = Subcategory::find();
     if ($id != null && ($cat = Categories::findOne($id)) !== null) {
         $subcatsArr = array_keys(self::find()->where(['category_attr' => $id])->groupBy('forum_name_id_attr')->indexBy('forum_name_id_attr')->limit(10000)->asArray()->all());
         $query->andWhere(['id' => $subcatsArr]);
     }
     return ArrayHelper::map($query->asArray()->all(), 'id', 'forum_name');
 }
 /**
  * Updates an existing Rubric model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $subcategories = ArrayHelper::map(Subcategory::find()->with('englishTranslate')->all(), 'id', 'englishTranslate.title');
     $model = $this->findModel($id);
     $enForm = new RubricTranslateForm();
     $enForm->attributes = $model->englishTranslate->attributes;
     $deForm = new RubricTranslateForm();
     $deForm->attributes = $model->germanTranslate->attributes;
     $post = Yii::$app->request->post();
     $translatePost = Yii::$app->request->post('RubricTranslateForm');
     $model->scenario = 'update';
     $oldImage = $model->image;
     if ($model->load($post) && $enForm->load($translatePost, 'en') && $deForm->load($translatePost, 'de')) {
         if ($model->validate() && $enForm->validate() && $deForm->validate()) {
             $transaction = $model::getDb()->beginTransaction();
             try {
                 $model->image = UploadedFile::getInstance($model, 'image');
                 if ($model->image) {
                     if ($model->save()) {
                         $model->upload();
                     }
                 } else {
                     $model->image = $oldImage;
                     $model->save();
                 }
                 $model->englishTranslate->update($enForm->attributes);
                 $model->germanTranslate->update($deForm->attributes);
                 Yii::$app->session->setFlash('success', 'Rubric have been updated.');
             } catch (\Exception $e) {
                 $transaction->rollBack();
                 Yii::$app->session->setFlash('error', 'Failed to update rubric.');
             }
         }
     } else {
         return $this->render('update', ['model' => $model, 'enForm' => $enForm, 'deForm' => $deForm, 'subcategories' => $subcategories]);
     }
     return $this->redirect('index');
 }
Beispiel #3
0
                                    <input required type="text" name="text" class="form-control" style="width: 100%; margin-bottom: 20px;" placeholder="Поиск работы">
                                </div>
                            </div>
                            <div class="col-md-6">
                                <?php 
echo '<div class="form-group field-sub_cat has-success">
                                            <select id="region" class="form-control" name="region">';
echo '<option value>Выберете регион</option>';
foreach ($option->cities as $key => $value) {
    echo '<option value="' . $value . '">' . $key . '</option>';
}
echo '    </select>
                                          </div>';
?>
                                <?php 
echo $form->field($subcat, 'title')->dropDownList(ArrayHelper::map(\common\models\Subcategory::find()->where(['category_id' => 6])->all(), 'id', 'title'), ['prompt' => 'Выберете категорию', 'id' => 'sub_cat'])->label(false);
?>
                                <?php 
echo $form->field($subcat, 'category_id')->hiddenInput(['value' => '6'])->label(false);
?>

                            </div>
                            <div class="col-md-6">
                                <label class="control-label left-50" for="price-from">Зарплата от:</label>
                                <label class="control-label left-50" for="price-to">Зарплата до:</label>
                                <input type="number" name="price-from_dol" class="form-control left-50" style="margin-bottom: 20px">
                                <input type="number" name="price-to_dol" class="form-control left-50" style="margin-bottom: 20px">
                            </div>
                            <div class="search col-md-6 col-md-offset-3">
                                <?php 
echo Html::submitButton('Подать заявку', ['class' => 'btn btn-primary btn-info btn-block', 'name' => 'jobs']);
 /**
  * Lists all Subcategory models.
  * @return mixed
  */
 public function actionIndex()
 {
     $dataProvider = new ActiveDataProvider(['query' => Subcategory::find()->with(['englishTranslate', 'germanTranslate'])]);
     return $this->render('index', ['dataProvider' => $dataProvider]);
 }