Beispiel #1
0
 public function init()
 {
     parent::init();
     $view = $this->getView();
     $module = Yii::$app->getModule("versioning");
     $user_id = Yii::$app->user->id;
     $groups = \amilna\versioning\components\Libs::userGroups($user_id);
     $groups = [1];
     $bundle = NotificationAsset::register($view);
     $this->bundle = $bundle;
     $searchModel = new VersionSearch();
     $dataProvider = $searchModel->search([]);
     $query = $dataProvider->query;
     $query->andWhere([Version::tableName() . ".status" => true])->andWhere(Record::tableName() . ".record_id is not null");
     if (count($this->models) > 0) {
         $query->andWhere([Record::tableName() . ".model" => $this->models])->andWhere(Record::tableName() . ".filter_viewers = false");
     }
     if ($user_id > 0) {
         $query->andWhere("concat(','," . Record::tableName() . ".viewers,',') not like '%," . $user_id . ",%'")->andWhere(Record::tableName() . ".filter_viewers = false OR (" . Record::tableName() . ".filter_viewers = true AND (" . Record::tableName() . ".owner_id = :uid OR " . Record::tableName() . ".group_id in (" . implode(",", $groups) . ")) )", [":uid" => $user_id]);
     } else {
         $query->limit(10);
     }
     $query->orderBy(Route::tableName() . ".time DESC," . Version::tableName() . ".id DESC");
     $script = "\t\t\n\t\t" . PHP_EOL;
     $view->registerJs($script);
     echo $this->render($this->viewPath, ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'module' => $module, 'widget' => $this]);
 }
Beispiel #2
0
 public function bootstrap($app)
 {
     $events = [Controller::EVENT_BEFORE_ACTION];
     foreach ($events as $eventName) {
         Event::on(Controller::className(), $eventName, function ($event) use($app, $eventName) {
             Libs::mkView($app, $eventName, $event);
         });
     }
     $events = [ActiveRecord::EVENT_AFTER_INSERT, ActiveRecord::EVENT_BEFORE_UPDATE, ActiveRecord::EVENT_BEFORE_DELETE];
     $res0 = false;
     foreach ($events as $eventName) {
         Event::on(ActiveRecord::className(), $eventName, function ($event) use($app, $eventName) {
             $model = $event->sender;
             $res0 = Libs::mkVersion($app, $eventName, $model);
         });
     }
     if ($res0) {
         $events = [ActiveRecord::EVENT_AFTER_UPDATE, ActiveRecord::EVENT_AFTER_DELETE];
         foreach ($events as $eventName) {
             Event::on(ActiveRecord::className(), $eventName, function ($event) use($app, $eventName, $res0) {
                 $res = true;
                 $model = $event->sender;
                 foreach ($model->attributes as $a => $v) {
                     $m = $res0[1];
                     if ($eventName == ActiveRecord::EVENT_AFTER_UPDATE) {
                         $res = $m[$a] != $v ? false : $res;
                     } elseif ($eventName == ActiveRecord::EVENT_AFTER_DELETE) {
                         $res = $m[$a] != null ? false : $res;
                     }
                 }
                 if (!$res) {
                     $route = Route::findOne($res0[0]);
                     if ($route) {
                         $route->delete();
                     }
                 }
             });
         }
     }
 }