コード例 #1
0
ファイル: ShowController.php プロジェクト: guaykuru/pawtucket
 public function __construct(&$po_request, &$po_response, $pa_view_paths = null)
 {
     $this->ops_theme = __CA_THEME__;
     // get current theme
     if (!is_dir(__CA_APP_DIR__ . '/plugins/MetabolicChronology/themes/' . $this->ops_theme . '/views')) {
         // if theme is not defined for this plugin, try to use "default" theme
         $this->ops_theme = 'default';
     }
     parent::__construct($po_request, $po_response, array(__CA_APP_DIR__ . '/plugins/MetabolicChronology/themes/' . $this->ops_theme . '/views'));
     $this->opo_plugin_config = Configuration::load($this->request->getAppConfig()->get('application_plugins') . '/MetabolicChronology/conf/Chronology.conf');
     if (!(bool) $this->opo_plugin_config->get('enabled')) {
         die(_t('Metabolic Chronology plugin is not enabled'));
     }
     $this->_initView($pa_options);
     $this->opo_result_context = new ResultContext($po_request, 'ca_objects', 'MetabolicChronology');
     MetaTagManager::addLink('stylesheet', $po_request->getBaseUrlPath() . "/app/plugins/MetabolicChronology/themes/" . $this->ops_theme . "/css/chronology.css", 'text/css');
     JavascriptLoadManager::register('jcarousel');
     JavascriptLoadManager::register('maps');
     $t_list = new ca_lists();
     $this->opn_silo_type_id = $t_list->getItemIDFromList('collection_types', 'silo');
     $this->opn_action_type_id = $t_list->getItemIDFromList('occurrence_types', 'action');
     $this->opn_context_type_id = $t_list->getItemIDFromList('occurrence_types', 'context');
     $this->opn_yes_list_id = $t_list->getItemIDFromList('yes_no', 'yes');
     $t_relationship_types = new ca_relationship_types();
     $this->opn_rel_type_action_display_image = $t_relationship_types->getRelationshipTypeID("ca_objects_x_occurrences", "display");
     $this->opn_rel_type_action_secondary_images = $t_relationship_types->getRelationshipTypeID("ca_objects_x_occurrences", "secondary");
     $va_access_values = caGetUserAccessValues($this->request);
     $this->opa_access_values = $va_access_values;
     $this->view->setVar('access_values', $va_access_values);
 }
