protected function renderNextPageLinkLabel()
 {
     $importRulesClassName = ImportRulesUtil::getImportRulesClassNameByType($this->model->importRulesType);
     if (!is_subclass_of($importRulesClassName::getModelClassName(), 'SecurableItem')) {
         return Zurmo::t('ZurmoModule', 'Map Fields');
     } else {
         return Zurmo::t('ZurmoModule', 'Select Permissions');
     }
 }
 /**
  * Override to handle the form layout for this view.
  * @param $form If the layout is editable, then pass a $form otherwise it can
  * be null.
  * @return A string containing the element's content.
  */
 protected function renderFormLayout($form = null)
 {
     assert('$form instanceof ZurmoActiveForm');
     $importModelClassName = ImportRulesUtil::getImportRulesClassNameByType($this->model->importRulesType);
     $importRulesLabel = $importModelClassName::getDisplayLabel();
     $label = '<h3>' . Zurmo::t('ImportModule', 'Who can read and write the new {importRulesLabel}', array('{importRulesLabel}' => $importRulesLabel)) . '</h3>';
     $element = new ExplicitReadWriteModelPermissionsElement($this->model, 'explicitReadWriteModelPermissions', $form);
     $element->editableTemplate = $label . '{content}';
     $content = $form->errorSummary($this->model);
     $content .= ZurmoHtml::tag('div', array('class' => 'right-side-edit-view-panel'), $element->render());
     return $content;
 }
Esempio n. 3
0
 protected static function resolveModelForModelDerivedAttribute(RedBeanModel $model, $importRulesType, AttributeImportRules $attributeImportRules, $attributeValueData)
 {
     assert('is_string($importRulesType)');
     assert('$attributeImportRules instanceof ModelDerivedAttributeImportRules');
     assert('count($attributeValueData) == 1');
     assert('$attributeImportRules::getDerivedAttributeName() != null');
     $derivedAttributeName = $attributeImportRules::getDerivedAttributeName();
     if ($attributeValueData[$derivedAttributeName] != null) {
         $importRulesClassName = ImportRulesUtil::getImportRulesClassNameByType($importRulesType);
         $actualAttributeName = $importRulesClassName::getActualModelAttributeNameForDerivedAttribute();
         $actualModel = $attributeValueData[$derivedAttributeName];
         if (!$model->{$actualAttributeName}->contains($actualModel)) {
             $model->{$actualAttributeName}->add($actualModel);
         }
     }
 }
 /**
  * Make a mapping rule form object.
  * @param string $importRulesType
  * @param string $attributeIndexOrDerivedType
  * @param string $mappingRuleFormClassName
  */
 public static function makeForm($importRulesType, $attributeIndexOrDerivedType, $mappingRuleFormClassName)
 {
     assert('is_string($importRulesType)');
     assert('is_string($attributeIndexOrDerivedType)');
     assert('is_string($mappingRuleFormClassName)');
     $importRulesTypeClassName = ImportRulesUtil::getImportRulesClassNameByType($importRulesType);
     $modelClassName = $importRulesTypeClassName::getModelClassNameByAttributeIndexOrDerivedType($attributeIndexOrDerivedType);
     $attributeName = AttributeImportRulesFactory::resolveModelClassNameAndAttributeNameByAttributeIndexOrDerivedType($modelClassName, $attributeIndexOrDerivedType);
     $mappingRuleForm = new $mappingRuleFormClassName($modelClassName, $attributeName);
     return $mappingRuleForm;
 }
 /**
  * Given an import rules type and attribute index or derived type, return the attribute import rules class name.
  * @param string $importRulesType
  * @param string $attributeIndexOrDerivedType
  */
 public static function getClassNameByImportRulesTypeAndAttributeIndexOrDerivedType($importRulesType, $attributeIndexOrDerivedType)
 {
     assert('is_string($importRulesType)');
     assert('is_string($attributeIndexOrDerivedType)');
     $importRulesTypeClassName = ImportRulesUtil::getImportRulesClassNameByType($importRulesType);
     $attributeImportRulesType = $importRulesTypeClassName::getAttributeImportRulesType($attributeIndexOrDerivedType);
     assert('$attributeImportRulesType !== null');
     $attributeImportRulesClassName = $attributeImportRulesType . 'AttributeImportRules';
     return $attributeImportRulesClassName;
 }
