예제 #1
0
 public function __call($ps_function, $pa_args)
 {
     $ps_function = strtolower($ps_function);
     if (!($va_form_info = $this->_checkForm($ps_function))) {
         return;
     }
     $this->view->setVar('t_subject', $t_subject = $this->pt_subject);
     $va_tags = $this->view->getTagList($va_form_info['view']);
     foreach ($va_tags as $vs_tag) {
         if (in_array($vs_tag, array('form', '/form', 'submit', 'reset'))) {
             continue;
         }
         $va_parse = caParseTagOptions($vs_tag);
         $vs_tag_proc = $va_parse['tag'];
         $va_opts = $va_parse['options'];
         if (($vs_default_value = caGetOption('default', $va_opts, null)) || ($vs_default_value = caGetOption($vs_tag_proc, $va_default_form_values, null))) {
             $va_default_form_values[$vs_tag_proc] = $vs_default_value;
             unset($va_opts['default']);
         }
         $vs_tag_val = null;
         switch (strtolower($vs_tag_proc)) {
             case 'submit':
                 $this->view->setVar($vs_tag, "<a href='#' class='caContributeFormSubmit'>" . (isset($va_opts['label']) && $va_opts['label'] ? $va_opts['label'] : _t('Submit')) . "</a>");
                 break;
             case 'reset':
                 $this->view->setVar($vs_tag, "<a href='#' class='caContributeFormReset'>" . (isset($va_opts['label']) && $va_opts['label'] ? $va_opts['label'] : _t('Reset')) . "</a>");
                 $vs_script = "<script type='text/javascript'>\n\tjQuery('.caContributeFormSubmit').bind('click', function() {\n\t\tjQuery('#caContribute').submit();\n\t\treturn false;\n\t});\n\tjQuery('.caContributeFormReset').bind('click', function() {\n\t\tjQuery('#caContribute').find('input[type!=\"hidden\"],textarea').val('');\n\t\tjQuery('#caContribute').find('select.caContributeBoolean').val('AND');\n\t\tjQuery('#caContribute').find('select').prop('selectedIndex', 0);\n\t\treturn false;\n\t});\n\tjQuery(document).ready(function() {\n\t\tvar f, defaultValues = " . json_encode($va_default_form_values) . ", defaultBooleans = " . json_encode($va_default_form_booleans) . ";\n\t\tfor (f in defaultValues) {\n\t\t\tvar f_proc = f + '[]';\n\t\t\tjQuery('input[name=\"' + f_proc+ '\"], textarea[name=\"' + f_proc+ '\"], select[name=\"' + f_proc+ '\"]').each(function(k, v) {\n\t\t\t\tif (defaultValues[f][k]) { jQuery(v).val(defaultValues[f][k]); } \n\t\t\t});\n\t\t}\n\t\tfor (f in defaultBooleans) {\n\t\t\tvar f_proc = f + '[]';\n\t\t\tjQuery('select[name=\"' + f_proc+ '\"].caContributeBoolean').each(function(k, v) {\n\t\t\t\tif (defaultBooleans[f][k]) { jQuery(v).val(defaultBooleans[f][k]); }\n\t\t\t});\n\t\t}\n\t});\n</script>\n";
                 break;
             default:
                 if (preg_match("!^(.*):label\$!", $vs_tag_proc, $va_matches)) {
                     $this->view->setVar($vs_tag, $vs_tag_val = $t_subject->getDisplayLabel($va_matches[1]));
                 } else {
                     $va_opts['asArrayElement'] = true;
                     if ($vs_tag_val = $t_subject->htmlFormElementForSimpleForm($this->request, $vs_tag_proc, $va_opts)) {
                         $this->view->setVar($vs_tag, $vs_tag_val);
                     }
                     $va_tmp = explode('.', $vs_tag_proc);
                     if (($t_element = ca_metadata_elements::getInstance($va_tmp[1])) && $t_element->get('datatype') == 0) {
                         if (is_array($va_elements = $t_element->getElementsInSet())) {
                             foreach ($va_elements as $va_element) {
                                 if ($va_element['datatype'] > 0) {
                                     $va_form_elements[] = $va_tmp[0] . '.' . $va_tmp[1] . '.' . $va_element['element_code'];
                                 }
                             }
                         }
                         break;
                     }
                 }
                 if ($vs_tag_val) {
                     $va_form_elements[] = $vs_tag_proc;
                 }
                 break;
         }
     }
     $this->view->setVar("form", caFormTag($this->request, "Send", 'caContribute', null, 'post', 'multipart/form-data', '_top', array('disableUnsavedChangesWarning' => true)));
     $this->view->setVar("/form", $vs_script . caHTMLHiddenInput("_contributeFormName", array("value" => $ps_function)) . caHTMLHiddenInput("_formElements", array("value" => join(';', $va_form_elements))) . caHTMLHiddenInput("_contribute", array("value" => 1)) . "</form>");
     $this->render($va_form_info['view']);
 }
 /**
  * Returns list of placements for the currently loaded display.
  *
  * @param array $pa_options Optional array of options. Supports the following options:
  * 		noCache = if set to true then the returned list if always generated directly from the database, otherwise it is returned from the cache if possible. Set this to true if you expect the cache may be stale. Default is false.
  *		returnAllAvailableIfEmpty = if set to true then the list of all available bundles will be returned if the currently loaded display has no placements, or if there is no display loaded
  *		table = if using the returnAllAvailableIfEmpty option and you expect a list of available bundles to be returned if no display is loaded, you must specify the table the bundles are intended for use with with this option. Either the table name or number may be used.
  *		user_id = if specified then placements are only returned if the user has at least read access to the display
  *		settingsOnly = if true the settings forms are omitted and only setting values are returned; default is false
  * @return array List of placements in display order. Array is keyed on bundle name. Values are arrays with the following keys:
  *		placement_id = primary key of ca_bundle_display_placements row - a unique id for the placement
  *		bundle_name = bundle name (a code - not for display)
  *		settings = array of placement settings. Keys are setting names.
  *		display = display string for bundle
  */
 public function getPlacements($pa_options = null)
 {
     $pb_no_cache = isset($pa_options['noCache']) ? (bool) $pa_options['noCache'] : false;
     $pb_settings_only = isset($pa_options['settingsOnly']) ? (bool) $pa_options['settingsOnly'] : false;
     $pb_return_all_available_if_empty = isset($pa_options['returnAllAvailableIfEmpty']) && !$pb_settings_only ? (bool) $pa_options['returnAllAvailableIfEmpty'] : false;
     $ps_table = isset($pa_options['table']) ? $pa_options['table'] : null;
     $pn_user_id = isset($pa_options['user_id']) ? $pa_options['user_id'] : null;
     if ($pn_user_id && !$this->haveAccessToDisplay($pn_user_id, __CA_BUNDLE_DISPLAY_READ_ACCESS__)) {
         return array();
     }
     if (!($vn_display_id = $this->getPrimaryKey())) {
         if ($pb_return_all_available_if_empty && $ps_table) {
             return ca_bundle_displays::$s_placement_list_cache[$vn_display_id] = $this->getAvailableBundles($ps_table);
         }
         return array();
     }
     $vs_cache_key = $vn_display_id . '/' . ($pb_settings_only ? 1 : 0);
     if (!$pb_no_cache && isset(ca_bundle_displays::$s_placement_list_cache[$vs_cache_key]) && ca_bundle_displays::$s_placement_list_cache[$vs_cache_key]) {
         return ca_bundle_displays::$s_placement_list_cache[$vs_cache_key];
     }
     $o_dm = $this->getAppDatamodel();
     $o_db = $this->getDb();
     $t_list = new ca_lists();
     if ($this->inTransaction()) {
         $t_list->setTransaction($this->getTransaction());
     }
     $qr_res = $o_db->query("\n\t\t\tSELECT placement_id, bundle_name, settings\n\t\t\tFROM ca_bundle_display_placements\n\t\t\tWHERE\n\t\t\t\tdisplay_id = ?\n\t\t\tORDER BY rank\n\t\t", (int) $vn_display_id);
     $va_available_bundles = $pb_settings_only ? array() : $this->getAvailableBundles(null, $pa_options);
     $va_placements = array();
     if ($qr_res->numRows() > 0) {
         $vs_subject_table = $o_dm->getTableName($this->get('table_num'));
         $t_subject = $o_dm->getInstanceByTableNum($this->get('table_num'), true);
         $t_placement = new ca_bundle_display_placements();
         if ($this->inTransaction()) {
             $t_placement->setTransaction($this->getTransaction());
         }
         while ($qr_res->nextRow()) {
             $vs_bundle_name = $qr_res->get('bundle_name');
             $va_bundle_name = explode(".", $vs_bundle_name);
             $va_placements[$vn_placement_id = (int) $qr_res->get('placement_id')] = $qr_res->getRow();
             $va_placements[$vn_placement_id]['settings'] = $va_settings = caUnserializeForDatabase($qr_res->get('settings'));
             if (!$pb_settings_only) {
                 $t_placement->setSettingDefinitionsForPlacement($va_available_bundles[$vs_bundle_name]['settings']);
                 $va_placements[$vn_placement_id]['display'] = $va_available_bundles[$vs_bundle_name]['display'];
                 $va_placements[$vn_placement_id]['settingsForm'] = $t_placement->getHTMLSettingForm(array('id' => $vs_bundle_name . '_' . $vn_placement_id, 'settings' => $va_settings));
             } else {
                 $va_tmp = explode('.', $vs_bundle_name);
                 $t_instance = $o_dm->getInstanceByTableName($va_tmp[0], true);
                 $va_placements[$vn_placement_id]['display'] = $t_instance ? $t_instance->getDisplayLabel($vs_bundle_name) : "???";
             }
             if ($va_bundle_name[0] == $vs_subject_table) {
                 // Only primary fields are inline-editable
                 // Check if it is one of the types of fields that is inline editable
                 if ($va_bundle_name[1] == 'preferred_labels') {
                     // Preferred labels are inline editable
                     $va_placements[$vn_placement_id]['allowInlineEditing'] = true;
                     $va_placements[$vn_placement_id]['inlineEditingType'] = DT_FIELD;
                 } elseif ($t_subject->hasField($va_bundle_name[1])) {
                     //
                     // Intrinsics are editable, except for type_id
                     //
                     if ($va_bundle_name[1] == $t_subject->getTypeFieldName()) {
                         $va_placements[$vn_placement_id]['allowInlineEditing'] = false;
                         $va_placements[$vn_placement_id]['inlineEditingType'] = null;
                     } else {
                         if (isset($va_bundle_name[1])) {
                             // check if identifier is editable
                             $id_editable = $t_subject->opo_idno_plugin_instance->isFormatEditable($vs_subject_table);
                             // Do not allow in-line editing if the intrinsic element is identifier and
                             // a). is not editable (editable = 0 in multipart_id_numbering.conf)
                             // b). consists of multiple elements
                             if ($va_bundle_name[1] == $t_subject->getProperty('ID_NUMBERING_ID_FIELD') && $id_editable == false) {
                                 $va_placements[$vn_placement_id]['allowInlineEditing'] = false;
                             } else {
                                 $va_placements[$vn_placement_id]['allowInlineEditing'] = true;
                             }
                         }
                         switch ($t_subject->getFieldInfo($va_bundle_name[1], 'DISPLAY_TYPE')) {
                             case 'DT_SELECT':
                                 if (($vs_list_code = $t_subject->getFieldInfo($va_bundle_name[1], 'LIST')) || ($vs_list_code = $t_subject->getFieldInfo($va_bundle_name[1], 'LIST_CODE'))) {
                                     $va_placements[$vn_placement_id]['inlineEditingType'] = DT_SELECT;
                                     if (!is_array($va_list_labels = $t_list->getItemsForList($vs_list_code, array('labelsOnly' => true)))) {
                                         $va_list_labels = array();
                                     }
                                     $va_placements[$vn_placement_id]['inlineEditingListValues'] = array_values($va_list_labels);
                                 } else {
                                     $va_placements[$vn_placement_id]['inlineEditingType'] = DT_FIELD;
                                 }
                                 break;
                             default:
                                 $va_placements[$vn_placement_id]['inlineEditingType'] = DT_FIELD;
                                 break;
                         }
                     }
                 } elseif ($t_subject->hasElement($va_bundle_name[1])) {
                     $vn_data_type = ca_metadata_elements::getElementDatatype($va_bundle_name[1]);
                     switch ($vn_data_type) {
                         case 1:
                         case 2:
                         case 5:
                         case 6:
                         case 8:
                         case 9:
                         case 10:
                         case 11:
                         case 12:
                             $va_placements[$vn_placement_id]['allowInlineEditing'] = true;
                             $va_placements[$vn_placement_id]['inlineEditingType'] = DT_FIELD;
                             break;
                         case 3:
                             // lists
                             if ($t_element = ca_metadata_elements::getInstance($va_bundle_name[1])) {
                                 switch ($t_element->getSetting('render')) {
                                     case 'select':
                                     case 'yes_no_checkboxes':
                                     case 'radio_buttons':
                                     case 'checklist':
                                         $va_placements[$vn_placement_id]['allowInlineEditing'] = true;
                                         $va_placements[$vn_placement_id]['inlineEditingType'] = DT_SELECT;
                                         $va_placements[$vn_placement_id]['inlineEditingListValues'] = array_values($t_list->getItemsForList($t_element->get("list_id"), array('labelsOnly' => true)));
                                         break;
                                     case 'lookup':
                                     case 'horiz_hierbrowser':
                                     case 'horiz_hierbrowser_with_search':
                                     case 'vert_hierbrowser':
                                         $va_placements[$vn_placement_id]['allowInlineEditing'] = true;
                                         $va_placements[$vn_placement_id]['inlineEditingType'] = DT_LOOKUP;
                                         $va_placements[$vn_placement_id]['inlineEditingList'] = $t_element->get('list_id');
                                         break;
                                     default:
                                         // if it's a render setting we don't know about it's not editable
                                         $va_placements[$vn_placement_id]['allowInlineEditing'] = false;
                                         $va_placements[$vn_placement_id]['inlineEditingType'] = null;
                                         break;
                                 }
                             }
                             break;
                         default:
                             $va_placements[$vn_placement_id]['allowInlineEditing'] = false;
                             $va_placements[$vn_placement_id]['inlineEditingType'] = null;
                             break;
                     }
                 } else {
                     $va_placements[$vn_placement_id]['allowInlineEditing'] = false;
                     $va_placements[$vn_placement_id]['inlineEditingType'] = null;
                 }
             } else {
                 // Related bundles are never inline-editable (for now)
                 $va_placements[$vn_placement_id]['allowInlineEditing'] = false;
                 $va_placements[$vn_placement_id]['inlineEditingType'] = null;
             }
         }
     } else {
         if ($pb_return_all_available_if_empty) {
             $va_placements = $this->getAvailableBundles($this->get('table_num'));
         }
     }
     return ca_bundle_displays::$s_placement_list_cache[$vs_cache_key] = $va_placements;
 }