コード例 #2
0
ファイル: BaseModel.php プロジェクト: samrahman/providence
 /**
  * Checks if a relationship exists between the currently loaded row and the specified target
  *
  * @param mixed $pm_rel_table_name_or_num Table name (eg. "ca_entities") or number as defined in datamodel.conf of table containing row to creation relationship to.
  * @param int $pn_rel_id primary key value of row to creation relationship to.
  * @param mixed $pm_type_id Relationship type type_code or type_id, as defined in the ca_relationship_types table. This is required for all relationships that use relationship types. This includes all of the most common types of relationships.
  * @param string $ps_effective_date Optional date expression to qualify relation with. Any expression that the TimeExpressionParser can handle is supported here.
  * @param string $ps_direction Optional direction specification for self-relationships (relationships linking two rows in the same table). Valid values are 'ltor' (left-to-right) and  'rtol' (right-to-left); the direction determines which "side" of the relationship the currently loaded row is on: 'ltor' puts the current row on the left side. For many self-relations the direction determines the nature and display text for the relationship.
  * @param array $pa_options Options are:
  *		relation_id = an optional relation_id to ignore when checking for existence. If you are checking for relations other than one you know exists you can set this to ensure that relationship is not considered.
  *
  * @return mixed Array of matched relation_ids on success, false on error.
  */
 public function relationshipExists($pm_rel_table_name_or_num, $pn_rel_id, $pm_type_id = null, $ps_effective_date = null, $ps_direction = null, $pa_options = null)
 {
     if (!($va_rel_info = $this->_getRelationshipInfo($pm_rel_table_name_or_num))) {
         $this->postError(1240, _t('Related table specification "%1" is not valid', $pm_rel_table_name_or_num), 'BaseModel->addRelationship()');
         return false;
     }
     $vn_relation_id = isset($pa_options['relation_id']) && (int) $pa_options['relation_id'] ? (int) $pa_options['relation_id'] : null;
     $vs_relation_id_sql = null;
     $t_item_rel = $va_rel_info['t_item_rel'];
     if ($pm_type_id && !is_numeric($pm_type_id)) {
         $t_rel_type = new ca_relationship_types();
         if ($vs_linking_table = $t_rel_type->getRelationshipTypeTable($this->tableName(), $t_item_rel->tableName())) {
             $pn_type_id = $t_rel_type->getRelationshipTypeID($vs_linking_table, $pm_type_id);
         }
     } else {
         $pn_type_id = $pm_type_id;
     }
     if (!is_numeric($pn_rel_id)) {
         if ($t_rel_item = $this->_DATAMODEL->getInstanceByTableName($va_rel_info['related_table_name'], true)) {
             if ($this->inTransaction()) {
                 $t_rel_item->setTransaction($this->getTransaction());
             }
             if (($vs_idno_fld = $t_rel_item->getProperty('ID_NUMBERING_ID_FIELD')) && $t_rel_item->load(array($vs_idno_fld => $pn_rel_id))) {
                 $pn_rel_id = $t_rel_item->getPrimaryKey();
             }
         }
     }
     $va_query_params = array();
     $o_db = $this->getDb();
     if (($t_item_rel = $va_rel_info['t_item_rel']) && method_exists($t_item_rel, 'getLeftTableName')) {
         $vs_rel_table_name = $t_item_rel->tableName();
         $vs_type_sql = $vs_timestamp_sql = '';
         $vs_left_table_name = $t_item_rel->getLeftTableName();
         $vs_left_field_name = $t_item_rel->getLeftTableFieldName();
         $vs_right_table_name = $t_item_rel->getRightTableName();
         $vs_right_field_name = $t_item_rel->getRightTableFieldName();
         if ($va_rel_info['related_table_name'] == $this->tableName()) {
             // is self relation
             if ($ps_direction == 'rtol') {
                 $vn_left_id = (int) $pn_rel_id;
                 $vn_right_id = (int) $this->getPrimaryKey();
             } else {
                 $vn_left_id = (int) $this->getPrimaryKey();
                 $vn_right_id = (int) $pn_rel_id;
             }
         } else {
             if ($vs_left_table_name == $this->tableName()) {
                 $vn_left_id = (int) $this->getPrimaryKey();
                 $vn_right_id = (int) $pn_rel_id;
             } else {
                 $vn_left_id = (int) $pn_rel_id;
                 $vn_right_id = (int) $this->getPrimaryKey();
             }
         }
         $va_query_params = array($vn_left_id, $vn_right_id);
         if ($t_item_rel->hasField('type_id')) {
             $vs_type_sql = ' AND type_id = ?';
             $va_query_params[] = (int) $pn_type_id;
         }
         if ($ps_effective_date && $t_item_rel->hasField('sdatetime') && ($va_timestamps = caDateToHistoricTimestamps($ps_effective_date))) {
             $vs_timestamp_sql = " AND (sdatetime = ? AND edatetime = ?)";
             $va_query_params[] = (double) $va_timestamps['start'];
             $va_query_params[] = (double) $va_timestamps['end'];
         }
         if ($vn_relation_id) {
             $vs_relation_id_sql = " AND relation_id <> ?";
             $va_query_params[] = $vn_relation_id;
         }
         $qr_res = $o_db->query("\n\t\t\t\tSELECT relation_id\n\t\t\t\tFROM {$vs_rel_table_name}\n\t\t\t\tWHERE\n\t\t\t\t\t{$vs_left_field_name} = ? AND {$vs_right_field_name} = ?\n\t\t\t\t\t{$vs_type_sql} {$vs_timestamp_sql} {$vs_relation_id_sql}\n\t\t\t", $va_query_params);
         $va_ids = $qr_res->getAllFieldValues('relation_id');
         if ($va_rel_info['related_table_name'] == $this->tableName()) {
             $qr_res = $o_db->query("\n\t\t\t\t\tSELECT relation_id\n\t\t\t\t\tFROM {$vs_rel_table_name}\n\t\t\t\t\tWHERE\n\t\t\t\t\t\t{$vs_right_field_name} = ? AND {$vs_left_field_name} = ?\n\t\t\t\t\t\t{$vs_type_sql} {$vs_timestamp_sql} {$vs_relation_id_sql}\n\t\t\t\t", $va_query_params);
             $va_ids += $qr_res->getAllFieldValues('relation_id');
         }
         if (sizeof($va_ids)) {
             return $va_ids;
         }
     } else {
         if (sizeof($va_rel_info['path']) == 2) {
             // many-one rel
             $va_rel_keys = $va_rel_info['rel_keys'];
             $vb_is_one_table = $this->tableName() == $va_rel_keys['one_table'] ? true : false;
             $vs_where_sql = "(ot." . $va_rel_keys['one_table_field'] . " = ?) AND (mt." . $va_rel_keys['many_table_field'] . " = ?)";
             if ($vb_is_one_table) {
                 $va_query_params[] = (int) $this->getPrimaryKey();
                 $va_query_params[] = (int) $pn_rel_id;
             } else {
                 $va_query_params[] = (int) $pn_rel_id;
                 $va_query_params[] = (int) $this->getPrimaryKey();
             }
             $vs_relation_id_fld = $vb_is_one_table ? "mt." . $va_rel_keys['many_table_field'] : "ot." . $va_rel_keys['one_table_field'];
             $qr_res = $o_db->query($x = "\n\t\t\t\t\tSELECT {$vs_relation_id_fld}\n\t\t\t\t\tFROM {$va_rel_keys['one_table']} ot\n\t\t\t\t\tINNER JOIN {$va_rel_keys['many_table']} AS mt ON mt.{$va_rel_keys['many_table_field']} = ot.{$va_rel_keys['one_table_field']}\n\t\t\t\t\tWHERE\n\t\t\t\t\t\t{$vs_where_sql}\n\t\t\t\t", $va_query_params);
             if (sizeof($va_ids = $qr_res->getAllFieldValues($vs_relation_id_fld))) {
                 return $va_ids;
             }
         }
     }
     return false;
 }
 /**
  * Returns list of items in the specified table related to the currently loaded row or rows specified in options.
  * 
  * @param $pm_rel_table_name_or_num - the table name or table number of the item type you want to get a list of (eg. if you are calling this on an ca_objects instance passing 'ca_entities' here will get you a list of entities related to the object)
  * @param $pa_options - array of options. Supported options are:
  *
  *		[Options controlling rows for which data is returned]
  *			row_ids = Array of primary key values to use when fetching related items. If omitted or set to a null value the 'row_id' option will be used. [Default is null]
  *			row_id = Primary key value to use when fetching related items. If omitted or set to a false value (null, false, 0) then the primary key value of the currently loaded row is used. [Default is currently loaded row]
  *			start = Zero-based index to begin return set at. [Default is 0]
  *			limit = Maximum number of related items to return. [Default is 1000]
  *			showDeleted = Return related items that have been deleted. [Default is false]
  *			primaryIDs = array of primary keys in related table to exclude from returned list of items. Array is keyed on table name for compatibility with the parameter as used in the caProcessTemplateForIDs() helper [Default is null - nothing is excluded].
  *			restrictToBundleValues = Restrict returned items to those with specified bundle values. Specify an associative array with keys set to bundle names and key values set to arrays of values to filter on (eg. [bundle_name1 => [value1, value2, ...]]). [Default is null]
  *			where = Restrict returned items to specified field values. The fields must be intrinsic and in the related table. This option can be useful when you want to efficiently fetch specific rows from a related table. Note that multiple fields/values are logically AND'ed together – all must match for a row to be returned - and that only equivalence is supported. [Default is null]			
  *			criteria = Restrict returned items using SQL criteria appended directly onto the query. Criteria is used as-is and must be compatible with the generated SQL query. [Default is null]
  *
  *		[Options controlling scope of data in return value]
  *			restrictToTypes = Restrict returned items to those of the specified types. An array of list item idnos and/or item_ids may be specified. [Default is null]
  *			restrictToRelationshipTypes =  Restrict returned items to those related using the specified relationship types. An array of relationship type idnos and/or type_ids may be specified. [Default is null]
  *			excludeTypes = Restrict returned items to those *not* of the specified types. An array of list item idnos and/or item_ids may be specified. [Default is null]
  *			excludeRelationshipTypes = Restrict returned items to those *not* related using the specified relationship types. An array of relationship type idnos and/or type_ids may be specified. [Default is null]
  *			restrictToType = Synonym for restrictToTypes. [Default is null]
  *			restrictToRelationshipType = Synonym for restrictToRelationshipTypes. [Default is null]
  *			excludeType = Synonym for excludeTypes. [Default is null]
  *			excludeRelationshipType = Synonym for excludeRelationshipTypes. [Default is null]
  *			restrictToLists = Restrict returned items to those that are in one or more specified lists. This option is only relevant when fetching related ca_list_items. An array of list list_codes or list_ids may be specified. [Default is null]
  * 			fields = array of fields (in table.fieldname format) to include in returned data. [Default is null]
  *			returnNonPreferredLabels = Return non-preferred labels in returned data. [Default is false]
  *			returnLabelsAsArray = Return all labels associated with row in an array, rather than as a text value in the current locale. [Default is false]
  *			dontReturnLabels = Don't include labels in returned data. [Default is false]
  *			idsOnly = Return one-dimensional array of related primary key values only. [Default is false]
  *
  *		[Options controlling format of data in return value]
  *			useLocaleCodes = Return locale values as codes (Ex. en_US) rather than numeric database-specific locale_ids. [Default is false]
  *			sort = Array list of bundles to sort returned values on. The sortable bundle specifiers are fields with or without tablename. Only those fields returned for the related tables (intrinsics, attributes and label fields) are sortable. [Default is null]
  *			sortDirection = Direction of sort. Use "asc" (ascending) or "desc" (descending). [Default is asc]
  *			groupFields = Groups together fields in an arrangement that is easier for import to another system. Used by the ItemInfo web service when in "import" mode. [Default is false]
  *
  *		[Front-end access control]	
  *			checkAccess = Array of access values to filter returned values on. Available for any related table with an "access" field (ca_objects, ca_entities, etc.). If omitted no filtering is performed. [Default is null]
  *			user_id = Perform item level access control relative to specified user_id rather than currently logged in user. [Default is user_id for currently logged in user]
  *
  * @return array List of related items
  */
 public function getRelatedItems($pm_rel_table_name_or_num, $pa_options = null)
 {
     global $AUTH_CURRENT_USER_ID;
     $vn_user_id = isset($pa_options['user_id']) && $pa_options['user_id'] ? $pa_options['user_id'] : (int) $AUTH_CURRENT_USER_ID;
     $vb_show_if_no_acl = (bool) ($this->getAppConfig()->get('default_item_access_level') > __CA_ACL_NO_ACCESS__);
     // convert options
     if (($pa_options['restrictToTypes'] = caGetOption(array('restrictToTypes', 'restrict_to_types', 'restrictToType', 'restrict_to_type'), $pa_options, null)) && !is_array($pa_options['restrictToTypes'])) {
         $pa_options['restrictToTypes'] = array($pa_options['restrictToTypes']);
     }
     if (($pa_options['restrictToRelationshipTypes'] = caGetOption(array('restrictToRelationshipTypes', 'restrict_to_relationship_types', 'restrictToRelationshipType', 'restrict_to_relationship_type'), $pa_options, null)) && !is_array($pa_options['restrictToRelationshipTypes'])) {
         $pa_options['restrictToRelationshipTypes'] = array($pa_options['restrictToRelationshipTypes']);
     }
     if (($pa_options['excludeTypes'] = caGetOption(array('excludeTypes', 'exclude_types', 'excludeType', 'exclude_type'), $pa_options, null)) && !is_array($pa_options['excludeTypes'])) {
         $pa_options['excludeTypes'] = array($pa_options['excludeTypes']);
     }
     if (($pa_options['excludeRelationshipTypes'] = caGetOption(array('excludeRelationshipTypes', 'exclude_relationship_types', 'excludeRelationshipType', 'exclude_relationship_type'), $pa_options, null)) && !is_array($pa_options['excludeRelationshipTypes'])) {
         $pa_options['excludeRelationshipTypes'] = array($pa_options['excludeRelationshipTypes']);
     }
     if (!isset($pa_options['dontIncludeSubtypesInTypeRestriction']) && (isset($pa_options['dont_include_subtypes_in_type_restriction']) && $pa_options['dont_include_subtypes_in_type_restriction'])) {
         $pa_options['dontIncludeSubtypesInTypeRestriction'] = $pa_options['dont_include_subtypes_in_type_restriction'];
     }
     if (!isset($pa_options['returnNonPreferredLabels']) && (isset($pa_options['restrict_to_type']) && $pa_options['restrict_to_type'])) {
         $pa_options['returnNonPreferredLabels'] = $pa_options['restrict_to_type'];
     }
     if (!isset($pa_options['returnLabelsAsArray']) && (isset($pa_options['return_labels_as_array']) && $pa_options['return_labels_as_array'])) {
         $pa_options['returnLabelsAsArray'] = $pa_options['return_labels_as_array'];
     }
     if (!isset($pa_options['restrictToLists']) && (isset($pa_options['restrict_to_lists']) && $pa_options['restrict_to_lists'])) {
         $pa_options['restrictToLists'] = $pa_options['restrict_to_lists'];
     }
     $vb_group_fields = isset($pa_options['groupFields']) ? $pa_options['groupFields'] : false;
     $va_primary_ids = isset($pa_options['primaryIDs']) && is_array($pa_options['primaryIDs']) ? $pa_options['primaryIDs'] : null;
     $vb_show_current_only = isset($pa_options['showCurrentOnly']) ? $pa_options['showCurrentOnly'] : false;
     if (!isset($pa_options['useLocaleCodes']) && (isset($pa_options['returnLocaleCodes']) && $pa_options['returnLocaleCodes'])) {
         $pa_options['useLocaleCodes'] = $pa_options['returnLocaleCodes'];
     }
     $vb_use_locale_codes = isset($pa_options['useLocaleCodes']) ? $pa_options['useLocaleCodes'] : false;
     $va_get_where = isset($pa_options['where']) && is_array($pa_options['where']) && sizeof($pa_options['where']) ? $pa_options['where'] : null;
     $va_row_ids = isset($pa_options['row_ids']) && is_array($pa_options['row_ids']) ? $pa_options['row_ids'] : null;
     $vn_row_id = isset($pa_options['row_id']) && $pa_options['row_id'] ? $pa_options['row_id'] : $this->getPrimaryKey();
     $o_db = $this->getDb();
     $t_locale = $this->getLocaleInstance();
     $o_tep = $this->getTimeExpressionParser();
     $vb_uses_effective_dates = false;
     if (isset($pa_options['sort']) && !is_array($pa_options['sort'])) {
         $pa_options['sort'] = array($pa_options['sort']);
     }
     $va_sort_fields = isset($pa_options['sort']) && is_array($pa_options['sort']) ? $pa_options['sort'] : null;
     $vs_sort_direction = isset($pa_options['sortDirection']) && $pa_options['sortDirection'] ? $pa_options['sortDirection'] : null;
     if (!$va_row_ids && $vn_row_id > 0) {
         $va_row_ids = array($vn_row_id);
     }
     if (!$va_row_ids || !is_array($va_row_ids) || !sizeof($va_row_ids)) {
         return array();
     }
     $vb_return_labels_as_array = isset($pa_options['returnLabelsAsArray']) && $pa_options['returnLabelsAsArray'] ? true : false;
     $vn_limit = isset($pa_options['limit']) && (int) $pa_options['limit'] > 0 ? (int) $pa_options['limit'] : 1000;
     $vn_start = isset($pa_options['start']) && (int) $pa_options['start'] > 0 ? (int) $pa_options['start'] : 0;
     if (is_numeric($pm_rel_table_name_or_num)) {
         if (!($vs_related_table_name = $this->getAppDatamodel()->getTableName($pm_rel_table_name_or_num))) {
             return null;
         }
     } else {
         if (sizeof($va_tmp = explode(".", $pm_rel_table_name_or_num)) > 1) {
             $pm_rel_table_name_or_num = array_shift($va_tmp);
         }
         if (!($o_instance = $this->getAppDatamodel()->getInstanceByTableName($pm_rel_table_name_or_num, true))) {
             return null;
         }
         $vs_related_table_name = $pm_rel_table_name_or_num;
     }
     if (!is_array($pa_options)) {
         $pa_options = array();
     }
     $vb_is_combo_key_relation = false;
     // indicates relation is via table_num/row_id combination key
     switch (sizeof($va_path = array_keys($this->getAppDatamodel()->getPath($this->tableName(), $vs_related_table_name)))) {
         case 3:
             $t_item_rel = $this->getAppDatamodel()->getTableInstance($va_path[1]);
             $t_rel_item = $this->getAppDatamodel()->getTableInstance($va_path[2]);
             $vs_key = $t_item_rel->primaryKey();
             //'relation_id';
             break;
         case 2:
             $t_item_rel = $this->isRelationship() ? $this : null;
             $t_rel_item = $this->getAppDatamodel()->getTableInstance($va_path[1]);
             $vs_key = $t_rel_item->primaryKey();
             break;
         default:
             // is this related with row_id/table_num combo?
             if (($t_rel_item = $this->getAppDatamodel()->getTableInstance($vs_related_table_name)) && $t_rel_item->hasField('table_num') && $t_rel_item->hasField('row_id')) {
                 $vs_key = $t_rel_item->primaryKey();
                 $vb_is_combo_key_relation = true;
                 $va_path = array($this->tableName(), $t_rel_item->tableName());
             } else {
                 // bad related table
                 return null;
             }
             break;
     }
     // check for self relationship
     $vb_self_relationship = false;
     if ($this->tableName() == $vs_related_table_name) {
         $vb_self_relationship = true;
         $t_rel_item = $this->getAppDatamodel()->getTableInstance($va_path[0]);
         $t_item_rel = $this->getAppDatamodel()->getTableInstance($va_path[1]);
     }
     $va_wheres = array();
     $va_selects = array();
     $va_joins_post_add = array();
     $vs_related_table = $t_rel_item->tableName();
     if ($t_rel_item->hasField('type_id')) {
         $va_selects[] = "{$vs_related_table}.type_id item_type_id";
     }
     if ($t_rel_item->hasField('source_id')) {
         $va_selects[] = "{$vs_related_table}.source_id item_source_id";
     }
     // TODO: get these field names from models
     if (($t_tmp = $t_item_rel) || $t_rel_item->isRelationship() && ($t_tmp = $t_rel_item)) {
         //define table names
         $vs_linking_table = $t_tmp->tableName();
         $va_selects[] = "{$vs_related_table}." . $t_rel_item->primaryKey();
         // include dates in returned data
         if ($t_tmp->hasField('effective_date')) {
             $va_selects[] = $vs_linking_table . '.sdatetime';
             $va_selects[] = $vs_linking_table . '.edatetime';
             $vb_uses_effective_dates = true;
         }
         if ($t_rel_item->hasField('is_enabled')) {
             $va_selects[] = "{$vs_related_table}.is_enabled";
         }
         if ($t_tmp->hasField('type_id')) {
             $va_selects[] = $vs_linking_table . '.type_id relationship_type_id';
             require_once __CA_MODELS_DIR__ . '/ca_relationship_types.php';
             $t_rel = new ca_relationship_types();
             $vb_uses_relationship_types = true;
         }
         // limit related items to a specific type
         if ($vb_uses_relationship_types && isset($pa_options['restrictToRelationshipTypes']) && $pa_options['restrictToRelationshipTypes']) {
             if (!is_array($pa_options['restrictToRelationshipTypes'])) {
                 $pa_options['restrictToRelationshipTypes'] = array($pa_options['restrictToRelationshipTypes']);
             }
             if (sizeof($pa_options['restrictToRelationshipTypes'])) {
                 $va_rel_types = array();
                 foreach ($pa_options['restrictToRelationshipTypes'] as $vm_type) {
                     if (!$vm_type) {
                         continue;
                     }
                     if (!($vn_type_id = $t_rel->getRelationshipTypeID($vs_linking_table, $vm_type))) {
                         $vn_type_id = (int) $vm_type;
                     }
                     if ($vn_type_id > 0) {
                         $va_rel_types[] = $vn_type_id;
                         if (is_array($va_children = $t_rel->getHierarchyChildren($vn_type_id, array('idsOnly' => true)))) {
                             $va_rel_types = array_merge($va_rel_types, $va_children);
                         }
                     }
                 }
                 if (sizeof($va_rel_types)) {
                     $va_wheres[] = '(' . $vs_linking_table . '.type_id IN (' . join(',', $va_rel_types) . '))';
                 }
             }
         }
         if ($vb_uses_relationship_types && isset($pa_options['excludeRelationshipTypes']) && $pa_options['excludeRelationshipTypes']) {
             if (!is_array($pa_options['excludeRelationshipTypes'])) {
                 $pa_options['excludeRelationshipTypes'] = array($pa_options['excludeRelationshipTypes']);
             }
             if (sizeof($pa_options['excludeRelationshipTypes'])) {
                 $va_rel_types = array();
                 foreach ($pa_options['excludeRelationshipTypes'] as $vm_type) {
                     if ($vn_type_id = $t_rel->getRelationshipTypeID($vs_linking_table, $vm_type)) {
                         $va_rel_types[] = $vn_type_id;
                         if (is_array($va_children = $t_rel->getHierarchyChildren($vn_type_id, array('idsOnly' => true)))) {
                             $va_rel_types = array_merge($va_rel_types, $va_children);
                         }
                     }
                 }
                 if (sizeof($va_rel_types)) {
                     $va_wheres[] = '(' . $vs_linking_table . '.type_id NOT IN (' . join(',', $va_rel_types) . '))';
                 }
             }
         }
     }
     // limit related items to a specific type
     $va_type_ids = caMergeTypeRestrictionLists($t_rel_item, $pa_options);
     if (is_array($va_type_ids) && sizeof($va_type_ids) > 0) {
         $va_wheres[] = "({$vs_related_table}.type_id IN (" . join(',', $va_type_ids) . ')' . ($t_rel_item->getFieldInfo('type_id', 'IS_NULL') ? " OR ({$vs_related_table}.type_id IS NULL)" : '') . ')';
     }
     $va_source_ids = caMergeSourceRestrictionLists($t_rel_item, $pa_options);
     if (method_exists($t_rel_item, "getSourceFieldName") && ($vs_source_id_fld = $t_rel_item->getSourceFieldName()) && is_array($va_source_ids) && sizeof($va_source_ids) > 0) {
         $va_wheres[] = "({$vs_related_table}.{$vs_source_id_fld} IN (" . join(',', $va_source_ids) . "))";
     }
     if (isset($pa_options['excludeType']) && $pa_options['excludeType']) {
         if (!isset($pa_options['excludeTypes']) || !is_array($pa_options['excludeTypes'])) {
             $pa_options['excludeTypes'] = array();
         }
         $pa_options['excludeTypes'][] = $pa_options['excludeType'];
     }
     if (isset($pa_options['excludeTypes']) && is_array($pa_options['excludeTypes'])) {
         $va_type_ids = caMakeTypeIDList($vs_related_table, $pa_options['excludeTypes']);
         if (is_array($va_type_ids) && sizeof($va_type_ids) > 0) {
             $va_wheres[] = "({$vs_related_table}.type_id NOT IN (" . join(',', $va_type_ids) . "))";
         }
     }
     if ($this->getAppConfig()->get('perform_item_level_access_checking')) {
         $t_user = new ca_users($vn_user_id, true);
         if (is_array($va_groups = $t_user->getUserGroups()) && sizeof($va_groups)) {
             $va_group_ids = array_keys($va_groups);
         } else {
             $va_group_ids = array();
         }
         // Join to limit what browse table items are used to generate facet
         $va_joins_post_add[] = 'LEFT JOIN ca_acl ON ' . $vs_related_table_name . '.' . $t_rel_item->primaryKey() . ' = ca_acl.row_id AND ca_acl.table_num = ' . $t_rel_item->tableNum() . "\n";
         $va_wheres[] = "(\n\t\t\t\t((\n\t\t\t\t\t(ca_acl.user_id = " . (int) $vn_user_id . ")\n\t\t\t\t\t" . (sizeof($va_group_ids) > 0 ? "OR\n\t\t\t\t\t(ca_acl.group_id IN (" . join(",", $va_group_ids) . "))" : "") . "\n\t\t\t\t\tOR\n\t\t\t\t\t(ca_acl.user_id IS NULL and ca_acl.group_id IS NULL)\n\t\t\t\t) AND ca_acl.access >= " . __CA_ACL_READONLY_ACCESS__ . ")\n\t\t\t\t" . ($vb_show_if_no_acl ? "OR ca_acl.acl_id IS NULL" : "") . "\n\t\t\t)";
     }
     if (is_array($va_get_where)) {
         foreach ($va_get_where as $vs_fld => $vm_val) {
             if ($t_rel_item->hasField($vs_fld)) {
                 $va_wheres[] = "({$vs_related_table_name}.{$vs_fld} = " . (!is_numeric($vm_val) ? "'" . $this->getDb()->escape($vm_val) . "'" : $vm_val) . ")";
             }
         }
     }
     if ($vs_idno_fld = $t_rel_item->getProperty('ID_NUMBERING_ID_FIELD')) {
         $va_selects[] = "{$vs_related_table}.{$vs_idno_fld}";
     }
     if ($vs_idno_sort_fld = $t_rel_item->getProperty('ID_NUMBERING_SORT_FIELD')) {
         $va_selects[] = "{$vs_related_table}.{$vs_idno_sort_fld}";
     }
     $va_selects[] = $va_path[1] . '.' . $vs_key;
     if (isset($pa_options['fields']) && is_array($pa_options['fields'])) {
         $va_selects = array_merge($va_selects, $pa_options['fields']);
     }
     // if related item is labelable then include the label table in the query as well
     $vs_label_display_field = null;
     if (method_exists($t_rel_item, "getLabelTableName") && (!isset($pa_options['dontReturnLabels']) || !$pa_options['dontReturnLabels'])) {
         if ($vs_label_table_name = $t_rel_item->getLabelTableName()) {
             // make sure it actually has a label table...
             $va_path[] = $vs_label_table_name;
             $t_rel_item_label = $this->getAppDatamodel()->getTableInstance($vs_label_table_name);
             $vs_label_display_field = $t_rel_item_label->getDisplayField();
             if ($vb_return_labels_as_array || is_array($va_sort_fields) && sizeof($va_sort_fields)) {
                 $va_selects[] = $vs_label_table_name . '.*';
             } else {
                 $va_selects[] = $vs_label_table_name . '.' . $vs_label_display_field;
                 $va_selects[] = $vs_label_table_name . '.locale_id';
                 if ($t_rel_item_label->hasField('surname')) {
                     // hack to include fields we need to sort entity labels properly
                     $va_selects[] = $vs_label_table_name . '.surname';
                     $va_selects[] = $vs_label_table_name . '.forename';
                 }
             }
             if ($t_rel_item_label->hasField('is_preferred') && (!isset($pa_options['returnNonPreferredLabels']) || !$pa_options['returnNonPreferredLabels'])) {
                 $va_wheres[] = "(" . $vs_label_table_name . '.is_preferred = 1)';
             }
         }
     }
     if ($vb_show_current_only && $t_item_rel && $t_item_rel->hasField('source_info') && $t_item_rel->tableName() == 'ca_movements_x_objects') {
         // TODO: table check is temporary hack while we get "current" support into non-movement relationships
         $va_wheres[] = '(' . $t_item_rel->tableName() . '.source_info = \'current\')';
     }
     // return source info in returned data
     if ($t_item_rel && $t_item_rel->hasField('source_info')) {
         $va_selects[] = $vs_linking_table . '.source_info';
     }
     if (isset($pa_options['checkAccess']) && is_array($pa_options['checkAccess']) && sizeof($pa_options['checkAccess']) && $t_rel_item->hasField('access')) {
         $va_wheres[] = "({$vs_related_table}.access IN (" . join(',', $pa_options['checkAccess']) . "))";
     }
     if ((!isset($pa_options['showDeleted']) || !$pa_options['showDeleted']) && $t_rel_item->hasField('deleted')) {
         $va_wheres[] = "({$vs_related_table}.deleted = 0)";
     }
     if (($va_criteria = isset($pa_options['criteria']) ? $pa_options['criteria'] : null) && is_array($va_criteria) && sizeof($va_criteria)) {
         $va_wheres[] = "(" . join(" AND ", $va_criteria) . ")";
     }
     if ($vb_self_relationship) {
         //
         // START - traverse self relation
         //
         $va_rel_info = $this->getAppDatamodel()->getRelationships($va_path[0], $va_path[1]);
         if ($vs_label_table_name) {
             $va_label_rel_info = $this->getAppDatamodel()->getRelationships($va_path[0], $vs_label_table_name);
         }
         $va_rels = array();
         $vn_i = 0;
         foreach ($va_rel_info[$va_path[0]][$va_path[1]] as $va_possible_keys) {
             $va_joins = array();
             $va_joins[] = "INNER JOIN " . $va_path[1] . " ON " . $va_path[1] . '.' . $va_possible_keys[1] . ' = ' . $va_path[0] . '.' . $va_possible_keys[0] . "\n";
             if ($vs_label_table_name) {
                 $va_joins[] = "INNER JOIN " . $vs_label_table_name . " ON " . $vs_label_table_name . '.' . $va_label_rel_info[$va_path[0]][$vs_label_table_name][0][1] . ' = ' . $va_path[0] . '.' . $va_label_rel_info[$va_path[0]][$vs_label_table_name][0][0] . "\n";
             }
             $vs_other_field = $vn_i == 0 ? $va_rel_info[$va_path[0]][$va_path[1]][1][1] : $va_rel_info[$va_path[0]][$va_path[1]][0][1];
             $vs_direction = preg_match('!left!', $vs_other_field) ? 'ltor' : 'rtol';
             $va_selects['row_id'] = $va_path[1] . '.' . $vs_other_field . ' AS row_id';
             $vs_order_by = '';
             $vs_sort_fld = '';
             if ($t_item_rel && $t_item_rel->hasField('rank')) {
                 $vs_order_by = ' ORDER BY ' . $t_item_rel->tableName() . '.rank';
                 $vs_sort_fld = 'rank';
                 $va_selects[] = $t_item_rel->tableName() . ".rank";
             } else {
                 if ($t_rel_item && ($vs_sort = $t_rel_item->getProperty('ID_NUMBERING_SORT_FIELD'))) {
                     $vs_order_by = " ORDER BY {$vs_related_table}.{$vs_sort}";
                     $vs_sort_fld = $vs_sort;
                     $va_selects[] = "{$vs_related_table}.{$vs_sort}";
                 }
             }
             $vs_sql = "\n\t\t\t\t\tSELECT " . join(', ', $va_selects) . "\n\t\t\t\t\tFROM " . $va_path[0] . "\n\t\t\t\t\t" . join("\n", array_merge($va_joins, $va_joins_post_add)) . "\n\t\t\t\t\tWHERE\n\t\t\t\t\t\t" . join(' AND ', array_merge($va_wheres, array('(' . $va_path[1] . '.' . $vs_other_field . ' IN (' . join(',', $va_row_ids) . '))'))) . "\n\t\t\t\t\t{$vs_order_by}";
             $qr_res = $o_db->query($vs_sql);
             if ($vb_uses_relationship_types) {
                 $va_rel_types = $t_rel->getRelationshipInfo($va_path[1]);
             }
             $vn_c = 0;
             if ($vn_start > 0) {
                 $qr_res->seek($vn_start);
             }
             while ($qr_res->nextRow()) {
                 if ($vn_c >= $vn_limit) {
                     break;
                 }
                 if (is_array($va_primary_ids) && is_array($va_primary_ids[$vs_related_table])) {
                     if (in_array($qr_res->get($vs_key), $va_primary_ids[$vs_related_table])) {
                         continue;
                     }
                 }
                 $va_row = $qr_res->getRow();
                 $vn_id = $va_row[$vs_key] . '/' . $va_row['row_id'];
                 $vs_sort_key = $qr_res->get($vs_sort_fld);
                 $vs_display_label = $va_row[$vs_label_display_field];
                 if (!$va_rels[$vs_sort_key][$vn_id]) {
                     $va_rels[$vs_sort_key][$vn_id] = $qr_res->getRow();
                 }
                 if ($vb_uses_effective_dates) {
                     // return effective dates as display/parse-able text
                     if ($va_rels[$vs_sort_key][$vn_id]['sdatetime'] || $va_rels[$vs_sort_key][$vn_id]['edatetime']) {
                         $o_tep->setHistoricTimestamps($va_rels[$vs_sort_key][$vn_id]['sdatetime'], $va_rels[$vs_sort_key][$vn_id]['edatetime']);
                         $va_rels[$vs_sort_key][$vn_id]['effective_date'] = $o_tep->getText();
                     }
                 }
                 $vn_locale_id = $qr_res->get('locale_id');
                 if ($vb_use_locale_codes) {
                     $va_rels[$vs_v]['locale_id'] = $vn_locale_id = $t_locale->localeIDToCode($vn_locale_id);
                 }
                 $va_rels[$vs_sort_key][$vn_id]['labels'][$vn_locale_id] = $vb_return_labels_as_array ? $va_row : $vs_display_label;
                 $va_rels[$vs_sort_key][$vn_id]['_key'] = $vs_key;
                 $va_rels[$vs_sort_key][$vn_id]['direction'] = $vs_direction;
                 $vn_c++;
                 if ($vb_uses_relationship_types) {
                     $va_rels[$vs_sort_key][$vn_id]['relationship_typename'] = $vs_direction == 'ltor' ? $va_rel_types[$va_row['relationship_type_id']]['typename'] : $va_rel_types[$va_row['relationship_type_id']]['typename_reverse'];
                     $va_rels[$vs_sort_key][$vn_id]['relationship_type_code'] = $va_rel_types[$va_row['relationship_type_id']]['type_code'];
                 }
                 //
                 // Return data in an arrangement more convenient for the data importer
                 //
                 if ($vb_group_fields) {
                     $vs_rel_pk = $t_rel_item->primaryKey();
                     if ($t_rel_item_label) {
                         foreach ($t_rel_item_label->getFormFields() as $vs_field => $va_field_info) {
                             if (!isset($va_rels[$vs_v][$vs_field]) || $vs_field == $vs_rel_pk) {
                                 continue;
                             }
                             $va_rels[$vs_v]['preferred_labels'][$vs_field] = $va_rels[$vs_v][$vs_field];
                             unset($va_rels[$vs_v][$vs_field]);
                         }
                     }
                     foreach ($t_rel_item->getFormFields() as $vs_field => $va_field_info) {
                         if (!isset($va_rels[$vs_v][$vs_field]) || $vs_field == $vs_rel_pk) {
                             continue;
                         }
                         $va_rels[$vs_v]['intrinsic'][$vs_field] = $va_rels[$vs_v][$vs_field];
                         unset($va_rels[$vs_v][$vs_field]);
                     }
                     unset($va_rels[$vs_v]['_key']);
                     unset($va_rels[$vs_v]['row_id']);
                 }
             }
             $vn_i++;
         }
         ksort($va_rels);
         // sort by sort key... we'll remove the sort key in the next loop while we add the labels
         // Set 'label' entry - display label in current user's locale
         $va_sorted_rels = array();
         foreach ($va_rels as $vs_sort_key => $va_rels_by_sort_key) {
             foreach ($va_rels_by_sort_key as $vn_id => $va_rel) {
                 $va_tmp = array(0 => $va_rel['labels']);
                 $va_sorted_rels[$vn_id] = $va_rel;
                 $va_values_filtered_by_locale = caExtractValuesByUserLocale($va_tmp);
                 $va_sorted_rels[$vn_id]['label'] = array_shift($va_values_filtered_by_locale);
             }
         }
         $va_rels = $va_sorted_rels;
         //
         // END - traverse self relation
         //
     } else {
         if (method_exists($this, 'isSelfRelationship') && $this->isSelfRelationship()) {
             //
             // START - from self relation itself (Eg. get related ca_objects from ca_objects_x_objects); in this case there are two possible paths (keys) to check, "left" and "right"
             //
             $va_wheres[] = "(" . $this->tableName() . '.' . $this->primaryKey() . " IN (" . join(",", $va_row_ids) . "))";
             $vs_cur_table = array_shift($va_path);
             $vs_rel_table = array_shift($va_path);
             $va_rel_info = $this->getAppDatamodel()->getRelationships($vs_cur_table, $vs_rel_table);
             $va_rels = array();
             foreach ($va_rel_info[$vs_cur_table][$vs_rel_table] as $vn_i => $va_rel) {
                 $va_joins = array('INNER JOIN ' . $vs_rel_table . ' ON ' . $vs_cur_table . '.' . $va_rel[0] . ' = ' . $vs_rel_table . '.' . $va_rel[1] . "\n");
                 $vs_base_table = $vs_rel_table;
                 foreach ($va_path as $vs_join_table) {
                     $va_label_rel_info = $this->getAppDatamodel()->getRelationships($vs_base_table, $vs_join_table);
                     $va_joins[] = 'INNER JOIN ' . $vs_join_table . ' ON ' . $vs_base_table . '.' . $va_label_rel_info[$vs_base_table][$vs_join_table][0][0] . ' = ' . $vs_join_table . '.' . $va_label_rel_info[$vs_base_table][$vs_join_table][0][1] . "\n";
                     $vs_base_table = $vs_join_table;
                 }
                 $va_selects[] = $this->tableName() . '.' . $this->primaryKey() . ' AS row_id';
                 $vs_order_by = '';
                 if ($t_item_rel && $t_item_rel->hasField('rank')) {
                     $vs_order_by = ' ORDER BY ' . $t_item_rel->tableName() . '.rank';
                     $va_selects[] = $t_item_rel->tableName() . '.rank';
                 } else {
                     if ($t_rel_item && ($vs_sort = $t_rel_item->getProperty('ID_NUMBERING_SORT_FIELD'))) {
                         $vs_order_by = " ORDER BY {$vs_related_table}.{$vs_sort}";
                         $va_selects[] = "{$vs_related_table}.{$vs_sort}";
                     }
                 }
                 $vs_sql = "\n\t\t\t\t\tSELECT DISTINCT " . join(', ', $va_selects) . "\n\t\t\t\t\tFROM " . $this->tableName() . "\n\t\t\t\t\t" . join("\n", array_merge($va_joins, $va_joins_post_add)) . "\n\t\t\t\t\tWHERE\n\t\t\t\t\t\t" . join(' AND ', $va_wheres) . "\n\t\t\t\t\t{$vs_order_by}\n\t\t\t\t";
                 //print "<pre>$vs_sql</pre>\n";
                 $qr_res = $o_db->query($vs_sql);
                 if ($vb_uses_relationship_types) {
                     $va_rel_types = $t_rel->getRelationshipInfo($t_item_rel->tableName());
                     $vs_left_table = $t_item_rel->getLeftTableName();
                     $vs_direction = $vs_left_table == $this->tableName() ? 'ltor' : 'rtol';
                 }
                 $vn_c = 0;
                 if ($vn_start > 0) {
                     $qr_res->seek($vn_start);
                 }
                 while ($qr_res->nextRow()) {
                     if ($vn_c >= $vn_limit) {
                         break;
                     }
                     if (is_array($va_primary_ids) && is_array($va_primary_ids[$vs_related_table])) {
                         if (in_array($qr_res->get($vs_key), $va_primary_ids[$vs_related_table])) {
                             continue;
                         }
                     }
                     if (isset($pa_options['idsOnly']) && $pa_options['idsOnly']) {
                         $va_rels[] = $qr_res->get($t_rel_item->primaryKey());
                         continue;
                     }
                     $va_row = $qr_res->getRow();
                     $vs_v = $va_row['row_id'] . '/' . $va_row[$vs_key];
                     $vs_display_label = $va_row[$vs_label_display_field];
                     if (!isset($va_rels[$vs_v]) || !$va_rels[$vs_v]) {
                         $va_rels[$vs_v] = $va_row;
                     }
                     if ($vb_uses_effective_dates) {
                         // return effective dates as display/parse-able text
                         if ($va_rels[$vs_v]['sdatetime'] || $va_rels[$vs_v]['edatetime']) {
                             $o_tep->setHistoricTimestamps($va_rels[$vs_v]['sdatetime'], $va_rels[$vs_v]['edatetime']);
                             $va_rels[$vs_v]['effective_date'] = $o_tep->getText();
                         }
                     }
                     $vn_locale_id = $qr_res->get('locale_id');
                     if ($vb_use_locale_codes) {
                         $va_rels[$vs_v]['locale_id'] = $vn_locale_id = $t_locale->localeIDToCode($vn_locale_id);
                     }
                     $va_rels[$vs_v]['labels'][$vn_locale_id] = $vb_return_labels_as_array ? $va_row : $vs_display_label;
                     $va_rels[$vs_v]['_key'] = $vs_key;
                     $va_rels[$vs_v]['direction'] = $vs_direction;
                     $vn_c++;
                     if ($vb_uses_relationship_types) {
                         $va_rels[$vs_v]['relationship_typename'] = $vs_direction == 'ltor' ? $va_rel_types[$va_row['relationship_type_id']]['typename'] : $va_rel_types[$va_row['relationship_type_id']]['typename_reverse'];
                         $va_rels[$vs_v]['relationship_type_code'] = $va_rel_types[$va_row['relationship_type_id']]['type_code'];
                     }
                     if ($vb_group_fields) {
                         $vs_rel_pk = $t_rel_item->primaryKey();
                         if ($t_rel_item_label) {
                             foreach ($t_rel_item_label->getFormFields() as $vs_field => $va_field_info) {
                                 if (!isset($va_rels[$vs_v][$vs_field]) || $vs_field == $vs_rel_pk) {
                                     continue;
                                 }
                                 $va_rels[$vs_v]['preferred_labels'][$vs_field] = $va_rels[$vs_v][$vs_field];
                                 unset($va_rels[$vs_v][$vs_field]);
                             }
                         }
                         foreach ($t_rel_item->getFormFields() as $vs_field => $va_field_info) {
                             if (!isset($va_rels[$vs_v][$vs_field]) || $vs_field == $vs_rel_pk) {
                                 continue;
                             }
                             $va_rels[$vs_v]['intrinsic'][$vs_field] = $va_rels[$vs_v][$vs_field];
                             unset($va_rels[$vs_v][$vs_field]);
                         }
                         unset($va_rels[$vs_v]['_key']);
                         unset($va_rels[$vs_v]['row_id']);
                     }
                 }
                 if (!isset($pa_options['idsOnly']) || !$pa_options['idsOnly']) {
                     // Set 'label' entry - display label in current user's locale
                     foreach ($va_rels as $vs_v => $va_rel) {
                         $va_tmp = array(0 => $va_rel['labels']);
                         $va_tmp2 = caExtractValuesByUserLocale($va_tmp);
                         $va_rels[$vs_v]['label'] = array_shift($va_tmp2);
                     }
                 }
             }
             //
             // END - from self relation itself
             //
         } else {
             //
             // BEGIN - non-self relation
             //
             $va_wheres[] = "(" . $this->tableName() . '.' . $this->primaryKey() . " IN (" . join(",", $va_row_ids) . "))";
             $vs_cur_table = array_shift($va_path);
             $va_joins = array();
             // Enforce restrict_to_lists for related list items
             if ($vs_related_table_name == 'ca_list_items' && is_array($pa_options['restrictToLists'])) {
                 $va_list_ids = array();
                 foreach ($pa_options['restrictToLists'] as $vm_list) {
                     if ($vn_list_id = ca_lists::getListID($vm_list)) {
                         $va_list_ids[] = $vn_list_id;
                     }
                 }
                 if (sizeof($va_list_ids)) {
                     $va_wheres[] = "(ca_list_items.list_id IN (" . join(",", $va_list_ids) . "))";
                 }
             }
             if ($vb_is_combo_key_relation) {
                 $va_joins = array("INNER JOIN {$vs_related_table_name} ON {$vs_related_table_name}.row_id = " . $this->primaryKey(true) . " AND {$vs_related_table_name}.table_num = " . $this->tableNum());
             } else {
                 foreach ($va_path as $vs_join_table) {
                     $va_rel_info = $this->getAppDatamodel()->getRelationships($vs_cur_table, $vs_join_table);
                     $vs_join = 'INNER JOIN ' . $vs_join_table . ' ON ';
                     $va_tmp = array();
                     foreach ($va_rel_info[$vs_cur_table][$vs_join_table] as $vn_i => $va_rel) {
                         $va_tmp[] = $vs_cur_table . "." . $va_rel_info[$vs_cur_table][$vs_join_table][$vn_i][0] . ' = ' . $vs_join_table . '.' . $va_rel_info[$vs_cur_table][$vs_join_table][$vn_i][1] . "\n";
                     }
                     $va_joins[] = $vs_join . join(' OR ', $va_tmp);
                     $vs_cur_table = $vs_join_table;
                 }
             }
             // If we're getting ca_set_items, we have to rename the intrinsic row_id field because the pk is named row_id below. Hence, this hack.
             if ($vs_related_table_name == 'ca_set_items') {
                 $va_selects[] = 'ca_set_items.row_id AS record_id';
             }
             $va_selects[] = $this->tableName() . '.' . $this->primaryKey() . ' AS row_id';
             $vs_order_by = '';
             if ($t_item_rel && $t_item_rel->hasField('rank')) {
                 $vs_order_by = ' ORDER BY ' . $t_item_rel->tableName() . '.rank';
                 $va_selects[] = $t_item_rel->tableName() . '.rank';
             } else {
                 if ($t_rel_item && ($vs_sort = $t_rel_item->getProperty('ID_NUMBERING_SORT_FIELD'))) {
                     $vs_order_by = " ORDER BY {$vs_related_table}.{$vs_sort}";
                     $va_selects[] = "{$vs_related_table}.{$vs_sort}";
                 }
             }
             $vs_sql = "\n\t\t\t\tSELECT DISTINCT " . join(', ', $va_selects) . "\n\t\t\t\tFROM " . $this->tableName() . "\n\t\t\t\t" . join("\n", array_merge($va_joins, $va_joins_post_add)) . "\n\t\t\t\tWHERE\n\t\t\t\t\t" . join(' AND ', $va_wheres) . "\n\t\t\t\t{$vs_order_by}\n\t\t\t";
             $qr_res = $o_db->query($vs_sql);
             if ($vb_uses_relationship_types) {
                 $va_rel_types = $t_rel->getRelationshipInfo($t_tmp->tableName());
                 if (method_exists($t_tmp, 'getLeftTableName')) {
                     $vs_left_table = $t_tmp->getLeftTableName();
                     $vs_direction = $vs_left_table == $this->tableName() ? 'ltor' : 'rtol';
                 }
             }
             $va_rels = array();
             $vn_c = 0;
             if ($vn_start > 0) {
                 $qr_res->seek($vn_start);
             }
             while ($qr_res->nextRow()) {
                 if ($vn_c >= $vn_limit) {
                     break;
                 }
                 if (is_array($va_primary_ids) && is_array($va_primary_ids[$vs_related_table])) {
                     if (in_array($qr_res->get($vs_key), $va_primary_ids[$vs_related_table])) {
                         continue;
                     }
                 }
                 if (isset($pa_options['idsOnly']) && $pa_options['idsOnly']) {
                     $va_rels[] = $qr_res->get($t_rel_item->primaryKey());
                     continue;
                 }
                 $va_row = $qr_res->getRow();
                 $vs_v = sizeof($va_path) <= 2 ? $va_row['row_id'] . '/' . $va_row[$vs_key] : $va_row[$vs_key];
                 $vs_display_label = $va_row[$vs_label_display_field];
                 //unset($va_row[$vs_label_display_field]);
                 if (!isset($va_rels[$vs_v]) || !$va_rels[$vs_v]) {
                     $va_rels[$vs_v] = $va_row;
                 }
                 if ($vb_uses_effective_dates) {
                     // return effective dates as display/parse-able text
                     if ($va_rels[$vs_v]['sdatetime'] || $va_rels[$vs_v]['edatetime']) {
                         $o_tep->setHistoricTimestamps($va_rels[$vs_v]['sdatetime'], $va_rels[$vs_v]['edatetime']);
                         $va_rels[$vs_v]['effective_date'] = $o_tep->getText();
                     }
                 }
                 $vn_locale_id = $qr_res->get('locale_id');
                 if ($vb_use_locale_codes) {
                     $va_rels[$vs_v]['locale_id'] = $vn_locale_id = $t_locale->localeIDToCode($vn_locale_id);
                 }
                 $va_rels[$vs_v]['labels'][$vn_locale_id] = $vb_return_labels_as_array ? $va_row : $vs_display_label;
                 $va_rels[$vs_v]['_key'] = $vs_key;
                 $va_rels[$vs_v]['direction'] = $vs_direction;
                 $vn_c++;
                 if ($vb_uses_relationship_types) {
                     $va_rels[$vs_v]['relationship_typename'] = $vs_direction == 'ltor' ? $va_rel_types[$va_row['relationship_type_id']]['typename'] : $va_rel_types[$va_row['relationship_type_id']]['typename_reverse'];
                     $va_rels[$vs_v]['relationship_type_code'] = $va_rel_types[$va_row['relationship_type_id']]['type_code'];
                 }
                 if ($vb_group_fields) {
                     $vs_rel_pk = $t_rel_item->primaryKey();
                     if ($t_rel_item_label) {
                         foreach ($t_rel_item_label->getFormFields() as $vs_field => $va_field_info) {
                             if (!isset($va_rels[$vs_v][$vs_field]) || $vs_field == $vs_rel_pk) {
                                 continue;
                             }
                             $va_rels[$vs_v]['preferred_labels'][$vs_field] = $va_rels[$vs_v][$vs_field];
                             unset($va_rels[$vs_v][$vs_field]);
                         }
                     }
                     foreach ($t_rel_item->getFormFields() as $vs_field => $va_field_info) {
                         if (!isset($va_rels[$vs_v][$vs_field]) || $vs_field == $vs_rel_pk) {
                             continue;
                         }
                         $va_rels[$vs_v]['intrinsic'][$vs_field] = $va_rels[$vs_v][$vs_field];
                         unset($va_rels[$vs_v][$vs_field]);
                     }
                     unset($va_rels[$vs_v]['_key']);
                     unset($va_rels[$vs_v]['row_id']);
                 }
             }
             if (!isset($pa_options['idsOnly']) || !$pa_options['idsOnly']) {
                 // Set 'label' entry - display label in current user's locale
                 foreach ($va_rels as $vs_v => $va_rel) {
                     $va_tmp = array(0 => $va_rel['labels']);
                     $va_tmp2 = caExtractValuesByUserLocale($va_tmp);
                     $va_rels[$vs_v]['label'] = array_shift($va_tmp2);
                 }
             }
             //
             // END - non-self relation
             //
         }
     }
     // Apply restrictToBundleValues
     $va_filters = isset($pa_options['restrictToBundleValues']) ? $pa_options['restrictToBundleValues'] : null;
     if (is_array($va_filters) && sizeof($va_filters) > 0) {
         foreach ($va_rels as $vn_pk => $va_related_item) {
             foreach ($va_filters as $vs_filter => $va_filter_vals) {
                 if (!$vs_filter) {
                     continue;
                 }
                 if (!is_array($va_filter_vals)) {
                     $va_filter_vals = array($va_filter_vals);
                 }
                 foreach ($va_filter_vals as $vn_index => $vs_filter_val) {
                     // is value a list attribute idno?
                     $va_tmp = explode('.', $vs_filter);
                     $vs_element = array_pop($va_tmp);
                     if (!is_numeric($vs_filter_val) && (($t_element = $t_rel_item->_getElementInstance($vs_element)) && $t_element->get('datatype') == 3)) {
                         $va_filter_vals[$vn_index] = caGetListItemID($t_element->get('list_id'), $vs_filter_val);
                     }
                 }
                 $t_rel_item->load($va_related_item[$t_rel_item->primaryKey()]);
                 $va_filter_values = $t_rel_item->get($vs_filter, array('returnAsArray' => true, 'alwaysReturnItemID' => true));
                 $vb_keep = false;
                 if (is_array($va_filter_values)) {
                     foreach ($va_filter_values as $vm_filtered_val) {
                         if (!is_array($vm_filtered_val)) {
                             $vm_filtered_val = array($vm_filtered_val);
                         }
                         foreach ($vm_filtered_val as $vs_val) {
                             if (in_array($vs_val, $va_filter_vals)) {
                                 // one match is enough to keep it
                                 $vb_keep = true;
                             }
                         }
                     }
                 }
                 if (!$vb_keep) {
                     unset($va_rels[$vn_pk]);
                 }
             }
         }
     }
     //
     // Sort on fields if specified
     //
     if (is_array($va_sort_fields) && sizeof($va_rels)) {
         $va_ids = array();
         $vs_rel_pk = $t_rel_item->primaryKey();
         foreach ($va_rels as $vn_i => $va_rel) {
             $va_ids[] = $va_rel[$vs_rel_pk];
         }
         // Handle sorting on attribute values
         $vs_rel_pk = $t_rel_item->primaryKey();
         foreach ($va_sort_fields as $vn_x => $vs_sort_field) {
             if ($vs_sort_field == 'relation_id') {
                 // sort by relationship primary key
                 if ($t_item_rel) {
                     $va_sort_fields[$vn_x] = $vs_sort_field = $t_item_rel->tableName() . '.' . $t_item_rel->primaryKey();
                 }
                 continue;
             }
             $va_tmp = explode('.', $vs_sort_field);
             if ($va_tmp[0] == $vs_related_table_name) {
                 $qr_rel = $t_rel_item->makeSearchResult($va_tmp[0], $va_ids);
                 $vs_table = array_shift($va_tmp);
                 $vs_key = join(".", $va_tmp);
                 while ($qr_rel->nextHit()) {
                     $vn_pk_val = $qr_rel->get($vs_table . "." . $vs_rel_pk);
                     foreach ($va_rels as $vn_rel_id => $va_rel) {
                         if ($va_rel[$vs_rel_pk] == $vn_pk_val) {
                             $va_rels[$vn_rel_id][$vs_key] = $qr_rel->get($vs_sort_field, array("delimiter" => ";", 'sortable' => 1));
                             break;
                         }
                     }
                 }
             }
         }
         // Perform sort
         $va_rels = caSortArrayByKeyInValue($va_rels, $va_sort_fields, $vs_sort_direction);
     }
     return $va_rels;
 }
コード例 #4
0
ファイル: BrowseEngine.php プロジェクト: kai-iak/pawtucket2
 /**
  *
  */
 private function getCollapseMapForLocationFacet($pa_facet_info)
 {
     $va_collapse_map = array();
     if (is_array($pa_facet_info['collapse'])) {
         foreach ($pa_facet_info['collapse'] as $vs_selector => $vs_text) {
             $va_selector = explode('/', $vs_selector);
             if (sizeof($va_selector) == 1) {
                 $va_collapse_map[$va_selector[0]]['*'] = $vs_text;
             } elseif (sizeof($va_selector) > 1) {
                 switch ($va_selector[0]) {
                     case 'ca_objects_x_storage_locations':
                         $t_rel_type = new ca_relationship_types();
                         $vn_type_id = $t_rel_type->getRelationshipTypeID('ca_objects_x_storage_locations', $va_selector[1]);
                         break;
                     default:
                         $vn_type_id = null;
                         if ($t_instance = $this->opo_datamodel->getInstanceByTableName($va_selector[0], true)) {
                             $vn_type_id = $t_instance->getTypeIDForCode($va_selector[1]);
                         }
                         break;
                 }
                 $va_collapse_map[$va_selector[0]][$vn_type_id] = $vs_text;
             }
         }
     }
     return $va_collapse_map;
 }
