Example #1
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getAttrsAll()
 {
     $parents = $this->getTopHierarchy();
     $parents = ArrayHelper::map($parents, 'id', 'id');
     array_push($parents, $this->id);
     return Attributes::find()->select('attributes.id, attributes.name, attributes.attr_type_id, attributes.alias,' . ' attributes.description, attributes.is_system,' . ' attributes_attached.object_type_id as fromType, object_types.name as fromTypeName')->joinWith('attributesAttached')->innerJoin('object_types', 'object_types.id = attributes_attached.object_type_id')->where(['attributes_attached.object_type_id' => $parents]);
 }
Example #2
0
 public function search($params, $withAttrTypes = false)
 {
     $query = $withAttrTypes ? AttributesModel::find()->with('attributeType') : AttributesModel::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'attr_type_id' => $this->attr_type_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 getAttr()
 {
     return $this->hasOne(Attributes::className(), ['id' => 'object_type_id']);
 }
 /**
  * Finds the Attributes model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  *
  * @param string $id
  *
  * @return Attributes the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Attributes::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }