GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 1ba1f4...ea41a5 )
by Alexey
05:37
created

ProductController::renderPage()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 25
Code Lines 14

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 25
rs 8.8571
cc 2
eloc 14
nc 2
nop 2
1
<?php
2
/**
3
 * @author Sergey Glagolev <[email protected]>
4
 * @link https://github.com/shogodev/argilla/
5
 * @copyright Copyright &copy; 2003-2014 Shogo
6
 * @license http://argilla.ru/LICENSE
7
 * @package frontend.controllers
8
 */
9
10
/**
11
 * Class ProductController
12
 * @mixin ProductTextBehavior
13
 * @mixin ProductFilterBehavior
14
 * @mixin ProductSortingBehavior
15
 */
16
class ProductController extends FController
17
{
18
  public $pageSize = 10;
19
20
  public function behaviors()
21
  {
22
    return CMap::mergeArray(parent::behaviors(), array(
23
      'productTextBehavior' => array('class' => 'backend.modules.product.modules.text.frontend.ProductTextBehavior'),
24
      'productFilterBehavior' => array('class' => 'ProductFilterBehavior'),
25
      'productSortingBehavior' => array(
26
        'class' => 'ProductSortingBehavior',
27
        'defaultSorting' => 'default',
28
        'pageSizeRange' => array(20, 40, 60)
29
      )
30
    ));
31
  }
32
33
  public function actionCategories()
34
  {
35
    $this->breadcrumbs = array('Производители');
36
37
    $categories = ProductCategory::model()->findAll();
38
39
    $this->render('categories', array('categories' => $categories));
40
  }
41
42 View Code Duplication
  public function actionCategory($category)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
43
  {
44
    /**
45
     * @var ProductCategory $model
46
     */
47
    $model = ProductCategory::model()->findByAttributes(array('url' => $category));
48
49
    if( !$model )
50
      throw new CHttpException(404, 'Страница не найдена');
51
52
    $this->breadcrumbs = array(
53
      'Производители' => $this->createUrl('product/categories'),
54
      $model->name,
55
    );
56
57
    $criteria = new CDbCriteria();
58
    $criteria->compare('a.category_id', $model->id);
59
60
    $this->renderPage(array($model), $criteria);
61
  }
62
63 View Code Duplication
  public function actionSection($section)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
64
  {
65
    /**
66
     * @var ProductSection $model
67
     */
68
    $model = ProductSection::model()->findByAttributes(array('url' => $section));
69
70
    if( !$model )
71
      throw new CHttpException(404, 'Страница не найдена');
72
73
    $this->breadcrumbs = array(
74
      $model->name,
75
    );
76
77
    $criteria = new CDbCriteria();
78
    $criteria->compare('a.section_id', $model->id);
79
80
    $this->renderPage(array($model), $criteria);
81
  }
82
83 View Code Duplication
  public function actionType($type)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
84
  {
85
    /**
86
     * @var ProductType $model
87
     */
88
    $model = ProductType::model()->findByAttributes(array('url' => $type));
89
90
    if( !$model )
91
      throw new CHttpException(404, 'Страница не найдена');
92
93
    $this->breadcrumbs = array(
94
      $model->name,
95
    );
96
97
    $criteria = new CDbCriteria();
98
    $criteria->compare('a.type_id', $model->id);
99
100
    $this->renderPage(array($model), $criteria);
101
  }
102
103
  public function actionOne($url)
104
  {
105
    /**
106
     * @var Product $model
107
     */
108
    $model = Product::model()->visible()->findByAttributes(array('url' => $url));
109
110
    if( !$model )
111
      throw new CHttpException(404, 'Страница не найдена');
112
113
    $this->breadcrumbs = array(
114
      $model->section->name => array('product/section', 'section' => $model->section->url),
115
      $model->name,
116
    );
117
118
    $data = array(
119
      'model' => $model,
120
      'similarDataProvider' => $model->getSimilarProducts(4),
121
      'relatedDataProvider' => $model->getRelatedProducts(4),
122
    );
123
124
    if( Yii::app()->request->isAjaxRequest )
125
      $this->renderPartial('_details', array('data' => $model));
126
    else
127
      $this->render('one/product', $data);
128
  }
129
130
  public function isFirstPage()
131
  {
132
    $page = Yii::app()->request->getParam('page');
133
    return $page === null || $page == 1;
134
  }
135
136
  private function renderPage(array $models, CDbCriteria $criteria)
137
  {
138
    Yii::app()->meta->addModels($models);
139
140
    $productList = new ProductList($criteria, $this->getSorting(), true, $this->getFilter());
141
    $dataProvider = $productList->getDataProvider();
142
143
    $this->getFilter()->setSelectedModels($models);
144
145
    $data = array(
146
      'model' => Arr::reset($models),
147
      'dataProvider' => $dataProvider,
148
      'filter' => $this->getFilter(),
149
      'menus' => array()
150
    );
151
152
    if( Yii::app()->request->isAjaxRequest )
153
    {
154
      $this->renderPartial('content', $data);
155
    }
156
    else
157
    {
158
      $this->render('content', $data);
159
    }
160
  }
161
}