コード例 #5
0
 public function processUserInterfaces()
 {
     require_once __CA_MODELS_DIR__ . "/ca_editor_uis.php";
     require_once __CA_MODELS_DIR__ . "/ca_editor_ui_screens.php";
     require_once __CA_MODELS_DIR__ . "/ca_lists.php";
     require_once __CA_MODELS_DIR__ . "/ca_list_items.php";
     require_once __CA_MODELS_DIR__ . "/ca_relationship_types.php";
     $vo_dm = Datamodel::load();
     $t_list = new ca_lists();
     $t_rel_types = new ca_relationship_types();
     $va_uis = array();
     if ($this->ops_base_name) {
         // "merge" profile and its base
         foreach ($this->opo_base->userInterfaces->children() as $vo_ui) {
             $va_uis[self::getAttribute($vo_ui, "code")] = $vo_ui;
         }
         foreach ($this->opo_profile->userInterfaces->children() as $vo_ui) {
             $va_uis[self::getAttribute($vo_ui, "code")] = $vo_ui;
         }
     } else {
         foreach ($this->opo_profile->userInterfaces->children() as $vo_ui) {
             $va_uis[self::getAttribute($vo_ui, "code")] = $vo_ui;
         }
     }
     foreach ($va_uis as $vs_ui_code => $vo_ui) {
         $vs_type = self::getAttribute($vo_ui, "type");
         if (!($vn_type = $vo_dm->getTableNum($vs_type))) {
             $this->addError("Invalid type {$vs_type} for UI code {$vs_ui_code}");
             return false;
         }
         // model instance of UI type
         $t_instance = $vo_dm->getInstanceByTableNum($vn_type);
         // create ui row
         $t_ui = ca_editor_uis::find(array('editor_code' => $vs_ui_code, 'editor_type' => $vn_type), array('returnAs' => 'firstModelInstance'));
         $t_ui = $t_ui ? $t_ui : new ca_editor_uis();
         $t_ui->setMode(ACCESS_WRITE);
         $t_ui->set('user_id', null);
         $t_ui->set('is_system_ui', 1);
         $t_ui->set('editor_code', $vs_ui_code);
         $t_ui->set('editor_type', $vn_type);
         if ($t_ui->getPrimaryKey()) {
             $t_ui->update();
         } else {
             $t_ui->insert();
         }
         if ($t_ui->numErrors()) {
             $this->addError("Errors inserting UI {$vs_ui_code}: " . join("; ", $t_ui->getErrors()));
             return false;
         }
         $vn_ui_id = $t_ui->getPrimaryKey();
         self::addLabelsFromXMLElement($t_ui, $vo_ui->labels, $this->opa_locales);
         // create ui type restrictions
         if ($vo_ui->typeRestrictions) {
             foreach ($vo_ui->typeRestrictions->children() as $vo_restriction) {
                 $vs_restriction_type = self::getAttribute($vo_restriction, "type");
                 if (strlen($vs_restriction_type) > 0) {
                     // interstitial with type restriction -> code is relationship type code
                     if ($t_instance instanceof BaseRelationshipModel) {
                         $vn_type_id = $t_rel_types->getRelationshipTypeID($t_instance->tableName(), $vs_restriction_type);
                     } else {
                         // "normal" type restriction -> code is from actual type list
                         $vs_type_list_name = $t_instance->getFieldListCode($t_instance->getTypeFieldName());
                         $vn_type_id = $t_list->getItemIDFromList($vs_type_list_name, $vs_restriction_type);
                     }
                     if ($vn_type_id) {
                         $t_ui->addTypeRestriction($vn_type_id);
                     }
                 }
             }
         }
         // create ui screens
         foreach ($vo_ui->screens->children() as $vo_screen) {
             $vs_screen_idno = self::getAttribute($vo_screen, "idno");
             $vn_is_default = self::getAttribute($vo_screen, "default");
             $t_ui_screens = ca_editor_ui_screens::find(array('idno' => $vs_screen_idno, 'ui_id' => $vn_ui_id), array('returnAs' => 'firstModelInstance'));
             $t_ui_screens = $t_ui_screens ? $t_ui_screens : new ca_editor_ui_screens();
             $t_ui_screens->setMode(ACCESS_WRITE);
             $t_ui_screens->set('idno', $vs_screen_idno);
             $t_ui_screens->set('ui_id', $vn_ui_id);
             $t_ui_screens->set('is_default', $vn_is_default);
             if ($t_ui_screens->getPrimaryKey()) {
                 $t_ui_screens->update();
             } else {
                 $t_ui_screens->set('parent_id', null);
                 $t_ui_screens->insert();
             }
             if ($t_ui_screens->numErrors()) {
                 $this->addError("Errors inserting UI screen {$vs_screen_idno} for UI {$vs_ui_code}: " . join("; ", $t_ui_screens->getErrors()));
                 return false;
             }
             self::addLabelsFromXMLElement($t_ui_screens, $vo_screen->labels, $this->opa_locales);
             $va_available_bundles = $t_ui_screens->getAvailableBundles(null, array('dontCache' => true));
             // create ui bundle placements
             foreach ($vo_screen->bundlePlacements->children() as $vo_placement) {
                 $vs_placement_code = self::getAttribute($vo_placement, "code");
                 $vs_bundle = trim((string) $vo_placement->bundle);
                 $va_settings = $this->_processSettings(null, $vo_placement->settings);
                 $t_ui_screens->addPlacement($vs_bundle, $vs_placement_code, $va_settings, null, array('additional_settings' => $va_available_bundles[$vs_bundle]['settings']));
             }
             // create ui screen type restrictions
             if ($vo_screen->typeRestrictions) {
                 foreach ($vo_screen->typeRestrictions->children() as $vo_restriction) {
                     $vs_restriction_type = self::getAttribute($vo_restriction, "type");
                     if (strlen($vs_restriction_type) > 0) {
                         // interstitial with type restriction -> code is relationship type code
                         if ($t_instance instanceof BaseRelationshipModel) {
                             $vn_type_id = $t_rel_types->getRelationshipTypeID($t_instance->tableName(), $vs_restriction_type);
                         } else {
                             // "normal" type restriction -> code is from actual type list
                             $vs_type_list_name = $t_instance->getFieldListCode($t_instance->getTypeFieldName());
                             $vn_type_id = $t_list->getItemIDFromList($vs_type_list_name, $vs_restriction_type);
                         }
                         if ($vn_type_id) {
                             $t_ui_screens->addTypeRestriction($vn_type_id);
                         }
                     }
                 }
             }
         }
         // set user and group access
         if ($vo_ui->userAccess) {
             $t_user = new ca_users();
             $va_ui_users = array();
             foreach ($vo_ui->userAccess->children() as $vo_permission) {
                 $vs_user = trim((string) self::getAttribute($vo_permission, "user"));
                 $vn_access = $this->_convertUserGroupAccessStringToInt(self::getAttribute($vo_permission, 'access'));
                 if ($vn_access && $t_user->load(array('user_name' => $vs_user))) {
                     $va_ui_users[$t_user->getUserID()] = $vn_access;
                 } else {
                     $this->addError("User name or access value invalid for UI {$vs_ui_code} (permission item with user name '{$vs_user}')");
                 }
             }
             if (sizeof($va_ui_users) > 0) {
                 $t_ui->addUsers($va_ui_users);
             }
         }
         if ($vo_ui->groupAccess) {
             $t_group = new ca_user_groups();
             $va_ui_groups = array();
             foreach ($vo_ui->groupAccess->children() as $vo_permission) {
                 $vs_group = trim((string) self::getAttribute($vo_permission, "group"));
                 $vn_access = $this->_convertUserGroupAccessStringToInt(self::getAttribute($vo_permission, 'access'));
                 if ($vn_access && $t_group->load(array('code' => $vs_group))) {
                     $va_ui_groups[$t_group->getPrimaryKey()] = $vn_access;
                 } else {
                     $this->addError("Group code or access value invalid for UI {$vs_ui_code} (permission item with group code '{$vs_group}')");
                 }
             }
             if (sizeof($va_ui_groups) > 0) {
                 $t_ui->addUserGroups($va_ui_groups);
             }
         }
     }
     return true;
 }
