public function save() { $model = CCoreObjectsManager::getCoreModel($this->id); foreach ($this->getItems()->getItems() as $item) { $field = new CCoreModelField(); $field->model_id = $model->getId(); $field->field_name = $item["name"]; $field->save(); if ($item["translation"] !== "") { $t = new CCoreModelFieldTranslation(); $t->field_id = $field->getId(); $t->value = $item["translation"]; $t->save(); } if ($item["validator"] !== "0") { $v = new CCoreModelFieldValidator(); $v->field_id = $field->getId(); $v->validator_id = $item["validator"]; $v->save(); } } }
public function actionSave() { $field = new CCoreModelField(); $field->setAttributes(CRequest::getArray($field::getClassName())); if ($field->validate()) { $field->save(); if ($this->continueEdit()) { $this->redirect("fields.php?action=edit&id=" . $field->getId()); } else { $this->redirect("models.php?action=edit&id=" . $field->model_id); } return true; } $this->setData("field", $field); $this->renderView("_core/field/edit.tpl"); }
public function actionImport() { /** * Берем папку моделей и ищем все подпапки */ $models = array(); $modelsDir = opendir(CORE_CWD . CORE_DS . "_core" . CORE_DS . "_models"); while (false !== ($dir = readdir($modelsDir))) { if ($dir != "." && $dir != "..") { if (is_dir(CORE_CWD . CORE_DS . '_core' . CORE_DS . '_models' . CORE_DS . $dir)) { /** * Ищем файлы */ $modelDir = opendir(CORE_CWD . CORE_DS . '_core' . CORE_DS . '_models' . CORE_DS . $dir); while (($file = readdir($modelDir)) !== false) { if ($file != "." && $file != "..") { $models[] = $file; } } } } } /** * Последовательно создаем классы и смотрим, являются ли они наследниками * CModel или CActiveModel */ foreach ($models as $model) { $model = substr($model, 0, strpos($model, ".")); $obj = new $model(); if (is_a($obj, "CModel")) { /** * Это модельный класс, отсюда берем названия полей */ $persistedObj = CCoreObjectsManager::getCoreModel(get_class($obj)); if (is_null($persistedObj)) { /** * Создаем сам класс */ $persistedObj = new CCoreModel(); $persistedObj->title = get_class($obj); $persistedObj->class_name = get_class($obj); $persistedObj->save(); $fields = $obj->attributeLabels(); foreach ($fields as $key => $value) { $field = new CCoreModelField(); $field->model_id = $persistedObj->getId(); $field->field_name = $key; $field->save(); $t = new CCoreModelFieldTranslation(); $t->field_id = $field->getId(); $t->language_id = CSettingsManager::getSettingValue("system_language_default"); $t->value = $value; $t->save(); } } } } }