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

BModificationBehavior::onAfterRenderTableRow()   B

Complexity

Conditions 4
Paths 3

Size

Total Lines 24
Code Lines 13

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 24
rs 8.6845
cc 4
eloc 13
nc 3
nop 1
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
 * 'modificationBehavior' => array('class' => 'BModificationBehavior')
10
 */
11
/**
12
 * Class BModificationBehavior
13
 *
14
 * @property BProduct $owner
15
 * @property BProduct[] $modifications
16
 * @property BProduct|null $parentModel
17
 */
18
class BModificationBehavior extends SActiveRecordBehavior
19
{
20
  const SCENARIO_MODIFICATION = 'modification';
21
22
  public $gridTableRowHtmlOptions = array('class' => 'modification');
23
24
  public function init()
25
  {
26
    if( $this->owner->isNewRecord )
27
    {
28
      $this->owner->parent = Yii::app()->request->getParam('modificationParent');
29
    }
30
31
    $this->attachRelations();
32
33
    $this->owner->attachEventHandler('onBeforeSearch', array($this, 'beforeSearch'));
34
    $this->attachEventHandler('onAfterRenderTableRow', array($this, 'onAfterRenderTableRow'));
35
36
    //to do: добавить параметр блокирующей отключение одного значения
37
    $this->owner->attachBehavior('radioToggleBehavior', array(
38
      'class' => 'RadioToggleBehavior',
39
      'conditionAttribute' => 'parent',
40
      'toggleAttribute' => 'default_modification'
41
    ));
42
43
    $this->owner->enableBehavior('radioToggleBehavior');
44
  }
45
46
  public function beforeSearch(CEvent $event)
47
  {
48
    /**
49
     * @var CDbCriteria $criteria
50
     */
51
    $criteria = $event->params['criteria'];
52
53
    $criteria->addCondition('t.parent IS NULL');
54
55
    return $criteria;
56
  }
57
58
  public function beforeValidate($event)
59
  {
60
    if( $this->isModification() )
61
      $this->owner->scenario = self::SCENARIO_MODIFICATION;
62
63
    return parent::beforeValidate($event);
64
  }
65
66
  /**
67
   * @return BProduct
68
   */
69
  public function getParentModel()
70
  {
71
    return $this->owner->parentModel;
72
  }
73
74
  /**
75
   * @return bool
76
   */
77
  public function isModification()
78
  {
79
    return !empty($this->owner->parent);
80
  }
81
82 View Code Duplication
  private function attachRelations()
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...
83
  {
84
    $this->owner->getMetaData()->addRelation('modifications', array(
85
      BActiveRecord::HAS_MANY, 'BProduct', array('parent' => 'id'),
86
    ));
87
88
    $this->owner->getMetaData()->addRelation('parentModel', array(
89
      BActiveRecord::HAS_ONE, 'BProduct', array('id' => 'parent'),
90
    ));
91
  }
92
93
  protected function onAfterRenderTableRow(CEvent $event)
94
  {
95
    if( empty($this->owner->modifications) && Yii::app()->controller->popup)
96
      return;
97
98
    /**
99
     * @var BGridView $grid
100
     */
101
    $grid = $event->sender;
102
    $oldDataProvider = $grid->dataProvider;
103
    $oldRowCssClassExpression = $grid->rowCssClassExpression;
104
105
    $dataProvider = new CArrayDataProvider($this->owner->modifications);
106
    $grid->dataProvider = $dataProvider;
107
    $grid->rowCssClassExpression = '"modification"';
108
109
    foreach($grid->dataProvider->getData() as $row => $data)
110
    {
111
      $grid->renderTableRow($row);
112
    }
113
114
    $grid->dataProvider = $oldDataProvider;
115
    $grid->rowCssClassExpression = $oldRowCssClassExpression;
116
  }
117
}