/** * @param string $slug * @return mixed */ public function actionSlugrubric($slug) { $rubric = ContentRubrics::find()->where(['=', 'slug', $slug])->andWhere(['=', 'section_id', 7])->one(); if (!isset($rubric->id)) { return $this->redirect('/methods'); } $query = Content::find()->where(['=', 'section_id', 7])->andWhere(['=', '`contentmanager_content`.`lang_id`', Lang::getCurrent()->id])->andWhere(['=', 'published', true])->andWhere(['=', 'rubric_id', $rubric->id])->orderBy('date DESC'); $countQuery = clone $query; $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => 3]); $models = $query->offset($pages->offset)->limit($pages->limit)->all(); return $this->render('rubric', ['models' => $models, 'pages' => $pages, 'rubric' => $rubric, 'rubrics' => ContentRubrics::findBySection(7)]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = ContentRubrics::find()->with('section'); if (isset(Yii::$app->controller->module->sectionId)) { $params['ContentRubricsSearch']['section_id'] = Yii::$app->controller->module->sectionId; } $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'section_id' => $this->section_id]); $query->andFilterWhere(['like', 'name', $this->name]); return $dataProvider; }
/** * @param $section_id * @return array|null */ public static function findBySection($section_id) { return ContentRubrics::find()->where(['=', 'section_id', $section_id])->all(); }
<?php echo $form->field($model, 'slug', ['template' => '<div class="col-lg-5">{input}</div>', 'options' => ['class' => 'inline']])->textInput(['maxlength' => true]); ?> </div> <div class="form-group row"> <div class="col-lg-2 small"><?php echo Yii::t('main', 'Rubric'); ?> </div> <?php echo $form->field($model, 'section_id', ['template' => '<div class="col-lg-4">{input}</div>', 'options' => ['class' => 'inline']])->dropDownList(ContentSections::selector()); ?> <?php echo $form->field($model, 'rubric_id', ['template' => '<div class="col-lg-4">{input}</div>', 'options' => ['class' => 'inline']])->dropDownList(ContentRubrics::selector($model->section_id)); ?> <?php echo $form->field($model, 'content_type', ['template' => '<div class="col-lg-2">{input}</div>', 'options' => ['class' => 'inline']])->dropDownList($model->contentTypes); ?> </div> <?php if ($model->content_type == 'javascript') { echo $form->field($model, 'text')->widget(CodemirrorWidget::class, ['preset' => 'javascript', 'assets' => [CodemirrorAsset::MODE_CLIKE, CodemirrorAsset::KEYMAP_EMACS, CodemirrorAsset::ADDON_EDIT_MATCHBRACKETS, CodemirrorAsset::ADDON_COMMENT, CodemirrorAsset::ADDON_DIALOG, CodemirrorAsset::ADDON_SEARCHCURSOR, CodemirrorAsset::ADDON_SEARCH], 'options' => ['rows' => 20], 'settings' => ['mode' => 'javascript']]); } else { echo $form->field($model, 'text')->widget(TinyMce::class, ['clientOptions' => ['language' => 'ru', 'menubar' => false, 'height' => 500, 'image_dimensions' => false, 'apply_source_formatting' => false, 'verify_html' => false, 'plugins' => ['advlist autolink lists link image charmap print preview anchor searchreplace visualblocks code contextmenu table paste insertdatetime'], 'toolbar' => 'undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | code preview ']]); } ?>
<!-- Blog Search Well --> <div class="well"> <h4>Content Search</h4> <div class="input-group"> <input type="text" class="form-control"> <span class="input-group-btn"> <button class="btn btn-default" type="button"><i class="fa fa-search"></i></button> </span> </div> <!-- /.input-group --> </div> <!-- Blog Categories Well --> <br> <?php echo partialWidget::widget(['items' => ContentRubrics::findBySection(8), 'itemView' => '@frontend/views/partials/rubricsBlocks/items.php', 'wrapView' => '@frontend/views/partials/rubricsBlocks/blockWrapper.php', 'itemParams' => ['controller' => 'events/rubric']]); ?> <!-- Side Widget Well --> <div class="well"> <h4>Tags Cloud</h4> <p></p> </div> </div> </div> <!-- /.row --> <hr> <!-- Pagination --> <div class="row text-center"> <div class="col-lg-12"> <?php
/** * Finds the ContentRubrics model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return ContentRubrics the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = ContentRubrics::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }