public function down()
 {
     $objects = \app\models\Object::find()->asArray()->all();
     foreach ($objects as $object) {
         $this->dropColumn($object['eav_table_name'], 'property_group_id');
     }
 }
示例#2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = ObjectModel::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['like', 'user_name', $this->user_name])->andFilterWhere(['like', 'auth', $this->auth])->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
示例#3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Object::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'id_user' => $this->id_user, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'status' => $this->status]);
     $query->andFilterWhere(['like', 'title', $this->title]);
     return $dataProvider;
 }
示例#4
0
 /**
  * @param string $class_name
  * @return null|\app\models\Object
  */
 public static function getForClass($class_name)
 {
     if (isset(static::$ids_for_class_name[$class_name])) {
         $id = static::$ids_for_class_name[$class_name];
         return Object::findById($id);
     } else {
         $object = Yii::$app->cache->get('ObjectByClassName: ' . $class_name);
         if ($object === false) {
             $object = Object::find()->where(['object_class' => $class_name])->one();
             if ($object !== null) {
                 Yii::$app->cache->set('ObjectByClassName: ' . $class_name, $object, 86400, new TagDependency(['tags' => [\devgroup\TagDependencyHelper\ActiveRecordHelper::getObjectTag($object, $object->id)]]));
             }
         }
         if (is_object($object)) {
             static::$identity_map[$object->id] = $object;
             static::$ids_for_class_name[$class_name] = $object->id;
             return static::$identity_map[$object->id];
         }
     }
     return null;
 }
 /**
  * @return string
  */
 public function actionIndex()
 {
     $objects = new ActiveDataProvider(['query' => Object::find()->with(['lastExport', 'lastImport']), 'pagination' => ['pageSize' => 10], 'sort' => false]);
     return $this->render('index', ['objects' => $objects]);
 }
示例#6
0
 public function actionPosts()
 {
     if (!\Yii::$app->user->isGuest) {
         $sort = new Sort(['attributes' => ['id' => ['label' => 'ID'], 'urlimg' => ['asc' => ['urlimg' => SORT_ASC], 'desc' => ['urlimg' => SORT_DESC], 'default' => SORT_ASC, 'label' => 'Картинка'], 'id_router' => ['asc' => ['id_router' => SORT_ASC], 'desc' => ['id_router' => SORT_DESC], 'default' => SORT_ASC, 'label' => 'ID Роутора'], 'created_at' => ['label' => 'Дата создания'], 'status' => ['label' => 'Статус']]]);
         $arrayobject = array();
         $arrayrouter = array();
         if (Yii::$app->user->identity->role == 1) {
             $modelsobject = Object::find()->where(['id_user' => Yii::$app->user->identity->id])->select(['id', 'title'])->all();
             $n_object = 0;
             if ($modelsobject != NULL) {
                 foreach ($modelsobject as $modelobject) {
                     $arrayobject[$n_object] = $modelobject->id;
                     $n_object++;
                 }
             }
             $modelsrouter = Router::find()->where(['id_object' => $arrayobject])->select(['id'])->all();
             $n_router = 0;
             if ($modelsrouter != NULL) {
                 foreach ($modelsrouter as $modelrouter) {
                     $arrayrouter[$n_router] = $modelrouter->id;
                     $n_router++;
                 }
             }
             $query = Post::find()->where(['id_router' => $arrayrouter])->orderBy($sort->orders);
         }
         if (Yii::$app->user->identity->role == 5) {
             $modelsuser = Users::find()->where(['role' => 1, 'id_manager' => Yii::$app->user->identity->id])->select(['id'])->all();
             if ($modelsuser != NULL) {
                 $n_user = 0;
                 $arrayuser = array();
                 foreach ($modelsuser as $modeluser) {
                     $arrayuser[$n_user] = $modeluser->id;
                     $n_user++;
                 }
             }
             $modelsobject = Object::find()->where(['id_user' => $arrayuser])->select(['id', 'title'])->all();
             $n_object = 0;
             if ($modelsobject != NULL) {
                 foreach ($modelsobject as $modelobject) {
                     $arrayobject[$n_object] = $modelobject->id;
                     $n_object++;
                 }
             }
             $modelsrouter = Router::find()->where(['id_object' => $arrayobject])->select(['id'])->all();
             $n_router = 0;
             if ($modelsrouter != NULL) {
                 foreach ($modelsrouter as $modelrouter) {
                     $arrayrouter[$n_router] = $modelrouter->id;
                     $n_router++;
                 }
             }
             $query = Post::find()->where(['id_router' => $arrayrouter])->orderBy($sort->orders);
         }
         if (Yii::$app->user->identity->role == 10) {
             $query = Post::find()->orderBy($sort->orders);
         }
         $countQuery = clone $query;
         $pages = new Pagination(['totalCount' => $countQuery->count()]);
         $modelspost = $query->offset($pages->offset)->limit($pages->limit)->all();
         return $this->render('posts', ['modelspost' => $modelspost, 'pages' => $pages, 'sort' => $sort]);
     } else {
         return $this->redirect(['login']);
     }
 }