public function actionCategory($slug) { $sql = 'SELECT id, title, keywords, description FROM category WHERE slug=:slug'; $category = \app\modules\category\models\Category::findBySql($sql, [':slug' => $slug])->one(); $dataProvider = new ActiveDataProvider(['query' => Post::find()->where(['cat_id' => $category->id, 'status' => 1]), 'pagination' => ['pageSize' => 10]]); return $this->render('category', ['dataProvider' => $dataProvider, 'category' => $category]); }
public function getJobIndustryCoverageTitle() { $items = array(); if ($this->agent_job_industry and is_array($this->agent_job_industry)) { $items = ArrayHelper::map(\app\modules\category\models\Category::find()->where(['module' => 'job'])->andWhere(['IN', '_id', $this->agent_job_industry])->asArray()->all(), '_id', 'name'); } return $items ? implode(', ', $items) : Yii::t('common', 'Not set'); }
public function run() { // Get list category of module question $model = \app\modules\category\models\Category::getCategory('question', '- '); // Get question quan tam nhieu nhat $concernedQuestion = Question::find()->where(['status' => 1])->andWhere(['stats.comment_count' => ['$gt' => 0]])->orderBy(['stats.comment_count' => -1])->limit(5)->all(); return $this->render('sidebar', ['model' => $model, 'concernedQuestion' => $concernedQuestion]); }
/** * Finds the model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Category::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Renders the widget. */ public function run() { $categories = Html::getAttributeValue($this->model, $this->attribute); $model = new Category(); $tree = Category::findOne(['module' => $this->model->moduleName, $model->leftAttribute => 1]); if ($tree) { $tree = $tree->buildTreeHtml([], [], ['actions' => '<div class="btn-group pull-right"> <input type="checkbox" {check} class="choseCategories" name="choseCategories[]" value="{_id}"> </div>'], $categories); } echo $tree; }
public function actionIndex($id, $module = null) { if ($module != 'faq') { $query = Question::find(); } else { $query = \app\modules\faq\models\Faq::find(); } $query->orderBy('_id ASC'); $query->where(['category' => $id]); Yii::$app->view->title = Category::findOne($id)->name; $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 20]]); return $this->render('index', ['model' => $dataProvider]); }
public function actionIndex($module, $id) { $modelClassName = ucfirst($module); $modelClass = "\\app\\modules\\{$module}\\models\\{$modelClassName}"; if (!class_exists($modelClass)) { throw new NotFoundHttpException('The requested page does not exist.'); } if (($category = Category::findOne($id)) == NULL) { throw new NotFoundHttpException('The requested page does not exist.'); } $obj = Yii::createObject($modelClass); $query = $obj::find()->where(['status' => '1', 'category' => $category->primaryKey]); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 20], 'sort' => ['defaultOrder' => ['sort' => SORT_DESC, 'create_time' => SORT_DESC]]]); return $this->render('index', ['category' => $category, 'dataProvider' => $dataProvider]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Category::find(); // add conditions that should always apply here $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['position' => SORT_ASC]]]); $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; } // grid filtering conditions $query->andFilterWhere(['id' => $this->id, 'parent_id' => $this->parent_id, 'position' => $this->position]); $query->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'keywords', $this->keywords]); return $dataProvider; }
public function run() { switch ($this->type) { case '': $questions = Question::find()->where(['category' => $this->cat_id])->limit(10)->orderBy('rand()')->all(); break; case 'comment': $questions = Question::find()->where(['count_comment' => ['$gt' => 0]])->limit(10)->orderBy('rand()')->all(); break; case 'cat': $questions = Category::find()->where(['lft' => ['$gt' => 1], 'module' => 'question'])->limit(4)->orderBy('rand()')->all(); default: break; } $assign = ['questions' => $questions, 'name' => $this->name]; return $this->render($this->view, $assign); }
public function run() { Yii::$app->cache->flush(); $cacheKey = $this->module . '_Tree_' . $this->module . '_' . $this->category; $cache = Yii::$app->cache->get($cacheKey); if (!$cache) { $model = new Category(); $where = [$model->leftAttribute => 1]; if (!empty($this->module)) { $where['module'] = $this->module; } if (!empty($this->category)) { $where['_id'] = $this->category; } $models = Category::findOne($where); $models = $models->leaves()->all(); Yii::$app->cache->set($cacheKey, $models); } else { $models = $cache; } if (!empty($models)) { return $this->render($this->view, ['models' => $models, 'title' => $this->title, 'module' => $this->module, 'category' => $this->category]); } }
public static function createRootIfNotExist($module) { $root = self::find()->where(['module' => $module])->andWhere(['lft' => 1])->addOrderBy('lft')->one(); if ($root === NULL) { // Create root for module $root = new Category(); $root->name = $module; $root->module = $module; $root->makeRoot(); } return $root; }
public function actionDeletecategory() { $id = Yii::$app->request->post('id', NULL); $category = Category::findOne(['_id' => $id]); $category->deleteWithChildren(); echo json_encode(1); }
<div> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'title')->textInput(['maxlength' => 100]); ?> <?php echo $form->field($model, 'slug')->textInput(['maxlength' => 100]); ?> <?php echo $form->field($model, 'parent_id')->dropdownList(\yii\helpers\ArrayHelper::map(\app\modules\category\models\Category::find()->all(), 'id', 'title'), ['prompt' => '---']); ?> <div class="alert alert-success" role="alert"> <b>SEO</b> </div> <?php echo $form->field($model, 'keywords')->textInput(['maxlength' => 200]); ?> <?php echo $form->field($model, 'description')->textArea(['maxlength' => 200, 'rows' => 4]); ?>
public function getCategoryNames() { $items = array(); if ($this->category_ids and is_array($this->category_ids)) { $items = ArrayHelper::map(Category::find()->where(['module' => 'job'])->andWhere(['IN', '_id', $this->category_ids])->asArray()->all(), '_id', 'name'); } return implode('<br/>', $items); }
public function getParent() { return $this->hasOne(Category::className(), ['id' => 'parent_id']); }
<div class="post-index"> <p> <?php echo Html::a('Создать запись', ['create'], ['class' => 'btn btn-success']); ?> </p> <?php Pjax::begin(); ?> <?php echo himiklab\sortablegrid\SortableGridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'id' => 'post_tbl', 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['class' => CheckboxColumn::classname()], ['attribute' => 'title', 'format' => 'html', 'value' => function ($model) { return Html::a($model['title'], ['update', 'id' => $model['id']]); }], ['attribute' => 'cat_id', 'content' => function ($data) { return $data->getCategoryName(); }, 'filter' => \yii\helpers\Arrayhelper::map(\app\modules\category\models\Category::find()->all(), 'id', 'title')], ['attribute' => 'created_at', 'format' => ['date', 'dd.MM.yyyy'], 'options' => array('width' => '225px'), 'filter' => \yii\jui\DatePicker::widget(['dateFormat' => 'dd.MM.yyyy', 'model' => $searchModel, 'attribute' => 'created_at', 'options' => ['class' => 'form-control'], 'clientOptions' => ['dateFormat' => 'dd.mm.yy']])], ['attribute' => 'status', 'format' => 'html', 'value' => function ($model) { $class = $model->status === 1 ? '<i class="icon-ok"></i>' : '<i class="icon-lock">'; return $class; }, 'options' => array('width' => '100px'), 'filter' => Html::activeDropDownList($searchModel, 'status', array(1 => 'On', 0 => 'Off'), ['class' => 'form-control', 'prompt' => 'Все'])], ['attribute' => 'main', 'format' => 'html', 'value' => function ($model) { $res = $model->main === 1 ? '<i class="icon-ok"></i>' : '<i class="icon-minus">'; return $res; }, 'options' => array('width' => '100px'), 'filter' => Html::activeDropDownList($searchModel, 'main', array(1 => 'Да', 0 => 'Нет'), ['class' => 'form-control', 'prompt' => 'Все'])], 'username', ['class' => 'yii\\grid\\ActionColumn', 'header' => 'Действия', 'headerOptions' => ['width' => '100']]]]); ?> <p> <?php echo Html::a('Удалить выбранные', ['massdelete'], ['class' => 'btn btn-danger', 'data' => ['confirm' => 'Вы уверены?', 'data-method' => 'post']]); ?> </p>
protected function findModel($id) { if (is_array($id)) { $model = Category::findAll($id); } else { $model = Category::findOne($id); } if ($model !== null) { return $model; } else { throw new HttpException(404); } }