示例#1
0
 public static function renderDynamicSearchAttributeInput($viewClassName, $modelClassName, $formModelClassName, $rowNumber, $attributeIndexOrDerivedType, $searchAttributes = array(), $suffix = null)
 {
     assert('is_string($viewClassName)');
     assert('is_string($modelClassName)');
     assert('is_string($formModelClassName)');
     assert('is_int($rowNumber)');
     assert('is_string($attributeIndexOrDerivedType) || $attributeIndexOrDerivedType == null');
     assert('is_array($searchAttributes)');
     assert('is_string($suffix) || $suffix == null');
     $content = null;
     if (count(explode(FormModelUtil::RELATION_DELIMITER, $attributeIndexOrDerivedType)) > 1) {
         $model = new $modelClassName(false);
         $nestedAttributes = explode(FormModelUtil::RELATION_DELIMITER, $attributeIndexOrDerivedType);
         $inputPrefix = array($formModelClassName, DynamicSearchForm::DYNAMIC_NAME, $rowNumber);
         $totalNestedCount = count($nestedAttributes);
         $processCount = 1;
         $nestedSearchAttributes = $searchAttributes;
         foreach ($nestedAttributes as $attribute) {
             if ($processCount < $totalNestedCount && isset($nestedSearchAttributes[$attribute])) {
                 $nestedSearchAttributes = $nestedSearchAttributes[$attribute];
                 if (isset($nestedSearchAttributes['relatedData'])) {
                     unset($nestedSearchAttributes['relatedData']);
                 }
             }
             if ($processCount < $totalNestedCount) {
                 $model = SearchUtil::resolveModelToUseByModelAndAttributeName($model, $attribute);
                 $inputPrefix[] = $attribute;
                 $relatedDataName = Element::resolveInputNamePrefixIntoString($inputPrefix) . '[relatedData]';
                 $content .= ZurmoHtml::hiddenField($relatedDataName, true);
             }
             $processCount++;
         }
         $attributeIndexOrDerivedType = $attribute;
         $modelToUse = $model;
         $modelToUse->setAttributes($nestedSearchAttributes);
         $cellElementModelClassName = get_class($model->getModel());
         //Dynamic Search needs to always assume there is an available SearchForm
         //Always assumes the SearchView to use matches the exact pluralCamelCasedName.
         //Does not support nested relations to leads persay.  It will resolve as a Contact.
         //This is not a problem since you can't relate a model to a lead, it is related to a contact.
         //So this scenario would not come up naturally.
         $moduleClassName = $model->getModel()->getModuleClassName();
         $viewClassName = $moduleClassName::getPluralCamelCasedName() . 'SearchView';
         $element = DynamicSearchUtil::getCellElement($viewClassName, $cellElementModelClassName, $attributeIndexOrDerivedType);
     } else {
         $model = new $modelClassName(false);
         $model->setScenario('importModel');
         //this is so attributes such as modified user can be set
         $modelToUse = new $formModelClassName($model);
         $modelToUse->setAttributes($searchAttributes);
         $inputPrefix = array($formModelClassName, DynamicSearchForm::DYNAMIC_NAME, $rowNumber);
         $element = DynamicSearchUtil::getCellElement($viewClassName, $modelClassName, $attributeIndexOrDerivedType);
     }
     $form = new NoRequiredsActiveForm();
     $form->id = "search-form";
     $element['inputPrefix'] = $inputPrefix;
     $elementclassname = $element['type'] . 'Element';
     $element = new $elementclassname($modelToUse, $element['attributeName'], $form, array_slice($element, 2));
     $element->editableTemplate = '{content}{error}';
     $content .= $element->render();
     DropDownUtil::registerScripts(CClientScript::POS_END);
     return $content;
 }