Blame view

common/modules/comment/behaviors/ParentBehavior.php 1.09 KB
4253cbec   root   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
  <?php
      namespace common\modules\comment\behaviors;
      
      use common\modules\comment\models\CommentModel;
      use yii\base\Behavior;
      use yii\base\Event;
      use yii\db\ActiveRecord;
  
      class ParentBehavior extends Behavior
      {
          public function events()
          {
              return [
                  ActiveRecord::EVENT_AFTER_VALIDATE => 'afterValidate',
              ];
          }
      
          /**
           * @param Event $event
           */
          public function afterValidate($event) {
              /**
               * @var CommentModel $owner
               */
              $owner = $this->owner;
              if(!empty($owner->artbox_comment_pid)) {
                  /**
                   * @var CommentModel $parent
                   */
                  $parent = CommentModel::find()->where(['artbox_comment_id' => $owner->artbox_comment_pid])->one();
                  if(!empty($parent->artbox_comment_pid)) {
                      $owner->related_id = $owner->artbox_comment_pid;
                      $owner->artbox_comment_pid = $parent->artbox_comment_pid;
                  }
              }
          }
      }