Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. public function actionIndexPopular($category_slug, $period = false, $year = false, $month = false, $day = false)
  2. {
  3. $this->withSlash();
  4.  
  5. $this->page_class = 'page_news_list_view';
  6. $this->layout = 'index';
  7.  
  8. $category = Category::model()->findByAttributes(array('slug' => $category_slug));
  9. $category_id = $category->id;
  10. $category_name = $category->name;
  11. $all_id = Yii::app()->views->getPopularForCategory($category_id, 30, 5, '2015-05-25 04:56:21', '2017-03-25 04:56:21');
  12.  
  13. $criteria = new CDbCriteria();
  14. $criteria->addInCondition('t.id',$all_id);
  15. if(!empty($all_id)) $criteria->order = 'FIELD(t.id,'.implode(',',$all_id).')';
  16.  
  17. $materials = Material::model()->cache(60*5)->published()->findAll($criteria);
  18. $count = count($materials);
  19.  
  20. $d_material = Material::model()->cache(60)->with('category')->published()->find(array('condition'=>'is_newsoftheday = 1 AND category_id = :category_id', 'params'=>array(':category_id'=>$category->id), 'limit'=>1));
  21.  
  22. $this->setTitle($category->name);
  23. if ($period) {
  24. switch ($period) {
  25. case 'today':
  26. $range[0] = mktime(0, 0, 0, date('m'), date('d'), date('Y'));
  27. $range[1] = mktime(23, 59, 59, date('m'), date('d'), date('Y'));
  28. $this->setTitle($category->name . lnParams::get('delimiter') . 'За день');
  29. break;
  30.  
  31. case 'week':
  32. $range[0] = strtotime('-1 week');
  33. $range[1] = strtotime('now');
  34. $this->setTitle($category->name . lnParams::get('delimiter') . 'За неделю');
  35. break;
  36.  
  37. case 'month':
  38. $range[0] = strtotime('-1 month');
  39. $range[1] = strtotime('now');
  40. $this->setTitle($category->name . lnParams::get('delimiter') . 'За месяц');
  41. break;
  42.  
  43. case 'year':
  44. $range[0] = strtotime('-1 year');
  45. $range[1] = strtotime('now');
  46. $this->setTitle($category->name . lnParams::get('delimiter') . 'За год');
  47. break;
  48. }
  49. }
  50.  
  51. $pages=new CPagination($count);
  52. $pages->pageSize=20;
  53. $pages->applyLimit($criteria);
  54.  
  55. $this->render('index', array(
  56. 'category'=>$category,
  57. 'category_name'=>$category_name,
  58. 'materials'=>$materials,
  59. 'd_material' => $d_material,
  60. 'pages' => $pages,
  61. 'period' => $period,
  62. 'year' => $year,
  63. 'month' => $month,
  64. 'day' => $day,
  65. ));
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement