/** * 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'); }
/** * @return \yii\db\ActiveQuery */ public function getSubcategory() { return $this->hasOne(Subcategory::className(), ['id' => 'subcategory_id']); }
/** * Создание подкатегории (forum_name) * * @param string $subcat_name * @return bool|Subcategory */ private function importSubcategory($subcat_name) { $model = Subcategory::findOne(['forum_name' => $subcat_name]); if ($model === null) { $model = new Subcategory(['forum_name' => $subcat_name]); } if ($model->save()) { return $model; } else { VarDumper::dump($model->errors); } return false; }
/** * Возвращает массив с одной категорией, если передана подкатегория * * @param null|integer $id * @return array */ public static function catForSubs($id = null) { $query = Categories::find(); if ($id != null && ($subCat = Subcategory::findOne($id)) !== null) { /** @var TorrentSearch $category */ $category = self::find()->where(['forum_name_id_attr' => $id])->one(); $query->andWhere(['id' => $category->category_attr]); } return ArrayHelper::map($query->asArray()->all(), 'id', 'category_name'); }
<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']);
/** * Finds the Subcategory model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Subcategory the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Subcategory::findOne(['id' => $id])) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getForumName() { return $this->hasOne(Subcategory::className(), ['id' => 'forum_name_id']); }
* User: andrew72ru * Date: 01.01.16 * Time: 13:15 * File: index.php * * @var \yii\web\View $this * @var TorrentSearch $searchModel * @var \yii\sphinx\ActiveDataProvider $dataProvider */ $this->title = Yii::t('app', 'Rutracker Torrents Search'); use common\models\Categories; use common\models\Subcategory; use common\models\Torrents; use common\models\TorrentSearch; use yii\grid\GridView; use yii\helpers\Html; use yii\widgets\Pjax; ?> <?php Pjax::begin(['scrollTo' => 0]); echo GridView::widget(['filterModel' => $searchModel, 'dataProvider' => $dataProvider, 'columns' => ['name_attr' => ['attribute' => 'name_attr', 'value' => function ($model) { return Html::a($model['name_attr'], 'http://rutracker.org/forum/viewtopic.php?t=' . $model['topic_id_attr'], ['target' => '_blank']); }, 'format' => 'raw', 'contentOptions' => ['style' => ['white-space' => 'normal']]], ['attribute' => 'category_attr', 'value' => function ($model) { return Categories::findOne($model['category_attr'])->category_name; }, 'filter' => TorrentSearch::catForSubs($searchModel->forum_name_id_attr)], ['attribute' => 'forum_name_id_attr', 'value' => function ($model) { return Subcategory::findOne($model['forum_name_id_attr'])->forum_name; }, 'contentOptions' => ['style' => ['white-space' => 'normal']], 'filter' => TorrentSearch::subsForCat($searchModel->category_attr)], ['attribute' => 'size_attr', 'format' => 'shortSize', 'contentOptions' => ['class' => 'text-right'], 'filter' => false], ['attribute' => 'datetime_attr', 'format' => 'datetime', 'headerOptions' => ['class' => 'text-nowrap'], 'filter' => false], ['header' => null, 'value' => function ($model) { return Html::a(Html::tag('span', '', ['class' => 'glyphicon glyphicon-download-alt']), 'magnet:?xt=urn:btih:' . Torrents::findOne($model['id'])->hash . '&tr=http://bt.rutracker.cc/ann?magnet'); }, 'format' => 'raw']]]); Pjax::end();