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

ParameterGridBehavior::updateAvailable()   C

Complexity

Conditions 7
Paths 10

Size

Total Lines 26
Code Lines 13

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 26
rs 6.7272
cc 7
eloc 13
nc 10
nop 0
1
<?php
2
/**
3
 * @author Alexey Tatarinov <[email protected]>
4
 * @link https://github.com/shogodev/argilla/
5
 * @copyright Copyright &copy; 2003-2015 Shogo
6
 * @license http://argilla.ru/LICENSE
7
 *
8
 * Пример подключения:
9
 * 'parameterGridBehavior' => array('class' => 'backend.modules.product.modules.parameterGrid.ParameterGridBehavior', 'parameterKey' => 'basket')
10
 */
11
12
/**
13
 * Class ParameterGridBehavior
14
 * @property BProduct $owner
15
 */
16
class ParameterGridBehavior extends SActiveRecordBehavior
17
{
18
  public $parameterKey;
19
20
  private $parametersDataProvider;
21
22
  public function init()
23
  {
24
    if( empty($this->parameterKey) )
25
      throw new RequiredPropertiesException(get_class($this), 'parameterKey');
26
  }
27
28
  /**
29
   * @param $key
30
   *
31
   * @return BActiveDataProvider
32
   */
33
  public function getParametersDataProvider($key = null)
34
  {
35
    if( is_null($key) )
36
      $key = $this->parameterKey;
37
38
    if( !isset($this->parametersDataProvider[$key]) )
39
    {
40
      $criteriaParamName = new CDbCriteria();
41
      $criteriaParamName->compare('t.key', $key);
42
      $paramIds = BProductParamName::model()->listData('id', 'id', $criteriaParamName);
43
44
      $criteria = new CDbCriteria();
45
      $criteria->compare('t.product_id', $this->owner->id);
46
      $criteria->addInCondition('t.param_id', $paramIds);
47
      $criteria->with = array('variant');
48
      $criteria->order = 'IF(variant.position=0, 1, 0), variant.position';
49
50
      $this->parametersDataProvider[$key] = new BActiveDataProvider('BProductParam', array('criteria' => $criteria, 'pagination' => false));
51
    }
52
53
    return $this->parametersDataProvider[$key];
54
  }
55
56
  public function beforeSave($event)
57
  {
58
    $this->updatePrice();
59
    $this->updateAvailable();
60
61
    parent::beforeSave($event);
62
  }
63
64
  protected function updatePrice()
65
  {
66
    if( $this->getParametersDataProvider($this->parameterKey)->totalItemCount > 0 )
67
      $this->owner->price = Arr::reset($this->getParametersDataProvider($this->parameterKey)->getData())->price;
68
  }
69
70
  protected function updateAvailable()
71
  {
72
    if( $this->owner->dump == BProductDump::AVAILABLE_ORDER )
73
      return;
74
75
    $available = false;
76
77
    if( $this->getParametersDataProvider($this->parameterKey)->totalItemCount == 0)
78
    {
79
      if( !empty($this->owner->articul) )
80
        return;
81
    }
82
    else
83
    {
84
      foreach($this->getParametersDataProvider($this->parameterKey)->getData() as $productParam)
85
      {
86
        if( $productParam->dump )
87
        {
88
          $available = true;
89
          break;
90
        }
91
      }
92
    }
93
94
    $this->owner->dump = $available ? BProductDump::AVAILABLE : BProductDump::NOT_AVAILABLE;
95
  }
96
}