Ejemplo n.º 1
0
 public function __construct(RedBeanModel $model = null, $attributeName = null)
 {
     assert('$attributeName === null || is_string($attributeName)');
     assert('$model === null || $model->isAttribute($attributeName)');
     if ($model !== null) {
         $this->attributeName = $attributeName;
         $this->attributeLabels = $model->getAttributeLabelsForAllActiveLanguagesByAttributeName($attributeName);
         $this->attributePropertyToDesignerFormAdapter = new AttributePropertyToDesignerFormAdapter();
         $validators = $model->getValidators($attributeName);
         foreach ($validators as $validator) {
             if ($validator instanceof CDefaultValueValidator) {
                 $this->defaultValue = $validator->value;
             } elseif ($validator instanceof CRequiredValidator) {
                 $this->isRequired = true;
                 $modelAttributesAdapter = new ModelAttributesAdapter($model);
                 if ($modelAttributesAdapter->isStandardAttribute($attributeName) && $modelAttributesAdapter->isStandardAttributeRequiredByDefault($attributeName)) {
                     $this->attributePropertyToDesignerFormAdapter->setUpdateRequiredFieldStatus(false);
                 }
             }
         }
         if ($model instanceof Item && $attributeName != null) {
             $this->isAudited = $model->isAttributeAudited($attributeName);
         }
     }
 }
 public function testRebuildDatabaseWithNonSuperAdminUser()
 {
     $steven = UserTestHelper::createBasicUser('Steven');
     Yii::app()->user->userModel = $steven;
     $item = NamedSecurableItem::getByName('AccountsModule');
     $this->assertEquals(Permission::NONE, $item->getEffectivePermissions($steven));
     $accounts = Account::getAll();
     $users = User::getAll();
     $this->assertEquals(0, count($accounts));
     $this->assertEquals(2, count($users));
     $adapter = new ModelAttributesAdapter(new Account());
     $adapter->resolveDatabaseSchemaForModel('Account');
     //Confirm the counts of data are still correct
     $accounts = Account::getAll();
     $users = User::getAll();
     $this->assertEquals(0, count($accounts));
     $this->assertEquals(2, count($users));
     //Explicitly deny read, write, and deny
     Yii::app()->user->userModel = User::getByUsername('super');
     $item->addPermissions($steven, Permission::READ_WRITE_DELETE, Permission::DENY);
     $this->assertTrue($item->save());
     //Make sure steven has explicit deny
     $item = NamedSecurableItem::getByName('AccountsModule');
     $this->assertEquals(Permission::NONE, $item->getEffectivePermissions($steven));
     Yii::app()->user->userModel = $steven;
     $adapter = new ModelAttributesAdapter(new Account());
     $adapter->resolveDatabaseSchemaForModel('Account');
     //Confirm the counts of data are still correct
     $accounts = Account::getAll();
     $users = User::getAll();
     $this->assertEquals(0, count($accounts));
     $this->assertEquals(2, count($users));
 }
Ejemplo n.º 3
0
 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;
 }
 public function getAttributes()
 {
     $adapter = new ModelAttributesAdapter($this->model);
     $attributes = $adapter->getAttributes();
     foreach ($attributes as $attributeName => $data) {
         if (!in_array($data['elementType'], array('Decimal', 'Integer', 'CurrencyValue'))) {
             unset($attributes[$attributeName]);
         }
     }
     return $attributes;
 }
