News.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace app\models\front;
  3. use app\models\base\Image;
  4. use yii\db\Expression;
  5. use yii\helpers\ArrayHelper;
  6. use Yii;
  7. class News extends \app\models\News
  8. {
  9. public static function find()
  10. {
  11. return parent::find()
  12. ->andWhere(["<=","dt_pub",date("Y-m-d H:i:00")])
  13. ->andWhere(["news.active"=>'Y'])
  14. ->orderBy(["dt_pub"=>SORT_DESC]);
  15. }
  16. public static function findFilter()
  17. {
  18. $session = Yii::$app->session;
  19. $x = $session->get('filterx');
  20. if( is_array( $x ) && count( $x ) > 0 ){
  21. return parent::find()
  22. ->select( 'news.*' )
  23. ->from(new Expression("news FORCE INDEX (top,calendar)"))
  24. ->leftJoin('tags_relation', '`tags_relation`.`news_id` = `news`.`id`')
  25. ->Where(['tags_relation.topic_id'=>$x])
  26. ->andWhere(["<=","dt_pub",date("Y-m-d H:i:00")])
  27. ->andWhere(["news.active"=>'Y'])
  28. ->orderBy(["dt_pub"=>SORT_DESC]);
  29. }else{
  30. return self::find();
  31. }
  32. }
  33. public static function keyFilter()
  34. {
  35. $session = Yii::$app->session;
  36. $x = $session->get('filterx');
  37. if( is_array( $x ) && count( $x ) > 0 ){
  38. sort($x);
  39. return implode( '-', $x );
  40. }
  41. return '';
  42. }
  43. public function afterFind()
  44. {
  45. parent::afterFind();
  46. }
  47. }