Ejemplo n.º 1
0
 /**
  * Creates the custom field group array with group info and fields values and attributes
  *
  * @param array $entries Entry array must have keys for entry id and criteriaid
  */
 function getFieldsArray($elements, $type = 'listing')
 {
     $fields = array();
     $field_pairs = array();
     $element_ids = array();
     $rows = array();
     $this->criteria_ids = array();
     // Alejandro = for discussion functionality
     //build entry_ids and criteria_ids array
     switch ($type) {
         case 'listing':
             foreach ($elements as $key => $element) {
                 if (isset($element['Criteria'])) {
                     $element_ids[] = $element[inflector::camelize($type)]['listing_id'];
                     if ($element['Criteria']['criteria_id'] != '') {
                         $this->criteria_ids[] = $element['Criteria']['criteria_id'];
                     }
                 }
             }
             break;
         case 'review':
             foreach ($elements as $element) {
                 if (isset($element['Criteria'])) {
                     $element_ids[] = $element[inflector::camelize($type)]['review_id'];
                     if ($element['Criteria']['criteria_id'] != '') {
                         $this->criteria_ids[] = $element['Criteria']['criteria_id'];
                     }
                 }
             }
             break;
     }
     $this->group_ids = $this->_criteria2Groups($this->criteria_ids, $type);
     $criteria_ids = implode(',', $this->criteria_ids);
     $element_ids = implode(',', array_unique($element_ids));
     if (empty($this->group_ids)) {
         return;
     }
     $group_ids = implode(',', $this->group_ids);
     $field_type = $type == 'listing' ? 'content' : $type;
     // Get field attributes and field values
     $query = "SELECT Field.fieldid AS `Field.field_id`, Field.groupid AS `Field.group_id`, Field.name AS `Field.name`, Field.title AS `Field.title`," . "\n Field.showtitle AS `Field.showTitle`, Field.description AS `Field.description`, Field.required AS `Field.required`," . "\n Field.type AS `Field.type`, Field.location AS `Field.location`, Field.options AS `Field.params`," . "\n Field.contentview AS `Field.contentView`, Field.listview AS `Field.listView`, Field.compareview AS `Field.compareView`, Field.listsort AS `Field.listSort`," . "\n Field.search AS `Field.search`, Field.access AS `Field.access`, Field.access_view AS `Field.accessView`," . "\n Field.published As `Field.published`," . "\n `Group`.groupid AS `Group.group_id`, `Group`.title AS `Group.title`, `Group`.name AS `Group.name`, `Group`.showtitle AS `Group.showTitle`" . "\n FROM #__jreviews_fields AS Field" . "\n INNER JOIN #__jreviews_groups AS `Group` ON (`Group`.groupid = Field.groupid AND " . "\n `Group`.groupid IN ({$group_ids}) AND `Group`.type =  '{$field_type}' )" . "\n WHERE Field.location = '{$field_type}' AND Field.published = 1" . "\n ORDER BY Group.ordering, Field.ordering";
     $this->_db->setQuery($query);
     $rows = $this->_db->loadObjectList('Field.name');
     if (!$rows || empty($rows)) {
         return;
     }
     # Extract list of field names from array
     $fieldNames = array();
     $fieldNamesByType = array();
     $fieldRows = array();
     $optionFields = array('selectmultiple', 'checkboxes', 'select', 'radiobuttons');
     foreach ($rows as $key => $row) {
         $fieldNames[] = $row->{'Field.name'};
         $fieldIds[$row->{'Field.name'}] = $row->{'Field.field_id'};
         $fieldRows[$key] = (array) $row;
         if (in_array($row->{'Field.type'}, $optionFields)) {
             $query = "SELECT * FROM #__jreviews_fieldoptions" . "\n WHERE fieldid = " . $row->{'Field.field_id'} . "\n ORDER BY ordering ASC ,optionid ASC";
             $this->_db->setQuery($query);
             $this->fieldOptions[$row->{'Field.field_id'}] = $this->_db->loadObjectList('value');
         }
     }
     # Get field values from current element ids
     switch ($type) {
         case 'listing':
             # PaidListings integration
             if (Configure::read('ListingEdit') && Configure::read('PaidListings.enabled')) {
                 // Load the paid_listing_fields table instead of the jos_content table so users can see all their
                 // fields when editing a listing
                 Configure::write('ListingEdit', false);
                 $fieldValues = PaidListingFieldModel::edit($element_ids);
                 if ($fieldValues) {
                     break;
                 }
             }
             $query = "SELECT Listing.contentid AS element_id," . implode(',', $fieldNames) . "\n FROM #__jreviews_content AS Listing" . "\n WHERE Listing.contentid IN (" . $element_ids . ")";
             $this->_db->setQuery($query);
             $fieldValues = $this->_db->loadObjectList('element_id');
             break;
         case 'review':
             $query = "SELECT Review.reviewid AS element_id," . implode(',', $fieldNames) . "\n FROM #__jreviews_review_fields AS Review" . "\n WHERE Review.reviewid IN (" . $element_ids . ")";
             $this->_db->setQuery($query);
             $fieldValues = $this->_db->loadObjectList('element_id');
             break;
     }
     # Now for each option field add array of selected value,text,images
     $elementFields = array();
     if (!empty($fieldValues)) {
         foreach ($fieldValues as $fieldValue) {
             $fieldValue = (array) $fieldValue;
             foreach ($fieldValue as $key => $value) {
                 if ($key != 'element_id' && $value != '' && isset($rows[$key])) {
                     !in_array($rows[$key]->{'Field.type'}, array('textarea', 'code')) and $value = htmlspecialchars($value, ENT_QUOTES, 'UTF-8');
                     if ($rows[$key]->{'Field.type'} != 'date' || $rows[$key]->{'Field.type'} == 'date' && $value != NULL_DATE) {
                         $elementFields[$fieldValue['element_id']]['field_id'] = $fieldRows[$key]['Field.field_id'];
                         if (!in_array($rows[$key]->{'Field.type'}, $optionFields)) {
                             $elementFields[$fieldValue['element_id']][$key]['Field.text'][] = $value;
                             $elementFields[$fieldValue['element_id']][$key]['Field.value'][] = $value;
                             $elementFields[$fieldValue['element_id']][$key]['Field.image'][] = '';
                         } elseif (in_array($rows[$key]->{'Field.type'}, $optionFields)) {
                             $fieldOptions = $this->fieldOptions[$rows[$key]->{'Field.field_id'}];
                             $selOptions = explode('*', $value);
                             foreach ($selOptions as $selOption) {
                                 if (isset($fieldOptions[$selOption])) {
                                     $elementFields[$fieldValue['element_id']][$key]['Field.value'][] = $fieldOptions[$selOption]->value;
                                     $elementFields[$fieldValue['element_id']][$key]['Field.text'][] = $fieldOptions[$selOption]->text;
                                     $elementFields[$fieldValue['element_id']][$key]['Field.image'][] = $fieldOptions[$selOption]->image;
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     // Reformat array so array keys match element ids
     foreach ($elementFields as $key => $elementField) {
         $element_id = $key;
         $field_id = $elementField['field_id'];
         unset($elementField['field_id']);
         $field_name = key($elementField);
         foreach ($elementField as $field_name => $field_options) {
             //FieldGroups array
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Group']['group_id'] = $fieldRows[$field_name]['Field.group_id'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Group']['title'] = $fieldRows[$field_name]['Group.title'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Group']['name'] = $fieldRows[$field_name]['Group.name'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Group']['show_title'] = $fieldRows[$field_name]['Group.showTitle'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['id'] = $field_id;
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['group_id'] = $fieldRows[$field_name]['Field.group_id'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['name'] = $fieldRows[$field_name]['Field.name'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['type'] = $fieldRows[$field_name]['Field.type'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['title'] = $fieldRows[$field_name]['Field.title'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['description'] = $fieldRows[$field_name]['Field.description'];
             // Field values
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['value'] = $field_options['Field.value'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['text'] = $field_options['Field.text'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['image'] = $field_options['Field.image'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['properties']['show_title'] = $fieldRows[$field_name]['Field.showTitle'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['properties']['location'] = $fieldRows[$field_name]['Field.location'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['properties']['contentview'] = $fieldRows[$field_name]['Field.contentView'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['properties']['listview'] = $fieldRows[$field_name]['Field.listView'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['properties']['compareview'] = $fieldRows[$field_name]['Field.compareView'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['properties']['listsort'] = $fieldRows[$field_name]['Field.listSort'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['properties']['search'] = $fieldRows[$field_name]['Field.search'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['properties']['access'] = $fieldRows[$field_name]['Field.access'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['properties']['access_view'] = $fieldRows[$field_name]['Field.accessView'];
             //FieldPairs associative array with field name as key and field value as value
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['group_id'] = $fieldRows[$field_name]['Field.group_id'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['group_show_title'] = $fieldRows[$field_name]['Group.showTitle'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['group_title'] = $fieldRows[$field_name]['Group.title'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['group_name'] = $fieldRows[$field_name]['Group.name'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['name'] = $fieldRows[$field_name]['Field.name'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['title'] = $fieldRows[$field_name]['Field.title'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['value'] = $field_options['Field.value'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['text'] = $field_options['Field.text'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['image'] = $field_options['Field.image'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['type'] = $fieldRows[$field_name]['Field.type'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['properties']['show_title'] = $fieldRows[$field_name]['Field.showTitle'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['properties']['location'] = $fieldRows[$field_name]['Field.location'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['properties']['contentview'] = $fieldRows[$field_name]['Field.contentView'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['properties']['listview'] = $fieldRows[$field_name]['Field.listView'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['properties']['compareview'] = $fieldRows[$field_name]['Field.compareView'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['properties']['listsort'] = $fieldRows[$field_name]['Field.listSort'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['properties']['search'] = $fieldRows[$field_name]['Field.search'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['properties']['access'] = $fieldRows[$field_name]['Field.access'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['properties']['access_view'] = $fieldRows[$field_name]['Field.accessView'];
             $properties = stringToArray($fieldRows[$field_name]['Field.params']);
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['properties'] = array_merge($fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['properties'], $properties);
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['properties'] = array_merge($field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['properties'], $properties);
             //$params = explode("\n",$fieldRows[$field_name]['Field.params']);
         }
     }
     $this->custom_fields = $fields;
     $this->field_pairs = $field_pairs;
 }
Ejemplo n.º 2
0
 /**
  * Returns a json object of field options used to dynamicaly show and populate dependent fields
  *         
  */
 function _loadFieldData($json = true, $_data = array())
 {
     !empty($_data) and $this->data = $_data;
     $fields = $field_options = $selected_values = $group_ids = array();
     $selected_values_autocomplete = array();
     $dependent_fields = $dependent_groups = $control_fields = $fields = $responses = array();
     $location = strtolower(Sanitize::getString($this->data, 'fieldLocation', 'content'));
     $location == 'listing' and $location = 'content';
     $recursive = Sanitize::getBool($this->data, 'recursive');
     $field_names = Sanitize::getVar($this->data, 'fields');
     $control_field = $field_names = is_array($field_names) ? array_filter($field_names) : array($field_names);
     $page_setup = Sanitize::getInt($this->data, 'page_setup', false);
     $control_value = Sanitize::getVar($this->data, 'value');
     $entry_id = Sanitize::getInt($this->data, 'entry_id');
     $referrer = Sanitize::getString($this->data, 'referrer');
     $edit = (bool) $entry_id || is_array($control_value);
     // In adv. search module we make it work like edit for previously searched values which are passed as an array in $control_value
     # Access check
     # Need to pass token to validate the listing id and check user access.
     # Filter passed field names to fix those with double underscores which are checkboxes and radiobuttons
     foreach ($field_names as $key => $name) {
         if (substr_count($name, '_') > 1) {
             $tmp = explode('_', $name);
             array_pop($tmp);
             $field_names[$key] = implode('_', $tmp);
         }
     }
     $field_names = array_unique($field_names);
     /** 
      * We are in edit mode. Find selected values
      */
     if ($page_setup && $entry_id > 0) {
         # PaidListings integration
         if ($location == 'content' && Configure::read('PaidListings.enabled') && PaidPlanCategoryModel::isInPaidCategoryByListingId($entry_id)) {
             // Load the paid_listing_fields table instead of the jos_content table so users can see all their
             // fields when editing a listing
             Configure::write('ListingEdit', false);
             $curr_field_values = PaidListingFieldModel::edit($entry_id);
             if ($curr_field_values && !empty($curr_field_values)) {
                 $curr_field_values = (array) array_shift($curr_field_values);
                 $curr_field_values['contentid'] = $curr_field_values['element_id'];
                 unset($curr_field_values['element_id'], $curr_field_values['email']);
             }
         }
         if (empty($curr_field_values)) {
             $query = $location == 'content' ? "SELECT * FROM #__jreviews_content WHERE contentid = {$entry_id}" : "SELECT * FROM #__jreviews_review_fields WHERE reviewid = {$entry_id}";
             $this->_db->setQuery($query);
             $curr_field_values = array_shift($this->_db->loadAssocList());
         }
         if (!empty($curr_field_values)) {
             foreach ($curr_field_values as $key => $val) {
                 if (substr($key, 0, 3) == 'jr_') {
                     $selected_values[$key] = $val != '' ? is_array($val) ? $val : array($val) : array();
                 }
             }
         }
     } elseif (is_array($control_value)) {
         $selected_values = $control_value;
         $control_value = '';
     }
     /****************************************************************************************
      *  Control field option selected, so we find all dependent fields and groups
      *  Need to look in FieldOptions, Fields and FieldGroups
      ****************************************************************************************/
     if (!$page_setup) {
         # Find dependent FieldOptions
         $query = "\r\n                SELECT \r\n                    DISTINCT Field.name\r\n                FROM \r\n                    #__jreviews_fieldoptions AS FieldOption\r\n                LEFT JOIN\r\n                    #__jreviews_fields AS Field ON Field.fieldid = FieldOption.fieldid AND (\r\n                        Field.published = 1 AND Field.location = " . $this->quote($location) . "\r\n                    )\r\n                LEFT JOIN\r\n                    #__jreviews_groups AS FieldGroup ON Field.groupid = FieldGroup.groupid\r\n                WHERE\r\n                    Field.published = 1 AND Field.location = " . $this->quote($location) . "\r\n                    AND FieldOption.control_field = " . $this->quote($control_field) . " AND FieldOption.control_value LIKE " . $this->quoteLike('*' . $control_value . '*') . "\r\n                ORDER BY \r\n                    FieldGroup.ordering, Field.ordering \r\n            ";
         $this->_db->setQuery($query);
         $field_names = $this->_db->loadResultArray();
         # Find dependent Fields
         $query = "\r\n                SELECT \r\n                    DISTINCT Field.name\r\n                FROM \r\n                    #__jreviews_fields AS Field\r\n                LEFT JOIN\r\n                    #__jreviews_groups AS FieldGroup ON Field.groupid = FieldGroup.groupid\r\n                WHERE\r\n                    Field.published = 1 AND Field.location = " . $this->quote($location) . "\r\n                    AND Field.control_field = " . $this->quote($control_field) . " AND Field.control_value LIKE " . $this->quoteLike('*' . $control_value . '*') . "\r\n                ORDER BY \r\n                    FieldGroup.ordering, Field.ordering \r\n            ";
         $this->_db->setQuery($query);
         $field_names = is_array($field_names) ? array_merge($field_names, $this->_db->loadResultArray()) : $this->_db->loadResultArray();
         # Find depedent Field Groups
         $query = "\r\n                SELECT DISTINCT\r\n                   FieldGroup.groupid\r\n                FROM \r\n                    #__jreviews_groups AS FieldGroup\r\n                LEFT JOIN\r\n                    #__jreviews_fields AS Field ON Field.groupid = FieldGroup.groupid\r\n                WHERE\r\n                    Field.published = 1 AND Field.location = " . $this->quote($location) . "  \r\n                    AND FieldGroup.type = " . $this->quote($location) . "\r\n                    AND FieldGroup.control_field = " . $this->quote($control_field) . "\r\n                    AND FieldGroup.control_value LIKE " . $this->quoteLike('*' . $control_value . '*') . "\r\n                ORDER BY\r\n                    FieldGroup.ordering\r\n           ";
         $this->_db->setQuery($query);
         $group_ids = $this->_db->loadResultArray();
         !empty($field_names) and $field_names = array_unique($field_names);
         if (empty($field_names) && empty($group_ids)) {
             return json_encode(compact('control_field', 'dependent_fields', 'dependent_groups', 'data'));
         }
     }
     # Get info for all fields
     $query = "\r\n            SELECT \r\n                Field.fieldid, Field.groupid, Field.title, Field.name, Field.type, Field.options, Field.control_field, Field.control_value, FieldGroup.name AS group_name\r\n            FROM \r\n                #__jreviews_fields AS Field \r\n            LEFT JOIN\r\n                #__jreviews_groups AS FieldGroup ON Field.groupid = FieldGroup.groupid\r\n            WHERE \r\n                Field.published = 1 AND Field.location = " . $this->quote($location) . "\r\n                AND (\r\n                    " . (!empty($field_names) ? "Field.name IN (" . $this->quote($field_names) . ")" : '') . "\r\n                    " . (!empty($field_names) && !empty($group_ids) ? " OR " : '') . "\r\n                    " . (!empty($group_ids) ? "Field.groupid IN (" . $this->quote($group_ids) . ")" : '') . "\r\n                )\r\n            ORDER BY \r\n                FieldGroup.ordering, Field.ordering\r\n        ";
     $this->_db->setQuery($query);
     $curr_form_fields = $this->_db->loadAssocList('name');
     if (empty($curr_form_fields)) {
         return json_encode(compact('control_field', 'dependent_fields', 'dependent_groups', 'data'));
     }
     foreach ($curr_form_fields as $key => $curr_form_field) {
         $curr_form_fields[$key]['options'] = stringToArray($curr_form_field['options']);
     }
     /****************************************************************************************
      *  Check if fields have any dependents to avoid unnecessary ajax requests 
      *  Three tables need to be checked: fieldoptions, fields, and fieldgroups
      ****************************************************************************************/
     # FieldOptions
     $query = "\r\n            SELECT DISTINCT     \r\n                Field.name AS dependent_field, FieldOption.control_field\r\n            FROM \r\n                #__jreviews_fieldoptions AS FieldOption\r\n            LEFT JOIN\r\n                #__jreviews_fields AS Field ON Field.fieldid = FieldOption.fieldid\r\n            WHERE\r\n                Field.published = 1 AND Field.location = " . $this->quote($location) . "\r\n                AND FieldOption.control_field IN ( " . $this->quote($page_setup ? array_keys($curr_form_fields) : $control_field) . ")\r\n            " . (!$page_setup ? "AND FieldOption.control_value LIKE " . $this->quoteLike('*' . $control_value . '*') : '') . "\r\n            ORDER BY Field.ordering\r\n       ";
     $this->_db->setQuery($query);
     $controlling_and_dependent_fields = $this->_db->loadAssocList();
     # Fields
     $query = "\r\n            SELECT DISTINCT\r\n                Field.name AS dependent_field, Field.control_field\r\n            FROM \r\n                #__jreviews_fields AS Field\r\n            WHERE\r\n                Field.published = 1 AND Field.location = " . $this->quote($location) . "\r\n                AND Field.control_field IN ( " . $this->quote($page_setup ? array_keys($curr_form_fields) : $control_field) . ")\r\n            " . (!$page_setup ? "AND Field.control_value LIKE " . $this->quoteLike('*' . $control_value . '*') : '') . "\r\n            ORDER BY Field.ordering\r\n       ";
     $this->_db->setQuery($query);
     $controlling_and_dependent_fields = is_array($controlling_and_dependent_fields) ? array_merge($controlling_and_dependent_fields, $this->_db->loadAssocList()) : $this->_db->loadAssocList();
     # Groups
     $query = "\r\n            SELECT DISTINCT\r\n               FieldGroup.name AS dependent_group, FieldGroup.control_field\r\n            FROM \r\n                #__jreviews_groups AS FieldGroup\r\n            LEFT JOIN\r\n                #__jreviews_fields AS Field ON Field.groupid = FieldGroup.groupid\r\n            WHERE\r\n                Field.published = 1 AND Field.location = " . $this->quote($location) . "  \r\n                AND FieldGroup.type = " . $this->quote($location) . "\r\n                AND FieldGroup.control_field IN ( " . $this->quote($page_setup ? array_keys($curr_form_fields) : $control_field) . ")\r\n            " . (!$page_setup ? "AND FieldGroup.control_value LIKE " . $this->quoteLike('*' . $control_value . '*') : '') . "\r\n            ORDER BY\r\n                FieldGroup.ordering\r\n       ";
     $this->_db->setQuery($query);
     $controlling_and_dependent_fields = is_array($controlling_and_dependent_fields) ? array_merge($controlling_and_dependent_fields, $this->_db->loadAssocList()) : $this->_db->loadAssocList();
     #Extract controlling and dependent fields
     foreach ($controlling_and_dependent_fields as $row) {
         isset($row['dependent_field']) and $dependent_fields[$row['dependent_field']] = $row['dependent_field'];
         if (isset($row['dependent_group'])) {
             $group_name = str_replace(' ', '', $row['dependent_group']);
             $dependent_groups[$group_name] = $group_name;
         }
         $control_fields[$row['control_field']] = $row['control_field'];
     }
     $ids_to_names = $ids_to_names_autocomplete = $ids_to_names_noautocomplete = array();
     $control_fields_array = array();
     foreach ($curr_form_fields as $curr_form_field) {
         $ordering = Sanitize::getVar($curr_form_field['options'], 'option_ordering', null);
         $fields[$curr_form_field['name']]['name'] = $curr_form_field['name'];
         $fields[$curr_form_field['name']]['type'] = $curr_form_field['type'];
         $fields[$curr_form_field['name']]['group'] = $curr_form_field['group_name'];
         $fields[$curr_form_field['name']]['autocomplete'] = Sanitize::getVar($curr_form_field['options'], in_array($referrer, array('adv_search', 'adv_search_module')) ? 'autocomplete.search' : 'autocomplete', 0);
         $fields[$curr_form_field['name']]['autocompletetype'] = Sanitize::getVar($curr_form_field['options'], 'autocomplete.option_type', 'link');
         $fields[$curr_form_field['name']]['autocompletepos'] = Sanitize::getVar($curr_form_field['options'], 'autocomplete.option_pos', 'after');
         $fields[$curr_form_field['name']]['title'] = $curr_form_field['title'];
         $entry_id and $fields[$curr_form_field['name']]['selected'] = array();
         !is_null($ordering) and $fields[$curr_form_field['name']]['order_by'] = !$ordering ? 'ordering' : 'text';
         // Add selected value for text fields
         if (isset($selected_values[$curr_form_field['name']])) {
             switch ($fields[$curr_form_field['name']]['type']) {
                 case 'date':
                     if (isset($selected_values[$curr_form_field['name']][0])) {
                         if ($selected_values[$curr_form_field['name']][0] == NULL_DATE) {
                             $fields[$curr_form_field['name']]['selected'] = array();
                         } else {
                             $fields[$curr_form_field['name']]['selected'] = array(str_replace(" 00:00:00", "", $selected_values[$curr_form_field['name']][0]));
                         }
                     }
                     break;
                 case 'relatedlisting':
                     if (isset($selected_values[$curr_form_field['name']][0]) && $selected_values[$curr_form_field['name']][0] > 0) {
                         $fields[$curr_form_field['name']]['selected'] = $selected_values[$curr_form_field['name']];
                     }
                     break;
                 case 'radiobuttons':
                 case 'select':
                 case 'checkboxes':
                 case 'selectmultiple':
                     if (!empty($selected_values[$curr_form_field['name']])) {
                         $selected_values[$curr_form_field['name']] = explode('*', ltrim(rtrim($selected_values[$curr_form_field['name']][0], '*'), '*'));
                         $fields[$curr_form_field['name']]['selected'] = $selected_values[$curr_form_field['name']];
                     }
                     break;
                 default:
                     $fields[$curr_form_field['name']]['selected'] = $selected_values[$curr_form_field['name']];
                     break;
             }
         }
         // Add control related vars
         // If field is text type, then it has no control and we check the controlBy values
         if ($fields[$curr_form_field['name']]['type'] == 'text') {
             $fields[$curr_form_field['name']]['control'] = false;
             $fields[$curr_form_field['name']]['controlled'] = $curr_form_field['control_field'] != '' && $curr_form_field['control_value'];
         } else {
             $fields[$curr_form_field['name']]['control'] = $recursive ? true : in_array($curr_form_field['name'], $control_fields);
             $fields[$curr_form_field['name']]['controlled'] = in_array($curr_form_field['name'], $dependent_fields);
         }
         if (in_array($curr_form_field['groupid'], $group_ids)) {
             $fields[$curr_form_field['name']]['controlgroup'] = true;
         }
         // Create an array of field ids to field names used below to save on additional queries.
         // The initial field option values are loaded for the fields in this array
         if (!$page_setup || !$fields[$curr_form_field['name']]['autocomplete'] || !empty($fields[$curr_form_field['name']]['selected'])) {
             if (in_array($fields[$curr_form_field['name']]['type'], array('select', 'selectmultiple'))) {
                 $ids_to_names[$curr_form_field['fieldid']] = $curr_form_field['name'];
             }
             if (!empty($fields[$curr_form_field['name']]['selected']) && $fields[$curr_form_field['name']]['autocomplete'] && in_array($fields[$curr_form_field['name']]['type'], array('select', 'selectmultiple'))) {
                 $ids_to_names_autocomplete[$curr_form_field['fieldid']] = $curr_form_field['name'];
                 $selected_values_autocomplete = array_merge($selected_values_autocomplete, $selected_values[$curr_form_field['name']]);
             } elseif (!$fields[$curr_form_field['name']]['autocomplete'] && in_array($fields[$curr_form_field['name']]['type'], array('select', 'selectmultiple'))) {
                 $ids_to_names_noautocomplete[$curr_form_field['fieldid']] = $curr_form_field['name'];
             }
         }
         $control_fields_array[] = $curr_form_field['name'];
     }
     //prx($ids_to_names);
     //prx($ids_to_names_autocomplete);
     //prx($ids_to_names_noautocomplete);
     //prx('------------------BEGIN-------------------');
     //prx($recursive);
     //prx($curr_form_fields);
     //prx($fields);
     //prx($control_fields);
     //prx('------------------END-------------------');
     /****************************************************************************************
      * Build the fields array for control and controlled fields 
      ****************************************************************************************/
     # For FieldOption-FieldOption relationships get field options ordered by a-z ASC to start building the fields array.
     if (!empty($ids_to_names)) {
         if ($edit) {
             if (!empty($ids_to_names_autocomplete)) {
                 $query = "\r\n                        SELECT \r\n                            Field.name, Field.fieldid, FieldOption.optionid, FieldOption.text, FieldOption.value, FieldOption.image, FieldOption.ordering\r\n                        FROM \r\n                            #__jreviews_fieldoptions AS FieldOption\r\n                        LEFT JOIN\r\n                            #__jreviews_fields AS Field ON Field.fieldid = FieldOption.fieldid\r\n                        WHERE\r\n                            Field.published = 1 AND Field.location = " . $this->quote($location) . "  \r\n                            AND " . ($page_setup ? " FieldOption.fieldid IN (" . $this->quote(array_keys($ids_to_names_autocomplete)) . ") " : '1 = 1') . " \r\n                            " . ($page_setup ? " AND FieldOption.control_field = ''" : " AND FieldOption.control_field = " . $this->quote($control_field) . " AND FieldOption.control_value LIKE " . $this->quoteLike('*' . $control_value . '*')) . " \r\n                            " . (!empty($selected_values_autocomplete) ? "AND FieldOption.value IN ( " . $this->quote($selected_values_autocomplete) . ")" : '') . "\r\n                        ORDER BY \r\n                            FieldOption.fieldid, FieldOption.text\r\n                    ";
                 $this->_db->setQuery($query);
                 $field_options_ac = $this->_db->loadAssocList();
             }
             if (!empty($ids_to_names_noautocomplete)) {
                 $query = "\r\n                        SELECT \r\n                            Field.name, Field.fieldid, FieldOption.optionid, FieldOption.text, FieldOption.value, FieldOption.image, FieldOption.ordering\r\n                        FROM \r\n                            #__jreviews_fieldoptions AS FieldOption\r\n                        LEFT JOIN\r\n                            #__jreviews_fields AS Field ON Field.fieldid = FieldOption.fieldid\r\n                        WHERE\r\n                            Field.published = 1 AND Field.location = " . $this->quote($location) . "  \r\n                            AND " . ($page_setup ? " FieldOption.fieldid IN (" . $this->quote(array_keys($ids_to_names_noautocomplete)) . ") " : '1 = 1') . " \r\n                            " . ($page_setup ? " AND FieldOption.control_field = ''" : " AND FieldOption.control_field = " . $this->quote($control_field) . " AND FieldOption.control_value LIKE " . $this->quoteLike('*' . $control_value . '*')) . " \r\n                        ORDER BY \r\n                            FieldOption.fieldid, FieldOption.text\r\n                    ";
                 $this->_db->setQuery($query);
                 $field_options_noac = $this->_db->loadAssocList();
             }
             empty($field_options_ac) and $field_options_ac = array();
             empty($field_options_noac) and $field_options_noac = array();
             $field_options = array_merge($field_options_ac, $field_options_noac);
         } else {
             $query = "\r\n                    SELECT \r\n                        Field.name, Field.fieldid, FieldOption.optionid, FieldOption.text, FieldOption.value, FieldOption.image, FieldOption.ordering\r\n                    FROM \r\n                        #__jreviews_fieldoptions AS FieldOption\r\n                    LEFT JOIN\r\n                        #__jreviews_fields AS Field ON Field.fieldid = FieldOption.fieldid\r\n                    WHERE\r\n                        Field.published = 1 AND Field.location = " . $this->quote($location) . "  \r\n                        AND " . ($page_setup ? " FieldOption.fieldid IN (" . $this->quote(array_keys($ids_to_names)) . ") " : '1 = 1') . " \r\n                        " . ($page_setup ? " AND FieldOption.control_field = ''" : " AND FieldOption.control_field = " . $this->quote($control_field) . " AND FieldOption.control_value LIKE " . $this->quoteLike('*' . $control_value . '*')) . " \r\n                    ORDER BY \r\n                        FieldOption.fieldid, FieldOption.text\r\n                ";
             $this->_db->setQuery($query);
             $field_options = $this->_db->loadAssocList();
         }
     }
     # For FieldOption-Field relationships get field options ordered by a-z ASC to start building the fields array.
     if (!$page_setup && !empty($ids_to_names)) {
         $query = "\r\n                SELECT \r\n                    Field.name, Field.fieldid, FieldOption.optionid, FieldOption.text, FieldOption.value, FieldOption.image, FieldOption.ordering\r\n                FROM \r\n                    #__jreviews_fieldoptions AS FieldOption\r\n                LEFT JOIN\r\n                    #__jreviews_fields AS Field ON Field.fieldid = FieldOption.fieldid\r\n                WHERE\r\n                    Field.published = 1 AND Field.location = " . $this->quote($location) . "  \r\n                    AND " . ($page_setup ? " FieldOption.fieldid IN (" . $this->quote(array_keys($ids_to_names)) . ") " : '1 = 1') . " \r\n                    " . ($page_setup ? " AND Field.control_field = ''" : " AND Field.control_field = " . $this->quote($control_field) . " AND Field.control_value LIKE " . $this->quoteLike('*' . $control_value . '*')) . " \r\n                ORDER BY \r\n                    FieldOption.fieldid, FieldOption.text\r\n            ";
         $this->_db->setQuery($query);
         $field_options = array_merge($field_options, $this->_db->loadAssocList());
     }
     foreach ($field_options as $field_option) {
         $field_id = $field_option['fieldid'];
         $field_name = $field_option['name'];
         unset($field_option['fieldid'], $field_option['name']);
         if (isset($ids_to_names[$field_id])) {
             $fields[$ids_to_names[$field_id]]['options'][] = $field_option;
             isset($selected_values[$field_name]) and $fields[$ids_to_names[$field_id]]['selected'] = $selected_values[$field_name];
         }
     }
     if ($page_setup) {
         $control_field = array_values($control_fields_array);
         $dependent_fields = array();
     } else {
         $control_field = $control_field;
         $dependent_fields = array_values($dependent_fields);
     }
     # Edit mode: for each control field that has a selected value find dependent field options
     foreach ($selected_values as $key => $val) {
         if (!empty($val) && $val != '' && in_array($key, $field_names)) {
             foreach ($val as $selected) {
                 $res = $this->_loadFieldData(false, array('recursive' => true, 'fields' => $key, 'value' => array_shift($val), 'fieldLocation' => $location));
                 if (is_array($res)) {
                     $responses[$res['control_field'][0]][$res['control_value']] = $res;
                     foreach ($res['fields'] as $res_fields) {
                         if (isset($selected_values[$res_fields['name']]) && !empty($res_fields['options']) && empty($fields[$res_fields['name']]['options'])) {
                             $fields[$res_fields['name']] = $res_fields;
                             $fields[$res_fields['name']]['selected'] = $selected_values[$res_fields['name']];
                         }
                     }
                 } elseif ($fields[$key]['type'] != 'text') {
                     $responses[$key][$selected] = array('location' => $location, 'control_field' => array($key), 'control_value' => $selected, 'dependent_groups' => array(), 'dependent_fields' => array(), 'fields' => array());
                 }
             }
         }
     }
     /** DEBUG **/
     //if($json) {prx(compact('page_setup','control_field','control_value','dependent_fields','dependent_groups','fields','responses'));}
     //if($json && !$page_setup) {prx(compact('page_setup','control_field','control_value','dependent_fields','dependent_groups','fields','responses'));}
     $dependent_groups = array_values($dependent_groups);
     $location = $location == 'content' ? 'Listing' : 'Review';
     return $json ? json_encode(compact('page_setup', 'edit', 'location', 'control_field', 'control_value', 'dependent_groups', 'dependent_fields', 'fields', 'responses')) : compact('location', 'control_field', 'control_value', 'dependent_groups', 'dependent_fields', 'fields');
 }
Ejemplo n.º 3
0
 /**
  * Creates the custom field group array with group info and fields values and attributes
  *
  * @param array $entries Entry array must have keys for entry id and criteriaid
  */
 function getFieldsArray($elements, $type = 'listing')
 {
     $fields = array();
     $field_pairs = array();
     $element_ids = array();
     $rows = array();
     $this->criteria_ids = array();
     // Alejandro = for discussion functionality
     //build entry_ids and criteria_ids array
     switch ($type) {
         case 'listing':
             foreach ($elements as $key => $element) {
                 if (isset($element['Criteria'])) {
                     $element_ids[] = $element[inflector::camelize($type)]['listing_id'];
                     if ($element['Criteria']['criteria_id'] != '') {
                         $this->criteria_ids[] = $element['Criteria']['criteria_id'];
                     }
                 }
             }
             break;
         case 'review':
             foreach ($elements as $element) {
                 if (isset($element['Criteria'])) {
                     $element_ids[] = $element[inflector::camelize($type)]['review_id'];
                     if ($element['Criteria']['criteria_id'] != '') {
                         $this->criteria_ids[] = $element['Criteria']['criteria_id'];
                     }
                 }
             }
             break;
     }
     $this->group_ids = $this->_criteria2Groups($this->criteria_ids, $type);
     $criteria_ids = implode(',', $this->criteria_ids);
     $element_ids = implode(',', array_unique($element_ids));
     if (empty($this->group_ids)) {
         return;
     }
     $group_ids = implode(',', $this->group_ids);
     $field_type = $type == 'listing' ? 'content' : $type;
     // Get field attributes and field values
     $query = "SELECT Field.fieldid AS `Field.field_id`, Field.groupid AS `Field.group_id`, Field.name AS `Field.name`, Field.title AS `Field.title`," . "\n Field.showtitle AS `Field.showTitle`, Field.description AS `Field.description`, Field.required AS `Field.required`," . "\n Field.type AS `Field.type`, Field.location AS `Field.location`, Field.options AS `Field.params`," . "\n Field.contentview AS `Field.contentView`, Field.listview AS `Field.listView`, Field.compareview AS `Field.compareView`, Field.listsort AS `Field.listSort`," . "\n Field.search AS `Field.search`, Field.access AS `Field.access`, Field.access_view AS `Field.accessView`," . "\n Field.published As `Field.published`," . "\n `Group`.groupid AS `Group.group_id`, `Group`.title AS `Group.title`, `Group`.name AS `Group.name`, `Group`.showtitle AS `Group.showTitle`" . "\n FROM #__jreviews_fields AS Field" . "\n INNER JOIN #__jreviews_groups AS `Group` ON (`Group`.groupid = Field.groupid AND " . "\n `Group`.groupid IN ({$group_ids}) AND `Group`.type =  '{$field_type}' )" . "\n WHERE Field.location = '{$field_type}' AND Field.published = 1" . "\n ORDER BY Group.ordering, Field.ordering";
     $this->_db->setQuery($query);
     $rows = $this->_db->loadObjectList('Field.name');
     if (!$rows || empty($rows)) {
         return;
     }
     # Extract list of field names from array
     $fieldNames = $optionFieldNames = $nonInputFieldNames = $fieldNamesByType = $fieldRows = array();
     $optionFields = array('selectmultiple', 'checkboxes', 'select', 'radiobuttons');
     $nonInputFields = array('banner');
     foreach ($rows as $key => $row) {
         // Exclude non-input fields, like banner, from forms
         if (!in_array($row->{'Field.type'}, $nonInputFields)) {
             $fieldNames[] = $row->{'Field.name'};
         } else {
             $row->{'Field.search'} = 0;
             $nonInputFieldNames[] = $row->{'Field.name'};
         }
         $fieldIds[$row->{'Field.name'}] = $row->{'Field.field_id'};
         $fieldRows[$key] = (array) $row;
         if (in_array($row->{'Field.type'}, $optionFields)) {
             $optionFieldNames[$row->{'Field.name'}] = $row->{'Field.field_id'};
             // Used to find the option text for each option value
         }
     }
     # Get field values from current element ids
     switch ($type) {
         case 'listing':
             # PaidListings integration
             if (Configure::read('ListingEdit') && Configure::read('PaidListings.enabled') && is_int($element_ids)) {
                 // Load the paid_listing_fields table instead of the jos_content table so users can see all their
                 // fields when editing a listing
                 Configure::write('ListingEdit', false);
                 $fieldValues = PaidListingFieldModel::edit($element_ids);
                 if ($fieldValues) {
                     break;
                 }
             }
             $query = "SELECT Listing.contentid AS element_id," . implode(',', $fieldNames) . "\n FROM #__jreviews_content AS Listing" . "\n WHERE Listing.contentid IN (" . $element_ids . ")";
             $this->_db->setQuery($query);
             $fieldValues = $this->_db->loadObjectList('element_id');
             break;
         case 'review':
             $query = "SELECT Review.reviewid AS element_id," . implode(',', $fieldNames) . "\n FROM #__jreviews_review_fields AS Review" . "\n WHERE Review.reviewid IN (" . $element_ids . ")";
             $this->_db->setQuery($query);
             $fieldValues = $this->_db->loadObjectList('element_id');
             break;
     }
     //prx($optionFieldNames);
     //prx($fieldValues);
     # Now for each option field add array of selected value,text,images
     $elementFields = array();
     $relatedListingIds = array();
     if (!empty($fieldValues)) {
         foreach ($fieldValues as $fieldValue) {
             $fieldValue = array_filter((array) $fieldValue);
             $fieldOptionValuesTemp = array_intersect_key($fieldValue, $optionFieldNames);
             foreach ($fieldOptionValuesTemp as $fname => $optionval) {
                 $values = !is_array($optionval) ? explode('*', $optionval) : $optionval;
                 foreach ($values as $optionval) {
                     if ($optionval != '') {
                         $fieldOptionValuesToSearch[] = $optionval;
                         $fieldOptionFieldIdsToSearch[$optionFieldNames[$fname]] = $optionFieldNames[$fname];
                     }
                 }
             }
         }
         if (!empty($fieldOptionValuesToSearch)) {
             $query = "\n                    SELECT \n                        * \n                    FROM \n                        #__jreviews_fieldoptions\n                    WHERE \n                        fieldid IN ( " . $this->Quote($fieldOptionFieldIdsToSearch) . ")\n                        AND\n                        value IN ( " . $this->Quote($fieldOptionValuesToSearch) . ")\n                    ORDER \n                        BY ordering ASC ,optionid ASC\n                ";
             $this->_db->setQuery($query);
             $SelectedFieldOptionsArray = $this->_db->loadObjectList('optionid');
             # Reformat array, group by field id
             $SelelectedFieldOptionsByValue = array();
             foreach ($SelectedFieldOptionsArray as $option) {
                 $SelelectedFieldOptionsByValue[$option->fieldid][$option->value] = (array) $option;
             }
         }
         //prx($nonInputFieldNames);
         $fnameArray = array_keys($rows);
         foreach ($fieldValues as $fieldValue) {
             $fieldValue = (array) $fieldValue;
             $fieldvalue = $this->sortArrayByArray($fieldValue, $fnameArray);
             foreach ($fnameArray as $key) {
                 $value = '';
                 if (isset($fieldValue[$key])) {
                     $value = $fieldValue[$key];
                 } elseif (in_array($key, $nonInputFieldNames)) {
                     $value = 'banner';
                 }
                 if ($key != 'element_id' && $value != '' && isset($rows[$key])) {
                     $properties = stringToArray($rows[$key]->{'Field.params'});
                     // Process related listing fields. Need to get listing info to build the url
                     if ($rows[$key]->{'Field.type'} == 'relatedlisting') {
                         if ($value == 0) {
                             continue;
                         }
                         $relatedListingIds[] = $value;
                     }
                     // Strip html from fields except those where it is allowed
                     if (!is_array($value) && (!in_array($rows[$key]->{'Field.type'}, array('text', 'textarea', 'code')) || in_array($rows[$key]->{'Field.type'}, array('text', 'textarea')) && Sanitize::getBool($properties, 'allow_html') == false)) {
                         $value = htmlspecialchars($value, ENT_QUOTES, 'UTF-8');
                     }
                     if ($rows[$key]->{'Field.type'} != 'date' || $rows[$key]->{'Field.type'} == 'date' && $value != NULL_DATE) {
                         $elementFields[$fieldValue['element_id']]['field_id'] = $fieldRows[$key]['Field.field_id'];
                         if (!in_array($rows[$key]->{'Field.type'}, $optionFields)) {
                             $elementFields[$fieldValue['element_id']][$key]['Field.text'][] = $value;
                             $elementFields[$fieldValue['element_id']][$key]['Field.value'][] = $value;
                             $elementFields[$fieldValue['element_id']][$key]['Field.image'][] = '';
                         } elseif (in_array($rows[$key]->{'Field.type'}, $optionFields)) {
                             $fieldOptions = Sanitize::getVar($SelelectedFieldOptionsByValue, $rows[$key]->{'Field.field_id'});
                             $selOptions = !is_array($value) ? explode('*', $value) : $value;
                             foreach ($selOptions as $selOption) {
                                 if ($selOption != '' && isset($fieldOptions[$selOption])) {
                                     $elementFields[$fieldValue['element_id']][$key]['Field.value'][] = $fieldOptions[$selOption]['value'];
                                     $elementFields[$fieldValue['element_id']][$key]['Field.text'][] = $fieldOptions[$selOption]['text'];
                                     $elementFields[$fieldValue['element_id']][$key]['Field.image'][] = $fieldOptions[$selOption]['image'];
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     $relatedListings = $this->getRelatedListings($relatedListingIds);
     // Reformat array so array keys match element ids
     foreach ($elementFields as $key => $elementField) {
         $element_id = $key;
         $field_id = $elementField['field_id'];
         unset($elementField['field_id']);
         $field_name = key($elementField);
         foreach ($elementField as $field_name => $field_options) {
             //FieldGroups array
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Group']['group_id'] = $fieldRows[$field_name]['Field.group_id'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Group']['title'] = $fieldRows[$field_name]['Group.title'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Group']['name'] = $fieldRows[$field_name]['Group.name'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Group']['show_title'] = $fieldRows[$field_name]['Group.showTitle'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['id'] = $field_id;
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['group_id'] = $fieldRows[$field_name]['Field.group_id'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['name'] = $fieldRows[$field_name]['Field.name'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['type'] = $fieldRows[$field_name]['Field.type'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['title'] = $fieldRows[$field_name]['Field.title'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['description'] = $fieldRows[$field_name]['Field.description'];
             // Field values
             //                prx($field_options);exit;
             if ($fieldRows[$field_name]['Field.type'] == 'relatedlisting') {
                 $value = isset($relatedListings[$field_options['Field.value'][0]]) ? array($relatedListings[$field_options['Field.value'][0]]['value']) : '';
                 $real_value = $field_options['Field.value'];
                 $text = isset($relatedListings[$field_options['Field.text'][0]]) ? array($relatedListings[$field_options['Field.value'][0]]['text']) : '';
                 $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['value'] = $value;
                 $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['text'] = $text;
                 $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['real_value'] = $field_options['Field.text'];
             } else {
                 $value = $field_options['Field.value'];
                 $text = $field_options['Field.text'];
                 $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['value'] = $value;
                 $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['text'] = $text;
             }
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['image'] = $field_options['Field.image'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['properties']['show_title'] = $fieldRows[$field_name]['Field.showTitle'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['properties']['location'] = $fieldRows[$field_name]['Field.location'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['properties']['contentview'] = $fieldRows[$field_name]['Field.contentView'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['properties']['listview'] = $fieldRows[$field_name]['Field.listView'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['properties']['compareview'] = $fieldRows[$field_name]['Field.compareView'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['properties']['listsort'] = $fieldRows[$field_name]['Field.listSort'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['properties']['search'] = $fieldRows[$field_name]['Field.search'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['properties']['access'] = $fieldRows[$field_name]['Field.access'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['properties']['access_view'] = $fieldRows[$field_name]['Field.accessView'];
             //FieldPairs associative array with field name as key and field value as value
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['field_id'] = $element_id;
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['group_id'] = $fieldRows[$field_name]['Field.group_id'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['group_show_title'] = $fieldRows[$field_name]['Group.showTitle'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['group_title'] = $fieldRows[$field_name]['Group.title'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['group_name'] = $fieldRows[$field_name]['Group.name'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['name'] = $fieldRows[$field_name]['Field.name'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['title'] = $fieldRows[$field_name]['Field.title'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['value'] = $value;
             isset($real_value) and $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['real_value'] = $real_value;
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['text'] = $text;
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['image'] = $field_options['Field.image'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['type'] = $fieldRows[$field_name]['Field.type'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['description'] = $fieldRows[$field_name]['Field.description'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['properties']['show_title'] = $fieldRows[$field_name]['Field.showTitle'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['properties']['location'] = $fieldRows[$field_name]['Field.location'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['properties']['contentview'] = $fieldRows[$field_name]['Field.contentView'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['properties']['listview'] = $fieldRows[$field_name]['Field.listView'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['properties']['compareview'] = $fieldRows[$field_name]['Field.compareView'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['properties']['listsort'] = $fieldRows[$field_name]['Field.listSort'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['properties']['search'] = $fieldRows[$field_name]['Field.search'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['properties']['access'] = $fieldRows[$field_name]['Field.access'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['properties']['access_view'] = $fieldRows[$field_name]['Field.accessView'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['properties']['access_view'] = $fieldRows[$field_name]['Field.accessView'];
             $properties = stringToArray($fieldRows[$field_name]['Field.params']);
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['properties'] = array_merge($fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['properties'], $properties);
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['properties'] = array_merge($field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['properties'], $properties);
             //$params = explode("\n",$fieldRows[$field_name]['Field.params']);
         }
     }
     $this->custom_fields = $fields;
     $this->field_pairs = $field_pairs;
 }