Esempio n. 6
0
 /**
  * Validation used in the saveMappingData scenario to make sure the mapping data is correct based on
  * user input. Runs several different validations on the data.  This does not validate the validity of the
  * mapping rules data itself. That is done seperately.
  * @see MappingRuleFormAndElementTypeUtil::validateMappingRuleForms
  * @param string $attribute
  * @param array $params
  */
 public function validateMappingData($attribute, $params)
 {
     assert('$this->importRulesType != null');
     assert('$this->mappingData != null');
     $atLeastOneAttributeMappedOrHasRules = false;
     $attributeMappedOrHasRulesMoreThanOnce = false;
     $mappedAttributes = array();
     $importRulesClassName = ImportRulesUtil::getImportRulesClassNameByType($this->importRulesType);
     foreach ($this->mappingData as $columnName => $data) {
         if ($data['attributeIndexOrDerivedType'] != null) {
             $atLeastOneAttributeMappedOrHasRules = true;
             if (in_array($data['attributeIndexOrDerivedType'], $mappedAttributes)) {
                 $attributeMappedOrHasRulesMoreThanOnce = true;
             } else {
                 $mappedAttributes[] = $data['attributeIndexOrDerivedType'];
             }
         }
     }
     if ($attributeMappedOrHasRulesMoreThanOnce) {
         $this->addError('mappingData', Zurmo::t('ImportModule', 'You can only map each field once.'));
     }
     if (!$atLeastOneAttributeMappedOrHasRules) {
         $this->addError('mappingData', Zurmo::t('ImportModule', 'You must map at least one of your import columns.'));
     }
     $mappedAttributeIndicesOrDerivedAttributeTypes = ImportMappingUtil::getMappedAttributeIndicesOrDerivedAttributeTypesByMappingData($this->mappingData);
     $requiredAttributeCollection = $importRulesClassName::getRequiredAttributesCollectionNotIncludingReadOnly();
     $mappedAttributeImportRulesCollection = AttributeImportRulesFactory::makeCollection($this->importRulesType, $mappedAttributeIndicesOrDerivedAttributeTypes);
     if (!ImportRulesUtil::areAllRequiredAttributesMappedOrHaveRules($requiredAttributeCollection, $mappedAttributeImportRulesCollection)) {
         $attributesLabelContent = null;
         foreach ($requiredAttributeCollection as $noteUsed => $attributeData) {
             if ($attributesLabelContent != null) {
                 $attributesLabelContent .= ', ';
             }
             $attributesLabelContent .= $attributeData['attributeLabel'];
         }
         $this->addError('mappingData', Zurmo::t('ImportModule', 'All required fields must be mapped or added: {attributesLabelContent}', array('{attributesLabelContent}' => $attributesLabelContent)));
     }
     try {
         ImportRulesUtil::checkIfAnyAttributesAreDoubleMapped($mappedAttributeImportRulesCollection);
     } catch (ImportAttributeMappedMoreThanOnceException $e) {
         $this->addError('mappingData', Zurmo::t('ImportModule', 'The following field is mapped more than once. {message}', array('{message}' => $e->getMessage())));
     }
 }
Esempio n. 7
0
 protected static function resolveModelForModelDerivedAttribute(RedBeanModel $model, $importRulesType, AttributeImportRules $attributeImportRules, $valueReadyToSanitize, $columnName, $columnMappingData, ImportSanitizeResultsUtil $importSanitizeResultsUtil)
 {
     assert('is_string($importRulesType)');
     assert('$attributeImportRules instanceof ModelDerivedAttributeImportRules');
     assert('is_string($columnName)');
     assert('is_array($columnMappingData)');
     $attributeValueData = $attributeImportRules->resolveValueForImport($valueReadyToSanitize, $columnName, $columnMappingData, $importSanitizeResultsUtil);
     assert('count($attributeValueData) == 1');
     assert('$attributeImportRules::getDerivedAttributeName() != null');
     $derivedAttributeName = $attributeImportRules::getDerivedAttributeName();
     if ($attributeValueData[$derivedAttributeName] != null) {
         $importRulesClassName = ImportRulesUtil::getImportRulesClassNameByType($importRulesType);
         $actualAttributeName = $importRulesClassName::getActualModelAttributeNameForDerivedAttribute();
         $actualModel = $attributeValueData[$derivedAttributeName];
         if (!$model->{$actualAttributeName}->contains($actualModel)) {
             $model->{$actualAttributeName}->add($actualModel);
         }
     }
 }
 /**
  * @expectedException NotSupportedException
  */
 public function testGetImportRulesClassNameByTypeWithBadType()
 {
     ImportRulesUtil::getImportRulesClassNameByType('abc');
 }
 /**
  * Step 4 ajax process.  When you click the 'Add Field' button in the user interface, this ajax action
  * is called and makes an extra row to display for mapping.
  */
 public function actionMappingAddExtraMappingRow($id, $columnCount)
 {
     $import = Import::getById((int) $_GET['id']);
     $importWizardForm = ImportWizardUtil::makeFormByImport($import);
     $importRulesClassName = ImportRulesUtil::getImportRulesClassNameByType($importWizardForm->importRulesType);
     $mappableAttributeIndicesAndDerivedTypes = $importRulesClassName::getMappableAttributeIndicesAndDerivedTypes();
     $extraColumnName = ImportMappingUtil::makeExtraColumnNameByColumnCount((int) $columnCount);
     $mappingDataMetadata = ImportWizardMappingViewUtil::makeExtraColumnMappingDataForViewByColumnName($extraColumnName);
     $extraColumnView = new ImportWizardMappingExtraColumnView($importWizardForm, $mappingDataMetadata, $mappableAttributeIndicesAndDerivedTypes);
     $view = new AjaxPageView($extraColumnView);
     echo $view->render();
 }