コード例 #6
0
ファイル: ModelSettings.php プロジェクト: guaykuru/pawtucket
 /**
  * Set setting value 
  * (you must call insert() or update() to write the settings to the database)
  */
 public function setSetting($ps_setting, $pm_value)
 {
     if (!$this->isValidSetting($ps_setting)) {
         return null;
     }
     $va_setting_info = $this->getSettingInfo($ps_setting);
     if ($va_setting_info['displayType'] == DT_CHECKBOXES) {
         $pm_value = (int) $pm_value;
     }
     if (isset($va_setting_info['useRelationshipTypeList']) && $va_setting_info['useRelationshipTypeList'] || isset($va_setting_info['useList']) && $va_setting_info['useList'] || isset($va_setting_info['showLists']) && $va_setting_info['showLists'] || isset($va_setting_info['showVocabularies']) && $va_setting_info['showVocabularies']) {
         if (!is_array($pm_value)) {
             $pm_value = array($pm_value);
         }
         foreach ($pm_value as $vn_i => $vm_value) {
             if (trim($vm_value) && !is_numeric($vm_value)) {
                 // need to convert codes to ids
                 if ($vs_t = $va_setting_info['useRelationshipTypeList']) {
                     $t_rel = new ca_relationship_types();
                     $pm_value[$vn_i] = $t_rel->getRelationshipTypeID($vs_t, $vm_value);
                 } else {
                     if ($vs_l = $va_setting_info['useList']) {
                         // is a list
                         $t_list = new ca_lists();
                         $pm_value[$vn_i] = $t_list->getItemIDFromList($vs_l, $vm_value);
                     } else {
                         if ($va_setting_info['showLists'] || $va_setting_info['showVocabularies']) {
                             // is a list
                             $t_list = new ca_lists();
                             $vn_list_id = null;
                             if ($t_list->load(array('list_code' => $vm_value))) {
                                 $vn_list_id = $t_list->getPrimaryKey();
                             } else {
                                 if ($t_list->load((int) $vm_value)) {
                                     $vn_list_id = $t_list->getPrimaryKey();
                                 }
                             }
                             if ($vn_list_id) {
                                 $pm_value[$vn_i] = $vn_list_id;
                             }
                         } else {
                             if ($va_setting_info['showSortableBundlesFor']) {
                             }
                         }
                     }
                 }
             }
         }
     }
     $va_settings = $this->getSettings();
     if ($va_setting_info['formatType'] == FT_NUMBER) {
         $pm_value = (double) $pm_value;
     }
     $va_settings[$ps_setting] = $pm_value;
     $this->o_instance->set($this->ops_settings_field, $va_settings);
     return true;
 }
