Пример #1
0
 function assignTemplateVariables($params)
 {
     global $variables_to_assign;
     $variables_to_assign = array();
     if ($this->objectHasProperty($params['property'])) {
         $object_property = $this->getObjectProperty($params['property']);
         $variables_to_assign = $object_property->getPropertyVariablesToAssign();
     }
     if (!empty($params['complexParent'])) {
         $complexParent = $params['complexParent'];
         $object = $this->object_properties[$complexParent]->type->complex;
         $object_properties = $object->getProperties();
         if (isset($object_properties[$params['property']])) {
             $variables_to_assign = $object_properties[$params['property']]->getPropertyVariablesToAssign();
         }
         if (isset($params['complexStep']) && !empty($this->object_properties[$complexParent]->value)) {
             if (is_string($this->object_properties[$complexParent]->value)) {
                 $complexValue = unserialize($this->object_properties[$complexParent]->value);
             } else {
                 $complexValue = $this->object_properties[$complexParent]->value;
             }
             //exception for monetary type
             if (!isset($variables_to_assign['list_currency'])) {
                 $variables_to_assign['value'] = '';
             }
             if (isset($complexValue[$params['property']]) && isset($complexValue[$params['property']][$params['complexStep']])) {
                 if ($object_properties[$params['property']]->getType() === 'date' && $object_properties[$params['property']]->type->getConvertToDBDate()) {
                     $field = $object_properties[$params['property']];
                     $field->type->property_info['value'] = $complexValue[$params['property']][$params['complexStep']];
                     if ($field->isValid() !== true) {
                         $complexValue[$params['property']][$params['complexStep']] = '';
                     }
                     $variables_to_assign['value'] = SJB_I18N::getInstance()->getInput('date', $complexValue[$params['property']][$params['complexStep']]);
                 } elseif ($object_properties[$params['property']]->getType() == 'monetary') {
                     if (isset($complexValue[$params['property']][$params['complexStep']]['value'])) {
                         $variables_to_assign['value']['value'] = htmlentities($complexValue[$params['property']][$params['complexStep']]['value'], ENT_QUOTES, "UTF-8");
                     } else {
                         $variables_to_assign['value'] = htmlentities($complexValue[$params['property']][$params['complexStep']], ENT_QUOTES, "UTF-8");
                     }
                 } elseif ($object_properties[$params['property']]->getType() == 'multilist') {
                     $value = $complexValue[$params['property']][$params['complexStep']];
                     if (!is_array($value) && strpos($value, ',')) {
                         $variables_to_assign['value'] = explode(',', $value);
                     } else {
                         $variables_to_assign['value'] = $value;
                     }
                 } elseif ($object_properties[$params['property']]->getType() !== 'text') {
                     $variables_to_assign['value'] = htmlentities($complexValue[$params['property']][$params['complexStep']], ENT_QUOTES, "UTF-8");
                 } else {
                     $variables_to_assign['value'] = $complexValue[$params['property']][$params['complexStep']];
                 }
             }
         }
     }
     if (!empty($params['parent'])) {
         $parent = $params['parent'];
         $object = $this->object_properties[$parent]->type->child;
         $object_properties = $object->getProperties();
         if (isset($object_properties[$params['property']])) {
             $variables_to_assign = $object_properties[$params['property']]->getPropertyVariablesToAssign();
         } elseif (strpos($params['property'], '.Code')) {
             $params['property'] = str_replace('.Code', '', $params['property']);
             if (!isset($object_properties[$params['property']])) {
                 return false;
             }
             $variables_to_assign = $object_properties[$params['property']]->getPropertyVariablesToAssign();
             if ($params['property'] == 'State') {
                 $country = !empty($params['country']) ? $params['country'] : false;
                 $variables_to_assign['list_values'] = SJB_StatesManager::getStatesNamesByCountry($country, true, 'state_code');
             }
             $variables_to_assign['displayAS'] = 'Code';
         } else {
             $params['property'] = str_replace('.Name', '', $params['property']);
             if (!isset($object_properties[$params['property']])) {
                 return false;
             }
             $variables_to_assign = $object_properties[$params['property']]->getPropertyVariablesToAssign();
             if ($params['property'] == 'State') {
                 $country = !empty($params['country']) ? $params['country'] : false;
                 $variables_to_assign['list_values'] = SJB_StatesManager::getStatesNamesByCountry($country, true, 'state_name');
             }
             $variables_to_assign['displayAS'] = 'Name';
         }
     }
     if (isset($params['fields'])) {
         $fields = $params['fields'];
         $object_property = $this->getObjectProperty($params['property']);
         $fieldProperties = $object_property->type->child->getProperties();
         foreach ($fieldProperties as $key => $property) {
             if (!array_key_exists($property->getSID(), $fields)) {
                 $object_property->type->child->deleteProperty($key);
             }
         }
         foreach ($fields as $key => $field) {
             $object_property->type->child->addProperty($field);
         }
         $variables_to_assign = $object_property->getPropertyVariablesToAssign();
     }
     if (isset($params['complexStep'])) {
         $variables_to_assign['complexStep'] = $params['complexStep'];
     }
     if (isset($params['parameters'])) {
         $variables_to_assign = array_merge($variables_to_assign, array('parameters' => $params['parameters']));
     }
     // made for FormBuilders Complex Fields. so admin could define custom html code
     if (isset($params['customHtml']) && !empty($params['customHtml'])) {
         $variables_to_assign['customHtml'] = trim($params['customHtml']);
     }
     $variables_to_assign = array_merge($variables_to_assign, $this->getVariablesToAssign($params));
     $varToAssignValueIsEmpty = $this->isEmptyVariablesToAssignValue($variables_to_assign);
     if (($this->useDefaultValues || !$this->object->getSID()) && $varToAssignValueIsEmpty && $this->errors === false) {
         if ($variables_to_assign['default_value'] != '') {
             if (is_array($variables_to_assign['default_value'])) {
                 $variables_to_assign['default_value']['currency'] = $variables_to_assign['default_value']['add_parameter'];
             }
             $variables_to_assign['value'] = $variables_to_assign['default_value'];
         } else {
             if ($variables_to_assign['profile_field_as_dv'] != '') {
                 $variables_to_assign['value'] = htmlentities($variables_to_assign['profile_field_as_dv'], ENT_QUOTES, 'UTF-8');
             }
         }
     }
     // заглушка для email - когда в value попадает массив из одного элемента [original]
     if ($variables_to_assign['id'] == 'email') {
         if (is_array($variables_to_assign['value'])) {
             $variables_to_assign['value'] = array_pop($variables_to_assign['value']);
         }
     }
     $variables_to_assign['defaultCountry'] = SJB_Settings::getSettingByName('default_country');
     if (isset($params['searchWithin'])) {
         $variables_to_assign['searchWithin'] = $params['searchWithin'];
     }
     if (!isset($variables_to_assign['displayAS'])) {
         $variables_to_assign['displayAS'] = false;
     }
     if ($variables_to_assign['id'] == 'default_value' && in_array($this->object->getProperty('default_value')->getType(), array('list', 'multilist'))) {
         $variables_to_assign['sort_by_alphabet'] = $this->object->getPropertyValue('sort_by_alphabet');
     }
     foreach ($variables_to_assign as $variable_name => $variable_value) {
         $this->template_processor->assign($variable_name, $variable_value);
     }
     return true;
 }