Ejemplo n.º 6
0
 public function __construct(RedBeanModel $model)
 {
     parent::__construct($model);
     $modelAttributesAdapter = new ModelAttributesAdapter($this->model);
     $attributeInformation = $modelAttributesAdapter->getAttributes();
     foreach ($attributeInformation as $attributeName => $attributeData) {
         if (in_array($attributeData['elementType'], static::getDynamicAttributeTypes())) {
             $this->dynamicAttributeNames[] = $attributeName . FormModelUtil::DELIMITER . $attributeData['elementType'];
         }
     }
 }
 protected function renderAvailableAttributesContent()
 {
     $modelClassName = $this->model->getModelClassName();
     $model = new $modelClassName(false);
     $adapter = new ModelNumberOrCurrencyAttributesAdapter($model);
     $attributeDataNumerOrCurrency = $adapter->getAttributes();
     $title = Zurmo::t('DesignerModule', 'Create a formula that is evaluated based on other fields. ' . 'The formula can be a math expression calculated from number ' . 'fields, for example, you can use an expression like ' . '(field1 * field2) / field3. The formula can also include an if ' . 'statement, use the IF(condition;trueValue;falseValue) syntax. ' . 'Within the condition and values you can use strings, string fields, ' . 'number fields or math expressions. Strings should be surrounded by ' . '\'. In the condition you can ' . 'use the operators <, >, ==, !=, <= and >=. An example of an if ' . 'statement is IF(field1 == field4;field2/365;0)');
     // Not Coding Standard
     $spanContent = '<span id="formula-tooltip" class="tooltip" title="' . $title . '">?</span>';
     $content = null;
     $adapter = new ModelAttributesAdapter($model);
     $attributeData = $adapter->getAttributes();
     if (count($attributeData) > 0) {
         $content .= '<strong>' . Zurmo::t('DesignerModule', 'Available Fields For Formula:') . '</strong> ';
         $content .= $spanContent;
         $content .= '<table id="available-fields">';
         $content .= '<tr><th>' . Zurmo::t('DesignerModule', 'Field Name') . '</th>';
         $content .= '<th>' . Zurmo::t('DesignerModule', 'Formula Name') . '</th>';
         $content .= '<th>' . Zurmo::t('DesignerModule', 'Can be used in math expression') . '</th></tr>';
         foreach ($attributeData as $attributeName => $data) {
             $content .= '<tr><td>' . $data['attributeLabel'] . '</td>';
             $content .= '<td>' . $attributeName . '</td>';
             $canBeUsedInMathExpression = Zurmo::t('DesignerModule', 'No');
             if (in_array($attributeName, array_keys($attributeDataNumerOrCurrency))) {
                 $canBeUsedInMathExpression = Zurmo::t('DesignerModule', 'Yes');
             }
             $content .= '<td>' . $canBeUsedInMathExpression . '</td></tr>';
         }
         $content .= '</table>';
     } else {
         $content .= '<span class="error">' . Zurmo::t('DesignerModule', 'There are no fields in this module to be used in an expression.');
         $content .= '</span>';
     }
     $qtip = new ZurmoTip();
     $qtip->addQTip("#formula-tooltip");
     return ZurmoHtml::tag('div', array('class' => 'field-instructions'), $content);
 }
 protected function getModelAttributes()
 {
     $modelAttributesAdapter = new ModelAttributesAdapter($this->model->getModel());
     return $modelAttributesAdapter->getAttributes();
 }