예제 #3
0
 private function processMetadataElement($po_element, $pn_parent_id)
 {
     require_once __CA_MODELS_DIR__ . "/ca_metadata_elements.php";
     require_once __CA_MODELS_DIR__ . "/ca_lists.php";
     if (($vn_datatype = ca_metadata_elements::getAttributeTypeCode(self::getAttribute($po_element, "datatype"))) === false) {
         return false;
         // should not happen due to XSD restrictions, but just in case
     }
     $vs_element_code = self::getAttribute($po_element, "code");
     $t_lists = new ca_lists();
     if ($this->opb_updating) {
         $t_md_element = ca_metadata_elements::getInstance($vs_element_code) ? ca_metadata_elements::getInstance($vs_element_code) : new ca_metadata_elements();
     } else {
         $t_md_element = new ca_metadata_elements();
     }
     $t_md_element->setMode(ACCESS_WRITE);
     $t_md_element->set('element_code', $vs_element_code);
     $t_md_element->set('parent_id', $pn_parent_id);
     $t_md_element->set('documentation_url', (string) $po_element->documentationUrl);
     $t_md_element->set('datatype', $vn_datatype);
     $vs_list = self::getAttribute($po_element, "list");
     if (isset($vs_list) && $vs_list && $t_lists->load(array('list_code' => $vs_list))) {
         $vn_list_id = $t_lists->getPrimaryKey();
     } else {
         $vn_list_id = null;
     }
     $t_md_element->set('list_id', $vn_list_id);
     $this->_processSettings($t_md_element, $po_element->settings);
     if ($t_md_element->getPrimaryKey()) {
         $t_md_element->update();
     } else {
         $t_md_element->insert();
     }
     if ($t_md_element->numErrors()) {
         $this->addError("There was an error while inserting metadata element {$vs_element_code}: " . join(" ", $t_md_element->getErrors()));
         return false;
     }
     $vn_element_id = $t_md_element->getPrimaryKey();
     // add element labels
     self::addLabelsFromXMLElement($t_md_element, $po_element->labels, $this->opa_locales);
     if ($po_element->elements) {
         foreach ($po_element->elements->children() as $vo_child) {
             $this->processMetadataElement($vo_child, $vn_element_id);
         }
     }
     return $vn_element_id;
 }
