Example #1
0
 public function actionIndex()
 {
     $otCount = ObjectTypes::find()->count();
     $otUnusedCount = (new Query())->from('{{object_types}} ot')->where(['not exists', (new Query())->from('{{objects}} o')->select('o.id')->where('o.object_type_id = ot.id')->limit(1)])->count();
     $attrUnusedCount = (new Query())->from('{{attributes}} attr')->where(['not exists', (new Query())->from('{{attributes_attached}} aa')->select('aa.attr_id')->where('aa.attr_id = attr.id')->limit(1)])->count();
     $uCount = User::find()->count();
     return $this->render('index', ['otCount' => $otCount, 'otUnusedCount' => $otUnusedCount, 'attrUnusedCount' => $attrUnusedCount, 'uCount' => $uCount]);
 }
Example #2
0
 public function search($params)
 {
     $query = ObjectTypesModel::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andWhere(['parent_id' => $this->parent_id ? $this->parent_id : null]);
     $query->andFilterWhere(['id' => $this->id, 'is_system' => $this->is_system]);
     $query->andFilterWhere(['like', 'alias', $this->alias])->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description]);
     return $dataProvider;
 }
Example #3
0
 /**
  * Attach existing attribute to existing object type.
  * @param int $objectTypeId
  * @param int $attributeId
  *
  * @throws \yii\base\UserException
  */
 public static function attachAttributeToObjectType($objectTypeId, $attributeId)
 {
     $objectType = ObjectTypes::getItem($objectTypeId);
     $attribute = Attributes::getItem($attributeId);
     $objectType->attachAttribute($attribute->id);
 }
Example #4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getObjectType()
 {
     return $this->hasOne(ObjectTypes::className(), ['id' => 'object_type_id']);
 }
Example #5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getObjectTypes()
 {
     return $this->hasMany(ObjectTypes::className(), ['id' => 'object_type_id'])->viaTable('allowed_links', ['attr_id' => 'id']);
 }
 /**
  * Finds the ObjectTypes model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  *
  * @param string $id
  *
  * @return ObjectTypes the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = ObjectTypes::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException(Yii::t('main', 'The requested page does not exist.'));
     }
 }
 /**
  * Updates an existing Attributes model.
  * If update is successful, the browser will be redirected to the 'view' page.
  *
  * @param string $id
  *
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $attachInfo = $objectType = null;
     $attachedTo = new ArrayDataProvider(['allModels' => AttributesAttached::find()->where(['attr_id' => $model->id])->with('objectType')->all(), 'pagination' => ['pageSize' => 10]]);
     $attachedToId = Yii::$app->request->getQueryParam('object_type_id');
     if ($attachedToId) {
         $objectType = ObjectTypes::getItem($attachedToId);
         $attachInfo = $objectType->getAttributesAttached()->where(['attr_id' => $model->id])->one();
     }
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         if ($attachInfo) {
             if ($attachInfo->load(Yii::$app->request->post()) && $attachInfo->save()) {
                 return $this->redirect(Yii::$app->request->getReferrer());
             }
         }
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('update', ['model' => $model, 'attrTypes' => $this->getAttributeTypes(), 'attachInfo' => $attachInfo, 'objectType' => $objectType, 'attachedTo' => $attachedTo]);
     }
 }
Example #8
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getObjectTypes()
 {
     return $this->hasMany(ObjectTypes::className(), ['parent_id' => 'id']);
 }