Exemplo n.º 1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Tag::find()->joinWith('translations');
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => Yii::$app->request->cookies->getValue('_grid_page_size', 20)], 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]);
     $this->load($params);
     if (!$this->validate()) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'title', $this->title]);
     return $dataProvider;
 }
Exemplo n.º 2
0
 /**
  * Displays homepage.
  *
  * @return mixed
  */
 public function actionIndex($slug = 'index')
 {
     if (empty($slug) || $slug == 'index') {
         throw new NotFoundHttpException('Page not found.');
     } else {
         $tag = Tag::find()->where(['slug' => $slug]);
         $tagCount = clone $tag;
         if (!$tagCount->count()) {
             throw new NotFoundHttpException('Page not found.');
         }
     }
     $query = Post::find()->joinWith('tags')->where(['status' => Post::STATUS_PUBLISHED, Tag::tableName() . '.slug' => $slug])->orderBy('published_at DESC');
     $countQuery = clone $query;
     $pagination = new Pagination(['totalCount' => $countQuery->count(), 'defaultPageSize' => Yii::$app->settings->get('reading.page_size', 10)]);
     $posts = $query->offset($pagination->offset)->limit($pagination->limit)->all();
     return $this->render('index', ['posts' => $posts, 'tag' => $tag->one(), 'pagination' => $pagination]);
 }
Exemplo n.º 3
0
 /**
  * Handle save tags event of the owner.
  */
 public function saveTags()
 {
     /** @var Post $owner */
     $owner = $this->owner;
     $post = Yii::$app->getRequest()->post('Post');
     $tags = isset($post['tagValues']) ? $post['tagValues'] : null;
     if (is_array($tags)) {
         $owner->unlinkAll('tags', true);
         foreach ($tags as $tag) {
             if (!ctype_digit($tag) || !($linkTag = Tag::findOne($tag))) {
                 $linkTag = new Tag(['title' => (string) $tag]);
                 $linkTag->setScenario(Tag::SCENARIO_AUTOGENERATED);
                 $linkTag->save();
             }
             $owner->link('tags', $linkTag);
         }
     }
 }
Exemplo n.º 4
0
    echo LanguagePills::widget();
    ?>
                        <?php 
}
?>

                        <?php 
echo $form->field($model, 'title')->textInput(['maxlength' => true]);
?>

                        <?php 
echo $form->field($model, 'slug')->textInput(['maxlength' => true]);
?>
                        
                        <?php 
echo $form->field($model, 'tagValues')->widget(MagicSuggest::className(), ['items' => Tag::getTags()]);
?>

                        <?php 
echo $form->field($model, 'content')->widget(TinyMce::className());
?>

                    </div>
                </div>
            </div>

            <div class="col-md-3">

                <div class="panel panel-default">
                    <div class="panel-body">
                        <div class="record-info">