예제 #4
0
 public function getFacet($pa_options = null)
 {
     $va_access_values = caGetUserAccessValues($this->request);
     $ps_facet_name = $this->request->getParameter('facet', pString);
     $this->view->setVar('only_show_group', $vs_show_group = $this->request->getParameter('show_group', pString));
     $this->view->setVar('grouping', $vs_grouping = $this->request->getParameter('grouping', pString));
     $this->view->setVar('id', $vm_id = $this->request->getParameter('id', pString));
     $vs_cache_key = md5(join("/", array($ps_facet_name, $vs_show_group, $vs_grouping, $vm_id)));
     $va_facet_info = $this->opo_browse->getInfoForFacet($ps_facet_name);
     if ($va_facet_info['group_mode'] != 'hierarchical' && ($vs_content = $this->opo_browse->getCachedFacetHTML($vs_cache_key))) {
         $this->response->addContent($vs_content);
         return;
     }
     // Enforce type restriction
     $this->opo_browse->setTypeRestrictions(array($this->opn_type_restriction_id));
     if ($this->request->getParameter('clear', pInteger)) {
         $this->opo_browse->removeAllCriteria();
         $this->opo_browse->execute(array('checkAccess' => $va_access_values));
         $this->opo_result_context->setSearchExpression($this->opo_browse->getBrowseID());
         $this->opo_result_context->saveContext();
     } else {
         if ($this->request->getParameter('modify', pString)) {
             $this->opo_browse->removeCriteria($ps_facet_name, array($vm_id));
             $this->opo_browse->execute(array('checkAccess' => $va_access_values));
             $this->view->setVar('modify', $vm_id);
         }
     }
     // Using the back-button can cause requests for facets that are no longer available
     // In these cases we reset the browse.
     if (!($va_facet = $this->opo_browse->getFacet($ps_facet_name, array('sort' => 'name', 'checkAccess' => $va_access_values)))) {
         $this->opo_browse->removeAllCriteria();
         $this->opo_browse->execute();
         $va_facet = $this->opo_browse->getFacet($ps_facet_name, array('sort' => 'name', 'checkAccess' => $va_access_values));
         $va_facet_info = $this->opo_browse->getInfoForFacet($ps_facet_name);
         $this->opo_result_context->setSearchExpression($this->opo_browse->getBrowseID());
         $this->opo_result_context->saveContext();
     }
     $this->view->setVar('browse_last_id', (int) $vm_id ? (int) $vm_id : (int) $this->opo_result_context->getParameter($ps_facet_name . '_browse_last_id'));
     $this->view->setVar('facet', $va_facet);
     $va_facet_info = $this->opo_browse->getInfoForFacet($ps_facet_name);
     if ($va_facet_info['type'] == 'attribute') {
         // set table for authority element so browse can use table-specific services (Eg. entity lookups for attributes of type Entity)
         if ($t_element = ca_metadata_elements::getInstance($va_facet_info['element_code'])) {
             if ($t_authority = AuthorityAttributeValue::elementTypeToInstance($t_element->get('datatype'))) {
                 $va_facet_info['table'] = $t_authority->tableName();
             }
         }
     }
     $this->view->setVar('facet_info', $va_facet_info);
     $this->view->setVar('facet_name', $ps_facet_name);
     $this->view->setVar('individual_group_display', isset($va_facet_info['individual_group_display']) ? (bool) $va_facet_info['individual_group_display'] : false);
     // this should be 'facet' but we don't want to render all old 'ajax_browse_facet_html' views (pawtucket themes) unusable
     $this->view->setVar('grouped_facet', $this->opo_browse->getFacetWithGroups($ps_facet_name, $va_facet_info["group_mode"], $vs_grouping, array('sort' => 'name', 'checkAccess' => $va_access_values)));
     // generate type menu and type value list for related authority table facet
     if ($va_facet_info['type'] === 'authority') {
         $t_model = $this->opo_datamodel->getTableInstance($va_facet_info['table']);
         if (method_exists($t_model, "getTypeList")) {
             $this->view->setVar('type_list', $t_model->getTypeList());
         }
         $t_rel_types = new ca_relationship_types();
         $this->view->setVar('relationship_type_list', $t_rel_types->getRelationshipInfo($va_facet_info['relationship_table']));
         $this->view->setVar('t_item', $t_model);
     }
     $this->view->setVar('t_subject', $this->opo_datamodel->getInstanceByTableName($this->ops_tablename, true));
     $this->opo_result_context->saveContext();
     if (isset($pa_options['view']) && $pa_options['view']) {
         $vs_content = $this->render($pa_options['view']);
     } else {
         $vs_content = $this->render('Browse/ajax_browse_facet_html.php');
     }
     $this->opo_browse->setCachedFacetHTML($vs_cache_key, $vs_content);
 }
예제 #5
0
 /** 
  * 
  */
 public function advanced()
 {
     $o_config = caGetSearchConfig();
     $ps_function = strtolower($this->request->getActionExtra());
     if (!($va_search_info = caGetInfoForAdvancedSearchType($ps_function))) {
         // invalid advanced search type – throw error
         die("Invalid advanced search type");
     }
     $vs_class = $va_search_info['table'];
     $va_types = caGetOption('restrictToTypes', $va_search_info, array(), array('castTo' => 'array'));
     $this->opo_result_context = new ResultContext($this->request, $va_search_info['table'], $this->ops_find_type . '_advanced');
     $this->opo_result_context->setAsLastFind();
     MetaTagManager::setWindowTitle($this->request->config->get("app_display_name") . ": " . _t("Search %1", $va_search_info["displayName"]));
     $this->view->setVar('searchInfo', $va_search_info);
     $this->view->setVar('options', caGetOption('options', $va_search_info, array(), array('castTo' => 'array')));
     $va_default_form_values = $this->opo_result_context->getParameter("pawtucketAdvancedSearchFormContent_{$ps_function}");
     $va_default_form_booleans = $this->opo_result_context->getParameter("pawtucketAdvancedSearchFormBooleans_{$ps_function}");
     $va_tags = $this->view->getTagList($va_search_info['view']);
     $t_subject = $this->request->datamodel->getInstanceByTableName($va_search_info['table'], true);
     $va_form_elements = array();
     $vs_script = null;
     foreach ($va_tags as $vs_tag) {
         $va_parse = caParseTagOptions($vs_tag);
         $vs_tag_proc = $va_parse['tag'];
         $va_opts = $va_parse['options'];
         if (($vs_default_value = caGetOption('default', $va_opts, null)) || ($vs_default_value = caGetOption($vs_tag_proc, $va_default_form_values, null))) {
             $va_default_form_values[$vs_tag_proc] = $vs_default_value;
             unset($va_opts['default']);
         }
         $vs_tag_val = null;
         switch (strtolower($vs_tag_proc)) {
             case 'submit':
                 $this->view->setVar($vs_tag, "<a href='#' class='caAdvancedSearchFormSubmit'>" . (isset($va_opts['label']) && $va_opts['label'] ? $va_opts['label'] : _t('Submit')) . "</a>");
                 break;
             case 'reset':
                 $this->view->setVar($vs_tag, "<a href='#' class='caAdvancedSearchFormReset'>" . (isset($va_opts['label']) && $va_opts['label'] ? $va_opts['label'] : _t('Reset')) . "</a>");
                 $vs_script = "<script type='text/javascript'>\n\tjQuery('.caAdvancedSearchFormSubmit').bind('click', function() {\n\t\tjQuery('#caAdvancedSearch').submit();\n\t\treturn false;\n\t});\n\tjQuery('.caAdvancedSearchFormReset').bind('click', function() {\n\t\tjQuery('#caAdvancedSearch').find('input[type!=\"hidden\"],textarea').val('');\n\t\tjQuery('#caAdvancedSearch').find('select.caAdvancedSearchBoolean').val('AND');\n\t\tjQuery('#caAdvancedSearch').find('select').prop('selectedIndex', 0);\n\t\treturn false;\n\t});\n\tjQuery(document).ready(function() {\n\t\tvar f, defaultValues = " . json_encode($va_default_form_values) . ", defaultBooleans = " . json_encode($va_default_form_booleans) . ";\n\t\tfor (f in defaultValues) {\n\t\t\tvar f_proc = f + '[]';\n\t\t\tjQuery('input[name=\"' + f_proc+ '\"], textarea[name=\"' + f_proc+ '\"], select[name=\"' + f_proc+ '\"]').each(function(k, v) {\n\t\t\t\tif (defaultValues[f][k]) { jQuery(v).val(defaultValues[f][k]); } \n\t\t\t});\n\t\t}\n\t\tfor (f in defaultBooleans) {\n\t\t\tvar f_proc = f + '[]';\n\t\t\tjQuery('select[name=\"' + f_proc+ '\"].caAdvancedSearchBoolean').each(function(k, v) {\n\t\t\t\tif (defaultBooleans[f][k]) { jQuery(v).val(defaultBooleans[f][k]); }\n\t\t\t});\n\t\t}\n\t});\n</script>\n";
                 break;
             default:
                 if (preg_match("!^(.*):label\$!", $vs_tag_proc, $va_matches)) {
                     $this->view->setVar($vs_tag, $vs_tag_val = $t_subject->getDisplayLabel($va_matches[1]));
                 } elseif (preg_match("!^(.*):boolean\$!", $vs_tag_proc, $va_matches)) {
                     $this->view->setVar($vs_tag, caHTMLSelect($vs_tag_proc . '[]', array(_t('AND') => 'AND', _t('OR') => 'OR', 'AND NOT' => 'AND NOT'), array('class' => 'caAdvancedSearchBoolean')));
                 } else {
                     $va_opts['asArrayElement'] = true;
                     if (isset($va_opts['restrictToTypes']) && $va_opts['restrictToTypes'] && !is_array($va_opts['restrictToTypes'])) {
                         $va_opts['restrictToTypes'] = explode(";", $va_opts['restrictToTypes']);
                     }
                     if ($vs_tag_val = $t_subject->htmlFormElementForSearch($this->request, $vs_tag_proc, $va_opts)) {
                         $this->view->setVar($vs_tag, $vs_tag_val);
                     }
                     $va_tmp = explode('.', $vs_tag_proc);
                     if (($t_element = ca_metadata_elements::getInstance($va_tmp[1])) && $t_element->get('datatype') == 0) {
                         if (is_array($va_elements = $t_element->getElementsInSet())) {
                             foreach ($va_elements as $va_element) {
                                 if ($va_element['datatype'] > 0) {
                                     $va_form_elements[] = $va_tmp[0] . '.' . $va_tmp[1] . '.' . $va_element['element_code'];
                                 }
                             }
                         }
                         break;
                     }
                 }
                 if ($vs_tag_val) {
                     $va_form_elements[] = $vs_tag_proc;
                 }
                 break;
         }
     }
     $this->view->setVar("form", caFormTag($this->request, "{$ps_function}", 'caAdvancedSearch', null, 'post', 'multipart/form-data', '_top', array('disableUnsavedChangesWarning' => true, 'submitOnReturn' => true)));
     $this->view->setVar("/form", $vs_script . caHTMLHiddenInput("_advancedFormName", array("value" => $ps_function)) . caHTMLHiddenInput("_formElements", array("value" => join(';', $va_form_elements))) . caHTMLHiddenInput("_advanced", array("value" => 1)) . "</form>");
     $this->render($va_search_info['view']);
 }
