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;
 }
예제 #2
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();
 }
예제 #5
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.');
 }
예제 #6
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;
 }