コード例 #7
0
$vn_list_item_type_facet = $t_list->getItemIDFromList('list_item_types', 'facet');
$vn_list_item_type_guide_term = $t_list->getItemIDFromList('list_item_types', 'guide_term');
$vn_list_item_type_hierarchy_name = $t_list->getItemIDFromList('list_item_types', 'hierarchy_name');
// get list item label types (should be defined by base installation profile [base.profile])
// if your installation didn't use a profile inheriting from base.profile then you should make sure
// that a list with code='list_item_label_types' is defined and the following four item codes are defined.
// If these are not defined then the AAT will still import, but without any distinction between
// terms, facets and guide terms
$vn_list_item_label_type_uf = $t_list->getItemIDFromList('list_item_label_types', 'uf');
$vn_list_item_label_type_alt = $t_list->getItemIDFromList('list_item_label_types', 'alt');
// get list item-to-item relationship type (should be defined by base installation profile [base.profile])
// if your installation didn't use a profile inheriting from base.profile then you should make sure
// that a ca_list_items_x_list_items relationship type with code='related' is defined. Otherwise import of term-to-term
// relationships will fail.
$t_rel_types = new ca_relationship_types();
$vn_list_item_relation_type_id_related = $t_rel_types->getRelationshipTypeID('ca_list_items_x_list_items', 'related');
// load voc_terms
$o_xml = new XMLReader();
$o_xml->open('AAT.xml');
print "READING AAT TERMS...\n";
$va_parent_child_links = array();
$va_item_item_links = array();
$va_aat_id_to_item_id = array();
$vn_last_message_length = 0;
$vn_term_count = 0;
while ($o_xml->read()) {
    switch ($o_xml->name) {
        # ---------------------------
        case 'record':
            if ($o_xml->nodeType == XMLReader::END_ELEMENT) {
                $vs_preferred_term_english = $va_subject['preferred_term_english'];
コード例 #8
0
         if (($vn_l = 100 - strlen($vs_message)) < 1) {
             $vn_l = 1;
         }
         $vs_message .= str_repeat(' ', $vn_l);
         $vn_last_message_length = strlen($vs_message);
         print $vs_message;
         if (!$t_place->load(array('idno' => $va_subject['subject_id']))) {
             print "[Error] could not load place for " . $va_subject['subject_id'] . "\n";
             continue;
         }
         if (!$t_related_place->load(array('idno' => ${$va_subject}['related_subject_id']))) {
             print "[Error] could not load related place " . $va_subject['related_subject_id'] . "\n";
             continue;
         }
         $va_tmp = explode("/", $va_subject['relationship_type']);
         $vn_rel_type_id = $t_rel_type->getRelationshipTypeID($t_link->tableNum(), $va_tmp[0], $pn_en_locale_id, array('typename' => $va_tmp[1]), array('create' => true));
         $t_link->set('term_left_id', $t_place->getPrimaryKey());
         $t_link->set('term_right_id', $t_related_place->getPrimaryKey());
         $t_link->set('type_id', $vn_rel_type_id);
         $t_link->insert();
         if ($t_link->numErrors()) {
             print "[Error] could not link " . $va_subject['subject_id'] . " to " . $va_subject['related_subject_id'] . ": " . join('; ', $t_place->getErrors()) . "\n";
         }
     } else {
         $va_subject = array('subject_id' => $o_xml->getAttribute('Subject_ID'));
     }
     break;
     # ---------------------------
 # ---------------------------
 case 'Associative_Relationships':
     $vn_parent_id = $vs_historic_flag = null;
コード例 #9
0
ファイル: ca_objects.php プロジェクト: kai-iak/pawtucket2
 /**
  * Sets the ca_objects.current_loc_class, ca_objects.current_loc_subclass and ca_objects.current_loc_id
  * fields in the currently loaded object row with information about the current location. These fields are used 
  * by BrowseEngine to browse objects on current location
  *
  * @param mixed $pm_loc_class
  * @param mixed $pm_current_loc_subclass
  * @param int $pn_current_loc_id
  * @param array $pa_options Options include:
  *		dontCheckID = Don't verify that the referenced row exists. This can save time if you're updating many object rows. [Default=false]
  *
  * @see BrowseEngine
  *
  * @return bool
  */
 private function setCurrentLocationForBrowse($pm_current_loc_class, $pm_current_loc_subclass, $pn_current_loc_id, $pa_options = null)
 {
     if (!$this->getPrimaryKey()) {
         return null;
     }
     if ($vn_table_num = $this->getAppDatamodel()->getTableNum($pm_current_loc_class)) {
         $t_instance = $this->getAppDatamodel()->getInstanceByTableNum($vn_table_num, true);
         if (!caGetOption('dontCheckID', $pa_options, false)) {
             if (!$t_instance->load(array($t_instance->primaryKey() => $pn_current_loc_id, 'deleted' => 0))) {
                 return false;
             }
         }
         if (!is_numeric($vn_type_id = $pm_current_loc_subclass)) {
             switch ($vs_table_name) {
                 case 'ca_storage_locations':
                     $t_rel_type = new ca_relationship_types();
                     $vn_type_id = $t_rel_type->getRelationshipTypeID('ca_objects_x_storage_locations', $pm_current_loc_subclass);
                     break;
                 default:
                     $vn_type_id = $t_instance->getTypeIDForCode($pm_current_loc_subclass);
                     break;
             }
         }
         $this->setMode(ACCESS_WRITE);
         $this->set('current_loc_class', $vn_table_num);
         $this->set('current_loc_subclass', $vn_type_id);
         $this->set('current_loc_id', $pn_current_loc_id);
         $this->update();
         if ($this->numErrors()) {
             return false;
         }
         return true;
     }
     return false;
 }
コード例 #10
0
 #		$i++;
 #	}
 #	if($i > $vn_num_more_link){
 #		print "</div>";
 #		print "<div class='class='moreLink'><a href='#' id='collectionMoreLink' onclick='jQuery(\"#collectionMore\").slideDown(250); jQuery(\"#collectionMoreLink\").hide(); return false;'>".(sizeof($va_collections) - $vn_num_more_link)._t(" More like this")." &rsaquo;</a></div>";
 #	}
 #	print "</div><!-- end unit -->";
 #}
 # --- output related object images as links
 $va_related_objects = $t_object->get("ca_objects", array("returnAsArray" => 1, 'checkAccess' => $va_access_values));
 if (sizeof($va_related_objects)) {
     print "<div class='unit' style='clear:both;'><H3 style='margin-bottom:8px;'>" . _t("Associated Artworks") . "</H3>";
     $va_rel_objs_by_type = array();
     $va_related_objs = array();
     $t_rel_types = new ca_relationship_types();
     $va_related_rel_type_ids = array($t_rel_types->getRelationshipTypeID('ca_objects_x_objects', 'related'), $t_rel_types->getRelationshipTypeID('ca_objects_x_objects', 'related_edition'), $t_rel_types->getRelationshipTypeID('ca_objects_x_objects', 'related_version'), $t_rel_types->getRelationshipTypeID('ca_objects_x_objects', 'related_element'));
     foreach ($va_related_objects as $vn_rel_id => $va_info) {
         # --- grab objects with type related works, related editions, related elements or related versions and put in separate array - will merge them later so related works appear last in list of related objects
         if (in_array($va_info['relationship_type_id'], $va_related_rel_type_ids)) {
             $va_related_objs[$va_info['relationship_typename']][$vn_rel_id] = $va_info;
         } else {
             $va_rel_objs_by_type[$va_info['relationship_typename']][$vn_rel_id] = $va_info;
         }
     }
     if (sizeof($va_related_objs) > 0) {
         $va_rel_objs_by_type = array_merge($va_rel_objs_by_type, $va_related_objs);
     }
     #print "<pre>";
     #print_r($va_rel_objs_by_type);
     #print "</pre>";
     ksort($va_rel_objs_by_type);
コード例 #11
0
/**
 * 
 *
 * @return string 
 */
function caLoadAAT($ps_path_to_aat_data = null, $pa_options = null)
{
    if (!$ps_path_to_aat_data) {
        $ps_path_to_aat_data = "./AAT.xml";
    }
    require_once __CA_LIB_DIR__ . '/core/Db.php';
    require_once __CA_MODELS_DIR__ . '/ca_locales.php';
    require_once __CA_MODELS_DIR__ . '/ca_lists.php';
    require_once __CA_MODELS_DIR__ . '/ca_list_items.php';
    require_once __CA_MODELS_DIR__ . '/ca_list_items_x_list_items.php';
    require_once __CA_MODELS_DIR__ . '/ca_relationship_types.php';
    $o_log = new KLogger(__CA_APP_DIR__ . '/log', KLogger::INFO);
    if (!file_exists($ps_path_to_aat_data)) {
        die("ERROR: cannot find AAT data.\n");
    }
    $_ = new Zend_Translate('gettext', __CA_APP_DIR__ . '/locale/en_US/messages.mo', 'en_US');
    $t_locale = new ca_locales();
    $pn_en_locale_id = $t_locale->loadLocaleByCode('en_US');
    // create vocabulary list record (if it doesn't exist already)
    $t_list = new ca_lists();
    if (!$t_list->load(array('list_code' => 'aat'))) {
        $t_list->setMode(ACCESS_WRITE);
        $t_list->set('list_code', 'aat');
        $t_list->set('is_system_list', 0);
        $t_list->set('is_hierarchical', 1);
        $t_list->set('use_as_vocabulary', 1);
        $t_list->insert();
        if ($t_list->numErrors()) {
            print "ERROR: couldn't create ca_list row for AAT: " . join('; ', $t_list->getErrors()) . "\n";
            die;
        }
        $t_list->addLabel(array('name' => 'Art & Architecture Thesaurus'), $pn_en_locale_id, null, true);
    }
    $vn_list_id = $t_list->getPrimaryKey();
    // get list item types (should be defined by base installation profile [base.profile])
    // if your installation didn't use a profile inheriting from base.profile then you should make sure
    // that a list with code='list_item_types' is defined and the following four item codes are defined.
    // If these are not defined then the AAT will still import, but without any distinction between
    // terms, facets and guide terms
    $vn_list_item_type_concept = $t_list->getItemIDFromList('list_item_types', 'concept');
    $vn_list_item_type_facet = $t_list->getItemIDFromList('list_item_types', 'facet');
    $vn_list_item_type_guide_term = $t_list->getItemIDFromList('list_item_types', 'guide_term');
    $vn_list_item_type_hierarchy_name = $t_list->getItemIDFromList('list_item_types', 'hierarchy_name');
    // get list item label types (should be defined by base installation profile [base.profile])
    // if your installation didn't use a profile inheriting from base.profile then you should make sure
    // that a list with code='list_item_label_types' is defined and the following four item codes are defined.
    // If these are not defined then the AAT will still import, but without any distinction between
    // terms, facets and guide terms
    $vn_list_item_label_type_uf = $t_list->getItemIDFromList('list_item_label_types', 'uf');
    $vn_list_item_label_type_alt = $t_list->getItemIDFromList('list_item_label_types', 'alt');
    // get list item-to-item relationship type (should be defined by base installation profile [base.profile])
    // if your installation didn't use a profile inheriting from base.profile then you should make sure
    // that a ca_list_items_x_list_items relationship type with code='related' is defined. Otherwise import of term-to-term
    // relationships will fail.
    $t_rel_types = new ca_relationship_types();
    $vn_list_item_relation_type_id_related = $t_rel_types->getRelationshipTypeID('ca_list_items_x_list_items', 'related');
    // load voc_terms
    $o_xml = new XMLReader();
    $o_xml->open($ps_path_to_aat_data);
    print "READING AAT TERMS...\n";
    $va_parent_child_links = array();
    $va_item_item_links = array();
    $va_aat_id_to_item_id = array();
    $vn_last_message_length = 0;
    $va_subject = array();
    $vn_term_count = 0;
    while ($o_xml->read()) {
        switch ($o_xml->name) {
            # ---------------------------
            case 'Subject':
                if ($o_xml->nodeType == XMLReader::END_ELEMENT) {
                    if ($va_subject['subject_id'] == '300000000') {
                        break;
                    }
                    // skip top-level root
                    $vs_preferred_term = $va_subject['preferred_term'];
                    switch ($va_subject['record_type']) {
                        case 'Concept':
                            $vn_type_id = $vn_list_item_type_hierarchy_name;
                            $pb_is_enabled = true;
                            break;
                        case 'Facet':
                            $vn_type_id = $vn_list_item_type_facet;
                            $vs_preferred_term = '<' . $vs_preferred_term . '>';
                            $pb_is_enabled = false;
                            break;
                        case 'Guide Term':
                            $vn_type_id = $vn_list_item_type_guide_term;
                            $vs_preferred_term = '<' . $vs_preferred_term . '>';
                            $pb_is_enabled = false;
                            break;
                        case 'Hierarchy Name':
                            $vn_type_id = $vn_list_item_type_hierarchy_name;
                            $pb_is_enabled = false;
                            break;
                        default:
                            $vn_type_id = null;
                            $pb_is_enabled = true;
                            break;
                    }
                    print str_repeat(chr(8), $vn_last_message_length);
                    $vs_message = "\tIMPORTING #" . ($vn_term_count + 1) . " [" . $va_subject['subject_id'] . "] " . $vs_preferred_term;
                    if (($vn_l = 100 - strlen($vs_message)) < 1) {
                        $vn_l = 1;
                    }
                    $vs_message .= str_repeat(' ', $vn_l);
                    $vn_last_message_length = strlen($vs_message);
                    print $vs_message;
                    if ($t_item = $t_list->addItem($va_subject['subject_id'], $pb_is_enabled, false, null, $vn_type_id, $va_subject['subject_id'], '', 4, 1)) {
                        $va_aat_id_to_item_id[$va_subject['subject_id']] = $t_item->getPrimaryKey();
                        if ($va_subject['preferred_parent_subject_id'] != 300000000) {
                            $va_parent_child_links[$va_subject['subject_id']] = $va_subject['preferred_parent_subject_id'];
                        }
                        // add preferred labels
                        if (!$t_item->addLabel(array('name_singular' => trim(htmlentities($vs_preferred_term, ENT_NOQUOTES)), 'name_plural' => trim(htmlentities($vs_preferred_term, ENT_NOQUOTES)), 'description' => $va_subject['description']), $pn_en_locale_id, null, true)) {
                            print "ERROR: Could not add preferred label to AAT term [" . $va_subject['subject_id'] . "] " . $vs_preferred_term . ": " . join("; ", $t_item->getErrors()) . "\n";
                        }
                        // add alternate labels
                        if (is_array($va_subject['non_preferred_terms'])) {
                            for ($vn_i = 0; $vn_i < sizeof($va_subject['non_preferred_terms']); $vn_i++) {
                                $vs_np_label = $va_subject['non_preferred_terms'][$vn_i];
                                $vs_np_term_type = $va_subject['non_preferred_term_types'][$vn_i];
                                switch ($vs_np_term_type) {
                                    case 'Used For Term':
                                        $vn_np_term_type_id = $vn_list_item_label_type_uf;
                                        break;
                                    case 'Alternate Descriptor':
                                        $vn_np_term_type_id = $vn_list_item_label_type_alt;
                                        break;
                                    default:
                                        $vn_np_term_type_id = null;
                                        break;
                                }
                                if (!$t_item->addLabel(array('name_singular' => trim(htmlentities($vs_np_label, ENT_NOQUOTES)), 'name_plural' => trim(htmlentities($vs_np_label, ENT_NOQUOTES)), 'description' => ''), $pn_en_locale_id, $vn_np_term_type_id, false)) {
                                    print "ERROR: Could not add non-preferred label to AAT term [" . $va_subject['subject_id'] . "] " . $vs_np_label . "\n";
                                    //: ".join("; ", $t_item->getErrors())."\n";
                                }
                            }
                        }
                        // record item-item relations
                        if (is_array($va_subject['related_subjects'])) {
                            foreach ($va_subject['related_subjects'] as $vs_rel_subject_id) {
                                $va_item_item_links[$va_subject['subject_id']] = $vs_rel_subject_id;
                            }
                        }
                        $vn_term_count++;
                    } else {
                        print "ERROR: Could not import AAT term [" . $va_subject['subject_id'] . "] " . $vs_preferred_term . ": " . join("; ", $t_list->getErrors()) . "\n";
                    }
                } else {
                    $va_subject = array('subject_id' => $o_xml->getAttribute('Subject_ID'));
                }
                break;
                # ---------------------------
            # ---------------------------
            case 'Descriptive_Note':
                while ($o_xml->read()) {
                    switch ($o_xml->name) {
                        case 'Note_Text':
                            switch ($o_xml->nodeType) {
                                case XMLReader::ELEMENT:
                                    $o_xml->read();
                                    $va_subject['description'] = $o_xml->value;
                                    break;
                            }
                            break;
                        case 'Descriptive_Note':
                            break 2;
                    }
                }
                break;
                # ---------------------------
            # ---------------------------
            case 'Record_Type':
                switch ($o_xml->nodeType) {
                    case XMLReader::ELEMENT:
                        $o_xml->read();
                        $va_subject['record_type'] = $o_xml->value;
                        break;
                }
                break;
                # ---------------------------
            # ---------------------------
            case 'Facet_Code':
                switch ($o_xml->nodeType) {
                    case XMLReader::ELEMENT:
                        $o_xml->read();
                        $va_subject['facet_code'] = $o_xml->value;
                        break;
                }
                break;
                # ---------------------------
            # ---------------------------
            case 'Parent_Relationships':
                $vn_parent_id = $vs_historic_flag = null;
                while ($o_xml->read()) {
                    switch ($o_xml->name) {
                        case 'Preferred_Parent':
                            while ($o_xml->read()) {
                                switch ($o_xml->name) {
                                    case 'Parent_Subject_ID':
                                        switch ($o_xml->nodeType) {
                                            case XMLReader::ELEMENT:
                                                $o_xml->read();
                                                $vn_parent_id = $o_xml->value;
                                                break;
                                        }
                                        break;
                                    case 'Historic_Flag':
                                        switch ($o_xml->nodeType) {
                                            case XMLReader::ELEMENT:
                                                $o_xml->read();
                                                $vs_historic_flag = $o_xml->value;
                                                break;
                                        }
                                        break;
                                    case 'Preferred_Parent':
                                        $va_subject['preferred_parent_subject_id'] = $vn_parent_id;
                                        break 2;
                                }
                            }
                            break;
                        case 'Parent_Relationships':
                            break 2;
                    }
                }
                break;
                # ---------------------------
            # ---------------------------
            case 'Preferred_Term':
                while ($o_xml->read()) {
                    switch ($o_xml->name) {
                        case 'Term_Type':
                            switch ($o_xml->nodeType) {
                                case XMLReader::ELEMENT:
                                    $o_xml->read();
                                    $va_subject['preferred_term_type'] = $o_xml->value;
                                    break;
                            }
                            break;
                        case 'Term_Text':
                            switch ($o_xml->nodeType) {
                                case XMLReader::ELEMENT:
                                    $o_xml->read();
                                    $va_subject['preferred_term'] = $o_xml->value;
                                    break;
                            }
                            break;
                        case 'Term_ID':
                            switch ($o_xml->nodeType) {
                                case XMLReader::ELEMENT:
                                    $o_xml->read();
                                    $va_subject['preferred_term_id'] = $o_xml->value;
                                    break;
                            }
                            break;
                            break;
                        case 'Preferred_Term':
                            break 2;
                    }
                }
                break;
                # ---------------------------
            # ---------------------------
            case 'Non-Preferred_Term':
                while ($o_xml->read()) {
                    switch ($o_xml->name) {
                        case 'Term_Type':
                            switch ($o_xml->nodeType) {
                                case XMLReader::ELEMENT:
                                    $o_xml->read();
                                    $va_subject['non_preferred_term_types'][] = $o_xml->value;
                                    break;
                            }
                            break;
                        case 'Term_Text':
                            switch ($o_xml->nodeType) {
                                case XMLReader::ELEMENT:
                                    $o_xml->read();
                                    $va_subject['non_preferred_terms'][] = $o_xml->value;
                                    break;
                            }
                            break;
                        case 'Term_ID':
                            switch ($o_xml->nodeType) {
                                case XMLReader::ELEMENT:
                                    $o_xml->read();
                                    $va_subject['non_preferred_term_ids'][] = $o_xml->value;
                                    break;
                            }
                            break;
                        case 'Non-Preferred_Term':
                            break 2;
                    }
                }
                break;
                # ---------------------------
            # ---------------------------
            case 'VP_Subject_ID':
                switch ($o_xml->nodeType) {
                    case XMLReader::ELEMENT:
                        $o_xml->read();
                        $va_subject['related_subjects'][] = $o_xml->value;
                        break;
                }
                break;
                # ---------------------------
        }
    }
    $o_xml->close();
    print "\n\nLINKING TERMS IN HIERARCHY...\n";
    $vn_last_message_length = 0;
    $t_item = new ca_list_items();
    $t_item->setMode(ACCESS_WRITE);
    foreach ($va_parent_child_links as $vs_child_id => $vs_parent_id) {
        print str_repeat(chr(8), $vn_last_message_length);
        $vs_message = "\tLINKING {$vs_child_id} to parent {$vs_parent_id}";
        if (($vn_l = 100 - strlen($vs_message)) < 1) {
            $vn_l = 1;
        }
        $vs_message .= str_repeat(' ', $vn_l);
        $vn_last_message_length = strlen($vs_message);
        print $vs_message;
        if (!($vn_child_item_id = $va_aat_id_to_item_id[$vs_child_id])) {
            print "ERROR: no list item id for child_id {$vs_child_id} (were there previous errors?)\n";
            continue;
        }
        if (!($vn_parent_item_id = $va_aat_id_to_item_id[$vs_parent_id])) {
            print "ERROR: no list item id for parent_id {$vs_child_id} (were there previous errors?)\n";
            continue;
        }
        if (!$t_item->load($vn_child_item_id)) {
            print "ERROR: could not load item for {$vs_child_id} (was translated to item_id={$vn_child_item_id})\n";
            continue;
        }
        $t_item->set('parent_id', $vn_parent_item_id);
        $t_item->update();
        if ($t_item->numErrors()) {
            print "ERROR: could not set parent_id for {$vs_child_id} (was translated to item_id={$vn_child_item_id}): " . join('; ', $t_item->getErrors()) . "\n";
        }
    }
    if ($vn_list_item_relation_type_id_related > 0) {
        print "\n\nADDING RELATED TERM LINKS...\n";
        $vn_last_message_length = 0;
        $t_item = new ca_list_items();
        $t_link = new ca_list_items_x_list_items();
        $t_link->setMode(ACCESS_WRITE);
        foreach ($va_item_item_links as $vs_left_id => $vs_right_id) {
            print str_repeat(chr(8), $vn_last_message_length);
            $vs_message = "\tLINKING {$vs_left_id} to {$vs_right_id}";
            if (($vn_l = 100 - strlen($vs_message)) < 1) {
                $vn_l = 1;
            }
            $vs_message .= str_repeat(' ', $vn_l);
            $vn_last_message_length = strlen($vs_message);
            print $vs_message;
            if (!($vn_left_item_id = $va_aat_id_to_item_id[$vs_left_id])) {
                print "ERROR: no list item id for left_id {$vs_left_id} (were there previous errors?)\n";
                continue;
            }
            if (!($vn_right_item_id = $va_aat_id_to_item_id[$vs_right_id])) {
                print "ERROR: no list item id for right_id {$vs_right_id} (were there previous errors?)\n";
                continue;
            }
            $t_link->set('term_left_id', $vn_left_item_id);
            $t_link->set('term_right_id', $vn_right_item_id);
            $t_link->set('type_id', $vn_list_item_relation_type_id_related);
            $t_link->insert();
            if ($t_link->numErrors()) {
                print "ERROR: could not set link between {$vs_left_id} (was translated to item_id={$vn_left_item_id}) and {$vs_right_id} (was translated to item_id={$vn_right_item_id}): " . join('; ', $t_link->getErrors()) . "\n";
            }
        }
    } else {
        print "WARNING: Skipped import of term-term relationships because the ca_list_items_x_list_items 'related' relationship type is not defined for your installation\n";
    }
    print "\n\nIMPORT COMPLETE.\n";
}
コード例 #12
0
ファイル: BrowseEngine.php プロジェクト: guaykuru/pawtucket
 /**
  * Converts list of relationships type codes and/or numeric ids to an id-only list
  */
 private function _getRelationshipTypeIDs($pa_relationship_types, $pm_relationship_table_or_id)
 {
     $t_rel_type = new ca_relationship_types();
     $va_type_list = $pa_relationship_types;
     foreach ($va_type_list as $vn_i => $vm_type) {
         if (!trim($vm_type)) {
             unset($pa_relationship_types[$vn_i]);
             continue;
         }
         if (!is_numeric($vm_type)) {
             // try to translate item_value code into numeric id
             if (!($vn_type_id = $t_rel_type->getRelationshipTypeID($pm_relationship_table_or_id, $vm_type))) {
                 unset($pa_relationship_types[$vn_i]);
                 continue;
             }
             unset($pa_relationship_types[$vn_i]);
             $pa_relationship_types[] = $vn_type_id;
         } else {
             if (!$t_rel_type->load($vm_type)) {
                 unset($pa_relationship_types[$vn_i]);
                 continue;
             }
             $vn_type_id = $t_rel_type->getPrimaryKey();
         }
         $va_ids = $t_rel_type->getHierarchyChildren($vn_type_id, array('idsOnly' => true));
         if (is_array($va_ids)) {
             foreach ($va_ids as $vn_id) {
                 $pa_relationship_types[] = $vn_id;
             }
         }
     }
     return $pa_relationship_types;
 }