123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- <?php
- /**
- * Created by PhpStorm.
- * User: NODELOG
- * Date: 16/3/17
- * Time: 上午10:19
- */
- namespace common\models\query;
- use common\models\Article;
- use yii\db\ActiveQuery;
- class ArticleQuery extends ActiveQuery
- {
- /**
- * @param null $db
- * @return array|Article[]
- */
- public function all($db = null)
- {
- return parent::all($db); // TODO: Change the autogenerated stub
- }
- /**
- * @param null $db
- * @return array|null|Article
- */
- public function one($db = null)
- {
- return parent::one($db); // TODO: Change the autogenerated stub
- }
- /**
- * 被删除的
- * @return $this
- */
- public function onlyTrashed()
- {
- return $this->andWhere(['not', ['deleted_at' => null]]);
- }
- /**
- * 未被删除的
- * @return $this
- */
- public function notTrashed()
- {
- return $this->andWhere(['deleted_at' => null]);
- }
- /**
- * 待审核的
- * @return $this
- */
- public function pending()
- {
- return $this->andWhere(['status' => Article::STATUS_PENDING]);
- }
- /**
- * 审核通过的
- */
- public function active()
- {
- return $this->andWhere(['status' => Article::STATUS_ACTIVE]);
- }
- /**
- * 未删除且审核通过的
- * @return $this
- */
- public function normal()
- {
- return $this->notTrashed()->active();
- }
- /**
- * 已经发布的
- * @return $this
- */
- public function published()
- {
- return $this->normal()->andWhere(['<', 'published_at', time()]);
- }
- /**
- * @return $this
- */
- public function my()
- {
- return $this->andWhere(['user_id' => \Yii::$app->user->id]);
- }
- }
|