public function testMakeCollectionByAttributeImportRules()
 {
     //Contact
     $attributeImportRules = new ContactAttributeImportRules(new ImportModelTestItem(), 'hasOne');
     $collection = MappingRuleFormAndElementTypeUtil::makeCollectionByAttributeImportRules($attributeImportRules, 'hasOne', 'importColumn');
     $this->assertEquals(2, count($collection));
     $this->assertEquals('ImportMappingRuleDefaultModelNameId', $collection[0]['elementType']);
     $this->assertEquals('DefaultModelNameIdMappingRuleForm', get_class($collection[0]['mappingRuleForm']));
     $this->assertEquals('ImportMappingRelatedModelValueTypeDropDown', $collection[1]['elementType']);
     $this->assertEquals('RelatedModelValueTypeMappingRuleForm', get_class($collection[1]['mappingRuleForm']));
     //Contact Derived
     $attributeImportRules = new ContactDerivedAttributeImportRules(new ImportModelTestItem(), 'contactDerived');
     $collection = MappingRuleFormAndElementTypeUtil::makeCollectionByAttributeImportRules($attributeImportRules, 'contactDerived', 'importColumn');
     $this->assertEquals(2, count($collection));
     $this->assertEquals('ImportMappingRuleDefaultModelNameId', $collection[0]['elementType']);
     $this->assertEquals('DefaultModelNameIdDerivedAttributeMappingRuleForm', get_class($collection[0]['mappingRuleForm']));
     $this->assertEquals('ImportMappingModelIdValueTypeDropDown', $collection[1]['elementType']);
     $this->assertEquals('IdValueTypeMappingRuleForm', get_class($collection[1]['mappingRuleForm']));
     //Contact State
     ContactsModule::loadStartingData();
     $attributeImportRules = new ContactStateAttributeImportRules(new ImportModelTestItem(), 'state');
     $collection = MappingRuleFormAndElementTypeUtil::makeCollectionByAttributeImportRules($attributeImportRules, 'state', 'importColumn');
     $this->assertEquals(1, count($collection));
     $this->assertEquals('ImportMappingRuleContactStatesDropDown', $collection[0]['elementType']);
     $this->assertEquals('DefaultContactStateIdMappingRuleForm', get_class($collection[0]['mappingRuleForm']));
 }
 public function testMakeCollectionByAttributeImportRules()
 {
     //Leads
     ContactsModule::loadStartingData();
     $attributeImportRules = new LeadStateAttributeImportRules(new ImportModelTestItem(), 'state');
     $collection = MappingRuleFormAndElementTypeUtil::makeCollectionByAttributeImportRules($attributeImportRules, 'state', 'importColumn');
     $this->assertEquals(1, count($collection));
     $this->assertEquals('ImportMappingRuleContactStatesDropDown', $collection[0]['elementType']);
     $this->assertEquals('DefaultLeadStateIdMappingRuleForm', get_class($collection[0]['mappingRuleForm']));
 }
 public function testMakeCollectionByAttributeImportRules()
 {
     //User
     $attributeImportRules = new UserAttributeImportRules(new ImportModelTestItem(), 'owner');
     $collection = MappingRuleFormAndElementTypeUtil::makeCollectionByAttributeImportRules($attributeImportRules, 'owner', 'importColumn');
     $this->assertEquals(2, count($collection));
     $this->assertEquals('ImportMappingRuleDefaultModelNameId', $collection[0]['elementType']);
     $this->assertEquals('DefaultModelNameIdMappingRuleForm', get_class($collection[0]['mappingRuleForm']));
     $this->assertEquals('ImportMappingUserValueTypeDropDown', $collection[1]['elementType']);
     $this->assertEquals('UserValueTypeModelAttributeMappingRuleForm', get_class($collection[1]['mappingRuleForm']));
     //User Password
     $attributeImportRules = new PasswordAttributeImportRules(new User(), 'hash');
     $collection = MappingRuleFormAndElementTypeUtil::makeCollectionByAttributeImportRules($attributeImportRules, 'hash', 'importColumn');
     $this->assertEquals(1, count($collection));
     $this->assertEquals('Text', $collection[0]['elementType']);
     $this->assertEquals('PasswordDefaultValueModelAttributeMappingRuleForm', get_class($collection[0]['mappingRuleForm']));
 }
 public function testMakeCollectionByAttributeImportRules()
 {
     //Opportunity
     $attributeImportRules = new OpportunityAttributeImportRules(new ImportModelTestItem(), 'hasOne');
     $collection = MappingRuleFormAndElementTypeUtil::makeCollectionByAttributeImportRules($attributeImportRules, 'hasOne', 'importColumn');
     $this->assertEquals(2, count($collection));
     $this->assertEquals('ImportMappingRuleDefaultModelNameId', $collection[0]['elementType']);
     $this->assertEquals('DefaultModelNameIdMappingRuleForm', get_class($collection[0]['mappingRuleForm']));
     $this->assertEquals('ImportMappingModelIdValueTypeDropDown', $collection[1]['elementType']);
     $this->assertEquals('IdValueTypeMappingRuleForm', get_class($collection[1]['mappingRuleForm']));
     //OpportunityDerived
     $attributeImportRules = new OpportunityDerivedAttributeImportRules(new ImportModelTestItem(), 'opportunityDerived');
     $collection = MappingRuleFormAndElementTypeUtil::makeCollectionByAttributeImportRules($attributeImportRules, 'opportunityDerived', 'importColumn');
     $this->assertEquals(2, count($collection));
     $this->assertEquals('ImportMappingRuleDefaultModelNameId', $collection[0]['elementType']);
     $this->assertEquals('DefaultModelNameIdDerivedAttributeMappingRuleForm', get_class($collection[0]['mappingRuleForm']));
     $this->assertEquals('ImportMappingModelIdValueTypeDropDown', $collection[1]['elementType']);
     $this->assertEquals('IdValueTypeMappingRuleForm', get_class($collection[1]['mappingRuleForm']));
 }
 /**
  * @param string $columnName
  * @param string $attributeIndexOrDerivedType
  * @param string $importRulesType
  * @param string $columnType
  * @param array $mappingRuleFormsAndElementTypes
  * @return string
  */
 public function renderMappingRulesElements($columnName, $attributeIndexOrDerivedType, $importRulesType, $columnType, $mappingRuleFormsAndElementTypes)
 {
     assert('is_string($columnName)');
     assert('is_string($attributeIndexOrDerivedType) || $attributeIndexOrDerivedType == null');
     assert('is_string($importRulesType)');
     assert('$columnType == "importColumn" || $columnType == "extraColumn"');
     assert('is_array($mappingRuleFormsAndElementTypes) || $mappingRuleFormsAndElementTypes == null');
     $content = null;
     $multipleMappingRulesCssClass = null;
     if ($attributeIndexOrDerivedType != null) {
         if ($mappingRuleFormsAndElementTypes == null) {
             $attributeImportRules = AttributeImportRulesFactory::makeByImportRulesTypeAndAttributeIndexOrDerivedType($importRulesType, $attributeIndexOrDerivedType);
             $mappingRuleFormsAndElementTypes = MappingRuleFormAndElementTypeUtil::makeCollectionByAttributeImportRules($attributeImportRules, $attributeIndexOrDerivedType, $columnType);
         }
         if (count($mappingRuleFormsAndElementTypes) > 0) {
             $title = Zurmo::t('ImportModule', 'Rules');
         } else {
             $title = null;
         }
         $content .= ZurmoHtml::tag('h4', array(), $title);
         foreach ($mappingRuleFormsAndElementTypes as $notUsed => $ruleFormAndElementType) {
             $mappingRuleForm = $ruleFormAndElementType['mappingRuleForm'];
             $elementClassName = $ruleFormAndElementType['elementType'] . 'Element';
             $classToEvaluate = new ReflectionClass($elementClassName);
             if ($classToEvaluate->implementsInterface('DerivedElementInterface')) {
                 $attributeName = 'null';
             } else {
                 $attributeName = $mappingRuleForm::getAttributeName();
             }
             $params = array();
             $params['inputPrefix'] = array($this->mappingFormModelClassName, $columnName, 'mappingRulesData', get_class($mappingRuleForm));
             $element = new $elementClassName($mappingRuleForm, $attributeName, $this->form, $params);
             $element->editableTemplate = '<div>{label}{content}{error}</div>';
             $content .= $element->render();
         }
     }
     $subDivsCssClass = 'has' . count($mappingRuleFormsAndElementTypes);
     $content = ZurmoHtml::tag('div', array('id' => self::getMappingRulesDivIdByColumnName($columnName), 'class' => 'mapping-rules ' . $subDivsCssClass), $content);
     // Not Coding Standard
     return $content;
 }
 public function testResolveAttributeIndexAndTheFormsAreUsingTheCorrectModelClassNameAndAttributeName()
 {
     $attributeImportRules = new EmailAttributeImportRules(new Email(), 'emailAddress');
     $collection = MappingRuleFormAndElementTypeUtil::makeCollectionByAttributeImportRules($attributeImportRules, 'primaryEmail__emailAddress', 'importColumn');
     $this->assertEquals(1, count($collection));
     $this->assertEquals('Text', $collection[0]['elementType']);
     $this->assertEquals('DefaultValueModelAttributeMappingRuleForm', get_class($collection[0]['mappingRuleForm']));
     $this->assertEquals('Email', static::getReflectedPropertyValue($collection[0]['mappingRuleForm'], 'modelClassName'));
     $this->assertEquals('emailAddress', static::getReflectedPropertyValue($collection[0]['mappingRuleForm'], 'modelAttributeName'));
 }
 /**
  * @param string $columnName
  * @param string $attributeIndexOrDerivedType
  * @param string $importRulesType
  * @param string $columnType
  * @param array $mappingRuleFormsAndElementTypes
  * @return string
  */
 public function renderMappingRulesElements($columnName, $attributeIndexOrDerivedType, $importRulesType, $columnType, $mappingRuleFormsAndElementTypes)
 {
     assert('is_string($columnName)');
     assert('is_string($attributeIndexOrDerivedType) || $attributeIndexOrDerivedType == null');
     assert('is_string($importRulesType)');
     assert('$columnType == "importColumn" || $columnType == "extraColumn"');
     assert('is_array($mappingRuleFormsAndElementTypes) || $mappingRuleFormsAndElementTypes == null');
     $content = null;
     $multipleMappingRulesCssClass = null;
     if ($attributeIndexOrDerivedType != null) {
         if ($mappingRuleFormsAndElementTypes == null) {
             $attributeImportRules = AttributeImportRulesFactory::makeByImportRulesTypeAndAttributeIndexOrDerivedType($importRulesType, $attributeIndexOrDerivedType);
             $mappingRuleFormsAndElementTypes = MappingRuleFormAndElementTypeUtil::makeCollectionByAttributeImportRules($attributeImportRules, $attributeIndexOrDerivedType, $columnType);
         }
         if (count($mappingRuleFormsAndElementTypes) > 0) {
             $title = Zurmo::t('ImportModule', 'Rules');
         } else {
             $title = null;
         }
         $content .= ZurmoHtml::tag('h4', array(), $title);
         foreach ($mappingRuleFormsAndElementTypes as $notUsed => $ruleFormAndElementType) {
             $mappingRuleForm = $ruleFormAndElementType['mappingRuleForm'];
             $elementClassName = $ruleFormAndElementType['elementType'] . 'Element';
             $classToEvaluate = new ReflectionClass($elementClassName);
             if ($classToEvaluate->implementsInterface('DerivedElementInterface')) {
                 $attributeName = 'null';
             } else {
                 $attributeName = $mappingRuleForm::getAttributeName();
             }
             $params = array();
             $params['inputPrefix'] = array($this->mappingFormModelClassName, $columnName, 'mappingRulesData', get_class($mappingRuleForm));
             $element = new $elementClassName($mappingRuleForm, $attributeName, $this->form, $params);
             $element->editableTemplate = '<div>{label}{content}{error}</div>';
             // In case of TagCloud or MultiSelectDropbox inform user that in cas of updating existing model, original values will be overwritten.
             // Prepend this text before content, so it will appear before "Rules" title
             if ($element instanceof ImportMappingRuleDefaultMultiSelectDropDownFormElement) {
                 $content = $this->resolveTextAboutOverwritingMultiselectOrTagCloudValues($columnName . $attributeIndexOrDerivedType) . $content;
             }
             $content .= $element->render();
         }
     }
     $subDivsCssClass = 'has' . count($mappingRuleFormsAndElementTypes);
     $content = ZurmoHtml::tag('div', array('id' => self::getMappingRulesDivIdByColumnName($columnName), 'class' => 'mapping-rules ' . $subDivsCssClass), $content);
     // Not Coding Standard
     return $content;
 }
 public function renderMappingRulesElements($columnName, $attributeIndexOrDerivedType, $importRulesType, $columnType, $mappingRuleFormsAndElementTypes)
 {
     assert('is_string($columnName)');
     assert('is_string($attributeIndexOrDerivedType) || $attributeIndexOrDerivedType == null');
     assert('is_string($importRulesType)');
     assert('$columnType == "importColumn" || $columnType == "extraColumn"');
     assert('is_array($mappingRuleFormsAndElementTypes) || $mappingRuleFormsAndElementTypes == null');
     $content = '<div id="' . self::getMappingRulesDivIdByColumnName($columnName) . '" class="mapping-rules">';
     if ($attributeIndexOrDerivedType != null) {
         if ($mappingRuleFormsAndElementTypes == null) {
             $attributeImportRules = AttributeImportRulesFactory::makeByImportRulesTypeAndAttributeIndexOrDerivedType($importRulesType, $attributeIndexOrDerivedType);
             $mappingRuleFormsAndElementTypes = MappingRuleFormAndElementTypeUtil::makeCollectionByAttributeImportRules($attributeImportRules, $attributeIndexOrDerivedType, $columnType);
         }
         foreach ($mappingRuleFormsAndElementTypes as $notUsed => $ruleFormAndElementType) {
             $mappingRuleForm = $ruleFormAndElementType['mappingRuleForm'];
             $elementClassName = $ruleFormAndElementType['elementType'] . 'Element';
             $classToEvaluate = new ReflectionClass($elementClassName);
             if ($classToEvaluate->implementsInterface('DerivedElementInterface')) {
                 $attributeName = 'null';
             } else {
                 $attributeName = $mappingRuleForm::getAttributeName();
             }
             $params = array();
             $params['inputPrefix'] = array($this->mappingFormModelClassName, $columnName, 'mappingRulesData', get_class($mappingRuleForm));
             $element = new $elementClassName($mappingRuleForm, $attributeName, $this->form, $params);
             $content .= '<table><tbody><tr>';
             $content .= $element->render();
             $content .= '</tr></tbody></table>';
         }
     }
     $content .= '</div>';
     return $content;
 }