';
$vs_buf .= caFormTag($po_view->request, 'Edit', 'NewChildForm', 'administrate/setup/list_item_editor/ListItemEditor', 'post', 'multipart/form-data', '_top', array('disableUnsavedChangesWarning' => true));
$vs_buf .= _t('Add a %1 to this list', $vs_type_list).caHTMLHiddenInput($t_list_item->primaryKey(), array('value' => '0')).caHTMLHiddenInput('parent_id', array('value' => $t_list_item->getPrimaryKey()));
$vs_buf .= caFormSubmitLink($po_view->request, caNavIcon($po_view->request, __CA_NAV_BUTTON_ADD__), '', 'NewChildForm');
$vs_buf .= "
\n";
}
}
//
// Output containing list for list items
//
if ($vs_table_name === 'ca_list_items') {
if ($t_list = $po_view->getVar('t_list')) {
$vn_list_id = $t_list->getPrimaryKey();
$vs_buf .= ""._t("Number of screens").": ".(int)$t_item->getScreenCount()."\n";
if ($t_item->getPrimaryKey()) {
$vs_buf .= "
"._t("Edits").": ".caGetTableDisplayName($t_item->get('editor_type'))."
\n";
} else {
$vs_buf .= "
"._t("Edits").": ".caGetTableDisplayName($po_view->request->getParameter('editor_type', pInteger))."
\n";
}
$vs_buf .= "
\n";
}
//
// Output related objects for ca_editor_uis and ca_editor_ui_screens
//
if ($vs_table_name === 'ca_editor_ui_screens') {
$t_ui = new ca_editor_uis($vn_ui_id = $t_item->get('ui_id'));
$vs_buf .= "
"._t("Part of").": ".caNavLink($po_view->request, $t_ui->getLabelForDisplay(), '', 'administrate/setup/interface_editor', 'InterfaceEditor', 'Edit', array('ui_id' => $vn_ui_id))."\n";
$vs_buf .= "
\n";
}
//
// Output extra useful info for bundle displays
//
if ($vs_table_name === 'ca_bundle_displays') {
$vs_buf .= "
"._t("Number of placements").": ".$t_item->getPlacementCount(array('user_id' => $po_view->request->getUserID()))."
\n";
if ($t_item->getPrimaryKey()) {
$vn_content_table_num = $t_item->get('table_num');
$vs_buf .= ""._t("Type of content").": ".caGetTableDisplayName($vn_content_table_num)."\n";
$vs_buf .= "
\n";
} else {
if ($vn_content_table_num = $po_view->request->getParameter('table_num', pInteger)) {
$vs_buf .= "
"._t("Type of content").": ".caGetTableDisplayName($vn_content_table_num)."\n";
$vs_buf .= "
\n";
}
}
$t_user = new ca_users(($vn_user_id = $t_item->get('user_id')) ? $vn_user_id : $po_view->request->getUserID());
if ($t_user->getPrimaryKey()) {
$vs_buf .= "
"._t('Owner').": ".$t_user->get('fname').' '.$t_user->get('lname')."
\n";
}
}
//
// Output extra useful info for search forms
//
if ($vs_table_name === 'ca_search_forms') {
$vs_buf .= "
"._t("Number of placements").": ".$t_item->getPlacementCount(array('user_id' => $po_view->request->getUserID()))."
\n";
if ($t_item->getPrimaryKey()) {
$vn_content_table_num = $t_item->get('table_num');
$vs_buf .= ""._t("Searches for").": ".caGetTableDisplayName($vn_content_table_num)."\n";
$vs_buf .= "
\n";
} else {
if ($vn_content_table_num = $po_view->request->getParameter('table_num', pInteger)) {
$vs_buf .= "
"._t("Searches for").": ".caGetTableDisplayName($vn_content_table_num)."\n";
$vs_buf .= "
\n";
}
}
$t_user = new ca_users(($vn_user_id = $t_item->get('user_id')) ? $vn_user_id : $po_view->request->getUserID());
if ($t_user->getPrimaryKey()) {
$vs_buf .= "
"._t('Owner').": ".$t_user->get('fname').' '.$t_user->get('lname')."
\n";
}
}
//
// Output extra useful info for tours
//
if (($vs_table_name === 'ca_tours') && $t_item->getPrimaryKey()) {
$vs_buf .= "
"._t("Number of stops").": ".$t_item->getStopCount()."
\n";
}
//
// Output containing tour for tour stops
//
if ($vs_table_name === 'ca_tour_stops') {
$t_tour = new ca_tours($vn_tour_id = $t_item->get('tour_id'));
$vs_buf .= "
"._t("Part of").": ".caEditorLink($po_view->request, $t_tour->getLabelForDisplay(), '', 'ca_tours', $vn_tour_id) ."
\n";
}
//
// Output extra useful info for bundle mappings
//
if ($vs_table_name === 'ca_bundle_mappings') {
if ($t_item->getPrimaryKey()) {
$vn_content_table_num = $t_item->get('table_num');
$vs_buf .= "
"._t("Type of content").": ".caGetTableDisplayName($vn_content_table_num)."
\n";
$vs_buf .= "
"._t("Type").": ".$t_item->getChoiceListValue('direction', $t_item->get('direction'))."
\n";
$vs_buf .= "
"._t("Target format").": ".$t_item->get('target')."
\n";
$va_stats = $t_item->getMappingStatistics();
$vs_buf .= "
"._t("Number of groups").": ".$va_stats['groupCount']."
\n";
$vs_buf .= ""._t("Number of rules").": ".$va_stats['ruleCount']."
\n";
$vs_buf .= "
\n";
} else {
if ($vn_content_table_num = $po_view->request->getParameter('table_num', pInteger)) {
$vs_buf .= "
"._t("Type of content").": ".caGetTableDisplayName($vn_content_table_num)."
\n";
$vs_buf .= "
"._t("Type").": ".$t_item->getChoiceListValue('direction', $po_view->request->getParameter('direction', pString))."
\n";
$vs_buf .= "
"._t("Target format").": ".$po_view->request->getParameter('target', pString)."
\n";
$vs_buf .= "
"._t("Number of groups").": 0
\n";
$vs_buf .= ""._t("Number of rules").": 0
\n";
$vs_buf .= "
\n";
}
}
}
//
// Output extra useful info for bundle mapping groups
//
if ($vs_table_name === 'ca_bundle_mapping_groups') {
$t_mapping = new ca_bundle_mappings($vn_mapping_id = $t_item->get('mapping_id'));
$vs_buf .= "
"._t("Part of").": ".caEditorLink($po_view->request, $t_mapping->getLabelForDisplay(), '', 'ca_bundle_mappings', $vn_mapping_id) ."
\n";
$vn_content_table_num = $t_mapping->get('table_num');
$vs_buf .= "
"._t("Type of content").": ".caGetTableDisplayName($vn_content_table_num)."
\n";
$vs_buf .= "
"._t("Type").": ".$t_mapping->getChoiceListValue('direction', $t_mapping->get('direction'))."
\n";
$vs_buf .= "
"._t("Target format").": ".$t_mapping->get('target')."
\n";
$vs_buf .= "
"._t("Number of rules").": ".$t_item->getRuleCount()."
\n";
}
// -------------------------------------------------------------------------------------
// Hierarchies
if ($t_item->getPrimaryKey() && $po_view->request->config->get($vs_table_name.'_show_add_child_control_in_inspector')) {
//
if ((bool)$po_view->request->config->get($vs_table_name.'_enforce_strict_type_hierarchy')) {
// strict menu
$vs_type_list = $t_item->getTypeListAsHTMLFormElement('type_id', array('style' => 'width: 90px; font-size: 9px;'), array('childrenOfCurrentTypeOnly' => true, 'directChildrenOnly' => ($po_view->request->config->get($vs_table_name.'_enforce_strict_type_hierarchy') == '~') ? false : true, 'returnHierarchyLevels' => true));
} else {
// all types
$vs_type_list = $t_item->getTypeListAsHTMLFormElement('type_id', array('style' => 'width: 90px; font-size: 9px;'));
}
if ($vs_type_list) {
$vs_buf .= '
';
$vs_buf .= caFormTag($po_view->request, 'Edit', 'NewChildForm', null, 'post', 'multipart/form-data', '_top', array('disableUnsavedChangesWarning' => true));
$vs_buf .= _t('Add a %1 under this', $vs_type_list).caHTMLHiddenInput($t_item->primaryKey(), array('value' => '0')).caHTMLHiddenInput('parent_id', array('value' => $t_item->getPrimaryKey()));
$vs_buf .= caFormSubmitLink($po_view->request, caNavIcon($po_view->request, __CA_NAV_BUTTON_ADD__), '', 'NewChildForm');
$vs_buf .= "
\n";
}
}
if($po_view->request->user->canDoAction('can_duplicate_'.$vs_table_name) && $t_item->getPrimaryKey()) {
$vs_buf .= '
';
$vs_buf .= caFormTag($po_view->request, 'Edit', 'DuplicateItemForm', $po_view->request->getModulePath().'/'.$po_view->request->getController(), 'post', 'multipart/form-data', '_top', array('disableUnsavedChangesWarning' => true, 'noTimestamp' => true));
$vs_buf .= _t('Duplicate this %1', mb_strtolower($vs_type_name, 'UTF-8')).' '.caFormSubmitLink($po_view->request, caNavIcon($po_view->request, __CA_NAV_BUTTON_ADD__), '', 'DuplicateItemForm');
$vs_buf .= caHTMLHiddenInput($t_item->primaryKey(), array('value' => $t_item->getPrimaryKey()));
$vs_buf .= caHTMLHiddenInput('mode', array('value' => 'dupe'));
$vs_buf .= "";
$vs_buf .= "
";
TooltipManager::add("#caDuplicateItemButton", "
"._t('Duplicate this %1', mb_strtolower($vs_type_name, 'UTF-8'))."
"._t("Click the [+] button to create and open for editing a duplicate of this %1. By default virtually all aspects of the %2 will be duplicated. You can exclude certain types of content from duplicates using settings in your user preferences under 'Duplication.'", mb_strtolower($vs_type_name, 'UTF-8'), mb_strtolower($vs_type_name, 'UTF-8')));
}
// -------------------------------------------------------------------------------------
if($t_item->getPrimaryKey()) {
if (sizeof($va_reps) > 0) {
$va_imgs = array();
$vs_buf .= "
\n";
}
$vs_more_info = '';
// list of sets in which item is a member
$t_set = new ca_sets();
if (is_array($va_sets = caExtractValuesByUserLocale($t_set->getSetsForItem($t_item->tableNum(), $t_item->getPrimaryKey(), array('user_id' => $po_view->request->getUserID(), 'access' => __CA_SET_READ_ACCESS__)))) && sizeof($va_sets)) {
$va_links = array();
foreach($va_sets as $vn_set_id => $va_set) {
$va_links[] = "
".$va_set['name']."";
}
$vs_more_info .= "
".((sizeof($va_links) == 1) ? _t("In set") : _t("In sets"))." ".join(", ", $va_links)."
\n";
}
// export options
if ($vn_item_id && $vs_select = $po_view->getVar('available_mappings_as_html_select')) {
$vs_more_info .= "
".caFormTag($po_view->request, 'exportItem', 'caExportForm', null, 'post', 'multipart/form-data', '_top', array('disableUnsavedChangesWarning' => true));
$vs_more_info .= $vs_select;
$vs_more_info .= caHTMLHiddenInput($t_item->primaryKey(), array('value' => $t_item->getPrimaryKey()));
$vs_more_info .= caHTMLHiddenInput('download', array('value' => 1));
$vs_more_info .= caFormSubmitLink($po_view->request, 'Export ›', 'button', 'caExportForm');
$vs_more_info .= "
";
}
$va_creation = $t_item->getCreationTimestamp();
$va_last_change = $t_item->getLastChangeTimestamp();
if ($va_creation['timestamp'] || $va_last_change['timestamp']) {
$vs_more_info .= "
";
if($va_creation['timestamp']) {
if (!trim($vs_name = $va_creation['fname'].' '.$va_creation['lname'])) { $vs_name = null; }
$vs_interval = (($vn_t = (time() - $va_creation['timestamp'])) == 0) ? _t('Just now') : _t('%1 ago', caFormatInterval($vn_t , 2));
$vs_more_info .= "
".
($vs_name ? _t('Created
%1 by %2', $vs_interval, $vs_name) : _t('Created
%1', $vs_interval)).
"
";
TooltipManager::add("#caInspectorCreationDate", "
"._t('Created on')."
"._t('Created on %1', caGetLocalizedDate($va_creation['timestamp'], array('dateFormat' => 'delimited'))));
}
if ($va_last_change['timestamp'] && ($va_creation['timestamp'] != $va_last_change['timestamp'])) {
if (!trim($vs_name = $va_last_change['fname'].' '.$va_last_change['lname'])) { $vs_name = null; }
$vs_interval = (($vn_t = (time() - $va_last_change['timestamp'])) == 0) ? _t('Just now') : _t('%1 ago', caFormatInterval($vn_t , 2));
$vs_more_info .= "
".
($vs_name ? _t('Last changed
%1 by %2', $vs_interval, $vs_name) : _t('Last changed
%1', $vs_interval)).
"
";
TooltipManager::add("#caInspectorChangeDate", "
"._t('Last changed on')."
"._t('Last changed on %1', caGetLocalizedDate($va_last_change['timestamp'], array('dateFormat' => 'delimited'))));
}
$vs_more_info .= "
\n";
}
if ($vs_more_info) {
$vs_buf .= "
";
$vs_buf .= $vs_more_info."
\n";
}
}
$vs_buf .= "
\n";
if($t_item->getPrimaryKey()) {
if ($vs_more_info) {
$vs_buf .= "
\n";
}
}
return $vs_buf;
}
# ------------------------------------------------------------------------------------------------
/**
*
*/
function caFilterTableList($pa_tables) {
require_once(__CA_MODELS_DIR__.'/ca_occurrences.php');
$o_config = Configuration::load();
$o_dm = Datamodel::load();
// assume table display names (*not actual database table names*) are keys and table_nums are values
$va_filtered_tables = array();
foreach($pa_tables as $vs_display_name => $vn_table_num) {
$vs_display_name = mb_strtolower($vs_display_name, 'UTF-8');
$vs_table_name = $o_dm->getTableName($vn_table_num);
if ((int)($o_config->get($vs_table_name.'_disable'))) { continue; }
switch($vs_table_name) {
case 'ca_occurrences':
$t_occ = new ca_occurrences();
$va_types = $t_occ->getTypeList();
$va_type_labels = array();
foreach($va_types as $vn_item_id => $va_type_info) {
$va_type_labels[] = mb_strtolower($va_type_info['name_plural'], 'UTF-8');
}
if (sizeof($va_type_labels)) {
$va_filtered_tables[join('/', $va_type_labels)] = $vn_table_num;
}
break;
default:
$va_filtered_tables[$vs_display_name] = $vn_table_num;
break;
}
}
return $va_filtered_tables;
}
# ------------------------------------------------------------------------------------------------
/**
*
*/
function caGetTableDisplayName($pm_table_name_or_num, $pb_use_plural=true) {
require_once(__CA_MODELS_DIR__.'/ca_occurrences.php');
$o_dm = Datamodel::load();
$vs_table = $o_dm->getTableName($pm_table_name_or_num);
switch($vs_table) {
case 'ca_occurrences':
$t_occ = new ca_occurrences();
$va_types = $t_occ->getTypeList();
$va_type_labels = array();
foreach($va_types as $vn_item_id => $va_type_info) {
$va_type_labels[] = $va_type_info[($pb_use_plural ? 'name_plural' : 'name_singular')];
}
return join('/', $va_type_labels);
break;
default:
if($t_instance = $o_dm->getInstanceByTableName($vs_table, true)) {
return $t_instance->getProperty(($pb_use_plural ? 'NAME_PLURAL' : 'NAME_SINGULAR'));
}
break;
}
return null;
}
# ------------------------------------------------------------------------------------------------
/**
*
*
* @param
*
* @return
*/
function caGetMediaDisplayInfo($ps_context, $ps_mimetype) {
$o_config = Configuration::load();
$o_media_display_config = Configuration::load($o_config->get('media_display'));
if (!is_array($va_context = $o_media_display_config->getAssoc($ps_context))) { return null; }
foreach($va_context as $vs_media_class => $va_media_class_info) {
if (!is_array($va_mimetypes = $va_media_class_info['mimetypes'])) { continue; }
if (in_array($ps_mimetype, $va_mimetypes)) {
return $va_media_class_info;
}
}
return null;
}
# ------------------------------------------------------------------------------------------------
/**
* Replace "^" tags (eg. ^forename) in a template with values from an array
*
* @param string $ps_template String with embedded tags. Tags are just alphanumeric strings prefixed with a caret ("^")
* @param array $pa_values Array of values; keys must match tag names
* @param array $pa_options Supported options are:
* removePrefix = string to remove from tags extracted from template before doing lookup into value array
* getFrom =
*
* @return string Output of processed template
*/
function caProcessTemplate($ps_template, $pa_values, $pa_options=null) {
$vs_remove_prefix = isset($pa_options['removePrefix']) ? $pa_options['removePrefix'] : null;
$va_tags = array();
if (preg_match_all("!\^([A-Za-z0-9_\.]+)!", $ps_template, $va_matches)) {
$va_tags = $va_matches[1];
}
$t_instance = null;
if (isset($pa_options['getFrom']) && (method_exists($pa_options['getFrom'], 'get'))) {
$t_instance = $pa_options['getFrom'];
}
foreach($va_tags as $vs_tag) {
$vs_proc_tag = $vs_tag;
if ($vs_remove_prefix) {
$vs_proc_tag = str_replace($vs_remove_prefix, '', $vs_proc_tag);
}
if ($t_instance && ($vs_gotten_val = $t_instance->get($vs_proc_tag, $pa_options))) {
$ps_template = str_replace('^'.$vs_tag, $vs_gotten_val, $ps_template);
} else {
$ps_template = str_replace('^'.$vs_tag, isset($pa_values[$vs_proc_tag]) ? $pa_values[$vs_proc_tag] : '', $ps_template);
}
}
return $ps_template;
}
# ------------------------------------------------------------------------------------------------
/**
* Returns date/time as a localized string for display, subject to the settings in the app/conf/datetime.conf configuration
*
* @param int $pn_timestamp Unix timestamp for date/time to localize; if omitted defaults to current date and time.
* @param array $pa_options All options supported by TimeExpressionParser::getText() are supported
*
* @return string Localized date/time expression
*/
function caGetLocalizedDate($pn_timestamp=null, $pa_options=null) {
if (!$pn_timestamp) { $pn_timestamp = time(); }
$o_tep = new TimeExpressionParser();
$o_tep->setUnixTimestamps($pn_timestamp, $pn_timestamp);
return $o_tep->getText($pa_options);
}
# ------------------------------------------------------------------------------------------------
/**
* Returns date range as a localized string for display, subject to the settings in the app/conf/datetime.conf configuration
*
* @param int $pn_start_timestamp Start of date range, as Unix timestamp
* @param int $pn_end_timestamp End of date range, as Unix timestamp
* @param array $pa_options All options supported by TimeExpressionParser::getText() are supported
*
* @return string Localized date range expression
*/
function caGetLocalizedDateRange($pn_start_timestamp, $pn_end_timestamp, $pa_options=null) {
$o_tep = new TimeExpressionParser();
$o_tep->setUnixTimestamps($pn_start_timestamp, $pn_end_timestamp);
return $o_tep->getText($pa_options);
}
# ------------------------------------------------------------------------------------------------
/**
* Returns text describing dimensions of object representation
*
* @param DbResult or ca_object_representations instance $po_rep An object containing representation data. Can be either a DbResult object (ie. a query result) or ca_object_representations instance (an instance representing a row in the ca_object_representation class)
* @param string $ps_version the name of the media version to return dimensions information for
* @param array $pa_options Array of options, including:
* returnAsArray = if set an array with elements of the dimensions display text is returned
* @return mixed Text ready for display describing dimensions of the representation's media. Can be array if 'returnAsArray' option is set.
*/
function caGetRepresentationDimensionsForDisplay($po_rep, $ps_version, $pa_options=null) {
$va_tmp = $po_rep->getMediaInfo('media', $ps_version);
$va_dimensions = array();
if (isset($va_tmp['WIDTH']) && isset($va_tmp['HEIGHT'])) {
if (($vn_w = $va_tmp['WIDTH']) && ($vn_h = $va_tmp['WIDTH'])) {
$va_dimensions[] = $va_tmp['WIDTH'].'p x '.$va_tmp['HEIGHT'].'p';
}
}
if (isset($va_tmp['PROPERTIES']['bitdepth']) && ($vn_depth = $va_tmp['PROPERTIES']['bitdepth'])) {
$va_dimensions[] = intval($vn_depth).' bpp';
}
if (isset($va_tmp['PROPERTIES']['colorspace']) && ($vs_colorspace = $va_tmp['PROPERTIES']['colorspace'])) {
$va_dimensions[] = $vs_colorspace;
}
if (isset($va_tmp['PROPERTIES']['resolution']) && is_array($va_resolution = $va_tmp['PROPERTIES']['resolution'])) {
if (isset($va_resolution['x']) && isset($va_resolution['y']) && $va_resolution['x'] && $va_resolution['y']) {
// TODO: units for resolution? right now assume pixels per inch
if ($va_resolution['x'] == $va_resolution['y']) {
$va_dimensions[] = $va_resolution['x'].'ppi';
} else {
$va_dimensions[] = $va_resolution['x'].'x'.$va_resolution['y'].'ppi';
}
}
}
if (isset($va_tmp['PROPERTIES']['duration']) && ($vn_duration = $va_tmp['PROPERTIES']['duration'])) {
$va_dimensions[] = sprintf("%4.1f", $vn_duration).'s';
}
if (isset($va_tmp['PROPERTIES']['pages']) && ($vn_pages = $va_tmp['PROPERTIES']['pages'])) {
$va_dimensions[] = $vn_pages.' '.(($vn_pages == 1) ? _t('page') : _t('pages'));
}
if (!isset($va_tmp['PROPERTIES']['filesize']) || !($vn_filesize = $va_tmp['PROPERTIES']['filesize'])) {
$vn_filesize = @filesize($po_rep->getMediaPath('media', $ps_version));
}
if ($vn_filesize) {
$va_dimensions[] = sprintf("%4.1f", $vn_filesize/(1024*1024)).'mb';
}
if(isset($pa_options['returnAsArray']) && $pa_options['returnAsArray']) {
return $va_dimensions;
}
return join('; ', $va_dimensions);
}
# ------------------------------------------------------------------------------------------------
/**
* Converts result set into display labels for relationship lookup
*
* @param SearchResult $qr_rel_items
* @param BaseModel $pt_rel
* @param array $pa_options Array of options, including:
* stripTags = default is false
* exclude = list of primary key values to omit from returned list
*
* @return mixed
*/
global $ca_relationship_lookup_parse_cache;
$ca_relationship_lookup_parse_cache = array();
function caProcessRelationshipLookupLabel($qr_rel_items, $pt_rel, $pa_options=null) {
global $ca_relationship_lookup_parse_cache;
$vb_is_hierarchical = $pt_rel->isHierarchical();
$vs_hier_parent_id_fld = $pt_rel->getProperty('HIERARCHY_PARENT_ID_FLD');
$vs_hier_fld = $pt_rel->getProperty('HIERARCHY_ID_FLD');
$vs_idno_fld = $pt_rel->getProperty('ID_NUMBERING_ID_FIELD');
$vs_idno_sort_fld = $pt_rel->getProperty('ID_NUMBERING_SORT_FIELD');
$vs_rel_pk = $pt_rel->primaryKey();
$vs_rel_table = $pt_rel->tableName();
$o_config = Configuration::load();
$va_exclude = (isset($pa_options['exclude']) && is_array($pa_options['exclude'])) ? $pa_options['exclude'] : array();
//
// Originally the lookup display setting was a string with embedded tokens prefixed with carets. We still have to support this
// in case someone is using an old config file, but the preferred configuration format is now to pass an array of bundles (still prefixed
// with a caret because the bundles may have HTML formatting around them) and a separate delimiter. We then join all non-blank values together
//
$vb_use_new_display_format = false;
$va_bundles = array();
if (isset($ca_relationship_lookup_parse_cache[$vs_rel_table])) {
$va_bundles = $ca_relationship_lookup_parse_cache[$vs_rel_table]['bundles'];
$va_display_format = $ca_relationship_lookup_parse_cache[$vs_rel_table]['display_format'];
$vs_display_delimiter = $ca_relationship_lookup_parse_cache[$vs_rel_table]['delimiter'];
$vb_use_new_display_format = true;
} else {
if (($vs_display_format = $o_config->get($vs_rel_table.'_lookup_settings')) && !is_array($vs_display_format)) {
if ($vs_display_format && is_string($vs_display_format) && !preg_match_all('!\^{1}([A-Za-z0-9\._]+)!', $vs_display_format, $va_matches)) {
$vs_display_format = '^'.$vs_rel_table.'.preferred_labels';
$va_bundles = array($vs_rel_table.'.preferred_labels');
} else {
$va_bundles = $va_matches[1];
}
} else {
if (is_array($va_display_format = $o_config->getList($vs_rel_table.'_lookup_settings'))) {
$vb_use_new_display_format = true;
if(!($vs_display_delimiter = $o_config->get($vs_rel_table.'_lookup_delimiter'))) {
$vs_display_delimiter = ' ';
} else {
$vs_display_delimiter = " {$vs_display_delimiter} ";
}
foreach($va_display_format as $vs_display_element) {
if (preg_match_all('!\^{1}([A-Za-z0-9\._]+)!', $vs_display_element, $va_matches)) {
$va_bundles = array_merge($va_bundles, $va_matches[1]);
}
}
}
}
$ca_relationship_lookup_parse_cache[$vs_rel_table] = array(
'bundles' => $va_bundles,
'display_format' => $va_display_format,
'delimiter' => $vs_display_delimiter
);
}
$va_related_item_info = $va_parent_ids = $va_hierarchy_ids = array();
$va_items = array();
$o_dm = Datamodel::load();
$t_rel = $o_dm->getInstanceByTableName($vs_rel_table, true);
$vs_type_id_fld = method_exists($t_rel, 'getTypeFieldName') ? $t_rel->getTypeFieldName() : null;
while($qr_rel_items->nextHit()) {
$vn_id = $qr_rel_items->get("{$vs_rel_table}.{$vs_rel_pk}");
if(in_array($vn_id, $va_exclude)) { continue; }
$va_item = array(
'id' => $vn_id,
$vs_rel_pk => $vn_id
);
if ($vs_type_id_fld) {
$va_item['type_id'] = $qr_rel_items->get("{$vs_rel_table}.{$vs_type_id_fld}");
}
if ($vb_use_new_display_format) {
$va_display_value = $va_display_format;
} else {
$vs_display_value = $vs_display_format;
}
foreach($va_bundles as $vs_bundle_name) {
if (in_array($vs_bundle_name, array('_parent', '_hierarchy'))) { continue;}
if (!($vs_value = trim($qr_rel_items->get($vs_bundle_name)))) {
if ((!isset($pa_options['stripTags']) || !$pa_options['stripTags']) && (sizeof($va_tmp = explode('.', $vs_bundle_name)) == 3)) { // is tag media?
$vs_value = trim($qr_rel_items->getMediaTag($va_tmp[0].'.'.$va_tmp[1], $va_tmp[2]));
}
}
if ($vb_use_new_display_format) {
foreach($va_display_value as $vn_x => $vs_display_element) {
$va_display_value[$vn_x] = str_replace("^{$vs_bundle_name}", $vs_value, $vs_display_element);
}
} else {
if ($vs_display_format) {
$vs_display_value = str_replace("^{$vs_bundle_name}", htmlspecialchars($vs_value), $vs_display_value);
} else {
$vs_display_value .= $vs_value.' ';
}
}
}
if ($vb_is_hierarchical) {
if ($vn_parent_id = $qr_rel_items->get("{$vs_rel_table}.{$vs_hier_parent_id_fld}")) {
$va_parent_ids[$vn_id] = $vn_parent_id;
} else {
if ($pt_rel->getHierarchyType() != __CA_HIER_TYPE_ADHOC_MONO__) { // don't show root for hierarchies unless it's adhoc (where the root is a valid record)
continue;
}
}
if ($vs_hier_fld) {
$va_hierarchy_ids[$vn_id] = $qr_rel_items->get("{$vs_rel_table}.{$vs_hier_fld}");
}
}
if ($vb_use_new_display_format) {
$va_related_item_info[$vn_id] = $va_display_value;
} else {
$va_related_item_info[$vn_id] = $vs_display_value;
}
$va_items[$vn_id] = $va_item;
}
$va_hierarchies = (method_exists($pt_rel, "getHierarchyList")) ? $pt_rel->getHierarchyList() : array();
// Get root entries for hierarchies and remove from labels (we don't want to show the root labels – they are not meant for display)
if (is_array($va_hierarchies)) {
foreach($va_hierarchies as $vn_root_id => $va_hier_info) {
foreach($va_parent_ids as $vn_item_id => $vn_parent_id) {
if ($vn_parent_id == $va_hier_info[$vs_rel_pk]) {
unset($va_parent_ids[$vn_item_id]);
}
}
}
}
if (method_exists($pt_rel, "getPreferredDisplayLabelsForIDs")) {
$va_parent_labels = $pt_rel->getPreferredDisplayLabelsForIDs($va_parent_ids);
} else {
$va_parent_labels = array();
}
if (isset($pa_options['relatedItems']) && is_array($pa_options['relatedItems'])) {
$va_tmp = array();
foreach ($pa_options['relatedItems'] as $vn_relation_id => $va_relation) {
$va_items[$va_relation[$vs_rel_pk]]['relation_id'] = $vn_relation_id;
$va_items[$va_relation[$vs_rel_pk]]['relationship_type_id'] = $va_items[$va_relation[$vs_rel_pk]]['type_id'] = $va_relation['relationship_type_id'];
$va_items[$va_relation[$vs_rel_pk]]['relationship_typename'] = $va_relation['relationship_typename'];
$va_items[$va_relation[$vs_rel_pk]]['idno'] = $va_relation[$vs_idno_fld];
$va_items[$va_relation[$vs_rel_pk]]['idno_sort'] = $va_relation[$vs_idno_sort_fld];
$va_items[$va_relation[$vs_rel_pk]]['label'] = $va_relation['label'];
$va_items[$va_relation[$vs_rel_pk]]['direction'] = $va_relation['direction'];
if (isset($va_relation['surname'])) { // pass forename and surname entity label fields to support proper sorting by name
$va_items[$va_relation[$vs_rel_pk]]['surname'] = $va_relation['surname'];
$va_items[$va_relation[$vs_rel_pk]]['forename'] = $va_relation['forename'];
}
$va_tmp[$vn_relation_id] = $va_items[$va_relation[$vs_rel_pk]];
}
$va_items = $va_tmp;
unset($va_tmp);
}
foreach ($va_items as $va_item) {
$vn_id = $va_item[$vs_rel_pk];
if(in_array($vn_id, $va_exclude)) { continue; }
$va_tmp = $va_related_item_info;
if ($vb_use_new_display_format) {
$vs_parent = $va_parent_labels[$va_parent_ids[$vn_id]];
$vs_hier = $va_hierarchies[$va_hierarchy_ids[$vn_id]]['name_plural'] ? $va_hierarchies[$va_hierarchy_ids[$vn_id]]['name_plural'] : $va_hierarchies[$va_hierarchy_ids[$vn_id]]['name'];
foreach($va_related_item_info[$vn_id] as $vn_x => $vs_display_value) {
$vs_display_value = str_replace("^_parent", $vs_parent, $vs_display_value);
$va_tmp[$vn_id][$vn_x] = str_replace("^_hierarchy", $vs_hier, $vs_display_value);
if (!strlen(trim($va_tmp[$vn_id][$vn_x]))) { unset($va_tmp[$vn_id][$vn_x]); }
}
$va_tmp[$vn_id] = join($vs_display_delimiter, $va_tmp[$vn_id]);
} else {
$va_tmp[$vn_id] = str_replace('^_parent', $va_parent_labels[$va_parent_ids[$vn_id]], $va_tmp[$vn_id]);
$va_tmp[$vn_id] = str_replace('^_hierarchy', $va_hierarchies[$va_hierarchy_ids[$vn_id]]['name_plural'] ? $va_hierarchies[$va_hierarchy_ids[$vn_id]]['name_plural'] : $va_hierarchies[$va_hierarchy_ids[$vn_id]]['name'], $va_tmp[$vn_id]);
}
$vs_display = trim(preg_replace("![\n\r]+!", " ", $va_tmp[$vn_id]));
if (isset($pa_options['stripTags']) && $pa_options['stripTags']) {
if (preg_match('!(<[A-Za-z0-9]+[ ]+[A-Za-z0-9 ,;\&\-_]*>)!', $vs_display, $va_matches)) { // convert text in <> to non-tags if the text has only letters, numbers and spaces in it
array_shift($va_matches);
foreach($va_matches as $vs_match) {
$vs_display = str_replace($vs_match, htmlspecialchars($vs_match), $vs_display);
}
}
$vs_display = trim(strip_tags($vs_display));
$vs_label = $va_item['label'];
if (preg_match('!(<[A-Za-z0-9]+[ ]+[A-Za-z0-9 ,;\&\-_]*>)!', $vs_label, $va_matches)) { // convert text in <> to non-tags if the text has only letters, numbers and spaces in it
array_shift($va_matches);
foreach($va_matches as $vs_match) {
$vs_label = str_replace($vs_match, htmlspecialchars($vs_match), $vs_label);
}
}
$va_item['label'] = trim(strip_tags($vs_label));
}
$va_initial_values[$va_item['relation_id'] ? (int)$va_item['relation_id'] : $va_item[$vs_rel_pk]] = array_merge(
$va_item,
array(
'_display' => $vs_display
)
);
}
return $va_initial_values;
}
# ------------------------------------------------------------------------------------------------
?>