Пример #1
0
 /**
  * @depends testExistingAttributeWillAlwaysSaveAsValidLength
  */
 public function testResolveMetadataFromSelectedListAttributes()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $model = new Account();
     $modelAttributesAdapter = new ModelAttributesAdapter($model);
     $editableMetadata = AccountsListView::getMetadata();
     $attributesLayoutAdapter = AttributesLayoutAdapterUtil::makeAttributesLayoutAdapter($modelAttributesAdapter->getAttributes(), new ListViewDesignerRules(), $editableMetadata);
     $adapter = new LayoutMetadataAdapter('AccountsListView', 'AccountsModule', $editableMetadata, new ListViewDesignerRules(), $attributesLayoutAdapter->getPlaceableLayoutAttributes(), $attributesLayoutAdapter->getRequiredDerivedLayoutAttributeTypes());
     $selectedListAttributes = array('name', 'officePhone');
     $data = $adapter->resolveMetadataFromSelectedListAttributes('AccountsListView', $selectedListAttributes);
     $compareMetadata = array('nonPlaceableAttributeNames' => array('account'), 'panels' => array(array('rows' => array(array('cells' => array(array('elements' => array(array('attributeName' => 'name', 'type' => 'Text', 'isLink' => true))))), array('cells' => array(array('elements' => array(array('attributeName' => 'officePhone', 'type' => 'Phone')))))))));
     $this->assertEquals($compareMetadata, $data['global']);
 }
Пример #2
0
 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;
 }