Esempio n. 1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  * @param int   $taxonomy_id
  *
  * @return ActiveDataProvider
  */
 public function search($params, $taxonomy_id)
 {
     $query = TermModel::find();
     $query->andWhere(['taxonomy_id' => $taxonomy_id]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'taxonomy_id' => $this->taxonomy_id, 'term_parent' => $this->term_parent, 'term_count' => $this->term_count]);
     $query->andFilterWhere(['like', 'term_name', $this->term_name])->andFilterWhere(['like', 'term_slug', $this->term_slug])->andFilterWhere(['like', 'term_description', $this->term_description]);
     return $dataProvider;
 }
Esempio n. 2
0
 /**
  * Finds the Term model based on its primary key value.
  * If the model is not found, it will return false.
  *
  * @param integer $id
  *
  * @return Term|bool|null|static
  */
 protected function findTerm($id)
 {
     if (($model = Term::findOne($id)) !== null) {
         return $model;
     } else {
         return false;
     }
 }
 /**
  * Finds the Term model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  *
  * @param integer $id
  *
  * @return Term the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findTerm($id)
 {
     if (($model = Term::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Esempio n. 4
0
 /**
  * @param bool $sameType
  * @param bool $sameTerm
  *
  * @return array|null|Post
  */
 public function getPrevPost($sameType = true, $sameTerm = false)
 {
     /* @var $query \yii\db\ActiveQuery */
     $query = static::find()->from(['post' => $this->tableName()])->andWhere(['<', 'post.id', $this->id])->andWhere(['post_status' => 'publish'])->orderBy(['post.id' => SORT_DESC]);
     if ($sameType) {
         $query->andWhere(['post_type' => $this->post_type]);
     }
     if ($sameTerm) {
         $query->innerJoinWith(['terms' => function ($query) {
             /* @var $query \yii\db\ActiveQuery */
             $query->from(['term' => Term::tableName()])->andWhere(['IN', 'term.id', implode(',', ArrayHelper::getColumn($this->terms, 'id'))]);
         }]);
     }
     return $query->one();
 }
Esempio n. 5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getTerms()
 {
     return $this->hasMany(Term::className(), ['taxonomy_id' => 'id']);
 }
Esempio n. 6
0
 /**
  * Finds the Post model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  *
  * @param $term_slug
  *
  * @throws \yii\web\NotFoundHttpException
  * @internal param string $post_slug
  *
  * @return Term the loaded model
  */
 protected function findModelBySlug($term_slug)
 {
     $model = Term::findOne(['term_slug' => $term_slug]);
     if ($model) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getTerm()
 {
     return $this->hasOne(Term::className(), ['id' => 'term_id']);
 }