예제 #6
0
 /**
  * Get sort keys for list of hits from a given table
  *
  * @param string $ps_element_code
  * @param int $pn_table_num
  * @param array $pa_hits
  * @return array|bool
  */
 private function _getSortKeysForElement($ps_element_code, $pn_table_num, $pa_hits)
 {
     if (!($t_element = ca_metadata_elements::getInstance($ps_element_code))) {
         return false;
     }
     // is metadata element
     $vn_element_id = $t_element->getPrimaryKey();
     if (!($vs_sortable_value_fld = Attribute::getSortFieldForDatatype($t_element->get('datatype')))) {
         return false;
     }
     $vs_sql = null;
     switch ($vn_datatype = (int) $t_element->get('datatype')) {
         case __CA_ATTRIBUTE_VALUE_LIST__:
             $vs_sql = "\n\t\t\t\t\t\t\tSELECT attr.row_id, lower(lil.name_plural) name_plural\n\t\t\t\t\t\t\tFROM ca_attributes attr\n\t\t\t\t\t\t\tINNER JOIN ca_attribute_values AS attr_vals ON attr_vals.attribute_id = attr.attribute_id\n\t\t\t\t\t\t\tINNER JOIN ca_list_item_labels AS lil ON lil.item_id = attr_vals.item_id\n\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t(attr_vals.element_id = ?) AND\n\t\t\t\t\t\t\t\t(attr.table_num = ?) AND\n\t\t\t\t\t\t\t\t(lil.name_plural IS NOT NULL) AND\n\t\t\t\t\t\t\t\t(attr.row_id IN (?))\n\t\t\t\t\t\t";
             break;
         case __CA_ATTRIBUTE_VALUE_OBJECTS__:
         case __CA_ATTRIBUTE_VALUE_ENTITIES__:
         case __CA_ATTRIBUTE_VALUE_PLACES__:
         case __CA_ATTRIBUTE_VALUE_OCCURRENCES__:
         case __CA_ATTRIBUTE_VALUE_COLLECTIONS__:
         case __CA_ATTRIBUTE_VALUE_LOANS__:
         case __CA_ATTRIBUTE_VALUE_MOVEMENTS__:
         case __CA_ATTRIBUTE_VALUE_STORAGELOCATIONS__:
         case __CA_ATTRIBUTE_VALUE_OBJECTLOTS__:
             if (!($vs_sortable_value_fld = Attribute::getSortFieldForDatatype($vn_datatype))) {
                 break;
             }
             if (!($t_auth_instance = AuthorityAttributeValue::elementTypeToInstance($vn_datatype))) {
                 break;
             }
             $vs_sql = "\n\t\t\t\t\t\t\tSELECT attr.row_id, lower(lil.{$vs_sortable_value_fld}) {$vs_sortable_value_fld}\n\t\t\t\t\t\t\tFROM ca_attributes attr\n\t\t\t\t\t\t\tINNER JOIN ca_attribute_values AS attr_vals ON attr_vals.attribute_id = attr.attribute_id\n\t\t\t\t\t\t\tINNER JOIN " . $t_auth_instance->getLabelTableName() . " AS lil ON lil.value_integer1 = attr_vals.item_id\n\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t(attr_vals.element_id = ?) AND\n\t\t\t\t\t\t\t\t(attr.table_num = ?) AND\n\t\t\t\t\t\t\t\t(lil.{$vs_sortable_value_fld} IS NOT NULL) AND\n\t\t\t\t\t\t\t\t(attr.row_id IN (?))\n\t\t\t\t\t\t";
             break;
         case __CA_ATTRIBUTE_VALUE_DATERANGE__:
             $vs_sortable_value_fld = 'attr_vals.' . $vs_sortable_value_fld;
             $vs_sort_field = array_pop(explode('.', $vs_sortable_value_fld));
             $vs_sql = "\n\t\t\t\t\t\t\tSELECT attr.row_id, {$vs_sortable_value_fld}\n\t\t\t\t\t\t\tFROM ca_attributes attr\n\t\t\t\t\t\t\tINNER JOIN ca_attribute_values AS attr_vals ON attr_vals.attribute_id = attr.attribute_id\n\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t(attr_vals.element_id = ?) AND\n\t\t\t\t\t\t\t\t(attr.table_num = ?) AND\n\t\t\t\t\t\t\t\t(attr_vals.{$vs_sort_field} IS NOT NULL) AND\n\t\t\t\t\t\t\t(attr.row_id IN (?))\n\t\t\t\t\t\t";
             break;
         default:
             $vs_sortable_value_fld = 'attr_vals.' . $vs_sortable_value_fld;
             $vs_sort_field = array_pop(explode('.', $vs_sortable_value_fld));
             $vs_sql = "\n\t\t\t\t\t\t\tSELECT attr.row_id, lower({$vs_sortable_value_fld}) {$vs_sort_field}\n\t\t\t\t\t\t\tFROM ca_attributes attr\n\t\t\t\t\t\t\tINNER JOIN ca_attribute_values AS attr_vals ON attr_vals.attribute_id = attr.attribute_id\n\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t(attr_vals.element_id = ?) AND\n\t\t\t\t\t\t\t\t(attr.table_num = ?) AND\n\t\t\t\t\t\t\t\t(attr_vals.{$vs_sort_field} IS NOT NULL) AND\n\t\t\t\t\t\t\t\t(attr.row_id IN (?))\n\t\t\t\t\t\t";
             break;
     }
     if (!$vs_sql) {
         return false;
     }
     $qr_sort = $this->opo_db->query($vs_sql, array((int) $vn_element_id, (int) $pn_table_num, $pa_hits));
     $va_sort_keys = array();
     while ($qr_sort->nextRow()) {
         $va_row = $qr_sort->getRow();
         $va_sort_keys[$va_row['row_id']] = $va_row[$vs_sort_field];
     }
     return $va_sort_keys;
 }
예제 #7
0
 /**
  * 
  */
 public static function getElementDatatype($pm_element_code_or_id)
 {
     if ($t_element = ca_metadata_elements::getInstance($pm_element_code_or_id)) {
         return $t_element->get('datatype');
     }
     return null;
 }
