public function actionAttributesList() { assert('!empty($_GET["moduleClassName"])'); $moduleClassName = $_GET['moduleClassName']; $module = new $_GET['moduleClassName'](null, null); $title = $moduleClassName::getModuleLabelByTypeAndLanguage('Plural') . ': ' . Zurmo::t('DesignerModule', 'Fields'); $breadcrumbLinks = array($title); $overrideClassName = $moduleClassName . 'AttributesListView'; $overrideClassFile = Yii::app()->getBasePath() . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $moduleClassName::getDirectoryName() . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . $overrideClassName . '.php'; if (is_file($overrideClassFile) && class_exists($overrideClassName)) { $viewClassName = $moduleClassName . 'AttributesListView'; $canvasView = new $viewClassName($this->getId(), $this->getModule()->getId()); } else { $modelClassName = $moduleClassName::getPrimaryModelName(); $model = new $modelClassName(); $adapter = new ModelAttributesAdapter($model); $derivedAttributesAdapter = new DerivedAttributesAdapter(get_class($model)); $customAttributes = array_merge($adapter->getCustomAttributes(), $derivedAttributesAdapter->getAttributes()); $customAttributes = ArrayUtil::subValueSort($customAttributes, 'attributeLabel', 'asort'); $standardAttributes = ArrayUtil::subValueSort($adapter->getStandardAttributes(), 'attributeLabel', 'asort'); $canvasView = new StandardAndCustomAttributesListView($this->getId(), $this->getModule()->getId(), $module, $moduleClassName::getModuleLabelByTypeAndLanguage('Plural'), $standardAttributes, $customAttributes, $modelClassName); } $view = new DesignerPageView(ZurmoDefaultAdminViewUtil::makeViewWithBreadcrumbsForCurrentUser($this, $canvasView, $breadcrumbLinks, 'DesignerBreadCrumbView')); echo $view->render(); }
/** * Helper function to get all model attributes as an array, that we can compare with responses from API. * @param OwnedSecurableItem $model * @return array */ public static function getModelAttributes(RedBeanModel $model) { $adapter = new ModelAttributesAdapter($model); $customAttributes = ArrayUtil::subValueSort($adapter->getCustomAttributes(), 'attributeLabel', 'asort'); $standardAttributes = ArrayUtil::subValueSort($adapter->getStandardAttributes(), 'attributeLabel', 'asort'); $allAttributes = array_merge($customAttributes, $standardAttributes); return $allAttributes; }
/** * @depends testSetNewAttributeFromAttributeForm */ public function testSetAndGetCustomAttributes() { Yii::app()->user->userModel = User::getByUsername('super'); $adapter = new ModelAttributesAdapter(new Account()); $attributes = $adapter->getCustomAttributes(); $this->assertEquals(0, count($attributes)); $attributeForm = new DropDownAttributeForm(); $attributeForm->attributeName = 'testText'; $attributeForm->attributeLabels = array('de' => 'Test Text de', 'en' => 'Test Text en', 'es' => 'Test Text es', 'fr' => 'Test Text fr', 'it' => 'Test Text it'); $attributeForm->isAudited = true; $attributeForm->isRequired = false; $attributeForm->customFieldDataName = 'Industries'; $modelAttributesAdapterClassName = $attributeForm::getModelAttributeAdapterNameForSavingAttributeFormData(); $adapter = new $modelAttributesAdapterClassName(new Account()); try { $adapter->setAttributeMetadataFromForm($attributeForm); } catch (FailedDatabaseSchemaChangeException $e) { echo $e->getMessage(); $this->fail(); } $account = new Account(); $this->assertTrue($account->isAttribute('testTextCstm')); $adapter = new ModelAttributesAdapter($account); $attributes = $adapter->getCustomAttributes(); $this->assertEquals(1, count($attributes)); $this->assertEquals('Test Text en', $attributes['testTextCstm']['attributeLabel']); $this->assertEquals('DropDown', $attributes['testTextCstm']['elementType']); }
/** * List all model attributes * @param $params * @return ApiResult * @throws ApiException */ protected function processListAttributes($params) { $data = array(); try { $modelClassName = $this->getModelName(); $model = new $modelClassName(); $adapter = new ModelAttributesAdapter($model); $customAttributes = ArrayUtil::subValueSort($adapter->getCustomAttributes(), 'attributeLabel', 'asort'); $standardAttributes = ArrayUtil::subValueSort($adapter->getStandardAttributes(), 'attributeLabel', 'asort'); $allAttributes = array_merge($customAttributes, $standardAttributes); $data['items'] = $allAttributes; $result = new ApiResult(ApiResponse::STATUS_SUCCESS, $data, null, null); } catch (Exception $e) { $message = $e->getMessage(); throw new ApiException($message); } return $result; }