Example #1
0
 public static function getCellElement($viewClassName, $modelClassName, $elementName)
 {
     assert('is_string($viewClassName)');
     assert('is_string($modelClassName) && is_subclass_of($modelClassName, "RedBeanModel")');
     assert('is_string($elementName)');
     $editableMetadata = $viewClassName::getMetadata();
     $designerRulesType = $viewClassName::getDesignerRulesType();
     $designerRulesClassName = $designerRulesType . 'DesignerRules';
     $designerRules = new $designerRulesClassName();
     $modelAttributesAdapter = DesignerModelToViewUtil::getModelAttributesAdapter($viewClassName, $modelClassName);
     $derivedAttributesAdapter = new DerivedAttributesAdapter($modelClassName);
     $attributeCollection = array_merge($modelAttributesAdapter->getAttributes(), $derivedAttributesAdapter->getAttributes());
     $attributesLayoutAdapter = AttributesLayoutAdapterUtil::makeAttributesLayoutAdapter($attributeCollection, $designerRules, $editableMetadata);
     $derivedAttributes = $attributesLayoutAdapter->getAvailableDerivedAttributeTypes();
     $placeableLayoutAttributes = $attributesLayoutAdapter->getPlaceableLayoutAttributes();
     if (in_array($elementName, $derivedAttributes)) {
         $element = array('attributeName' => 'null', 'type' => $elementName);
         // Not Coding Standard
     } elseif (isset($placeableLayoutAttributes[$elementName]) && $placeableLayoutAttributes[$elementName]['elementType'] == 'DropDownDependency') {
         throw new NotSupportedException();
     } elseif (isset($placeableLayoutAttributes[$elementName])) {
         $element = array('attributeName' => $elementName, 'type' => $placeableLayoutAttributes[$elementName]['elementType']);
     } else {
         throw new NotSupportedException();
     }
     return $designerRules->formatSavableElement($element, $viewClassName);
 }
 /**
  * @param string $viewClassName
  * @param string $modelClassName
  * @param DesignerRules $designerRules
  * @return AttributesLayoutAdapter
  */
 public static function makeByViewAndModelAndDesignerRules($viewClassName, $modelClassName, DesignerRules $designerRules)
 {
     assert('is_string($viewClassName)');
     assert('is_string($modelClassName)');
     $editableMetadata = $viewClassName::getMetadata();
     $modelAttributesAdapter = DesignerModelToViewUtil::getModelAttributesAdapter($viewClassName, $modelClassName);
     $attributeCollection = $modelAttributesAdapter->getAttributes();
     $attributesLayoutAdapter = AttributesLayoutAdapterUtil::makeAttributesLayoutAdapter($attributeCollection, $designerRules, $editableMetadata);
     return $attributesLayoutAdapter;
 }
 public function testGetEffectivePlacedAttributes()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $viewClassName = 'ContactEditAndDetailsView';
     $modelClassName = 'Contact';
     $designerRules = DesignerRulesFactory::createDesignerRulesByView($viewClassName);
     $attributesLayoutAdapter = AttributesLayoutAdapterUtil::makeByViewAndModelAndDesignerRules($viewClassName, $modelClassName, $designerRules);
     $this->assertFalse(in_array('industry', $attributesLayoutAdapter->getEffectivePlacedAttributes()));
     $this->assertTrue(in_array('firstName', $attributesLayoutAdapter->getEffectivePlacedAttributes()));
     $this->assertTrue(in_array('lastName', $attributesLayoutAdapter->getEffectivePlacedAttributes()));
     $this->assertTrue(in_array('source', $attributesLayoutAdapter->getEffectivePlacedAttributes()));
 }
 public function __construct($viewClassName, $moduleClassName)
 {
     assert('is_string($viewClassName)');
     assert('is_string($moduleClassName)');
     $modelClassName = $moduleClassName::getPrimaryModelName();
     $editableMetadata = $viewClassName::getMetadata();
     $designerRulesType = $viewClassName::getDesignerRulesType();
     $designerRulesClassName = $designerRulesType . 'DesignerRules';
     $designerRules = new $designerRulesClassName();
     $modelAttributesAdapter = DesignerModelToViewUtil::getModelAttributesAdapter($viewClassName, $modelClassName);
     $derivedAttributesAdapter = new DerivedAttributesAdapter($modelClassName);
     $attributeCollection = array_merge($modelAttributesAdapter->getAttributes(), $derivedAttributesAdapter->getAttributes());
     $attributesLayoutAdapter = AttributesLayoutAdapterUtil::makeAttributesLayoutAdapter($attributeCollection, $designerRules, $editableMetadata);
     $this->layoutMetadataAdapter = new LayoutMetadataAdapter($viewClassName, $moduleClassName, $editableMetadata, $designerRules, $attributesLayoutAdapter->getPlaceableLayoutAttributes(), $attributesLayoutAdapter->getRequiredDerivedLayoutAttributeTypes());
     $this->designerLayoutAttributes = $attributesLayoutAdapter->makeDesignerLayoutAttributes();
     $this->viewClassName = $viewClassName;
 }
 /**
  * @param string $modelClassName
  * @param string $attributeName
  */
 public static function resolveToRemoveAttributeAsMissingRequiredAttribute($modelClassName, $attributeName)
 {
     assert('is_string($modelClassName)');
     assert('is_string($attributeName)');
     $modules = Module::getModuleObjects();
     foreach ($modules as $module) {
         try {
             if ($module::getPrimaryModelName() == $modelClassName) {
                 $viewClassNames = $module::getViewClassNames();
                 foreach ($viewClassNames as $viewClassName) {
                     $classToEvaluate = new ReflectionClass($viewClassName);
                     if (is_subclass_of($viewClassName, 'MetadataView') && !$classToEvaluate->isAbstract() && $viewClassName::getDesignerRulesType() != null) {
                         $designerRules = DesignerRulesFactory::createDesignerRulesByView($viewClassName);
                         if ($designerRules->allowEditInLayoutTool() && $designerRules->requireAllRequiredFieldsInLayout()) {
                             $attributesLayoutAdapter = AttributesLayoutAdapterUtil::makeByViewAndModelAndDesignerRules($viewClassName, $modelClassName, $designerRules);
                             if (!in_array($attributeName, $attributesLayoutAdapter->getEffectivePlacedAttributes())) {
                                 self::removeAttributeAsMissingRequiredAttribute(get_class($module), $viewClassName);
                             }
                         }
                     }
                 }
             }
         } catch (NotSupportedException $e) {
         }
     }
 }
 public static function getMetadataByWebForm(ContactWebForm $contactWebForm)
 {
     assert('$contactWebForm instanceof ContactWebForm');
     $contactWebFormAttributes = unserialize($contactWebForm->serializedData);
     $viewClassName = 'ContactExternalEditAndDetailsView';
     $moduleClassName = 'ContactsModule';
     $modelClassName = $moduleClassName::getPrimaryModelName();
     $editableMetadata = $viewClassName::getMetadata();
     $designerRules = new EditAndDetailsViewDesignerRules();
     $modelAttributesAdapter = DesignerModelToViewUtil::getModelAttributesAdapter($viewClassName, $modelClassName);
     $derivedAttributesAdapter = new DerivedAttributesAdapter($modelClassName);
     $attributeCollection = array_merge($modelAttributesAdapter->getAttributes(), $derivedAttributesAdapter->getAttributes());
     $attributesLayoutAdapter = AttributesLayoutAdapterUtil::makeAttributesLayoutAdapter($attributeCollection, $designerRules, $editableMetadata);
     $layoutMetadataAdapter = new LayoutMetadataAdapter($viewClassName, $moduleClassName, $editableMetadata, $designerRules, $attributesLayoutAdapter->getPlaceableLayoutAttributes(), $attributesLayoutAdapter->getRequiredDerivedLayoutAttributeTypes());
     $metadata = $layoutMetadataAdapter->resolveMetadataFromSelectedListAttributes($viewClassName, $contactWebFormAttributes);
     foreach ($metadata['global']['panels'][0]['rows'] as $index => $data) {
         if ($data['cells'][0]['elements'][0]['type'] == 'EmailAddressInformation') {
             $metadata['global']['panels'][0]['rows'][$index]['cells'][0]['elements'][0]['hideOptOut'] = true;
         }
     }
     return $metadata;
 }
