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 testGetModelAttributesAdapter */ public function testGetStandardAttributes() { Yii::app()->user->userModel = User::getByUsername('super'); $account = new Account(); $adapter = new ModelAttributesAdapter($account); $attributes = $adapter->getStandardAttributes(); $this->assertEquals(21, count($attributes)); $this->assertEquals('Name', $attributes['name']['attributeLabel']); $this->assertEquals('Industry', $attributes['industry']['attributeLabel']); $this->assertEquals('Type', $attributes['type']['attributeLabel']); $this->assertEquals('Latest Activity Date Time', $attributes['latestActivityDateTime']['attributeLabel']); $this->assertEquals('Text', $attributes['name']['elementType']); $this->assertEquals('DropDown', $attributes['industry']['elementType']); $this->assertEquals('DropDown', $attributes['type']['elementType']); $this->assertEquals('DateTime', $attributes['latestActivityDateTime']['elementType']); $this->assertEquals('Account', $attributes['account']['elementType']); $this->assertTrue(!isset($attributes['notes'])); }
/** * 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; }