public function testGetSetAndMethods() { $availableCustomFieldAttributes = array('a', 'test', 'b'); $mappingData = array('Item 1' => 'parentItem1', 'Item2' => null); $customFieldData = CustomFieldData::getByName('Items'); $mapping = new DropDownDependencyCustomFieldMapping(3, 'test', $availableCustomFieldAttributes, $customFieldData, $mappingData); $this->assertEquals(true, $mapping->allowsAttributeSelection()); $mapping->doNotAllowAttributeSelection(); $this->assertEquals(false, $mapping->allowsAttributeSelection()); $this->assertEquals('Level: 4', $mapping->getTitle()); $this->assertEquals(3, $mapping->getPosition()); $this->assertEquals('test', $mapping->getAttributeName()); $this->assertEquals($availableCustomFieldAttributes, $mapping->getAvailableCustomFieldAttributes()); $this->assertEquals('First select level 3', $mapping->getSelectHigherLevelFirstMessage()); $this->assertEquals($customFieldData, $mapping->getCustomFieldData()); $this->assertEquals('parentItem1', $mapping->getMappingDataSelectedParentValueByValue('Item 1')); $this->assertEquals(null, $mapping->getMappingDataSelectedParentValueByValue('Item 2')); }
/** * Given an array of mapping data, create a collection of DropDownDependencyCustomFieldMapping objects. * Include the unmapped objects as well. For example, if the mapping data only has mappings for 2 attributes, * based on the @see $this->maxDepth, it should make additional DropDownDependencyCustomFieldMapping if required. * @param array $mappingData * @return array of DropDownDependencyCustomFieldMapping objects. */ public function makeDependencyCollectionByMappingData($mappingData) { assert('is_array($mappingData)'); $collection = array(); $depthCount = 0; $availableCustomFieldAttributes = self::getCustomFieldAttributesNotUsedInOtherDependencyAttributes(); $parentAttributeName = null; foreach ($mappingData as $dependencyData) { if ($dependencyData['attributeName'] == null) { break; } self::resolveAvailableCustomFieldAttributes($availableCustomFieldAttributes, $parentAttributeName); $valuesToParentValues = self::resolveValuesToParentValues($dependencyData); $dependencyMapping = new DropDownDependencyCustomFieldMapping($depthCount, $dependencyData['attributeName'], $availableCustomFieldAttributes, self::getAttributeCustomFieldData($dependencyData['attributeName']), $valuesToParentValues); $collection[] = $dependencyMapping; $parentAttributeName = $dependencyData['attributeName']; $depthCount++; } if ($this->maxDepth > $depthCount) { self::resolveAvailableCustomFieldAttributes($availableCustomFieldAttributes, $parentAttributeName); $allowSelection = true; for ($i = $depthCount; $i < $this->maxDepth; $i++) { $dependencyMapping = new DropDownDependencyCustomFieldMapping($depthCount, null, $availableCustomFieldAttributes, null, null); if (!$allowSelection) { $dependencyMapping->doNotAllowAttributeSelection(); } $collection[] = $dependencyMapping; $allowSelection = false; $depthCount++; } } return $collection; }
protected function renderValuesToParentValuesMappingDropDownContent(DropDownDependencyCustomFieldMapping $parentMapping, $position, $value, $valuePosition, $selectedParentValue) { assert('is_int($position)'); assert('is_string($value)'); assert('is_int($valuePosition)'); assert('is_string($selectedParentValue) || $selectedParentValue == null'); $inputName = $this->formName . '[mappingData][' . $position . '][valuesToParentValues][' . $value . ']'; $inputId = $this->formName . '_mappingData_' . $position . '_valuesToParentValues_' . $valuePosition; $htmlOptions = array(); $htmlOptions['id'] = $inputId; $htmlOptions['empty'] = Zurmo::t('Core', '(None)'); $dataAndLabels = CustomFieldDataUtil::getDataIndexedByDataAndTranslatedLabelsByLanguage($parentMapping->getCustomFieldData(), Yii::app()->language); $content = ZurmoHtml::dropDownList($inputName, $selectedParentValue, $dataAndLabels, $htmlOptions); return $content; }