/** * Saves the content of a form editing new or existing records. It returns the same form + status messages rendered into the current view, inherited from ActionController * * @param array $pa_options Array of options passed through to _initView and saveBundlesForScreen() */ public function Save($pa_options = null) { if (!is_array($pa_options)) { $pa_options = array(); } list($t_subject, $t_ui, $vn_parent_id, $vn_above_id) = $this->_initView(array_merge($pa_options, array('loadSubject' => true))); if (!$t_subject) { $this->postError(1220, _t('Invalid table %1', $this->ops_table_name), "BaseInterstitalController->Edit()"); return false; } if (!is_array($pa_options)) { $pa_options = array(); } // // Is record of correct type? // $va_restrict_to_types = null; if ($t_subject->getAppConfig()->get('perform_type_access_checking')) { $va_restrict_to_types = caGetTypeRestrictionsForUser($this->ops_table_name, array('access' => __CA_BUNDLE_ACCESS_EDIT__)); } if (is_array($va_restrict_to_types) && !in_array($t_subject->get('type_id'), $va_restrict_to_types)) { $this->response->setRedirect($this->request->config->get('error_display_url') . '/n/2560?r=' . urlencode($this->request->getFullUrlPath())); return; } $pn_placement_id = $this->request->getParameter('placement_id', pInteger); // placement_id of bundle that launched interstitial editor $ps_primary_table = $this->request->getParameter('primary', pString); $pn_primary_id = $this->request->getParameter('primary_id', pInteger); // Make sure request isn't empty if (!sizeof($_POST)) { $va_response = array('status' => 20, 'id' => null, 'table' => $t_subject->tableName(), 'type_id' => null, 'display' => null, 'errors' => array(_t("Cannot save using empty request. Are you using a bookmark?") => _t("Cannot save using empty request. Are you using a bookmark?"))); $this->view->setVar('response', $va_response); $this->render('interstitial/interstitial_result_json.php'); return; } // Set type name for display if (!($vs_type_name = $t_subject->getTypeName())) { $vs_type_name = $t_subject->getProperty('NAME_SINGULAR'); } # trigger "BeforeSaveItem" hook $this->opo_app_plugin_manager->hookBeforeSaveItem(array('id' => null, 'table_num' => $t_subject->tableNum(), 'table_name' => $t_subject->tableName(), 'instance' => $t_subject, 'is_insert' => true)); $t_placement = new ca_editor_ui_bundle_placements($pn_placement_id); $pa_bundle_settings = $t_placement->getSettings(); $va_opts = array_merge($pa_options, array('ui_instance' => $t_ui)); $vb_save_rc = $t_subject->saveBundlesForScreen($this->request->getParameter('screen', pString), $this->request, $va_opts); $this->view->setVar('t_ui', $t_ui); $vs_message = _t("Saved changes to %1", $vs_type_name); // // Regenerate display template for bundle that launched the interstitial editor so it will reflect any changes // $vs_related_table = $t_placement->getEditorType(); $vs_template = caGetBundleDisplayTemplate($t_subject, $vs_related_table, $pa_bundle_settings); $qr_rel_items = caMakeSearchResult($t_subject->tableName(), array($t_subject->getPrimaryKey())); // // Handle case of self relationships where we need to figure out which direction things are going in // $va_bundle_values = array_shift(caProcessRelationshipLookupLabel($qr_rel_items, $t_subject, array('template' => $vs_template, 'primaryIDs' => array($ps_primary_table => array($pn_primary_id))))); if ($t_subject->hasField('type_id')) { if (method_exists($t_subject, "isSelfRelationship") && $t_subject->isSelfRelationship()) { $vn_left_id = $t_subject->get($t_subject->getLeftTableFieldName()); $vn_right_id = $t_subject->get($t_subject->getRightTableFieldName()); $va_bundle_values['relationship_typename'] = $t_subject->getRelationshipTypename($vn_left_id == $pn_primary_id ? 'ltol' : 'rtol'); } else { $va_bundle_values['relationship_typename'] = $t_subject->getRelationshipTypename($t_subject->getLeftTableFieldName() == $vs_related_table ? 'rtol' : 'ltor'); } $va_bundle_values['relationship_type_code'] = $t_subject->getRelationshipTypeCode(); } // // Report errors // $va_errors = $this->request->getActionErrors(); // all errors from all sources $va_general_errors = $this->request->getActionErrors('general'); // just "general" errors - ones that are not attached to a specific part of the form if (sizeof($va_errors) - sizeof($va_general_errors) > 0) { $va_error_list = array(); $vb_no_save_error = false; foreach ($va_errors as $o_e) { $va_error_list[$o_e->getErrorDescription()] = $o_e->getErrorDescription() . "\n"; switch ($o_e->getErrorNumber()) { case 1100: // duplicate/invalid idno if (!$vn_subject_id) { // can't save new record if idno is not valid (when updating everything but idno is saved if it is invalid) $vb_no_save_error = true; } break; } } } else { $this->opo_result_context->invalidateCache(); } $this->opo_result_context->saveContext(); # trigger "SaveItem" hook $this->opo_app_plugin_manager->hookSaveItem(array('id' => $vn_subject_id, 'table_num' => $t_subject->tableNum(), 'table_name' => $t_subject->tableName(), 'instance' => $t_subject, 'is_insert' => true)); $vn_id = $t_subject->getPrimaryKey(); $va_response = array('status' => sizeof($va_error_list) ? 10 : 0, 'id' => $vn_id, 'table' => $t_subject->tableName(), 'type_id' => method_exists($t_subject, "getTypeID") ? $t_subject->getTypeID() : null, 'display' => 'relation', 'bundleDisplay' => $va_bundle_values, 'errors' => $va_error_list); $this->view->setVar('response', $va_response); $this->render('interstitial/interstitial_result_json.php'); }
/** * Saves the content of a form editing new or existing records. It returns the same form + status messages rendered into the current view, inherited from ActionController * * @param array $pa_options Array of options passed through to _initView and saveBundlesForScreen() */ public function Save($pa_options = null) { list($t_subject, $t_ui, $vn_parent_id, $vn_above_id) = $this->_initView($pa_options); if (!is_array($pa_options)) { $pa_options = array(); } // // Is record of correct type? // $va_restrict_to_types = null; if ($t_subject->getAppConfig()->get('perform_type_access_checking')) { $va_restrict_to_types = caGetTypeRestrictionsForUser($this->ops_table_name, array('access' => __CA_BUNDLE_ACCESS_EDIT__)); } if (is_array($va_restrict_to_types) && !in_array($t_subject->get('type_id'), $va_restrict_to_types)) { $this->response->setRedirect($this->request->config->get('error_display_url') . '/n/2560?r=' . urlencode($this->request->getFullUrlPath())); return; } // Make sure request isn't empty if (!sizeof($_POST)) { $va_response = array('status' => 20, 'id' => null, 'table' => $t_subject->tableName(), 'type_id' => null, 'display' => null, 'errors' => array(_t("Cannot save using empty request. Are you using a bookmark?") => _t("Cannot save using empty request. Are you using a bookmark?"))); $this->view->setVar('response', $va_response); $this->render('component_result_json.php'); return; } // Set "context" id from those editors that need to restrict idno lookups to within the context of another field value (eg. idno's for ca_list_items are only unique within a given list_id) $vn_context_id = null; if ($vs_idno_context_field = $t_subject->getProperty('ID_NUMBERING_CONTEXT_FIELD')) { if ($vn_subject_id > 0) { $this->view->setVar('_context_id', $vn_context_id = $t_subject->get($vs_idno_context_field)); } else { if ($vn_parent_id > 0) { $t_parent = $this->opo_datamodel->getInstanceByTableName($this->ops_table_name); if ($t_parent->load($vn_parent_id)) { $this->view->setVar('_context_id', $vn_context_id = $t_parent->get($vs_idno_context_field)); } } } if ($vn_context_id) { $t_subject->set($vs_idno_context_field, $vn_context_id); } } // Set type name for display if (!($vs_type_name = $t_subject->getTypeName())) { $vs_type_name = $t_subject->getProperty('NAME_SINGULAR'); } # trigger "BeforeSaveItem" hook $this->opo_app_plugin_manager->hookBeforeSaveItem(array('id' => null, 'table_num' => $t_subject->tableNum(), 'table_name' => $t_subject->tableName(), 'instance' => $t_subject, 'is_insert' => true)); $vn_parent_id = $this->request->getParameter('parent_id', pInteger); $t_subject->set('parent_id', $vn_parent_id); $this->opo_result_context->setParameter($t_subject->tableName() . '_last_parent_id', $vn_parent_id); $va_opts = array_merge($pa_options, array('ui_instance' => $t_ui)); $vb_save_rc = $t_subject->saveBundlesForScreen($this->request->getParameter('screen', pString), $this->request, $va_opts); $this->view->setVar('t_ui', $t_ui); if (!$vn_subject_id) { $vn_subject_id = $t_subject->getPrimaryKey(); if (!$vb_save_rc) { $vs_message = _t("Could not save %1", $vs_type_name); } else { $vs_message = _t("Added %1", $vs_type_name); $this->request->setParameter($t_subject->primaryKey(), $vn_subject_id, 'GET'); $this->view->setVar($t_subject->primaryKey(), $vn_subject_id); $this->view->setVar('subject_id', $vn_subject_id); $this->request->session->setVar($this->ops_table_name . '_browse_last_id', $vn_subject_id); // set last edited // Set ACL for newly created record if ($t_subject->getAppConfig()->get('perform_item_level_access_checking')) { $t_subject->setACLUsers(array($this->request->getUserID() => __CA_ACL_EDIT_DELETE_ACCESS__)); $t_subject->setACLWorldAccess($t_subject->getAppConfig()->get('default_item_access_level')); } } } else { $vs_message = _t("Saved changes to %1", $vs_type_name); } $va_errors = $this->request->getActionErrors(); // all errors from all sources $va_general_errors = $this->request->getActionErrors('general'); // just "general" errors - ones that are not attached to a specific part of the form if (sizeof($va_errors) - sizeof($va_general_errors) > 0) { $va_error_list = array(); $vb_no_save_error = false; foreach ($va_errors as $o_e) { $va_error_list[$o_e->getErrorDescription()] = $o_e->getErrorDescription() . "\n"; switch ($o_e->getErrorNumber()) { case 1100: // duplicate/invalid idno if (!$vn_subject_id) { // can't save new record if idno is not valid (when updating everything but idno is saved if it is invalid) $vb_no_save_error = true; } break; } } } else { $this->opo_result_context->invalidateCache(); } $this->opo_result_context->saveContext(); # trigger "SaveItem" hook $this->opo_app_plugin_manager->hookSaveItem(array('id' => $vn_subject_id, 'table_num' => $t_subject->tableNum(), 'table_name' => $t_subject->tableName(), 'instance' => $t_subject, 'is_insert' => true)); $vn_id = $t_subject->getPrimaryKey(); if ($vn_id) { $va_tmp = caProcessRelationshipLookupLabel($t_subject->makeSearchResult($t_subject->tableName(), array($vn_id)), $t_subject); $va_name = array_pop($va_tmp); } else { $va_name = array(); } $va_response = array('status' => sizeof($va_error_list) ? 10 : 0, 'id' => $vn_id, 'table' => $t_subject->tableName(), 'type_id' => method_exists($t_subject, "getTypeID") ? $t_subject->getTypeID() : null, 'display' => $va_name['label'], 'errors' => $va_error_list); $this->view->setVar('response', $va_response); $this->render('component_result_json.php'); }
/** * Returns array of users associated with the currently loaded row. The array * is key'ed on user user user_id; each value is an array containing information about the user. Array keys are: * user_id [user_id for user] * user_name [name of user] * code [short alphanumeric code identifying the group] * description [text description of group] * * @return array List of groups associated with the currently loaded row */ public function getUsers($pa_options = null) { if (!($vn_id = (int) $this->getPrimaryKey())) { return null; } if (!($vs_user_rel_table = $this->getProperty('USERS_RELATIONSHIP_TABLE'))) { return null; } $vs_pk = $this->primaryKey(); if (!is_array($pa_options)) { $pa_options = array(); } $vb_return_for_bundle = isset($pa_options['returnAsInitialValuesForBundle']) && $pa_options['returnAsInitialValuesForBundle'] ? true : false; $o_dm = Datamodel::load(); $t_rel = $o_dm->getInstanceByTableName($vs_user_rel_table); $vb_supports_date_restrictions = (bool) $t_rel->hasField('effective_date'); $o_tep = new TimeExpressionParser(); $o_db = $this->getDb(); $qr_res = $o_db->query("\n\t\t\t\tSELECT u.*, r.*\n\t\t\t\tFROM {$vs_user_rel_table} r\n\t\t\t\tINNER JOIN ca_users AS u ON u.user_id = r.user_id\n\t\t\t\tWHERE\n\t\t\t\t\tr.{$vs_pk} = ?\n\t\t\t", $vn_id); $va_users = array(); $va_user_ids = $qr_res->getAllFieldValues("user_id"); if ($qr_users = $this->makeSearchResult('ca_users', $va_user_ids)) { $va_initial_values = caProcessRelationshipLookupLabel($qr_users, new ca_users(), array('stripTags' => true)); } else { $va_initial_values = array(); } $qr_res->seek(0); while ($qr_res->nextRow()) { $va_row = array(); foreach (array('user_id', 'user_name', 'fname', 'lname', 'email', 'sdatetime', 'edatetime', 'access') as $vs_f) { $va_row[$vs_f] = $qr_res->get($vs_f); } if ($vb_supports_date_restrictions) { $o_tep->init(); $o_tep->setUnixTimestamps($qr_res->get('sdatetime'), $qr_res->get('edatetime')); $va_row['effective_date'] = $o_tep->getText(); } if ($vb_return_for_bundle) { $va_row['label'] = $va_initial_values[$va_row['user_id']]['label']; $va_row['id'] = $va_row['user_id']; $va_users[(int) $qr_res->get('relation_id')] = $va_row; } else { $va_users[(int) $qr_res->get('user_id')] = $va_row; } } return $va_users; }
/** * Returns array of user group ACL entries associated with the currently loaded row. The array * is key'ed on user group group_id; each value is an array containing information about the group. Array keys are: * group_id [group_id for group] * name [name of group] * code [short alphanumeric code identifying the group] * description [text description of group] * * @param array $pa_options Supported options: * returnAsInitialValuesForBundle = if set array is returned suitable for use with the ACLUsers bundle; the array is key'ed by acl_id and includes the _display entry required by the bundle * * @return array List of user group ACL-entries associated with the currently loaded row */ public function getACLUserGroups($pa_options = null) { if (!($vn_id = (int) $this->getPrimaryKey())) { return null; } if (!is_array($pa_options)) { $pa_options = array(); } $vb_return_for_bundle = isset($pa_options['returnAsInitialValuesForBundle']) && $pa_options['returnAsInitialValuesForBundle'] ? true : false; $o_db = $this->getDb(); $qr_res = $o_db->query("\n\t\t\tSELECT g.*, acl.*\n\t\t\tFROM ca_acl acl\n\t\t\tINNER JOIN ca_user_groups AS g ON g.group_id = acl.group_id\n\t\t\tWHERE\n\t\t\t\tacl.table_num = ? AND acl.row_id = ? AND acl.group_id IS NOT NULL\n\t\t", $this->tableNum(), $vn_id); $va_groups = array(); $va_group_ids = $qr_res->getAllFieldValues("group_id"); if ($qr_groups = $this->makeSearchResult('ca_user_groups', $va_group_ids)) { $va_initial_values = caProcessRelationshipLookupLabel($qr_groups, new ca_user_groups(), array('stripTags' => true)); } else { $va_initial_values = array(); } $t_acl = new ca_acl(); $qr_res->seek(0); while ($qr_res->nextRow()) { $va_row = array(); foreach (array('group_id', 'name', 'code', 'description', 'access') as $vs_f) { $va_row[$vs_f] = $qr_res->get($vs_f); } if ($vb_return_for_bundle) { $va_row['label'] = $va_initial_values[$va_row['group_id']]['label']; $va_row['id'] = $va_row['group_id']; $va_row['access_display'] = $t_acl->getChoiceListValue('access', $va_row['access']); $va_groups[(int) $qr_res->get('acl_id')] = $va_row; } else { $va_groups[(int) $qr_res->get('group_id')] = $va_row; } } return $va_groups; }
public function Get($pa_additional_query_params = null, $pa_options = null) { if (!$this->ops_search_class) { return null; } $ps_query = $this->request->getParameter('q', pString); $pb_exact = $this->request->getParameter('exact', pInteger); $ps_exclude = $this->request->getParameter('exclude', pString); $va_excludes = explode(";", $ps_exclude); $ps_type = $this->request->getParameter('type', pString); $ps_types = $this->request->getParameter('types', pString); $pb_no_subtypes = (bool) $this->request->getParameter('noSubtypes', pInteger); if (!($pn_limit = $this->request->getParameter('limit', pInteger))) { $pn_limit = 100; } $va_items = array(); if (($vn_str_len = mb_strlen($ps_query)) > 0) { if ($vn_str_len < 3) { $pb_exact = true; } // force short strings to be an exact match (using a very short string as a stem would perform badly and return too many matches in most cases) $o_search = new $this->ops_search_class(); $pa_types = array(); if ($ps_types) { $pa_types = explode(';', $ps_types); } else { if ($ps_type) { $pa_types = array($ps_type); } } // Get type_ids $vs_type_query = ''; $va_ids = array(); if (sizeof($pa_types)) { $va_types = $this->opo_item_instance->getTypeList(); $va_types_proc = array(); foreach ($va_types as $vn_type_id => $va_type) { $va_types_proc[$vn_type_id] = $va_types_proc[$va_type['idno']] = $vn_type_id; } foreach ($pa_types as $ps_type) { if (isset($va_types_proc[$ps_type])) { $va_ids[$va_types_proc[$ps_type]] = true; } } $va_ids = array_keys($va_ids); if (sizeof($va_ids) > 0) { $t_list = new ca_lists(); if (!$pb_no_subtypes) { foreach ($va_ids as $vn_id) { $va_children = $t_list->getItemsForList($this->opo_item_instance->getTypeListCode(), array('item_id' => $vn_id, 'idsOnly' => true)); $va_ids = array_merge($va_ids, $va_children); } $va_ids = array_flip(array_flip($va_ids)); } $o_search->addResultFilter($this->opo_item_instance->tableName() . '.' . $this->opo_item_instance->getTypeFieldName(), 'IN', join(",", $va_ids)); } } else { $va_ids = null; } // add any additional search elements $vs_additional_query_params = ''; if (is_array($pa_additional_query_params) && sizeof($pa_additional_query_params)) { $vs_additional_query_params = ' AND (' . join(' AND ', $pa_additional_query_params) . ')'; } // get sort field $vs_sort = ''; if ($vs_idno_fld = $this->opo_item_instance->getProperty('ID_NUMBERING_SORT_FIELD')) { $vs_sort = $this->opo_item_instance->tableName() . ".{$vs_idno_fld}"; } else { if (method_exists($this->opo_item_instance, "getLabelSortField")) { $vs_sort = $this->opo_item_instance->getLabelTableName() . '.' . $this->opo_item_instance->getLabelSortField(); } } $vs_hier_parent_id_fld = $this->opo_item_instance->getProperty('HIERARCHY_PARENT_ID_FLD'); $vs_hier_fld = $this->opo_item_instance->getProperty('HIERARCHY_ID_FLD'); if ($vs_hier_fld && ($vn_restrict_to_hier_id = $this->request->getParameter('currentHierarchyOnly', pInteger))) { $o_search->addResultFilter($this->opo_item_instance->tableName() . '.' . $vs_hier_fld, '=', (int) $vn_restrict_to_hier_id); } // add filters if (isset($pa_options['filters']) && is_array($pa_options['filters']) && sizeof($pa_options['filters'])) { foreach ($pa_options['filters'] as $va_filter) { $o_search->addResultFilter($va_filter[0], $va_filter[1], $va_filter[2]); } } // do search $qr_res = $o_search->search('(' . $ps_query . (intval($pb_exact) ? '' : '*') . ')' . $vs_type_query . $vs_additional_query_params, array('search_source' => 'Lookup', 'no_cache' => false, 'sort' => $vs_sort)); $qr_res->setOption('prefetch', $pn_limit); $qr_res->setOption('dontPrefetchAttributes', true); $va_items = caProcessRelationshipLookupLabel($qr_res, $this->opo_item_instance, array('exclude' => $va_excludes, 'config' => $this->opo_plugin_config)); } if (!is_array($va_items)) { $va_items = array(); } $this->view->setVar(str_replace(' ', '_', $this->ops_name_singular) . '_list', $va_items); return $this->render('lookup/' . str_replace(' ', '_', 'ajax_' . $this->ops_name_singular . '_list_html.php')); }
/** * Given a item_id (request parameter 'id') returns a list of direct children for use in the hierarchy browser * Returned data is JSON format */ public function Get($pa_additional_query_params = null, $pa_options = null) { $ps_query = $this->request->getParameter('term', pString); $pb_exact = $this->request->getParameter('exact', pInteger); $ps_exclude = $this->request->getParameter('exclude', pString); $va_excludes = explode(";", $ps_exclude); $ps_type = $this->request->getParameter('type', pString); $ps_types = $this->request->getParameter('types', pString); $pb_no_subtypes = (bool) $this->request->getParameter('noSubtypes', pInteger); $pb_quickadd = (bool) $this->request->getParameter('quickadd', pInteger); $pb_no_inline = (bool) $this->request->getParameter('noInline', pInteger); $t_object = new ca_objects(); $t_collection = new ca_collections(); if (!($pn_limit = $this->request->getParameter('limit', pInteger))) { $pn_limit = 100; } $va_items = array(); if (($vn_str_len = mb_strlen($ps_query)) > 0) { if ($vn_str_len < 3) { $pb_exact = true; } // force short strings to be an exact match (using a very short string as a stem would perform badly and return too many matches in most cases) $o_object_search = new ObjectSearch(); $o_collection_search = new CollectionSearch(); $pa_types = array(); if ($ps_types) { $pa_types = explode(';', $ps_types); } else { if ($ps_type) { $pa_types = array($ps_type); } } // Get type_ids $vs_type_query = ''; $va_ids = array(); if (sizeof($pa_types)) { $va_types = $this->opo_item_instance->getTypeList(); $va_types_proc = array(); foreach ($va_types as $vn_type_id => $va_type) { $va_types_proc[$vn_type_id] = $va_types_proc[$va_type['idno']] = $vn_type_id; } foreach ($pa_types as $ps_type) { if (isset($va_types_proc[$ps_type])) { $va_ids[$va_types_proc[$ps_type]] = true; } } $va_ids = array_keys($va_ids); if (sizeof($va_ids) > 0) { $t_list = new ca_lists(); if (!$pb_no_subtypes) { foreach ($va_ids as $vn_id) { $va_children = $t_list->getItemsForList($this->opo_item_instance->getTypeListCode(), array('item_id' => $vn_id, 'idsOnly' => true)); $va_ids = array_merge($va_ids, $va_children); } $va_ids = array_flip(array_flip($va_ids)); } $o_object_search->addResultFilter($this->opo_item_instance->tableName() . '.' . $this->opo_item_instance->getTypeFieldName(), 'IN', join(",", $va_ids)); } } else { $va_ids = null; } // add any additional search elements $vs_additional_query_params = ''; if (is_array($pa_additional_query_params) && sizeof($pa_additional_query_params)) { $vs_additional_query_params = ' AND (' . join(' AND ', $pa_additional_query_params) . ')'; } // add filters if (isset($pa_options['filters']) && is_array($pa_options['filters']) && sizeof($pa_options['filters'])) { foreach ($pa_options['filters'] as $va_filter) { $o_object_search->addResultFilter($va_filter[0], $va_filter[1], $va_filter[2]); } } // do search $va_opts = array('exclude' => $va_excludes, 'limit' => $pn_limit); if ($vn_restrict_to_hier_id = $this->request->getParameter('currentHierarchyOnly', pInteger)) { $o_object_search->addResultFilter('ca_objects.hier_object_id', '=', (int) $vn_restrict_to_hier_id); } $qr_res = $o_object_search->search('(' . $ps_query . (intval($pb_exact) ? '' : '*') . ')' . $vs_type_query . $vs_additional_query_params, array('search_source' => 'Lookup', 'no_cache' => false, 'sort' => 'ca_objects.idno_sort')); $qr_res->setOption('prefetch', $pn_limit); $qr_res->setOption('dontPrefetchAttributes', true); if (is_array($va_objects = caProcessRelationshipLookupLabel($qr_res, new ca_objects(), $va_opts))) { foreach ($va_objects as $vn_object_id => $va_object) { $va_objects[$vn_object_id]['id'] = 'ca_objects-' . $va_objects[$vn_object_id]['id']; } } //if ($vs_hier_fld && ($vn_restrict_to_hier_id = $this->request->getParameter('currentHierarchyOnly', pInteger))) { //$o_collection_search->addResultFilter('ca_collections.hier_collection_id', '=', (int)$vn_restrict_to_hier_id); // How to restrict objects? //} $qr_res = $o_collection_search->search('(' . $ps_query . (intval($pb_exact) ? '' : '*') . ')' . $vs_type_query . $vs_additional_query_params, array('search_source' => 'Lookup', 'no_cache' => false, 'sort' => 'ca_collections.idno_sort')); $qr_res->setOption('prefetch', $pn_limit); $qr_res->setOption('dontPrefetchAttributes', true); if (is_array($va_collections = caProcessRelationshipLookupLabel($qr_res, new ca_collections(), $va_opts))) { foreach ($va_collections as $vn_collection_id => $va_collection) { $va_collections[$vn_collection_id]['id'] = 'ca_collections-' . $va_collections[$vn_collection_id]['id']; } } } if (!is_array($va_objects)) { $va_objects = array(); } if (!is_array($va_collections)) { $va_collections = array(); } if (!sizeof($va_objects) && !sizeof($va_collections)) { $va_objects[-1] = _t('No matches found for <em>%1</em>', $ps_query); } $this->view->setVar('object_list', $va_objects); $this->view->setVar('collection_list', $va_collections); return $this->render(str_replace(' ', '_', 'ajax_object_collection_list_html.php')); }
public function Index() { AssetLoadManager::register('bundleableEditor'); $t_comm = new ca_commerce_communications(); $t_user = new ca_users(); $o_result_context = new ResultContext($this->request, 'ca_commerce_communications', 'basic_search_library'); $va_options = array(); $o_db = new Db(); // filtering options foreach (array('created_on' => 'string', 'search' => 'string', 'user_id' => 'int', 'read_status' => 'string') as $vs_f => $vs_type) { if (array_key_exists($vs_f, $_REQUEST)) { $vm_v = $this->request->getParameter($vs_f, pString); $o_result_context->setParameter('caClientCommunicationList_' . $vs_f, $vm_v); } else { $vm_v = $o_result_context->getParameter('caClientCommunicationList_' . $vs_f); } switch ($vs_type) { case 'int': if (strlen($vm_v)) { $vm_v = (int) $vm_v; } break; } if ($vs_f == 'read_status') { $va_options[$vs_f] = $vm_v; switch ($vm_v) { case 'read': $vs_f = 'readOnly'; $vm_v = true; break; case 'unread': $vs_f = 'unreadOnly'; $vm_v = true; break; default: break; } } if ($vs_f == 'user_id') { if (!$this->request->getParameter('client_user_id_autocomplete', pString)) { continue; } $o_search = new UserSearch(); $va_labels = caProcessRelationshipLookupLabel($o_search->search("ca_users.user_id:{$vm_v}"), $t_user, array('stripTags' => true)); if (sizeof($va_labels)) { $va_label = array_pop($va_labels); $va_options['_user_id_display'] = $va_label['label']; } } if ($vs_f != 'search') { $t_comm->set($vs_f, $vm_v); } $va_options[$vs_f] = $vm_v; } if ($pn_transaction_id = $this->request->getParameter('transaction_id', pInteger)) { // if set load messages for this transaction $va_options['transaction_id'] = $pn_transaction_id; } $this->view->setVar('t_communication', $t_comm); $this->view->setVar('filter_options', $va_options); $this->view->setVar('message_list', $t_comm->getMessages($this->request->getUserID(), $va_options)); //$o_result_context->setResultList($va_order_ids); $o_result_context->setAsLastFind(); $o_result_context->saveContext(); $this->render('list_communications_html.php'); }
public function Get($pa_additional_query_params = null, $pa_options = null) { header("Content-type: application/json"); if (!$this->ops_search_class) { return null; } $ps_query = $this->request->getParameter('term', pString); $pb_exact = $this->request->getParameter('exact', pInteger); $ps_exclude = $this->request->getParameter('exclude', pString); $va_excludes = explode(";", $ps_exclude); $ps_type = $this->request->getParameter('type', pString); $ps_types = $this->request->getParameter('types', pString); $pb_no_subtypes = (bool) $this->request->getParameter('noSubtypes', pInteger); $pb_quickadd = (bool) $this->request->getParameter('quickadd', pInteger); $pb_no_inline = (bool) $this->request->getParameter('noInline', pInteger); if (!($pn_limit = $this->request->getParameter('limit', pInteger))) { $pn_limit = 100; } $va_items = array(); if (($vn_str_len = mb_strlen($ps_query)) > 0) { if ($vn_str_len < 3) { $pb_exact = true; } // force short strings to be an exact match (using a very short string as a stem would perform badly and return too many matches in most cases) $o_search = new $this->ops_search_class(); $pa_types = array(); if ($ps_types) { $pa_types = explode(';', $ps_types); } else { if ($ps_type) { $pa_types = array($ps_type); } } // Get type_ids $vs_type_query = ''; $va_ids = array(); if (sizeof($pa_types)) { $va_types = $this->opo_item_instance->getTypeList(); $va_types_proc = array(); foreach ($va_types as $vn_type_id => $va_type) { $va_types_proc[$vn_type_id] = $va_types_proc[$va_type['idno']] = $vn_type_id; } foreach ($pa_types as $ps_type) { if (isset($va_types_proc[$ps_type])) { $va_ids[$va_types_proc[$ps_type]] = true; } } $va_ids = array_keys($va_ids); if (sizeof($va_ids) > 0) { $t_list = new ca_lists(); if (!$pb_no_subtypes) { foreach ($va_ids as $vn_id) { $va_children = $t_list->getItemsForList($this->opo_item_instance->getTypeListCode(), array('item_id' => $vn_id, 'idsOnly' => true)); $va_ids = array_merge($va_ids, $va_children); } $va_ids = array_flip(array_flip($va_ids)); } $o_search->addResultFilter($this->opo_item_instance->tableName() . '.' . $this->opo_item_instance->getTypeFieldName(), 'IN', join(",", $va_ids)); } } // add any additional search elements $vs_additional_query_params = ''; if (is_array($pa_additional_query_params) && sizeof($pa_additional_query_params)) { $vs_additional_query_params = ' AND (' . join(' AND ', $pa_additional_query_params) . ')'; } // get sort field $vs_sort = '_natural'; // always sort first on relevance... if ($vs_idno_fld = $this->opo_item_instance->getProperty('ID_NUMBERING_SORT_FIELD')) { $vs_sort .= ";" . $this->opo_item_instance->tableName() . ".{$vs_idno_fld}"; } else { if (method_exists($this->opo_item_instance, "getLabelSortField")) { $vs_sort .= ";" . $this->opo_item_instance->getLabelTableName() . '.' . $this->opo_item_instance->getLabelSortField(); } } $vs_hier_parent_id_fld = $this->opo_item_instance->getProperty('HIERARCHY_PARENT_ID_FLD'); $vs_hier_fld = $this->opo_item_instance->getProperty('HIERARCHY_ID_FLD'); if ($vs_hier_fld && ($vn_restrict_to_hier_id = $this->request->getParameter('currentHierarchyOnly', pInteger))) { $o_search->addResultFilter($this->opo_item_instance->tableName() . '.' . $vs_hier_fld, '=', (int) $vn_restrict_to_hier_id); } // add filters if (isset($pa_options['filters']) && is_array($pa_options['filters']) && sizeof($pa_options['filters'])) { foreach ($pa_options['filters'] as $va_filter) { $o_search->addResultFilter($va_filter[0], $va_filter[1], $va_filter[2]); } } // do search $qr_res = $o_search->search($ps_query . (intval($pb_exact) ? '' : '*') . $vs_type_query . $vs_additional_query_params, array('search_source' => 'Lookup', 'no_cache' => false, 'sort' => $vs_sort)); $qr_res->setOption('prefetch', $pn_limit); $qr_res->setOption('dontPrefetchAttributes', true); $va_opts = array('exclude' => $va_excludes, 'limit' => $pn_limit); if (!$pb_no_inline && ($pb_quickadd || $this->request->user && $this->request->user->canDoAction('can_quickadd_' . $this->opo_item_instance->tableName()))) { $va_opts['inlineCreateQuery'] = $ps_query; $va_opts['inlineCreateMessageDoesNotExist'] = _t('<em>%1</em> does not exist. Create?', $ps_query); $va_opts['inlineCreateMessage'] = _t('Create <em>%1</em>?', $ps_query); } else { $va_opts['emptyResultQuery'] = $ps_query; $va_opts['emptyResultMessage'] = _t('No matches found for <em>%1</em>', $ps_query); } $va_items = caProcessRelationshipLookupLabel($qr_res, $this->opo_item_instance, $va_opts); } if (!is_array($va_items)) { $va_items = array(); } // Optional output simple list of labels instead of full data format if ((bool) $this->request->getParameter('simple', pInteger)) { $va_items = caExtractValuesFromArrayList($va_items, 'label', array('preserveKeys' => false)); } $this->view->setVar(str_replace(' ', '_', $this->ops_name_singular) . '_list', $va_items); return $this->render(str_replace(' ', '_', 'ajax_' . $this->ops_name_singular . '_list_html.php')); }
/** * */ public function Get() { $ps_query = $this->request->getParameter('term', pString); $o_search = new ObjectSearch(); $qr_res = $o_search->search($ps_query); $va_object_ids = array(); while ($qr_res->nextHit()) { $va_object_ids[$qr_res->get('object_id')] = false; } if (sizeof($va_object_ids)) { // get checked out items $o_db = new Db(); $qr_checked_out_items = $o_db->query("\n\t\t\t\t\tSELECT DISTINCT i.object_id, i.loan_due_date\n\t\t\t\t\tFROM ca_commerce_order_items i\n\t\t\t\t\tWHERE\n\t\t\t\t\t\ti.loan_return_date IS NULL and i.loan_checkout_date > 0 AND i.object_id IN (?)\n\t\t\t\t", array(array_keys($va_object_ids))); while ($qr_checked_out_items->nextRow()) { $va_object_ids[$qr_checked_out_items->get('object_id')] = $qr_checked_out_items->get('loan_due_date'); } $t_object = new ca_objects(); $qr_res = $t_object->makeSearchResult('ca_objects', array_keys($va_object_ids)); $va_items = caProcessRelationshipLookupLabel($qr_res, $t_object, array()); foreach ($va_items as $vn_object_id => $va_object) { if ((int) $va_object_ids[$vn_object_id] > 0) { $vs_due_date_for_display = caGetLocalizedDate($va_object_ids[$vn_object_id], array('format' => 'delimited', 'timeOmit' => true)); $va_items[$vn_object_id]['label'] .= ' [<em>' . _t('on loan through %1', $vs_due_date_for_display) . '</em>]'; $va_items[$vn_object_id]['due_date'] = $va_object_ids[$vn_object_id]; $va_items[$vn_object_id]['due_date_display'] = $vs_due_date_for_display; } } } if (!is_array($va_items)) { $va_items = array(); } if (!sizeof($va_items)) { // nothing found $va_items[0] = array('label' => _t('No matches found'), 'type_id' => null, 'object_id' => 0); } $this->view->setVar('object_list', $va_items); $this->view->setVar('object_id_list', $va_object_ids); return $this->render('ajax_object_list_html.php'); }
public function Get($pa_additional_query_params = null, $pa_options = null) { header("Content-type: application/json"); $o_config = Configuration::load(); $o_search_config = caGetSearchConfig(); if (!$this->ops_search_class) { return null; } $ps_query = $this->request->getParameter('term', pString); $pb_exact = $this->request->getParameter('exact', pInteger); $ps_exclude = $this->request->getParameter('exclude', pString); $va_excludes = explode(";", $ps_exclude); $ps_type = $this->request->getParameter('type', pString); $ps_types = $this->request->getParameter('types', pString); $ps_restrict_to_search = trim($this->request->getParameter('restrictToSearch', pString)); $pb_no_subtypes = (bool) $this->request->getParameter('noSubtypes', pInteger); $pb_quickadd = (bool) $this->request->getParameter('quickadd', pInteger); $pb_no_inline = (bool) $this->request->getParameter('noInline', pInteger); if (!($pn_limit = $this->request->getParameter('limit', pInteger))) { $pn_limit = 100; } $va_items = array(); if (($vn_str_len = mb_strlen($ps_query)) > 0) { if ($vn_str_len < 3) { $pb_exact = true; } // force short strings to be an exact match (using a very short string as a stem would perform badly and return too many matches in most cases) $o_search = new $this->ops_search_class(); $pa_types = array(); if ($ps_types) { $pa_types = explode(';', $ps_types); } else { if ($ps_type) { $pa_types = array($ps_type); } } // Get type_ids $va_ids = array(); if (sizeof($pa_types)) { $va_types = $this->opo_item_instance->getTypeList(); $va_types_proc = array(); foreach ($va_types as $vn_type_id => $va_type) { $va_types_proc[$vn_type_id] = $va_types_proc[$va_type['idno']] = $vn_type_id; } foreach ($pa_types as $ps_type) { if (isset($va_types_proc[$ps_type])) { $va_ids[$va_types_proc[$ps_type]] = true; } } $va_ids = array_keys($va_ids); if (sizeof($va_ids) > 0) { $t_list = new ca_lists(); if (!$pb_no_subtypes) { foreach ($va_ids as $vn_id) { $va_children = $t_list->getItemsForList($this->opo_item_instance->getTypeListCode(), array('item_id' => $vn_id, 'idsOnly' => true)); $va_ids = array_merge($va_ids, $va_children); } $va_ids = array_flip(array_flip($va_ids)); } $o_search->addResultFilter($this->opo_item_instance->tableName() . '.' . $this->opo_item_instance->getTypeFieldName(), 'IN', join(",", $va_ids)); } } // add any additional search elements $vs_additional_query_params = ''; if (is_array($pa_additional_query_params) && sizeof($pa_additional_query_params)) { $vs_additional_query_params = ' AND (' . join(' AND ', $pa_additional_query_params) . ')'; } $vs_restrict_to_search = ''; if (strlen($ps_restrict_to_search) > 0) { $vs_restrict_to_search .= ' AND (' . $ps_restrict_to_search . ')'; } // get sort field $vs_sort = $this->request->getAppConfig()->get($this->opo_item_instance->tableName() . '_lookup_sort'); if (!$vs_sort) { $vs_sort = '_natural'; } $vs_hier_parent_id_fld = $this->opo_item_instance->getProperty('HIERARCHY_PARENT_ID_FLD'); $vs_hier_fld = $this->opo_item_instance->getProperty('HIERARCHY_ID_FLD'); if ($vs_hier_fld && ($vn_restrict_to_hier_id = $this->request->getParameter('currentHierarchyOnly', pInteger))) { $o_search->addResultFilter($this->opo_item_instance->tableName() . '.' . $vs_hier_fld, '=', (int) $vn_restrict_to_hier_id); } // add filters if (isset($pa_options['filters']) && is_array($pa_options['filters']) && sizeof($pa_options['filters'])) { foreach ($pa_options['filters'] as $va_filter) { $o_search->addResultFilter($va_filter[0], $va_filter[1], $va_filter[2]); } } if (!$pb_exact) { $ps_query = trim(preg_replace("![" . str_replace("!", "\\!", $o_search_config->get('search_tokenizer_regex')) . "]+!", " ", $ps_query)); } // do search if ($vs_additional_query_params || $vs_restrict_to_search) { $vs_search = '(' . trim($ps_query) . (intval($pb_exact) ? '' : '*') . ')' . $vs_additional_query_params . $vs_restrict_to_search; } else { $vs_search = trim($ps_query) . (intval($pb_exact) ? '' : '*'); } $qr_res = $o_search->search($vs_search); $qr_res->setOption('prefetch', $pn_limit); $qr_res->setOption('dontPrefetchAttributes', true); $va_opts = array('exclude' => $va_excludes, 'limit' => $pn_limit); if (!$pb_no_inline && ($pb_quickadd || !strlen($pb_quickadd) && $this->request->user && $this->request->user->canDoAction('can_quickadd_' . $this->opo_item_instance->tableName()) && !(bool) $o_config->get($this->opo_item_instance->tableName() . '_disable_quickadd'))) { // if the lookup was restricted by search, try the lookup without the restriction // so that we can notify the user that he might be about to create a duplicate if (strlen($ps_restrict_to_search) > 0) { $o_no_filter_result = $o_search->search(trim($ps_query) . (intval($pb_exact) ? '' : '*') . $vs_type_query . $vs_additional_query_params, array('search_source' => 'Lookup', 'no_cache' => false, 'sort' => $vs_sort)); if ($o_no_filter_result->numHits() != $qr_res->numHits()) { $va_opts['inlineCreateMessageDoesNotExist'] = _t("<em>%1</em> doesn't exist with this filter but %2 record(s) match overall. Create <em>%1</em>?", $ps_query, $o_no_filter_result->numHits()); $va_opts['inlineCreateMessage'] = _t('<em>%1</em> matches %2 more record(s) without the current filter. Create <em>%1</em>?', $ps_query, $o_no_filter_result->numHits() - $qr_res->numHits()); } } if (!isset($va_opts['inlineCreateMessageDoesNotExist'])) { $va_opts['inlineCreateMessageDoesNotExist'] = _t('<em>%1</em> does not exist. Create?', $ps_query); } if (!isset($va_opts['inlineCreateMessage'])) { $va_opts['inlineCreateMessage'] = _t('Create <em>%1</em>?', $ps_query); } $va_opts['inlineCreateQuery'] = $ps_query; } else { $va_opts['emptyResultQuery'] = $ps_query; $va_opts['emptyResultMessage'] = _t('No matches found for <em>%1</em>', $ps_query); } $va_items = caProcessRelationshipLookupLabel($qr_res, $this->opo_item_instance, $va_opts); } if (!is_array($va_items)) { $va_items = array(); } // Optional output simple list of labels instead of full data format if ((bool) $this->request->getParameter('simple', pInteger)) { $va_items = caExtractValuesFromArrayList($va_items, 'label', array('preserveKeys' => false)); } $this->view->setVar(str_replace(' ', '_', $this->ops_name_singular) . '_list', array_values($va_items)); return $this->render(str_replace(' ', '_', 'ajax_' . $this->ops_name_singular . '_list_html.php')); }