Example #7
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.');
 }
Example #8
0
 public function actionLayoutEdit()
 {
     assert('!empty($_GET["moduleClassName"])');
     assert('!empty($_GET["viewClassName"])');
     $viewClassName = $_GET['viewClassName'];
     $moduleClassName = $_GET['moduleClassName'];
     $modelClassName = $moduleClassName::getPrimaryModelName();
     $editableMetadata = $viewClassName::getMetadata();
     $designerRulesType = $viewClassName::getDesignerRulesType();
     $designerRulesClassName = $designerRulesType . 'DesignerRules';
     $designerRules = new $designerRulesClassName();
     $modelAttributesAdapter = DesignerModelToViewUtil::getModelAttributesAdapter($viewClassName, $modelClassName);
     $derivedAttributesAdapter = new DerivedAttributesAdapter($modelClassName);
     $attributeCollection = array_merge($modelAttributesAdapter->getAttributes(), $derivedAttributesAdapter->getAttributes());
     $attributesLayoutAdapter = AttributesLayoutAdapterUtil::makeAttributesLayoutAdapter($attributeCollection, $designerRules, $editableMetadata);
     if (isset($_POST['save'])) {
         $layoutMetadataAdapter = new LayoutMetadataAdapter($viewClassName, $moduleClassName, $editableMetadata, $designerRules, $attributesLayoutAdapter->getPlaceableLayoutAttributes(), $attributesLayoutAdapter->getRequiredDerivedLayoutAttributeTypes());
         $savableMetadata = array();
         if ($designerRules->canConfigureLayoutPanelsType() && !PanelsDisplayTypeLayoutMetadataUtil::populateSaveableMetadataFromPostData($savableMetadata, $_POST['LayoutPanelsTypeForm'])) {
             echo CJSON::encode(array('message' => Zurmo::t('DesignerModule', 'Invalid panel configuration type'), 'type' => 'error'));
         } elseif ($layoutMetadataAdapter->setMetadataFromLayout(ArrayUtil::getArrayValue($_POST, 'layout'), $savableMetadata)) {
             if ($designerRules->requireAllRequiredFieldsInLayout()) {
                 RequiredAttributesValidViewUtil::setAsContainingRequiredAttributes($moduleClassName, $viewClassName);
             }
             echo CJSON::encode(array('message' => $layoutMetadataAdapter->getMessage(), 'type' => 'message'));
         } else {
             echo CJSON::encode(array('message' => $layoutMetadataAdapter->getMessage(), 'type' => 'error'));
         }
         Yii::app()->end(0, false);
     }
     $title = Zurmo::t('DesignerModule', 'Edit Layout') . ': ' . $designerRules->resolveDisplayNameByView($_GET['viewClassName']);
     $breadcrumbLinks = array($moduleClassName::getModuleLabelByTypeAndLanguage('Plural') . ': ' . Zurmo::t('DesignerModule', 'Layouts') => array('default/moduleLayoutsList', 'moduleClassName' => $_GET['moduleClassName']), $title);
     $canvasView = new MetadataViewEditView($this->getId(), $this->getModule()->getId(), $_GET['moduleClassName'], $_GET['viewClassName'], $editableMetadata, $designerRules, $attributeCollection, $attributesLayoutAdapter->makeDesignerLayoutAttributes(), $title);
     $view = new DesignerPageView(ZurmoDefaultAdminViewUtil::makeViewWithBreadcrumbsForCurrentUser($this, $canvasView, $breadcrumbLinks, 'DesignerBreadCrumbView'));
     echo $view->render();
 }