public function install() { $model = PropertyModel::find()->where(['var_name' => $this->varName()])->one(); if ($model) { $model->setAttributes(['module_name' => $this->moduleName, 'class_name' => static::className()]); $model->update(false); return $model->id; } else { $model = new PropertyModel(); $model->setAttributes(['var_name' => $this->varName(), 'module_name' => $this->moduleName, 'class_name' => static::className()]); $insert = $model->insert(false); if ($insert) { return $model->id; } } }
public function bootstrap($app) { $findProperty = Property::findOne(['class_name' => GroupAuthProperty::className()]); if ($findProperty) { $this->properties = CmsProperty::findAll(['admin_prop_id' => $findProperty->id]); Yii::$app->menu->on(Container::MENU_ITEM_EVENT, [$this, 'hideElements']); } }
public function getProperty($varName) { $value = CmsProperty::find()->where(['nav_id' => $this->id])->leftJoin('admin_property', 'admin_prop_id=admin_property.id')->select(['cms_nav_property.value', 'admin_property.class_name'])->andWhere(['admin_property.var_name' => $varName])->asArray()->one(); if ($value) { return AdminProperty::getObject($value['class_name'], $value['value']); } return false; }
public function actionDataProperties() { $data = []; foreach (Property::find()->all() as $item) { $object = Property::getObject($item->class_name); $data[] = ['id' => $item->id, 'var_name' => $object->varName(), 'option_json' => $object->options(), 'label' => $object->label(), 'type' => $object->type(), 'default_value' => $object->defaultValue()]; } return $data; }
public function actionGetProperties($navId) { $data = []; foreach (Property::find()->select(['admin_prop_id', 'value'])->where(['nav_id' => $navId])->asArray()->all() as $row) { $object = \admin\models\Property::findOne($row['admin_prop_id']); $blockObject = $object->createObject($row['value']); $value = $blockObject->getValue(); $row['value'] = is_numeric($value) ? (int) $value : $value; $data[] = $row; } return $data; }
public function run() { $ids = []; foreach ($this->getImporter()->getDirectoryFiles('properties') as $file) { $className = $file['ns']; if (class_exists($className)) { $object = Yii::createObject(['class' => $className, 'moduleName' => $file['module']]); if ($object) { $ids[] = $object->install(); $this->getImporter()->addLog('properties', 'Property ' . $object->varName() . ' is installed and up to date.'); } } } foreach (Property::find()->where(['not in', 'id', $ids])->all() as $model) { $this->getImporter()->addLog('properties', 'Removing property (id:' . $model->id . ') ' . $model->var_name); $model->delete(); } }
public function getAdminProperty() { return $this->hasOne(AdminProperty::className(), ['id' => 'admin_prop_id']); }