예제 #8
0
 /**
  *
  * @param array $pa_hits
  * @param string $ps_table The table being sorted
  * @param string $ps_field A semicolon-delimited string of fully qualified bundle names (Eg. ca_objects.idno;ca_objects.due_date)
  * @param string $ps_key Key to use for temporary storage
  * @param string $ps_direction Direction to sort
  * @param array $pa_options
  *
  * @return array
  */
 public function sortHits(&$pa_hits, $ps_table, $ps_field, $ps_direction = 'asc', $pa_options = null)
 {
     if (!($t_table = $this->opo_datamodel->getInstanceByTableName($ps_table, true))) {
         return null;
     }
     // invalid table
     $vs_table_pk = $t_table->primaryKey();
     $vn_table_num = $t_table->tableNum();
     // TODO: allow override of this with field-specific directions
     // Default direction
     if (!in_array(strtolower($ps_direction), array('asc', 'desc'))) {
         $ps_direction = 'asc';
     }
     // Don't try to sort empty results
     if (!is_array($pa_hits) || !sizeof($pa_hits)) {
         return $pa_hits;
     }
     // Get field list
     //$va_sort_tmp = explode('/', $ps_field);		// strip any relationship type
     //$ps_field = $va_sort_tmp[0];
     //$vs_rel_type = (sizeof($va_sort_tmp) > 1) ? $va_sort_tmp[1] : null;
     $va_bundles = explode(';', $ps_field);
     // $va_sort_tmp[0]);
     $va_sorted_hits = array();
     $vs_sort_tmp_table = null;
     $va_sort_key_values = array();
     foreach ($va_bundles as $vs_bundle) {
         $va_sort_tmp = explode('/', $vs_bundle);
         // strip any relationship type
         $vs_rel_type = sizeof($va_sort_tmp) > 1 ? $va_sort_tmp[1] : null;
         $vs_bundle = $va_sort_tmp[0];
         list($vs_field_table, $vs_field, $vs_subfield) = explode(".", $vs_bundle);
         if (!($t_instance = $this->opo_datamodel->getInstanceByTableName($vs_field_table, true))) {
             break;
         }
         // Transform preferred_labels
         if ($vs_field == 'preferred_labels') {
             $vs_field_table = $t_instance->getLabelTableName();
             $vs_field = $vs_subfield ? $vs_subfield : $t_instance->getLabelDisplayField();
             $vs_subfield = null;
         }
         if ($vs_field_table === $ps_table) {
             // sort in primary table
             if (!$t_table->hasField($vs_field)) {
                 if ($t_element = ca_metadata_elements::getInstance($vs_subfield ? $vs_subfield : $vs_field)) {
                     // is metadata element
                     $vn_element_id = $t_element->getPrimaryKey();
                     if (!($vs_sortable_value_fld = Attribute::getSortFieldForDatatype($t_element->get('datatype')))) {
                         break;
                     }
                     switch ($vn_datatype = (int) $t_element->get('datatype')) {
                         case __CA_ATTRIBUTE_VALUE_LIST__:
                             $vs_sql = "\n\t\t\t\t\t\t\t\t\t\tSELECT attr.row_id, lower(lil.name_plural) name_plural\n\t\t\t\t\t\t\t\t\t\tFROM ca_attributes attr\n\t\t\t\t\t\t\t\t\t\tINNER JOIN ca_attribute_values AS attr_vals ON attr_vals.attribute_id = attr.attribute_id\n\t\t\t\t\t\t\t\t\t\tINNER JOIN ca_list_item_labels AS lil ON lil.item_id = attr_vals.item_id\n\t\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\t\t(attr_vals.element_id = ?) AND \n\t\t\t\t\t\t\t\t\t\t\t(attr.table_num = ?) AND \n\t\t\t\t\t\t\t\t\t\t\t(lil.name_plural IS NOT NULL) AND\n\t\t\t\t\t\t\t\t\t\t\t(attr.row_id IN (?))\n\t\t\t\t\t\t\t\t\t";
                             break;
                         case __CA_ATTRIBUTE_VALUE_OBJECTS__:
                         case __CA_ATTRIBUTE_VALUE_ENTITIES__:
                         case __CA_ATTRIBUTE_VALUE_PLACES__:
                         case __CA_ATTRIBUTE_VALUE_OCCURRENCES__:
                         case __CA_ATTRIBUTE_VALUE_COLLECTIONS__:
                         case __CA_ATTRIBUTE_VALUE_LOANS__:
                         case __CA_ATTRIBUTE_VALUE_MOVEMENTS__:
                         case __CA_ATTRIBUTE_VALUE_STORAGELOCATIONS__:
                         case __CA_ATTRIBUTE_VALUE_OBJECTLOTS__:
                             if (!($vs_sortable_value_fld = Attribute::getSortFieldForDatatype($vn_datatype))) {
                                 break;
                             }
                             if (!($t_auth_instance = AuthorityAttributeValue::elementTypeToInstance($vn_datatype))) {
                                 break;
                             }
                             $vs_sql = "\n\t\t\t\t\t\t\t\t\t\tSELECT attr.row_id, lower(lil.{$vs_sortable_value_fld}) {$vs_sortable_value_fld}\n\t\t\t\t\t\t\t\t\t\tFROM ca_attributes attr\n\t\t\t\t\t\t\t\t\t\tINNER JOIN ca_attribute_values AS attr_vals ON attr_vals.attribute_id = attr.attribute_id\n\t\t\t\t\t\t\t\t\t\tINNER JOIN " . $t_auth_instance->getLabelTableName() . " AS lil ON lil.value_integer1 = attr_vals.item_id\n\t\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\t\t(attr_vals.element_id = ?) AND \n\t\t\t\t\t\t\t\t\t\t\t(attr.table_num = ?) AND \n\t\t\t\t\t\t\t\t\t\t\t(lil.{$vs_sortable_value_fld} IS NOT NULL) AND\n\t\t\t\t\t\t\t\t\t\t\t(attr.row_id IN (?))\n\t\t\t\t\t\t\t\t\t";
                             break;
                         case __CA_ATTRIBUTE_VALUE_DATERANGE__:
                             $vs_sortable_value_fld = 'attr_vals.' . $vs_sortable_value_fld;
                             $vs_sort_field = array_pop(explode('.', $vs_sortable_value_fld));
                             $vs_sql = "\n\t\t\t\t\t\t\t\t\t\tSELECT attr.row_id, {$vs_sortable_value_fld}\n\t\t\t\t\t\t\t\t\t\tFROM ca_attributes attr\n\t\t\t\t\t\t\t\t\t\tINNER JOIN ca_attribute_values AS attr_vals ON attr_vals.attribute_id = attr.attribute_id\n\t\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\t\t(attr_vals.element_id = ?) AND \n\t\t\t\t\t\t\t\t\t\t\t(attr.table_num = ?) AND \n\t\t\t\t\t\t\t\t\t\t\t(attr_vals.{$vs_sort_field} IS NOT NULL) AND\n\t\t\t\t\t\t\t\t\t\t\t(attr.row_id IN (?))\n\t\t\t\t\t\t\t\t\t";
                             break;
                         default:
                             $vs_sortable_value_fld = 'attr_vals.' . $vs_sortable_value_fld;
                             $vs_sort_field = array_pop(explode('.', $vs_sortable_value_fld));
                             $vs_sql = "\n\t\t\t\t\t\t\t\t\t\tSELECT attr.row_id, lower({$vs_sortable_value_fld}) {$vs_sort_field}\n\t\t\t\t\t\t\t\t\t\tFROM ca_attributes attr\n\t\t\t\t\t\t\t\t\t\tINNER JOIN ca_attribute_values AS attr_vals ON attr_vals.attribute_id = attr.attribute_id\n\t\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\t\t(attr_vals.element_id = ?) AND \n\t\t\t\t\t\t\t\t\t\t\t(attr.table_num = ?) AND \n\t\t\t\t\t\t\t\t\t\t\t(attr_vals.{$vs_sort_field} IS NOT NULL) AND\n\t\t\t\t\t\t\t\t\t\t\t(attr.row_id IN (?))\n\t\t\t\t\t\t\t\t\t";
                             break;
                     }
                     $qr_sort = $this->opo_db->query($vs_sql, array((int) $vn_element_id, (int) $vn_table_num, $pa_hits));
                     $va_sort_keys = array();
                     while ($qr_sort->nextRow()) {
                         $va_row = $qr_sort->getRow();
                         $va_sort_keys[$va_row['row_id']] = $va_row[$vs_sort_field];
                     }
                     $va_sort_key_values[] = $va_sort_keys;
                 }
             } else {
                 // is intrinsic
                 $va_field_info = $t_table->getFieldInfo($vs_field);
                 if ($va_field_info['START'] && $va_field_info['END']) {
                     $vs_field = $va_field_info['START'];
                 }
                 $vs_sql = "\n\t\t\t\t\t\t\tSELECT {$vs_table_pk}, {$vs_field}\n\t\t\t\t\t\t\tFROM {$ps_table}\n\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t{$vs_table_pk} IN (?)\n\t\t\t\t\t\t";
                 $qr_sort = $this->opo_db->query($vs_sql, array($pa_hits));
                 $va_sort_keys = array();
                 while ($qr_sort->nextRow()) {
                     $va_row = $qr_sort->getRow();
                     $va_sort_keys[$va_row[$vs_table_pk]] = $va_row[$vs_field];
                 }
                 $va_sort_key_values[] = $va_sort_keys;
             }
         } else {
             // sort in related table
             if ($vs_field_table == 'ca_set_items' && $vs_field == 'rank' && (int) $vs_rel_type > 0) {
                 // sort by ranks in specific set
                 $vs_sql = "\n\t\t\t\t\t\t\tSELECT {$ps_table}.{$vs_table_pk}, ca_set_items.rank\n\t\t\t\t\t\t\tFROM ca_sets\n\t\t\t\t\t\t\tINNER JOIN ca_set_items ON ca_set_items.set_id = ca_sets.set_id\n\t\t\t\t\t\t\tINNER JOIN {$ps_table} ON {$ps_table}.{$vs_table_pk} = ca_set_items.row_id\n\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t(ca_set_items.table_num = ?) AND\n\t\t\t\t\t\t\t\t(ca_set_items.set_id = ?) AND\n\t\t\t\t\t\t\t\t{$ps_table}.{$vs_table_pk} IN (?)\n\t\t\t\t\t\t";
                 $qr_sort = $this->opo_db->query($vs_sql, array($vn_table_num, (int) $vs_rel_type, $pa_hits));
             } else {
                 $t_rel = $this->opo_datamodel->getInstanceByTableName($vs_field_table, true);
                 if (!$t_rel->hasField($vs_field)) {
                     break;
                 }
                 $va_path = $this->opo_datamodel->getPath($ps_table, $vs_field_table);
                 $vs_is_preferred_sql = null;
                 $va_joins = array();
                 if (sizeof($va_path) > 2) {
                     // many-many
                     $vs_last_table = null;
                     // generate related joins
                     foreach ($va_path as $vs_table => $va_info) {
                         $t_instance = $this->opo_datamodel->getInstanceByTableName($vs_table, true);
                         $vs_rel_type_sql = null;
                         if ($t_instance->isRelationship() && $vs_rel_type) {
                             if (is_array($va_rel_types = caMakeRelationshipTypeIDList($vs_table, array($vs_rel_type))) && sizeof($va_rel_types)) {
                                 $vs_rel_type_sql = " AND {$vs_table}.type_id IN (" . join(",", $va_rel_types) . ")";
                             }
                         }
                         if ($vs_last_table) {
                             $va_rels = $this->opo_datamodel->getOneToManyRelations($vs_last_table, $vs_table);
                             if (!sizeof($va_rels)) {
                                 $va_rels = $this->opo_datamodel->getOneToManyRelations($vs_table, $vs_last_table);
                             }
                             if ($vs_table == $va_rels['one_table']) {
                                 $va_joins[$vs_table] = "INNER JOIN " . $va_rels['one_table'] . " ON " . $va_rels['one_table'] . "." . $va_rels['one_table_field'] . " = " . $va_rels['many_table'] . "." . $va_rels['many_table_field'] . $vs_rel_type_sql;
                             } else {
                                 $va_joins[$vs_table] = "INNER JOIN " . $va_rels['many_table'] . " ON " . $va_rels['many_table'] . "." . $va_rels['many_table_field'] . " = " . $va_rels['one_table'] . "." . $va_rels['one_table_field'] . $vs_rel_type_sql;
                             }
                         }
                         $vs_last_table = $vs_table;
                     }
                 } else {
                     $va_rels = $this->opo_datamodel->getRelationships($ps_table, $vs_field_table);
                     if (!$va_rels) {
                         break;
                     }
                     // field is not valid
                     // TODO: allow sorting on related record attributes
                     $va_joins[$vs_field_table] = 'INNER JOIN ' . $vs_field_table . ' ON ' . $ps_table . '.' . $va_rels[$ps_table][$vs_field_table][0][0] . ' = ' . $vs_field_table . '.' . $va_rels[$ps_table][$vs_field_table][0][1] . "\n";
                     // if the related supports preferred values (eg. *_labels tables) then only consider those in the sort
                     if ($t_rel->hasField('is_preferred')) {
                         $vs_is_preferred_sql = " {$vs_field_table}.is_preferred = 1";
                     }
                 }
                 $vs_join_sql = join("\n", $va_joins);
                 $vs_sql = "\n\t\t\t\t\t\t\tSELECT {$ps_table}.{$vs_table_pk}, {$vs_field_table}.{$vs_field}\n\t\t\t\t\t\t\tFROM {$ps_table}\n\t\t\t\t\t\t\t{$vs_join_sql}\n\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t{$vs_is_preferred_sql} " . ($vs_is_preferred_sql ? ' AND ' : '') . " {$ps_table}.{$vs_table_pk} IN (?)\n\t\t\t\t\t\t";
                 $qr_sort = $this->opo_db->query($vs_sql, array($pa_hits));
             }
             $va_sort_keys = array();
             while ($qr_sort->nextRow()) {
                 $va_row = $qr_sort->getRow();
                 $va_sort_keys[$va_row[$vs_table_pk]] = $va_row[$vs_field];
             }
             $va_sort_key_values[] = $va_sort_keys;
         }
     }
     return $this->_doSort($pa_hits, $va_sort_key_values, $ps_direction);
 }
