Esempio n. 1
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();
 }