Ejemplo n.º 9
0
 /**
  * @depends testIsStandardAttributeRequiredByDefault
  */
 public function testSetMetadataFormLayoutWithAndWithOutRequiredCustomFieldForDropDownDependencyAttribute()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $education = array('aaaa', 'bbbb');
     $education_labels = array('fr' => array('aaaa fr', 'bbbb fr'), 'de' => array('aaaa de', 'bbbb de'));
     $educationFieldData = CustomFieldData::getByName('Education');
     $educationFieldData->serializedData = serialize($education);
     $this->assertTrue($educationFieldData->save());
     $attributeForm = new DropDownAttributeForm();
     $attributeForm->attributeName = 'testEducation';
     $attributeForm->attributeLabels = array('de' => 'Test Education 2 de', 'en' => 'Test Education 2 en', 'es' => 'Test Education 2 es', 'fr' => 'Test Education 2 fr', 'it' => 'Test Education 2 it');
     $attributeForm->isAudited = true;
     $attributeForm->isRequired = false;
     $attributeForm->customFieldDataData = $education;
     $attributeForm->customFieldDataName = 'Education';
     $attributeForm->customFieldDataLabels = $education_labels;
     $modelAttributesAdapterClassName = $attributeForm::getModelAttributeAdapterNameForSavingAttributeFormData();
     $adapter = new $modelAttributesAdapterClassName(new Account());
     try {
         $adapter->setAttributeMetadataFromForm($attributeForm);
     } catch (FailedDatabaseSchemaChangeException $e) {
         echo $e->getMessage();
         $this->fail();
     }
     $stream = array('aaa1', 'aaa2', 'bbb1', 'bbb2');
     $stream_labels = array('fr' => array('aaa1 fr', 'aaa2 fr', 'bbb1 fr', 'bbb2 fr'), 'de' => array('aaa1 de', 'aaa2 de', 'bbb1 de', 'bbb2 de'));
     $streamFieldData = CustomFieldData::getByName('Stream');
     $streamFieldData->serializedData = serialize($stream);
     $this->assertTrue($streamFieldData->save());
     $attributeForm = new DropDownAttributeForm();
     $attributeForm->attributeName = 'testStream';
     $attributeForm->attributeLabels = array('de' => 'Test Stream 2 de', 'en' => 'Test Stream 2 en', 'es' => 'Test Stream 2 es', 'fr' => 'Test Stream 2 fr', 'it' => 'Test Stream 2 it');
     $attributeForm->isAudited = true;
     $attributeForm->isRequired = true;
     $attributeForm->customFieldDataData = $stream;
     $attributeForm->customFieldDataName = 'Stream';
     $attributeForm->customFieldDataLabels = $stream_labels;
     $modelAttributesAdapterClassName = $attributeForm::getModelAttributeAdapterNameForSavingAttributeFormData();
     $adapter = new $modelAttributesAdapterClassName(new Account());
     try {
         $adapter->setAttributeMetadataFromForm($attributeForm);
     } catch (FailedDatabaseSchemaChangeException $e) {
         echo $e->getMessage();
         $this->fail();
     }
     $attributeName = "testQualification";
     $attributeForm = new DropDownDependencyAttributeForm();
     $attributeForm->attributeName = $attributeName;
     $attributeForm->attributeLabels = array('de' => 'Test Qualification Value 2 de', 'en' => 'Test Qualification Value 2 en', 'es' => 'Test Qualification Value 2 es', 'fr' => 'Test Qualification Value 2 fr', 'it' => 'Test Qualification Value 2 it');
     $attributeForm->mappingData = array(array('attributeName' => 'testEducation'), array('attributeName' => 'testStream', 'valuesToParentValues' => array('aaa1' => 'aaaa', 'aaa2' => 'aaaa', 'bbb1' => 'bbbb', 'bbb2' => 'bbbb')));
     $modelAttributesAdapterClassName = $attributeForm::getModelAttributeAdapterNameForSavingAttributeFormData();
     $adapter = new $modelAttributesAdapterClassName(new Account());
     try {
         $adapter->setAttributeMetadataFromForm($attributeForm);
     } catch (FailedDatabaseSchemaChangeException $e) {
         echo $e->getMessage();
         $this->fail();
     }
     $layout = array('panels' => array(array('rows' => array(array('cells' => array(array('element' => 'createdDateTime'), array('element' => 'modifiedDateTime'))), array('cells' => array(array('element' => 'owner'), array('element' => 'name'))), array('cells' => array(array('element' => 'industry')))))));
     $layout2 = array('panels' => array(array('rows' => array(array('cells' => array(array('element' => 'createdDateTime'), array('element' => 'modifiedDateTime'))), array('cells' => array(array('element' => 'owner'), array('element' => 'name'))), array('cells' => array(array('element' => 'industry'))), array('cells' => array(array('element' => 'testEducationCstm'), array('element' => 'testStreamCstm')))))));
     $model = new Account();
     $editableMetadata = AccountEditAndDetailsView::getMetadata();
     $modelAttributesAdapter = new ModelAttributesAdapter($model);
     $attributesLayoutAdapter = AttributesLayoutAdapterUtil::makeAttributesLayoutAdapter($modelAttributesAdapter->getAttributes(), new EditAndDetailsViewDesignerRules(), $editableMetadata);
     $adapter = new LayoutMetadataAdapter('AccountEditAndDetailsView', 'AccountsModule', $editableMetadata, new EditAndDetailsViewDesignerRules(), $attributesLayoutAdapter->getPlaceableLayoutAttributes(), $attributesLayoutAdapter->getRequiredDerivedLayoutAttributeTypes());
     $this->assertFalse($adapter->setMetadataFromLayout($layout, array()));
     $this->assertNotEmpty($adapter->getMessage());
     $this->assertEquals($adapter->getMessage(), 'All required fields must be placed in this layout.');
     $this->assertTrue($adapter->setMetadataFromLayout($layout2, array()));
     $this->assertEquals($adapter->getMessage(), 'Layout saved successfully.');
 }
 /**
  * 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;
 }
Ejemplo n.º 11
0
 /**
  * Gets model attributes for selected module.
  * @param string $moduleClassName
  * @return array
  */
 public static function getModelAttributesForSelectedModule($moduleClassName)
 {
     $modelClassName = $moduleClassName::getPrimaryModelName();
     $adapter = new ModelAttributesAdapter(new $modelClassName(false));
     $attributes = $adapter->getAttributes();
     $selectedAttributes = array();
     foreach ($attributes as $attribute => $value) {
         if ($value['elementType'] == 'DateTime' || $value['elementType'] == 'Date') {
             $selectedAttributes[$attribute] = $value['attributeLabel'];
         }
     }
     return $selectedAttributes;
 }
 protected static function isAttribute($expression, $modelClassName)
 {
     $model = new $modelClassName(false);
     $adapter = new ModelAttributesAdapter($model);
     $attributeNames = array_keys($adapter->getAttributes());
     if (in_array($expression, $attributeNames)) {
         return true;
     }
     return false;
 }