예제 #9
0
 /**
  * Generate form
  */
 public function __call($ps_function, $pa_args)
 {
     $ps_function = strtolower($ps_function);
     if (!($va_form_info = $this->_checkForm($ps_function))) {
         return;
     }
     MetaTagManager::setWindowTitle(caGetOption('formTitle', $va_form_info, $this->request->config->get("app_display_name") . ": " . _t("Contribute")));
     $this->view->setVar('t_subject', $t_subject = $this->pt_subject);
     $t_subject->set('type_id', $va_form_info['type']);
     $va_response_data = $this->view->getVar('response');
     $va_form_data = caGetOption('formData', $va_response_data, null);
     $va_tags = $this->view->getTagList($va_form_info['form_view']);
     // Format to wrap field-level error messages in
     $vs_error_format = caGetOption('errorFormat', $va_form_info, '<div class="error">^ERRORS</div>');
     $this->view->setVar('errors', is_array($va_response_data['errors']['_general_']) ? join("; ", $va_response_data['errors']['_general_']) : "");
     foreach ($va_tags as $vs_tag) {
         if (in_array($vs_tag, array('form', '/form', 'submit', 'reset'))) {
             continue;
         }
         $va_parse = caParseTagOptions($vs_tag);
         $vs_tag_proc = $va_parse['tag'];
         $va_opts = $va_parse['options'];
         if (($vs_default_value = caGetOption('default', $va_opts, null)) || ($vs_default_value = caGetOption($vs_tag_proc, $va_default_form_values, null))) {
             $va_default_form_values[$vs_tag_proc] = $vs_default_value;
             unset($va_opts['default']);
         }
         $vs_tag_val = null;
         switch (strtolower($vs_tag_proc)) {
             case 'submit':
                 $this->view->setVar($vs_tag, "<a href='#' class='caContributeFormSubmit'>" . (isset($va_opts['label']) && $va_opts['label'] ? $va_opts['label'] : _t('Submit')) . "</a>");
                 break;
             case 'reset':
                 $this->view->setVar($vs_tag, "<a href='#' class='caContributeFormReset'>" . (isset($va_opts['label']) && $va_opts['label'] ? $va_opts['label'] : _t('Reset')) . "</a>");
                 $vs_script = "<script type='text/javascript'>\n\tjQuery(document).ready(function() {\n\t\tvar f, defaultValues = " . json_encode($va_default_form_values) . ", defaultBooleans = " . json_encode($va_default_form_booleans) . ";\n\t\tfor (f in defaultValues) {\n\t\t\tvar f_proc = f + '[]';\n\t\t\tjQuery('input[name=\"' + f_proc+ '\"], textarea[name=\"' + f_proc+ '\"], select[name=\"' + f_proc+ '\"]').each(function(k, v) {\n\t\t\t\tif (defaultValues[f][k]) { jQuery(v).val(defaultValues[f][k]); } \n\t\t\t});\n\t\t}\n\t\tfor (f in defaultBooleans) {\n\t\t\tvar f_proc = f + '[]';\n\t\t\tjQuery('select[name=\"' + f_proc+ '\"].caContributeBoolean').each(function(k, v) {\n\t\t\t\tif (defaultBooleans[f][k]) { jQuery(v).val(defaultBooleans[f][k]); }\n\t\t\t});\n\t\t}\n\t\t\n\t\tjQuery('.caContributeFormSubmit').bind('click', function(e) {\n\t\t\tjQuery('#ContributeForm').submit();\n\t\t\treturn false;\n\t\t});\n\t\tjQuery('.caContributeFormReset').bind('click', function(e) {\n\t\t\tjQuery('#ContributeForm').find('input[type!=\"hidden\"],textarea').val('');\n\t\t\tjQuery('#ContributeForm').find('select.caContributeBoolean').val('AND');\n\t\t\tjQuery('#ContributeForm').find('select').prop('selectedIndex', 0);\n\t\t\te.preventDefault();\n\t\t\treturn false;\n\t\t});\n\t});\n</script>\n";
                 break;
             default:
                 if (preg_match("!^(.*):label\$!", $vs_tag_proc, $va_matches)) {
                     $this->view->setVar($vs_tag, $vs_tag_val = $t_subject->getDisplayLabel($va_matches[1]));
                 } elseif (preg_match("!^(.*):error\$!", $vs_tag_proc, $va_matches)) {
                     if (is_array($va_response_data['errors'][$va_matches[1]]) && sizeof($va_response_data['errors'][$va_matches[1]])) {
                         $vs_error_message = join("; ", $va_response_data['errors'][$va_matches[1]]);
                         if ($vs_error_format) {
                             $vs_error_message = str_replace("^ERRORS", $vs_error_message, $vs_error_format);
                         }
                         $this->view->setVar($vs_tag, $vs_error_message);
                     }
                 } else {
                     if ($vs_tag_proc == 'errors') {
                         break;
                     }
                     // skip general errors tag
                     $va_opts['asArrayElement'] = true;
                     $va_opts['IDNumberingConfig'] = $this->config;
                     $va_vals = array();
                     $va_tmp = explode('.', $vs_tag_proc);
                     if (($t_element = ca_metadata_elements::getInstance($va_tmp[1])) && $t_element->get('datatype') == 0) {
                         if (is_array($va_elements = $t_element->getElementsInSet())) {
                             foreach ($va_elements as $va_element) {
                                 if ($va_element['datatype'] > 0) {
                                     $va_form_elements[] = $vs_subfld = $va_tmp[0] . '.' . $va_tmp[1] . '.' . $va_element['element_code'];
                                     if (is_array($va_form_data[$va_tmp[0] . '.' . $va_tmp[1] . '.' . $va_element['element_code']])) {
                                         $va_vals[$va_tmp[0] . '.' . $va_tmp[1] . '.' . $va_element['element_code']] = array_shift($va_form_data[$va_tmp[0] . '.' . $va_tmp[1] . '.' . $va_element['element_code']]);
                                     }
                                 }
                             }
                         }
                     } else {
                         if (is_array($va_form_data[$vs_tag_proc])) {
                             $va_vals[$vs_tag_proc] = array_shift($va_form_data[$vs_tag_proc]);
                         }
                     }
                     $va_opts['values'] = $va_vals;
                     if ($vs_tag_val = $t_subject->htmlFormElementForSimpleForm($this->request, $vs_tag_proc, $va_opts)) {
                         $this->view->setVar($vs_tag, $vs_tag_val);
                     }
                 }
                 if ($vs_tag_val) {
                     $va_form_elements[] = $vs_tag_proc;
                 }
                 break;
         }
     }
     $this->view->setVar("form", caFormTag($this->request, "Send", 'ContributeForm', null, 'post', 'multipart/form-data', '_top', array('noTimestamp' => true, 'submitOnReturn' => true, 'disableUnsavedChangesWarning' => true)));
     $this->view->setVar("/form", $vs_script . caHTMLHiddenInput("_contributeFormName", array("value" => $ps_function)) . caHTMLHiddenInput("_formElements", array("value" => join(';', $va_form_elements))) . caHTMLHiddenInput("_contribute", array("value" => 1)) . "</form>");
     $this->view->setVar('spam_protection', caGetOption('spam_protection', $va_form_info, false) ? 1 : 0);
     $this->view->setVar('terms_and_conditions', caGetOption('terms_and_conditions', $va_form_info, false));
     $this->render($va_form_info['form_view']);
 }
예제 #10
0
 /**
  * Processes single exporter item for a given record
  *
  * @param int $pn_item_id Primary of exporter item
  * @param int $pn_table_num Table num of item to export
  * @param int $pn_record_id Primary key value of item to export
  * @param array $pa_options
  *		ignoreContext = don't switch context even though context may be set for current item
  *		relationship_type_id, relationship_type_code, relationship_typename =
  *			if this export is a sub-export (context-switch), we have no way of knowing the relationship
  *			to the 'parent' element in the export, so there has to be a means to pass it down to make it accessible
  * 		attribute_id = signals that this is an export relative to a specific attribute instance
  * 			this triggers special behavior that allows getting container values in a kind of sub-export
  *			it's really only useful for Containers but in theory can be any attribute
  *		logger = KLogger instance to use for logging. This option is mandatory!
  * @return array Item info
  */
 public function processExporterItem($pn_item_id, $pn_table_num, $pn_record_id, $pa_options = array())
 {
     $o_log = caGetOption('logger', $pa_options);
     // always set by exportRecord()
     $vb_ignore_context = caGetOption('ignoreContext', $pa_options);
     $vn_attribute_id = caGetOption('attribute_id', $pa_options);
     $o_log->logInfo(_t("Export mapping processor called with parameters [exporter_item_id:%1 table_num:%2 record_id:%3]", $pn_item_id, $pn_table_num, $pn_record_id));
     $t_exporter_item = ca_data_exporters::loadExporterItemByID($pn_item_id);
     $t_instance = ca_data_exporters::loadInstanceByID($pn_record_id, $pn_table_num);
     // switch context to a different set of records if necessary and repeat current exporter item for all those selected records
     // (e.g. hierarchy children or related items in another table, restricted by types or relationship types)
     if (!$vb_ignore_context && ($vs_context = $t_exporter_item->getSetting('context'))) {
         $va_restrict_to_types = $t_exporter_item->getSetting('restrictToTypes');
         $va_restrict_to_rel_types = $t_exporter_item->getSetting('restrictToRelationshipTypes');
         $va_restrict_to_bundle_vals = $t_exporter_item->getSetting('restrictToBundleValues');
         $va_check_access = $t_exporter_item->getSetting('checkAccess');
         $va_sort = $t_exporter_item->getSetting('sort');
         $vn_new_table_num = $this->getAppDatamodel()->getTableNum($vs_context);
         $vb_context_is_related_table = false;
         $va_related = null;
         if ($vn_new_table_num) {
             // switch to new table
             $vs_key = $this->getAppDatamodel()->getTablePrimaryKeyName($vs_context);
         } else {
             // this table, i.e. hierarchy context switch
             $vs_key = $t_instance->primaryKey();
         }
         $o_log->logInfo(_t("Initiating context switch to '%1' for mapping ID %2 and record ID %3. The processor now tries to find matching records for the switch and calls itself for each of those items.", $vs_context, $pn_item_id, $pn_record_id));
         switch ($vs_context) {
             case 'children':
                 $va_related = $t_instance->getHierarchyChildren();
                 break;
             case 'parent':
                 $va_related = array();
                 if ($vs_parent_id_fld = $t_instance->getProperty("HIERARCHY_PARENT_ID_FLD")) {
                     $va_related[] = array($vs_key => $t_instance->get($vs_parent_id_fld));
                 }
                 break;
             case 'ancestors':
                 $va_parents = $t_instance->getHierarchyAncestors(null, array('idsOnly' => true));
                 $va_related = array();
                 foreach (array_unique($va_parents) as $vn_pk) {
                     $va_related[] = array($vs_key => intval($vn_pk));
                 }
                 break;
             case 'ca_sets':
                 $t_set = new ca_sets();
                 $va_set_options = array();
                 if (isset($va_restrict_to_types[0])) {
                     // the utility used below doesn't support passing multiple types so we just pass the first.
                     // this should be enough for 99.99% of the actual use cases anyway
                     $va_set_options['setType'] = $va_restrict_to_types[0];
                 }
                 $va_set_options['checkAccess'] = $va_check_access;
                 $va_set_options['setIDsOnly'] = true;
                 $va_set_ids = $t_set->getSetsForItem($pn_table_num, $t_instance->getPrimaryKey(), $va_set_options);
                 $va_related = array();
                 foreach (array_unique($va_set_ids) as $vn_pk) {
                     $va_related[] = array($vs_key => intval($vn_pk));
                 }
                 break;
             case 'ca_list_items.firstLevel':
                 if ($t_instance->tableName() == 'ca_lists') {
                     $o_dm = Datamodel::load();
                     $va_related = array();
                     $va_items_legacy_format = $t_instance->getListItemsAsHierarchy(null, array('maxLevels' => 1, 'dontIncludeRoot' => true));
                     $vn_new_table_num = $o_dm->getTableNum('ca_list_items');
                     $vs_key = 'item_id';
                     foreach ($va_items_legacy_format as $va_item_legacy_format) {
                         $va_related[$va_item_legacy_format['NODE']['item_id']] = $va_item_legacy_format['NODE'];
                     }
                     break;
                 } else {
                     return array();
                 }
                 break;
             default:
                 if ($vn_new_table_num) {
                     $va_options = array('restrictToTypes' => $va_restrict_to_types, 'restrictToRelationshipTypes' => $va_restrict_to_rel_types, 'restrictToBundleValues' => $va_restrict_to_bundle_vals, 'checkAccess' => $va_check_access, 'sort' => $va_sort);
                     $o_log->logDebug(_t("Calling getRelatedItems with options: %1.", print_r($va_options, true)));
                     $va_related = $t_instance->getRelatedItems($vs_context, $va_options);
                     $vb_context_is_related_table = true;
                 } else {
                     // container or invalid context
                     $va_context_tmp = explode('.', $vs_context);
                     if (sizeof($va_context_tmp) != 2) {
                         $o_log->logError(_t("Invalid context %1. Ignoring this mapping.", $vs_context));
                         return array();
                     }
                     $va_attrs = $t_instance->getAttributesByElement($va_context_tmp[1]);
                     $va_info = array();
                     if (is_array($va_attrs) && sizeof($va_attrs) > 0) {
                         $o_log->logInfo(_t("Switching context for element code: %1.", $va_context_tmp[1]));
                         $o_log->logDebug(_t("Raw attribute value array is as follows. The mapping will now be repeated for each (outer) attribute. %1", print_r($va_attrs, true)));
                         foreach ($va_attrs as $vo_attr) {
                             $va_attribute_export = $this->processExporterItem($pn_item_id, $pn_table_num, $pn_record_id, array_merge(array('ignoreContext' => true, 'attribute_id' => $vo_attr->getAttributeID()), $pa_options));
                             $va_info = array_merge($va_info, $va_attribute_export);
                         }
                     } else {
                         $o_log->logInfo(_t("Switching context for element code %1 failed. Either there is no attribute with that code attached to the current row or the code is invalid. Mapping is ignored for current row.", $va_context_tmp[1]));
                     }
                     return $va_info;
                 }
                 break;
         }
         $va_info = array();
         if (is_array($va_related)) {
             $o_log->logDebug(_t("The current mapping will now be repreated for these items: %1", print_r($va_related, true)));
             if (!$vn_new_table_num) {
                 $vn_new_table_num = $pn_table_num;
             }
             foreach ($va_related as $va_rel) {
                 // if we're dealing with a related table, pass on some info the relationship type to the context-switched invocation of processExporterItem(),
                 // because we can't access that information from the related item simply because we don't exactly know where the call originated
                 if ($vb_context_is_related_table) {
                     $pa_options['relationship_typename'] = $va_rel['relationship_typename'];
                     $pa_options['relationship_type_code'] = $va_rel['relationship_type_code'];
                     $pa_options['relationship_type_id'] = $va_rel['relationship_type_id'];
                 }
                 $va_rel_export = $this->processExporterItem($pn_item_id, $vn_new_table_num, $va_rel[$vs_key], array_merge(array('ignoreContext' => true), $pa_options));
                 $va_info = array_merge($va_info, $va_rel_export);
             }
         } else {
             $o_log->logDebug(_t("No matching related items found for last context switch"));
         }
         return $va_info;
     }
     // end switch context
     // Don't prevent context switches for children of context-switched exporter items. This way you can
     // build cascades for jobs like exporting objects related to the creator of the record in question.
     unset($pa_options['ignoreContext']);
     $va_item_info = array();
     $vs_source = $t_exporter_item->get('source');
     $vs_element = $t_exporter_item->get('element');
     $vb_repeat = $t_exporter_item->getSetting('repeat_element_for_multiple_values');
     // if omitIfEmpty is set and get() returns nothing, we ignore this exporter item and all children
     if ($vs_omit_if_empty = $t_exporter_item->getSetting('omitIfEmpty')) {
         if (!(strlen($t_instance->get($vs_omit_if_empty)) > 0)) {
             return array();
         }
     }
     // if omitIfNotEmpty is set and get() returns a value, we ignore this exporter item and all children
     if ($vs_omit_if_not_empty = $t_exporter_item->getSetting('omitIfNotEmpty')) {
         if (strlen($t_instance->get($vs_omit_if_not_empty)) > 0) {
             return array();
         }
     }
     // always return URL for export, not an HTML tag
     $va_get_options = array('returnURL' => true);
     if ($vs_delimiter = $t_exporter_item->getSetting("delimiter")) {
         $va_get_options['delimiter'] = $vs_delimiter;
     }
     if ($vs_template = $t_exporter_item->getSetting('template')) {
         $va_get_options['template'] = $vs_template;
     }
     if ($vs_locale = $t_exporter_item->getSetting('locale')) {
         // the global UI locale for some reason has a higher priority
         // than the locale setting in BaseModelWithAttributes::get
         // which is why we unset it here and restore it later
         global $g_ui_locale;
         $vs_old_ui_locale = $g_ui_locale;
         $g_ui_locale = null;
         $va_get_options['locale'] = $vs_locale;
     }
     // AttributeValue settings that are simply passed through by the exporter
     if ($t_exporter_item->getSetting('convertCodesToDisplayText')) {
         $va_get_options['convertCodesToDisplayText'] = true;
         // try to return text suitable for display for system lists stored in intrinsics (ex. ca_objects.access, ca_objects.status, ca_objects.source_id)
         // this does not affect list attributes
     } else {
         $va_get_options['convertCodesToIdno'] = true;
         // if display text is not requested try to return list item idno's... since underlying integer ca_list_items.item_id values are unlikely to be useful in an export context
     }
     if ($t_exporter_item->getSetting('returnIdno')) {
         $va_get_options['returnIdno'] = true;
     }
     if ($t_exporter_item->getSetting('start_as_iso8601')) {
         $va_get_options['start_as_iso8601'] = true;
     }
     if ($t_exporter_item->getSetting('end_as_iso8601')) {
         $va_get_options['end_as_iso8601'] = true;
     }
     if ($t_exporter_item->getSetting('dontReturnValueIfOnSameDayAsStart')) {
         $va_get_options['dontReturnValueIfOnSameDayAsStart'] = true;
     }
     if ($vs_date_format = $t_exporter_item->getSetting('dateFormat')) {
         $va_get_options['dateFormat'] = $vs_date_format;
     }
     if ($vn_attribute_id) {
         $o_log->logInfo(_t("Processing mapping in attribute mode for attribute_id = %1.", $vn_attribute_id));
         if ($vs_source) {
             // trying to find the source only makes sense if the source is set
             $t_attr = new ca_attributes($vn_attribute_id);
             $va_values = $t_attr->getAttributeValues();
             $va_src_tmp = explode('.', $vs_source);
             if (sizeof($va_src_tmp) == 2) {
                 $o_dm = Datamodel::load();
                 if ($t_attr->get('table_num') == $o_dm->getTableNum($va_src_tmp[0])) {
                     $vs_source = $va_src_tmp[1];
                 }
             }
             $o_log->logDebug(_t("Trying to find code %1 in value array for the current attribute.", $vs_source));
             $o_log->logDebug(_t("Value array is %1.", print_r($va_values, true)));
             foreach ($va_values as $vo_val) {
                 $va_display_val_options = array();
                 if ($vo_val instanceof ListAttributeValue) {
                     $t_element = ca_metadata_elements::getInstance($t_attr->get('element_id'));
                     $va_display_val_options = array('list_id' => $t_element->get('list_id'));
                     if ($t_exporter_item->getSetting('returnIdno')) {
                         $va_display_val_options['returnIdno'] = true;
                     }
                 }
                 $o_log->logDebug(_t("Trying to match code from array %1 and the code we're looking for %2.", $vo_val->getElementCode(), $vs_source));
                 if ($vo_val->getElementCode() == $vs_source) {
                     $o_log->logDebug(_t("Found value %1.", $vo_val->getDisplayValue($va_display_val_options)));
                     $va_item_info[] = array('text' => $vo_val->getDisplayValue($va_display_val_options), 'element' => $vs_element);
                 }
             }
         } else {
             // no source in attribute context probably means this is some form of wrapper, e.g. a MARC field
             $va_item_info[] = array('element' => $vs_element);
         }
     } else {
         if ($vs_source) {
             $o_log->logDebug(_t("Source for current mapping is %1", $vs_source));
             $va_matches = array();
             // CONSTANT value
             if (preg_match("/^_CONSTANT_:(.*)\$/", $vs_source, $va_matches)) {
                 $o_log->logDebug(_t("This is a constant. Value for this mapping is '%1'", trim($va_matches[1])));
                 $va_item_info[] = array('text' => trim($va_matches[1]), 'element' => $vs_element);
             } else {
                 if (in_array($vs_source, array("relationship_type_id", "relationship_type_code", "relationship_typename"))) {
                     if (isset($pa_options[$vs_source]) && strlen($pa_options[$vs_source]) > 0) {
                         $o_log->logDebug(_t("Source refers to releationship type information. Value for this mapping is '%1'", $pa_options[$vs_source]));
                         $va_item_info[] = array('text' => $pa_options[$vs_source], 'element' => $vs_element);
                     }
                 } else {
                     if (!$vb_repeat) {
                         $vs_get = $t_instance->get($vs_source, $va_get_options);
                         $o_log->logDebug(_t("Source is a simple get() for some bundle. Value for this mapping is '%1'", $vs_get));
                         $o_log->logDebug(_t("get() options are: %1", print_r($va_get_options, true)));
                         $va_item_info[] = array('text' => $vs_get, 'element' => $vs_element);
                     } else {
                         // user wants current element repeated in case of multiple returned values
                         $va_get_options['delimiter'] = ';#;';
                         $vs_values = $t_instance->get($vs_source, $va_get_options);
                         $o_log->logDebug(_t("Source is a get() that should be repeated for multiple values. Value for this mapping is '%1'. It includes the custom delimiter ';#;' that is later used to split the value into multiple values.", $vs_values));
                         $o_log->logDebug(_t("get() options are: %1", print_r($va_get_options, true)));
                         $va_tmp = explode(";#;", $vs_values);
                         foreach ($va_tmp as $vs_text) {
                             $va_item_info[] = array('element' => $vs_element, 'text' => $vs_text);
                         }
                     }
                 }
             }
         } else {
             if ($vs_template) {
                 // templates without source are probably just static text, but you never know
                 // -> run them through processor anyways
                 $vs_proc_template = caProcessTemplateForIDs($vs_template, $pn_table_num, array($pn_record_id), array());
                 $o_log->logDebug(_t("Current mapping has no source but a template '%1'. Value from extracted via template processor is '%2'", $vs_template, $vs_proc_template));
                 $va_item_info[] = array('element' => $vs_element, 'text' => $vs_proc_template);
             } else {
                 // no source, no template -> probably wrapper
                 $o_log->logDebug(_t("Current mapping has no source and no template and is probably an XML/MARC wrapper element"));
                 $va_item_info[] = array('element' => $vs_element);
             }
         }
     }
     // reset UI locale if we unset it
     if ($vs_locale) {
         $g_ui_locale = $vs_old_ui_locale;
     }
     $o_log->logDebug(_t("We're now processing other settings like default, prefix, suffix, skipIfExpression, filterByRegExp, maxLength, plugins and replacements for this mapping"));
     $o_log->logDebug(_t("Local data before processing is: %1", print_r($va_item_info, true)));
     // handle other settings and plugin hooks
     $vs_default = $t_exporter_item->getSetting('default');
     $vs_prefix = $t_exporter_item->getSetting('prefix');
     $vs_suffix = $t_exporter_item->getSetting('suffix');
     //$vs_regexp = $t_exporter_item->getSetting('filterByRegExp');		// Deprecated -- remove?
     $vn_max_length = $t_exporter_item->getSetting('maxLength');
     $vs_skip_if_expr = $t_exporter_item->getSetting('skipIfExpression');
     $vs_original_values = $t_exporter_item->getSetting('original_values');
     $vs_replacement_values = $t_exporter_item->getSetting('replacement_values');
     $va_replacements = ca_data_exporter_items::getReplacementArray($vs_original_values, $vs_replacement_values);
     foreach ($va_item_info as $vn_key => &$va_item) {
         $this->opo_app_plugin_manager->hookExportItemBeforeSettings(array('instance' => $t_instance, 'exporter_item_instance' => $t_exporter_item, 'export_item' => &$va_item));
         // handle dontReturnValueIfOnSameDayAsStart
         if (caGetOption('dontReturnValueIfOnSameDayAsStart', $va_get_options, false)) {
             if (strlen($va_item['text']) < 1) {
                 unset($va_item_info[$vn_key]);
             }
         }
         // handle skipIfExpression setting
         if ($vs_skip_if_expr) {
             // Add current value as variable "value", accessible in expressions as ^value
             $va_vars = array_merge(array('value' => $va_item['text']), ca_data_exporters::$s_variables);
             if (ExpressionParser::evaluate($vs_skip_if_expr, $va_vars)) {
                 unset($va_item_info[$vn_key]);
                 continue;
             }
         }
         // filter by regex (deprecated since you can do the same thing and more with skipIfExpression) -- remove?
         //if((strlen($va_item['text'])>0) && $vs_regexp){
         //	if(!preg_match("!".$vs_regexp."!i", $va_item['text'])) {
         //		unset($va_item_info[$vn_key]);
         //		continue;
         //	}
         //}
         // do replacements
         $va_item['text'] = ca_data_exporter_items::replaceText($va_item['text'], $va_replacements);
         // if text is empty, fill in default
         // if text isn't empty, respect prefix and suffix
         if (strlen($va_item['text']) == 0) {
             if ($vs_default) {
                 $va_item['text'] = $vs_default;
             }
         } else {
             if (strlen($vs_prefix) > 0 || strlen($vs_suffix) > 0) {
                 $va_item['text'] = $vs_prefix . $va_item['text'] . $vs_suffix;
             }
         }
         if ($vn_max_length && strlen($va_item['text']) > $vn_max_length) {
             $va_item['text'] = substr($va_item['text'], 0, $vn_max_length) . " ...";
         }
         // if this is a variable, set the value and delete it from the export tree
         $va_matches = array();
         if (preg_match("/^_VARIABLE_:(.*)\$/", $va_item['element'], $va_matches)) {
             ca_data_exporters::$s_variables[$va_matches[1]] = $va_item['text'];
             unset($va_item_info[$vn_key]);
             continue;
         }
         // if returned value is null then we skip the item
         $this->opo_app_plugin_manager->hookExportItem(array('instance' => $t_instance, 'exporter_item_instance' => $t_exporter_item, 'export_item' => &$va_item));
     }
     $o_log->logInfo(_t("Extracted data for this mapping is as follows:"));
     foreach ($va_item_info as $va_tmp) {
         $o_log->logInfo(sprintf("    element:%-20s value: %-10s", $va_tmp['element'], $va_tmp['text']));
     }
     $va_children = $t_exporter_item->getHierarchyChildren();
     if (is_array($va_children) && sizeof($va_children) > 0) {
         $o_log->logInfo(_t("Now proceeding to process %1 direct children in the mapping hierarchy", sizeof($va_children)));
         foreach ($va_children as $va_child) {
             foreach ($va_item_info as &$va_info) {
                 $va_child_export = $this->processExporterItem($va_child['item_id'], $pn_table_num, $pn_record_id, $pa_options);
                 $va_info['children'] = array_merge((array) $va_info['children'], $va_child_export);
             }
         }
     }
     return $va_item_info;
 }