Example #1
0
 /**
  * Get a field value of the table row that is represented by this object.
  *
  * @param string $ps_field field name
  * @param array $pa_options options array; can be omitted.
  * It should be an associative array of boolean (except one of the options) flags. In case that some of the options are not set, they are treated as 'false'.
  * Possible options (keys) are:
  * 		BINARY: return field value as is
  * 		FILTER_HTML_SPECIAL_CHARS: convert all applicable chars to their html entities
  * 		DONT_PROCESS_GLOSSARY_TAGS: ?
  * 		CONVERT_HTML_BREAKS: similar to nl2br()
  * 		convertLineBreaks: same as CONVERT_HTML_BREAKS
  * 		getDirectDate: return raw date value from database if $ps_field adresses a date field, otherwise the value will be parsed using the TimeExpressionParser::getText() method
  * 		getDirectTime: return raw time value from database if $ps_field adresses a time field, otherwise the value will be parsed using the TimeExpressionParser::getText() method
  * 		TIMECODE_FORMAT: set return format for fields representing time ranges possible (string) values: COLON_DELIMITED, HOURS_MINUTES_SECONDS, RAW; data will be passed through floatval() by default
  * 		QUOTE: set return value into quotes
  * 		URL_ENCODE: value will be passed through urlencode()
  * 		ESCAPE_FOR_XML: convert <, >, &, ' and " characters for XML use
  * 		DONT_STRIP_SLASHES: if set to true, return value will not be passed through stripslashes()
  * 		template: formatting string to use for returned value; ^<fieldname> placeholder is used to represent field value in template
  * 		returnAsArray: if true, fields that can return multiple values [currently only <table_name>.children.<field>] will return values in an indexed array; default is false
  * 		returnAllLocales:
  * 		delimiter: if set, value is used as delimiter when fields that can return multiple fields are returned as strings; default is a single space
  * 		convertCodesToDisplayText: if set, id values refering to foreign keys are returned as preferred label text in the current locale
  * 		returnURL: if set then url is returned for media, otherwise an HTML tag for display is returned
  * 		dateFormat: format to return created or lastModified dates in. Valid values are iso8601 or text
  *		checkAccess = array of access values to filter results by; if defined only items with the specified access code(s) are returned. Only supported for table that have an "access" field.
  *		sort = optional field to sort returned values on. The field specifiers are fields with or without table name specified.	 
  *		sort_direction = direction to sort results by, either 'asc' for ascending order or 'desc' for descending order; default is 'asc'	 
  */
 public function get($ps_field, $pa_options = null)
 {
     if (!$ps_field) {
         return null;
     }
     if (!is_array($pa_options)) {
         $pa_options = array();
     }
     $vb_return_as_array = caGetOption('returnAsArray', $pa_options, false);
     $vb_return_with_structure = caGetOption('returnWithStructure', $pa_options, false);
     $vb_return_all_locales = caGetOption('returnAllLocales', $pa_options, false);
     $vs_delimiter = caGetOption('delimiter', $pa_options, ' ');
     if (($vb_return_with_structure || $vb_return_all_locales) && !$vb_return_as_array) {
         $vb_return_as_array = true;
     }
     $vn_row_id = $this->getPrimaryKey();
     if ($vb_return_as_array && $vb_return_as_array) {
         $vn_locale_id = $this->hasField('locale_id') ? $this->get('locale_id') : null;
     }
     $va_tmp = explode('.', $ps_field);
     if (sizeof($va_tmp) > 1) {
         if ($va_tmp[0] === $this->tableName()) {
             //
             // Return created on or last modified
             //
             if (in_array($va_tmp[1], array('created', 'lastModified'))) {
                 if ($vb_return_as_array) {
                     return $va_tmp[1] == 'lastModified' ? $this->getLastChangeTimestamp() : $this->getCreationTimestamp();
                 } else {
                     $va_data = $va_tmp[1] == 'lastModified' ? $this->getLastChangeTimestamp() : $this->getCreationTimestamp();
                     $vs_subfield = isset($va_tmp[2]) && isset($va_data[$va_tmp[2]]) ? $va_tmp[2] : 'timestamp';
                     $vm_val = $va_data[$vs_subfield];
                     if ($vs_subfield == 'timestamp') {
                         $o_tep = new TimeExpressionParser();
                         $o_tep->setUnixTimestamps($vm_val, $vm_val);
                         $vm_val = $o_tep->getText($pa_options);
                     }
                     return $vm_val;
                 }
             }
             //
             // Generalized get
             //
             $va_field_info = $this->getFieldInfo($va_tmp[1]);
             switch (sizeof($va_tmp)) {
                 case 2:
                     // support <table_name>.<field_name> syntax
                     $ps_field = $va_tmp[1];
                     break;
                 default:
                     // > 2 elements
                     // media field?
                     if ($va_field_info['FIELD_TYPE'] === FT_MEDIA && !isset($pa_options['returnAsArray']) && !$pa_options['returnAsArray']) {
                         $o_media_settings = new MediaProcessingSettings($va_tmp[0], $va_tmp[1]);
                         $va_versions = $o_media_settings->getMediaTypeVersions('*');
                         $vs_version = $va_tmp[2];
                         if (!isset($va_versions[$vs_version])) {
                             $va_available_versions = array_keys($va_versions);
                             $vs_version = $va_tmp[2] = array_shift($va_available_versions);
                         }
                         if (isset($va_tmp[3])) {
                             return $this->getMediaInfo($va_tmp[1], $vs_version, 'width');
                         } else {
                             if (isset($pa_options['returnURL']) && $pa_options['returnURL']) {
                                 return $this->getMediaUrl($va_tmp[1], $vs_version, $pa_options);
                             } else {
                                 return $this->getMediaTag($va_tmp[1], $vs_version, $pa_options);
                             }
                         }
                     }
                     if ($va_tmp[1] == 'parent' && $this->isHierarchical() && ($vn_parent_id = $this->get($this->getProperty('HIERARCHY_PARENT_ID_FLD')))) {
                         $t_instance = $this->getAppDatamodel()->getInstanceByTableNum($this->tableNum());
                         if (!$t_instance->load($vn_parent_id)) {
                             return $vb_return_as_array ? array() : null;
                         } else {
                             unset($va_tmp[1]);
                             $va_tmp = array_values($va_tmp);
                             if ($vb_return_as_array) {
                                 if ($vb_return_all_locales) {
                                     return array($vn_row_id => array($vn_locale_id => array($t_instance->get(join('.', $va_tmp)))));
                                 } else {
                                     return array($vn_row_id => $t_instance->get(join('.', $va_tmp)));
                                 }
                             } else {
                                 return $t_instance->get(join('.', $va_tmp));
                             }
                         }
                     } else {
                         if ($va_tmp[1] == 'children' && $this->isHierarchical()) {
                             $vb_check_access = is_array($pa_options['checkAccess']) && $this->hasField('access');
                             $va_sort = isset($pa_options['sort']) ? $pa_options['sort'] : null;
                             if (!is_array($va_sort) && $va_sort) {
                                 $va_sort = array($va_sort);
                             }
                             if (!is_array($va_sort)) {
                                 $va_sort = array();
                             }
                             $vs_sort_direction = isset($pa_options['sort_direction']) && in_array(strtolower($pa_options['sort_direction']), array('asc', 'desc')) ? strtolower($pa_options['sort_direction']) : 'asc';
                             unset($va_tmp[1]);
                             // remove 'children' from field path
                             $va_tmp = array_values($va_tmp);
                             $vs_childless_path = join('.', $va_tmp);
                             $va_data = array();
                             $va_children_ids = $this->getHierarchyChildren(null, array('idsOnly' => true));
                             if (is_array($va_children_ids) && sizeof($va_children_ids)) {
                                 $t_instance = $this->getAppDatamodel()->getInstanceByTableNum($this->tableNum());
                                 if ($va_tmp[1] == $this->primaryKey() && !$vs_sort) {
                                     foreach ($va_children_ids as $vn_child_id) {
                                         $va_data[$vn_child_id] = $vn_child_id;
                                     }
                                 } else {
                                     if (method_exists($this, "makeSearchResult")) {
                                         // Use SearchResult lazy loading when available
                                         $vs_table = $this->tableName();
                                         $vs_pk = $vs_table . '.' . $this->primaryKey();
                                         $qr_children = $this->makeSearchResult($this->tableName(), $va_children_ids);
                                         while ($qr_children->nextHit()) {
                                             if ($vb_check_access && !in_array($qr_children->get("{$vs_table}.access"), $pa_options['checkAccess'])) {
                                                 continue;
                                             }
                                             $vn_child_id = $qr_children->get($vs_pk);
                                             $vs_sort_key = '';
                                             foreach ($va_sort as $vs_sort) {
                                                 $vs_sort_key .= $vs_sort ? $qr_children->get($vs_sort) : 0;
                                             }
                                             if (!is_array($va_data[$vs_sort_key])) {
                                                 $va_data[$vs_sort_key] = array();
                                             }
                                             if ($vb_return_as_array) {
                                                 $va_data[$vs_sort_key][$vn_child_id] = array_shift($qr_children->get($vs_childless_path, array_merge($pa_options, array('returnAsArray' => $vb_return_as_array, 'returnAllLocales' => $vb_return_all_locales))));
                                             } else {
                                                 $va_data[$vs_sort_key][$vn_child_id] = $qr_children->get($vs_childless_path, array_merge($pa_options, array('returnAsArray' => false, 'returnAllLocales' => false)));
                                             }
                                         }
                                         ksort($va_data);
                                         if ($vs_sort_direction && $vs_sort_direction == 'desc') {
                                             $va_data = array_reverse($va_data);
                                         }
                                         $va_sorted_data = array();
                                         foreach ($va_data as $vs_sort_key => $va_items) {
                                             foreach ($va_items as $vs_k => $vs_v) {
                                                 $va_sorted_data[] = $vs_v;
                                             }
                                         }
                                         $va_data = $va_sorted_data;
                                     } else {
                                         // Fall-back to loading records row-by-row (slow)
                                         foreach ($va_children_ids as $vn_child_id) {
                                             if ($t_instance->load($vn_child_id)) {
                                                 if ($vb_check_access && !in_array($t_instance->get("access"), $pa_options['checkAccess'])) {
                                                     continue;
                                                 }
                                                 $vs_sort_key = $vs_sort ? $t_instance->get($vs_sort) : 0;
                                                 if (!is_array($va_data[$vs_sort_key])) {
                                                     $va_data[$vs_sort_key] = array();
                                                 }
                                                 if ($vb_return_as_array) {
                                                     $va_data[$vs_sort_key][$vn_child_id] = array_shift($t_instance->get($vs_childless_path, array_merge($pa_options, array('returnAsArray' => $vb_return_as_array, 'returnAllLocales' => $vb_return_all_locales))));
                                                 } else {
                                                     $va_data[$vs_sort_key][$vn_child_id] = $t_instance->get($vs_childless_path, array_merge($pa_options, array('returnAsArray' => false, 'returnAllLocales' => false)));
                                                 }
                                             }
                                         }
                                         ksort($va_data);
                                         if ($vs_sort_direction && $vs_sort_direction == 'desc') {
                                             $va_data = array_reverse($va_data);
                                         }
                                         $va_sorted_data = array();
                                         foreach ($va_data as $vs_sort_key => $va_items) {
                                             foreach ($va_items as $vs_k => $vs_v) {
                                                 $va_sorted_data[] = $vs_v;
                                             }
                                         }
                                         $va_data = $va_sorted_data;
                                     }
                                 }
                             }
                             if ($vb_return_as_array) {
                                 return $va_data;
                             } else {
                                 return join($vs_delimiter, $va_data);
                             }
                         }
                     }
                     break;
             }
         } else {
             $va_rels = $this->getRelatedItems($va_tmp[0]);
             $va_vals = array();
             if (is_array($va_rels)) {
                 foreach ($va_rels as $va_rel_item) {
                     if (isset($va_rel_item[$va_tmp[1]])) {
                         $va_vals[] = $va_rel_item[$va_tmp[1]];
                     }
                 }
                 return $vb_return_as_array ? $va_vals : join($vs_delimiter, $va_vals);
             }
             // can't pull fields from other tables!
             return $vb_return_as_array ? array() : null;
         }
     }
     if (isset($pa_options["BINARY"]) && $pa_options["BINARY"]) {
         return $this->_FIELD_VALUES[$ps_field];
     }
     if (array_key_exists($ps_field, $this->FIELDS)) {
         $ps_field_type = $this->getFieldInfo($ps_field, "FIELD_TYPE");
         if ($this->getFieldInfo($ps_field, 'IS_LIFESPAN')) {
             $pa_options['isLifespan'] = true;
         }
         switch ($ps_field_type) {
             case FT_BIT:
                 $vs_prop = isset($this->_FIELD_VALUES[$ps_field]) ? $this->_FIELD_VALUES[$ps_field] : "";
                 if (isset($pa_options['convertCodesToDisplayText']) && $pa_options['convertCodesToDisplayText']) {
                     $vs_prop = (bool) $vs_prop ? _t('yes') : _t('no');
                 }
                 return $vs_prop;
                 break;
             case FT_TEXT:
             case FT_NUMBER:
             case FT_PASSWORD:
                 $vs_prop = isset($this->_FIELD_VALUES[$ps_field]) ? $this->_FIELD_VALUES[$ps_field] : null;
                 if (isset($pa_options["FILTER_HTML_SPECIAL_CHARS"]) && $pa_options["FILTER_HTML_SPECIAL_CHARS"]) {
                     $vs_prop = htmlentities(html_entity_decode($vs_prop));
                 }
                 //
                 // Convert foreign keys and choice list values to display text is needed
                 //
                 if (isset($pa_options['convertCodesToDisplayText']) && $pa_options['convertCodesToDisplayText'] && ($vs_list_code = $this->getFieldInfo($ps_field, "LIST_CODE"))) {
                     $t_list = new ca_lists();
                     $vs_prop = $t_list->getItemFromListForDisplayByItemID($vs_list_code, $vs_prop);
                 } else {
                     if (isset($pa_options['convertCodesToDisplayText']) && $pa_options['convertCodesToDisplayText'] && ($vs_list_code = $this->getFieldInfo($ps_field, "LIST"))) {
                         $t_list = new ca_lists();
                         if (!($vs_tmp = $t_list->getItemFromListForDisplayByItemValue($vs_list_code, $vs_prop))) {
                             if ($vs_tmp = $this->getChoiceListValue($ps_field, $vs_prop)) {
                                 $vs_prop = $vs_tmp;
                             }
                         } else {
                             $vs_prop = $vs_tmp;
                         }
                     } else {
                         if (isset($pa_options['convertCodesToDisplayText']) && $pa_options['convertCodesToDisplayText'] && $ps_field === 'locale_id' && (int) $vs_prop > 0) {
                             $t_locale = new ca_locales($vs_prop);
                             $vs_prop = $t_locale->getName();
                         } else {
                             if (isset($pa_options['convertCodesToDisplayText']) && $pa_options['convertCodesToDisplayText'] && is_array($va_list = $this->getFieldInfo($ps_field, "BOUNDS_CHOICE_LIST"))) {
                                 foreach ($va_list as $vs_option => $vs_value) {
                                     if ($vs_value == $vs_prop) {
                                         $vs_prop = $vs_option;
                                         break;
                                     }
                                 }
                             }
                         }
                     }
                 }
                 if (isset($pa_options["CONVERT_HTML_BREAKS"]) && $pa_options["CONVERT_HTML_BREAKS"] || isset($pa_options["convertLineBreaks"]) && $pa_options["convertLineBreaks"]) {
                     $vs_prop = caConvertLineBreaks($vs_prop);
                 }
                 break;
             case FT_DATETIME:
             case FT_TIMESTAMP:
             case FT_HISTORIC_DATETIME:
             case FT_HISTORIC_DATE:
             case FT_DATE:
                 $vn_timestamp = isset($this->_FIELD_VALUES[$ps_field]) ? $this->_FIELD_VALUES[$ps_field] : 0;
                 if ($vb_return_with_structure) {
                     $vs_prop = array('start' => $this->_FIELD_VALUES[$ps_field], 'end' => $this->_FIELD_VALUES[$ps_field]);
                 } elseif (caGetOption('GET_DIRECT_DATE', $pa_options, false) || caGetOption('getDirectDate', $pa_options, false) || caGetOption('rawDate', $pa_options, false)) {
                     $vs_prop = $this->_FIELD_VALUES[$ps_field];
                 } elseif (isset($pa_options['sortable']) && $pa_options['sortable']) {
                     $vs_prop = $vn_timestamp . "/" . $vn_timestamp;
                 } else {
                     $o_tep = new TimeExpressionParser();
                     if ($ps_field_type == FT_HISTORIC_DATETIME || $ps_field_type == FT_HISTORIC_DATE) {
                         $o_tep->setHistoricTimestamps($vn_timestamp, $vn_timestamp);
                     } else {
                         $o_tep->setUnixTimestamps($vn_timestamp, $vn_timestamp);
                     }
                     if ($ps_field_type == FT_DATE || $ps_field_type == FT_HISTORIC_DATE) {
                         $vs_prop = $o_tep->getText(array_merge(array('timeOmit' => true), $pa_options));
                     } else {
                         $vs_prop = $o_tep->getText($pa_options);
                     }
                 }
                 break;
             case FT_TIME:
                 if ($vb_return_with_structure) {
                     $vs_prop = array('start' => $this->_FIELD_VALUES[$ps_field], 'end' => $this->_FIELD_VALUES[$ps_field]);
                 } elseif (caGetOption('GET_DIRECT_TIME', $pa_options, false) || caGetOption('getDirectTime', $pa_options, false) || caGetOption('rawTime', $pa_options, false)) {
                     $vs_prop = $this->_FIELD_VALUES[$ps_field];
                 } else {
                     $o_tep = new TimeExpressionParser();
                     $vn_timestamp = isset($this->_FIELD_VALUES[$ps_field]) ? $this->_FIELD_VALUES[$ps_field] : 0;
                     $o_tep->setTimes($vn_timestamp, $vn_timestamp);
                     $vs_prop = $o_tep->getText($pa_options);
                 }
                 break;
             case FT_DATERANGE:
             case FT_HISTORIC_DATERANGE:
                 $vs_start_field_name = $this->getFieldInfo($ps_field, "START");
                 $vs_end_field_name = $this->getFieldInfo($ps_field, "END");
                 $vn_start_date = isset($this->_FIELD_VALUES[$vs_start_field_name]) ? $this->_FIELD_VALUES[$vs_start_field_name] : null;
                 $vn_end_date = isset($this->_FIELD_VALUES[$vs_end_field_name]) ? $this->_FIELD_VALUES[$vs_end_field_name] : null;
                 if ($vb_return_with_structure) {
                     $vs_prop = array('start' => $vn_start_date, 'end' => $vn_end_date);
                 } elseif (!caGetOption('GET_DIRECT_DATE', $pa_options, false) && !caGetOption('getDirectDate', $pa_options, false) && !caGetOption('rawDate', $pa_options, false)) {
                     $o_tep = new TimeExpressionParser();
                     if ($ps_field_type == FT_HISTORIC_DATERANGE) {
                         $o_tep->setHistoricTimestamps($vn_start_date, $vn_end_date);
                     } else {
                         $o_tep->setUnixTimestamps($vn_start_date, $vn_end_date);
                     }
                     $vs_prop = $o_tep->getText($pa_options);
                 } elseif (isset($pa_options['sortable']) && $pa_options['sortable']) {
                     $vs_prop = $vn_start_date;
                     //."/".$vn_timestamp;
                 } else {
                     $vs_prop = $vn_start_date;
                     //array($vn_start_date, $vn_end_date);
                 }
                 break;
             case FT_TIMERANGE:
                 $vs_start_field_name = $this->getFieldInfo($ps_field, "START");
                 $vs_end_field_name = $this->getFieldInfo($ps_field, "END");
                 $vn_start_date = isset($this->_FIELD_VALUES[$vs_start_field_name]) ? $this->_FIELD_VALUES[$vs_start_field_name] : null;
                 $vn_end_date = isset($this->_FIELD_VALUES[$vs_end_field_name]) ? $this->_FIELD_VALUES[$vs_end_field_name] : null;
                 if ($vb_return_with_structure) {
                     $vs_prop = array('start' => $vn_start_date, 'end' => $vn_end_date);
                 } elseif (!caGetOption('GET_DIRECT_TIME', $pa_options, false) && !caGetOption('getDirectTime', $pa_options, false) && !caGetOption('rawTime', $pa_options, false)) {
                     $o_tep = new TimeExpressionParser();
                     $o_tep->setTimes($vn_start_date, $vn_end_date);
                     $vs_prop = $o_tep->getText($pa_options);
                 } else {
                     $vs_prop = array($vn_start_date, $vn_end_date);
                 }
                 break;
             case FT_TIMECODE:
                 $o_tp = new TimecodeParser();
                 $o_tp->setParsedValueInSeconds($this->_FIELD_VALUES[$ps_field]);
                 $vs_prop = $o_tp->getText(isset($pa_options["TIMECODE_FORMAT"]) ? $pa_options["TIMECODE_FORMAT"] : null);
                 break;
             case FT_MEDIA:
             case FT_FILE:
                 if ($vb_return_with_structure || $pa_options["USE_MEDIA_FIELD_VALUES"]) {
                     if (isset($pa_options["USE_MEDIA_FIELD_VALUES"]) && $pa_options["USE_MEDIA_FIELD_VALUES"]) {
                         $vs_prop = $this->_FIELD_VALUES[$ps_field];
                     } else {
                         $vs_prop = isset($this->_SET_FILES[$ps_field]['tmp_name']) && $this->_SET_FILES[$ps_field]['tmp_name'] ? $this->_SET_FILES[$ps_field]['tmp_name'] : $this->_FIELD_VALUES[$ps_field];
                     }
                 } else {
                     $va_versions = $this->getMediaVersions($ps_field);
                     $vs_tag = $this->getMediaTag($ps_field, array_shift($va_versions));
                     if ($vb_return_as_array) {
                         return array($vs_tag);
                     } else {
                         return $vs_tag;
                     }
                 }
                 break;
             case FT_VARS:
                 $vs_prop = isset($this->_FIELD_VALUES[$ps_field]) && $this->_FIELD_VALUES[$ps_field] ? $this->_FIELD_VALUES[$ps_field] : null;
                 break;
         }
         if (isset($pa_options["QUOTE"]) && $pa_options["QUOTE"]) {
             $vs_prop = $this->quote($ps_field, $vs_prop);
         }
     } else {
         $this->postError(710, _t("'%1' does not exist in this object", $ps_field), "BaseModel->get()");
         return $vb_return_as_array ? array() : null;
     }
     if (isset($pa_options["URL_ENCODE"]) && $pa_options["URL_ENCODE"]) {
         $vs_prop = urlEncode($vs_prop);
     }
     if (isset($pa_options["ESCAPE_FOR_XML"]) && $pa_options["ESCAPE_FOR_XML"]) {
         $vs_prop = caEscapeForXML($vs_prop);
     }
     if (!(isset($pa_options["DONT_STRIP_SLASHES"]) && $pa_options["DONT_STRIP_SLASHES"])) {
         if (is_string($vs_prop)) {
             $vs_prop = stripSlashes($vs_prop);
         }
     }
     if (isset($pa_options["template"]) && $pa_options["template"]) {
         $vs_template_with_substitution = str_replace("^" . $ps_field, $vs_prop, $pa_options["template"]);
         $vs_prop = str_replace("^" . $this->tableName() . "." . $ps_field, $vs_prop, $vs_template_with_substitution);
     }
     if ($vb_return_as_array) {
         if ($vb_return_all_locales) {
             return array($vn_row_id => array($vn_locale_id => array($vs_prop)));
         } else {
             return array($vn_row_id => $vs_prop);
         }
     } else {
         return $vs_prop;
     }
 }
 /**
  *
  */
 private function _getChangeLogFromRawData($pa_data, $pn_table_num, $pa_options = null)
 {
     //print "<pre>".print_r($pa_data, true)."</pre>\n";
     $va_log_output = array();
     $vs_blank_placeholder = '&lt;' . _t('BLANK') . '&gt;';
     if (!$pa_options) {
         $pa_options = array();
     }
     if (sizeof($pa_data)) {
         //
         // Init
         //
         $o_datamodel = Datamodel::load();
         $va_change_types = array('I' => _t('Added'), 'U' => _t('Edited'), 'D' => _t('Deleted'));
         $vs_label_table_name = $vs_label_display_name = '';
         $t_item = $o_datamodel->getInstanceByTableNum($pn_table_num, true);
         $vs_label_table_name = $vn_label_table_num = $vs_label_display_name = null;
         if (method_exists($t_item, 'getLabelTableName')) {
             $t_item_label = $t_item->getLabelTableInstance();
             $vs_label_table_name = $t_item->getLabelTableName();
             $vn_label_table_num = $t_item_label->tableNum();
             $vs_label_display_name = $t_item_label->getProperty('NAME_SINGULAR');
         }
         //
         // Group data by unit
         //
         $va_grouped_data = array();
         foreach ($pa_data as $va_log_entry) {
             $va_grouped_data[$va_log_entry['unit_id']]['ca_table_num_' . $va_log_entry['logged_table_num']][] = $va_log_entry;
         }
         //
         // Process units
         //
         $va_attributes = array();
         foreach ($va_grouped_data as $vn_unit_id => $va_log_entries_by_table) {
             foreach ($va_log_entries_by_table as $vs_table_key => $va_log_entries) {
                 foreach ($va_log_entries as $va_log_entry) {
                     $va_changes = array();
                     if (!is_array($va_log_entry['snapshot'])) {
                         $va_log_entry['snapshot'] = array();
                     }
                     //
                     // Get date/time stamp for display
                     //
                     $vs_datetime = date("n/d/Y@g:i:sa T", $va_log_entry['log_datetime']);
                     //
                     // Get user name
                     //
                     $vs_user = $va_log_entry['fname'] . ' ' . $va_log_entry['lname'];
                     $vs_email = $va_log_entry['email'];
                     // The "logged" table/row is the row to which the change was actually applied
                     // The "subject" table/row is the row to which the change is considered to have been made for workflow purposes.
                     //
                     // For example: if an entity is related to an object, strictly speaking the logging occurs on the ca_objects_x_entities
                     // row (ca_objects_x_entities is the "logged" table), but the subject is ca_objects since it's only in the context of the
                     // object (and probably the ca_entities row as well) that you can about the change.
                     //
                     $t_obj = $o_datamodel->getInstanceByTableNum($va_log_entry['logged_table_num'], true);
                     // get instance for logged table
                     if (!$t_obj) {
                         continue;
                     }
                     $vs_subject_display_name = '???';
                     $vn_subject_row_id = null;
                     $vn_subject_table_num = null;
                     if (isset($pa_options['return_item_names']) && $pa_options['return_item_names']) {
                         if (!($vn_subject_table_num = $va_log_entry['subject_table_num'])) {
                             $vn_subject_table_num = $va_log_entry['logged_table_num'];
                             $vn_subject_row_id = $va_log_entry['logged_row_id'];
                         } else {
                             $vn_subject_row_id = $va_log_entry['subject_row_id'];
                         }
                         if ($t_subject = $o_datamodel->getInstanceByTableNum($vn_subject_table_num, true)) {
                             if ($t_subject->load($vn_subject_row_id)) {
                                 if (method_exists($t_subject, 'getLabelForDisplay')) {
                                     $vs_subject_display_name = $t_subject->getLabelForDisplay(false);
                                 } else {
                                     if ($vs_idno_field = $t_subject->getProperty('ID_NUMBERING_ID_FIELD')) {
                                         $vs_subject_display_name = $t_subject->getProperty('NAME_SINGULAR') . ' [' . $t_subject->get($vs_idno_field) . ']';
                                     } else {
                                         $vs_subject_display_name = $t_subject->getProperty('NAME_SINGULAR') . ' [' . $vn_subject_row_id . ']';
                                     }
                                 }
                             }
                         }
                     }
                     //
                     // Get item changes
                     //
                     // ---------------------------------------------------------------
                     // is this an intrinsic field?
                     if ($pn_table_num == $va_log_entry['logged_table_num']) {
                         foreach ($va_log_entry['snapshot'] as $vs_field => $vs_value) {
                             $va_field_info = $t_obj->getFieldInfo($vs_field);
                             if (isset($va_field_info['IDENTITY']) && $va_field_info['IDENTITY']) {
                                 continue;
                             }
                             if (isset($va_field_info['DISPLAY_TYPE']) && $va_field_info['DISPLAY_TYPE'] == DT_OMIT) {
                                 continue;
                             }
                             if (isset($va_field_info['DISPLAY_FIELD']) && is_array($va_field_info['DISPLAY_FIELD']) && ($va_disp_fields = $va_field_info['DISPLAY_FIELD'])) {
                                 //
                                 // Lookup value in related table
                                 //
                                 if (!$vs_value) {
                                     continue;
                                 }
                                 if (sizeof($va_disp_fields)) {
                                     $va_rel = $o_datamodel->getManyToOneRelations($t_obj->tableName(), $vs_field);
                                     $va_rel_values = array();
                                     if ($t_rel_obj = $o_datamodel->getTableInstance($va_rel['one_table'], true)) {
                                         $t_rel_obj->load($vs_value);
                                         foreach ($va_disp_fields as $vs_display_field) {
                                             $va_tmp = explode('.', $vs_display_field);
                                             if (($vs_tmp = $t_rel_obj->get($va_tmp[1])) !== '') {
                                                 $va_rel_values[] = $vs_tmp;
                                             }
                                         }
                                     }
                                     $vs_proc_val = join(', ', $va_rel_values);
                                 }
                             } else {
                                 // Is field a foreign key?
                                 $va_keys = $o_datamodel->getManyToOneRelations($t_obj->tableName(), $vs_field);
                                 if (sizeof($va_keys)) {
                                     // yep, it's a foreign key
                                     $va_rel_values = array();
                                     if ($t_rel_obj = $o_datamodel->getTableInstance($va_keys['one_table'], true)) {
                                         if ($t_rel_obj->load($vs_value)) {
                                             if (method_exists($t_rel_obj, 'getLabelForDisplay')) {
                                                 $vs_proc_val = $t_rel_obj->getLabelForDisplay(false);
                                             } else {
                                                 $va_disp_fields = $t_rel_obj->getProperty('LIST_FIELDS');
                                                 foreach ($va_disp_fields as $vs_display_field) {
                                                     if (($vs_tmp = $t_rel_obj->get($vs_display_field)) !== '') {
                                                         $va_rel_values[] = $vs_tmp;
                                                     }
                                                 }
                                                 $vs_proc_val = join(' ', $va_rel_values);
                                             }
                                             if (!$vs_proc_val) {
                                                 $vs_proc_val = '???';
                                             }
                                         } else {
                                             $vs_proc_val = _t("Not set");
                                         }
                                     } else {
                                         $vs_proc_val = _t('Non-existent');
                                     }
                                 } else {
                                     // Adjust display of value for different field types
                                     switch ($va_field_info['FIELD_TYPE']) {
                                         case FT_BIT:
                                             $vs_proc_val = $vs_value ? 'Yes' : 'No';
                                             break;
                                         default:
                                             $vs_proc_val = $vs_value;
                                             break;
                                     }
                                     // Adjust display of value for lists
                                     if ($va_field_info['LIST']) {
                                         $t_list = new ca_lists();
                                         if ($t_list->load(array('list_code' => $va_field_info['LIST']))) {
                                             $vn_list_id = $t_list->getPrimaryKey();
                                             $t_list_item = new ca_list_items();
                                             if ($t_list_item->load(array('list_id' => $vn_list_id, 'item_value' => $vs_value))) {
                                                 $vs_proc_val = $t_list_item->getLabelForDisplay();
                                             }
                                         }
                                     } else {
                                         if ($va_field_info['BOUNDS_CHOICE_LIST']) {
                                             // TODO
                                         }
                                     }
                                 }
                             }
                             $va_changes[] = array('label' => $va_field_info['LABEL'], 'description' => strlen((string) $vs_proc_val) ? $vs_proc_val : $vs_blank_placeholder, 'value' => $vs_value);
                         }
                     }
                     // ---------------------------------------------------------------
                     // is this a label row?
                     if ($va_log_entry['logged_table_num'] == $vn_label_table_num) {
                         foreach ($va_log_entry['snapshot'] as $vs_field => $vs_value) {
                             $va_changes[] = array('label' => $t_item_label->getFieldInfo($vs_field, 'LABEL'), 'description' => $vs_value);
                         }
                     }
                     // ---------------------------------------------------------------
                     // is this an attribute?
                     if ($va_log_entry['logged_table_num'] == 3) {
                         // attribute_values
                         if ($t_element = ca_attributes::getElementInstance($va_log_entry['snapshot']['element_id'])) {
                             if ($o_attr_val = Attribute::getValueInstance($t_element->get('datatype'))) {
                                 $o_attr_val->loadValueFromRow($va_log_entry['snapshot']);
                                 $vs_attr_val = $o_attr_val->getDisplayValue();
                             } else {
                                 $vs_attr_val = '?';
                             }
                             // Convert list-based attributes to text
                             if ($vn_list_id = $t_element->get('list_id')) {
                                 $t_list = new ca_lists();
                                 $vs_attr_val = $t_list->getItemFromListForDisplayByItemID($vn_list_id, $vs_attr_val, true);
                             }
                             if (!$vs_attr_val) {
                                 $vs_attr_val = $vs_blank_placeholder;
                             }
                             $vs_label = $t_element->getLabelForDisplay();
                             $va_attributes[$va_log_entry['snapshot']['attribute_id']]['values'][] = array('label' => $vs_label, 'value' => $vs_attr_val);
                             $va_changes[] = array('label' => $vs_label, 'description' => $vs_attr_val);
                         }
                     }
                     // ---------------------------------------------------------------
                     // is this a related (many-many) row?
                     $va_keys = $o_datamodel->getOneToManyRelations($t_item->tableName(), $t_obj->tableName());
                     if (sizeof($va_keys) > 0) {
                         if (method_exists($t_obj, 'getLeftTableNum')) {
                             if ($t_obj->getLeftTableNum() == $t_item->tableNum()) {
                                 // other side of rel is on right
                                 $t_related_table = $o_datamodel->getInstanceByTableNum($t_obj->getRightTableNum(), true);
                                 $t_related_table->load($va_log_entry['snapshot'][$t_obj->getRightTableFieldName()]);
                             } else {
                                 // other side of rel is on left
                                 $t_related_table = $o_datamodel->getInstanceByTableNum($t_obj->getLeftTableNum(), true);
                                 $t_related_table->load($va_log_entry['snapshot'][$t_obj->getLeftTableFieldName()]);
                             }
                             $t_rel = $o_datamodel->getInstanceByTableNum($t_obj->tableNum(), true);
                             $va_changes[] = array('label' => caUcFirstUTF8Safe($t_related_table->getProperty('NAME_SINGULAR')), 'idno' => ($vs_idno_field = $t_related_table->getProperty('ID_NUMBERING_ID_FIELD')) ? $t_related_table->get($vs_idno_field) : null, 'description' => $t_related_table->getLabelForDisplay(), 'table_name' => $t_related_table->tableName(), 'table_num' => $t_related_table->tableNum(), 'row_id' => $t_related_table->getPrimaryKey(), 'rel_type_id' => $va_log_entry['snapshot']['type_id'], 'rel_typename' => $t_rel->getRelationshipTypename('ltor', $va_log_entry['snapshot']['type_id']));
                         }
                     }
                     // ---------------------------------------------------------------
                     // record log line
                     if (sizeof($va_changes)) {
                         $va_log_output[$vn_unit_id][] = array('datetime' => $vs_datetime, 'user_fullname' => $vs_user, 'user_email' => $vs_email, 'user' => $vs_user . ' (' . $vs_email . ')', 'changetype_display' => $va_change_types[$va_log_entry['changetype']], 'changetype' => $va_log_entry['changetype'], 'changes' => $va_changes, 'subject' => $vs_subject_display_name, 'subject_id' => $vn_subject_row_id, 'subject_table_num' => $vn_subject_table_num, 'logged_table_num' => $va_log_entry['logged_table_num'], 'logged_table' => $t_obj->tableName(), 'logged_row_id' => $va_log_entry['logged_row_id']);
                     }
                 }
             }
         }
     }
     return $va_log_output;
 }
 public function lookup()
 {
     $vs_search = $this->request->getParameter('q', pString);
     $t_list = new ca_lists();
     $va_data = array();
     $va_access_values = caGetUserAccessValues($this->request);
     #
     # Do "quicksearches" on so-configured tables
     #
     if ($this->request->config->get('quicksearch_return_ca_objects')) {
         $va_results = caExtractValuesByUserLocale(SearchEngine::quickSearch($vs_search, 'ca_objects', 57, array('limit' => 3, 'checkAccess' => $va_access_values)));
         // break found objects out by type
         foreach ($va_results as $vn_id => $va_match_info) {
             $vs_type = unicode_ucfirst($t_list->getItemFromListForDisplayByItemID('object_types', $va_match_info['type_id'], true));
             $va_data['ca_objects'][$vs_type][$vn_id] = $va_match_info;
         }
     }
     if ($this->request->config->get('quicksearch_return_ca_entities')) {
         $va_data['ca_entities'][_t('Entities')] = caExtractValuesByUserLocale(SearchEngine::quickSearch($vs_search, 'ca_entities', 20, array('limit' => 10, 'checkAccess' => $va_access_values)));
     }
     if ($this->request->config->get('quicksearch_return_ca_places')) {
         $va_data['ca_places'][_t('Places')] = caExtractValuesByUserLocale(SearchEngine::quickSearch($vs_search, 'ca_places', 72, array('limit' => 10, 'checkAccess' => $va_access_values)));
     }
     if ($this->request->config->get('quicksearch_return_ca_occurrences')) {
         $va_results = caExtractValuesByUserLocale(SearchEngine::quickSearch($vs_search, 'ca_occurrences', 67, array('limit' => 10, 'checkAccess' => $va_access_values)));
         // break found occurrences out by type
         foreach ($va_results as $vn_id => $va_match_info) {
             $vs_type = unicode_ucfirst($t_list->getItemFromListForDisplayByItemID('occurrence_types', $va_match_info['type_id'], true));
             $va_data['ca_occurrences'][$vs_type][$vn_id] = $va_match_info;
         }
     }
     if ($this->request->config->get('quicksearch_return_ca_collections')) {
         $va_data['ca_collections'][_t('Collections')] = caExtractValuesByUserLocale(SearchEngine::quickSearch($vs_search, 'ca_collections', 13, array('limit' => 10, 'checkAccess' => $va_access_values)));
     }
     $this->view->setVar('matches', $va_data);
     $this->render('Search/ajax_search_lookup_json.php');
 }
    print "<div class='unit'><b>" . _t('Type Status') . ":</b> " . caReturnDefaultIfBlank($vs_track_type_status) . "</div>";
    $vs_cast = $t_object->get("ca_objects.cast_model", array("convertCodesToDisplayText" => true));
    print "<div class='unit'><b>" . _t('Cast') . ":</b> " . ($vs_cast ? $vs_cast : "No") . "</div>";
    #if($va_taxonomy = $t_object->get('ca_objects.taxonomic_rank' , array('convertCodesToDisplayText' => true))){
    #	print "<div class='unit'><b>"._t('Taxonomy').":</b> ".$va_taxonomy."</div>";
    #}
    if ($vn_taxonomy = $t_object->get('ca_objects.taxonomic_rank', array('idsOnly' => true))) {
        ?>
				<br><div class="unit"><h2>Taxonomy</h2></div>
<?php 
        $t_list_item = new ca_list_items();
        $va_hierarchy = caExtractValuesByUserLocale($t_list_item->getHierarchyAncestors($vn_taxonomy, array("includeSelf" => true, "additionalTableToJoin" => "ca_list_item_labels", "additionalTableSelectFields" => array("name_singular"))));
        $va_hierarchy = array_reverse($va_hierarchy);
        foreach ($va_hierarchy as $va_hier_taxonomy) {
            if ($va_hier_taxonomy["parent_id"]) {
                print "<div class='unit'><b>" . $t_lists->getItemFromListForDisplayByItemID("list_item_types", $va_hier_taxonomy["type_id"]) . ": </b>" . $va_hier_taxonomy["name_singular"] . "</div>";
            }
        }
    }
    if ($vs_description = $t_object->get("ca_objects.description")) {
        print "<div class='unit'><b>" . _t('Description') . ":</b> {$vs_description}</div><!-- end unit -->";
    }
    $vs_era = $t_object->get('ca_places.era', array("convertCodesToDisplayText" => true, "delimiter" => ", "));
    $vs_period = $t_object->get('ca_places.period', array("convertCodesToDisplayText" => true, "delimiter" => ", "));
    $vs_epoch = $t_object->get('ca_places.epoch', array("convertCodesToDisplayText" => true, "delimiter" => ", "));
    $vs_ageNALMA = $t_object->get('ca_places.ageNALMA', array("convertCodesToDisplayText" => true, "delimiter" => ", "));
    $vs_unit = $t_object->get('ca_places.unit', array("convertCodesToDisplayText" => true, "delimiter" => ", "));
    $vs_group = $t_object->get('ca_places.group', array("convertCodesToDisplayText" => true, "delimiter" => ", "));
    $vs_formation = $t_object->get('ca_places.formation', array("convertCodesToDisplayText" => true, "delimiter" => ", "));
    $vs_member = $t_object->get('ca_places.member', array("convertCodesToDisplayText" => true, "delimiter" => ", "));
    ?>
Example #5
0
 /**
  * Returns a display label for a given criterion and facet.
  *
  * @param string $ps_facet_name Name of facet 
  * @param mixed $pm_criterion 
  * @return string
  */
 public function getCriterionLabel($ps_facet_name, $pn_row_id)
 {
     if (!($va_facet_info = $this->getInfoForFacet($ps_facet_name))) {
         return null;
     }
     switch ($va_facet_info['type']) {
         # -----------------------------------------------------
         case 'has':
             $vs_yes_text = isset($va_facet_info['label_yes']) && $va_facet_info['label_yes'] ? $va_facet_info['label_yes'] : _t('Yes');
             $vs_no_text = isset($va_facet_info['label_no']) && $va_facet_info['label_no'] ? $va_facet_info['label_no'] : _t('No');
             return (bool) $pn_row_id ? $vs_yes_text : $vs_no_text;
             break;
             # -----------------------------------------------------
         # -----------------------------------------------------
         case 'label':
             if (!($t_table = $this->opo_datamodel->getInstanceByTableName(isset($va_facet_info['relative_to']) && $va_facet_info['relative_to'] ? $va_facet_info['relative_to'] : $this->ops_browse_table_name, true))) {
                 break;
             }
             if (!$t_table->load($pn_row_id)) {
                 return '???';
             }
             return $t_table->getLabelForDisplay();
             break;
             # -----------------------------------------------------
         # -----------------------------------------------------
         case 'authority':
             if (!($t_table = $this->opo_datamodel->getInstanceByTableName($va_facet_info['table'], true))) {
                 break;
             }
             if (!$t_table->load($pn_row_id)) {
                 return '???';
             }
             return $t_table->getLabelForDisplay();
             break;
             # -----------------------------------------------------
         # -----------------------------------------------------
         case 'attribute':
             $t_element = new ca_metadata_elements();
             if (!$t_element->load(array('element_code' => $va_facet_info['element_code']))) {
                 return urldecode($pn_row_id);
             }
             $vn_element_id = $t_element->getPrimaryKey();
             switch ($vn_element_type = $t_element->get('datatype')) {
                 case __CA_ATTRIBUTE_VALUE_LIST__:
                     $t_list = new ca_lists();
                     return $t_list->getItemFromListForDisplayByItemID($t_element->get('list_id'), $pn_row_id, true);
                     break;
                 case __CA_ATTRIBUTE_VALUE_OBJECTS__:
                 case __CA_ATTRIBUTE_VALUE_ENTITIES__:
                 case __CA_ATTRIBUTE_VALUE_PLACES__:
                 case __CA_ATTRIBUTE_VALUE_OCCURRENCES__:
                 case __CA_ATTRIBUTE_VALUE_COLLECTIONS__:
                 case __CA_ATTRIBUTE_VALUE_LOANS__:
                 case __CA_ATTRIBUTE_VALUE_MOVEMENTS__:
                 case __CA_ATTRIBUTE_VALUE_STORAGELOCATIONS__:
                 case __CA_ATTRIBUTE_VALUE_OBJECTLOTS__:
                     if ($t_rel_item = AuthorityAttributeValue::elementTypeToInstance($vn_element_type)) {
                         return $t_rel_item->load($pn_row_id) ? $t_rel_item->getLabelForDisplay() : "???";
                     }
                     break;
                 default:
                     return urldecode($pn_row_id);
                     break;
             }
             break;
             # -----------------------------------------------------
         # -----------------------------------------------------
         case 'field':
             if (!($t_item = $this->opo_datamodel->getInstanceByTableName($this->ops_browse_table_name, true))) {
                 break;
             }
             if ($vb_is_bit = $t_item->getFieldInfo($va_facet_info['field'], 'FIELD_TYPE') == FT_BIT) {
                 return (bool) $pn_row_id ? caGetOption('label_yes', $va_facet_info, _t('Yes')) : caGetOption('label_no', $va_facet_info, _t('No'));
             }
             return urldecode($pn_row_id);
             break;
             # -----------------------------------------------------
         # -----------------------------------------------------
         case 'violations':
             if (!($t_rule = $this->opo_datamodel->getInstanceByTableName('ca_metadata_dictionary_rules', true))) {
                 break;
             }
             if ($t_rule->load(array('rule_code' => $pn_row_id))) {
                 return $t_rule->getSetting('label');
             }
             return urldecode($pn_row_id);
             break;
             # -----------------------------------------------------
         # -----------------------------------------------------
         case 'checkouts':
             $vs_status_text = null;
             $vs_status_code = isset($va_facet_info['status']) && $va_facet_info['status'] ? $va_facet_info['status'] : $pn_row_id;
             switch ($vs_status_code) {
                 case 'overdue':
                     $vs_status_text = _t('Overdue');
                     break;
                 case 'reserved':
                     $vs_status_text = _t('Reserved');
                     break;
                 case 'available':
                     $vs_status_text = _t('Available');
                     break;
                 default:
                 case 'out':
                     $vs_status_text = _t('Out');
                     break;
             }
             $va_params = array();
             switch ($va_facet_info['mode']) {
                 case 'user':
                     $vs_name = null;
                     $t_user = new ca_users($pn_row_id);
                     if ($t_user->getPrimaryKey()) {
                         $vs_name = $t_user->get('fname') . ' ' . $t_user->get('lname') . (($vs_email = $t_user->get('email')) ? " ({$vs_email})" : "");
                         return _t('%1 for %2', $vs_status_text, $vs_name);
                     }
                     break;
                 default:
                 case 'all':
                     return $vs_status_text;
                     break;
             }
             return urldecode($pn_row_id);
             break;
             # -----------------------------------------------------
         # -----------------------------------------------------
         case 'location':
             $va_tmp = explode(":", urldecode($pn_row_id));
             $vs_loc_table_name = $this->opo_datamodel->getTableName($va_tmp[0]);
             $va_collapse_map = $this->getCollapseMapForLocationFacet($va_facet_info);
             $t_instance = $this->opo_datamodel->getInstanceByTableName($vs_loc_table_name, true);
             if (($vs_table_name = $vs_loc_table_name) == 'ca_objects_x_storage_locations') {
                 $vs_table_name = 'ca_storage_locations';
             }
             if (isset($va_collapse_map[$vs_table_name][$va_tmp[1]])) {
                 // Class/subclass is collapsable
                 return $va_collapse_map[$vs_table_name][$va_tmp[1]];
             } elseif (isset($va_collapse_map[$vs_table_name]['*'])) {
                 // Class is collapsable
                 return $va_collapse_map[$vs_table_name]['*'];
             } elseif ($va_tmp[2] && ($qr_res = caMakeSearchResult($vs_table_name, array($va_tmp[2]))) && $qr_res->nextHit()) {
                 // Return label for id
                 $va_config = ca_objects::getConfigurationForCurrentLocationType($vs_table_name, $va_tmp[1]);
                 $vs_template = isset($va_config['template']) ? $va_config['template'] : "^{$vs_table_name}.preferred_labels";
                 return caTruncateStringWithEllipsis($qr_res->getWithTemplate($vs_template), 30, 'end');
             }
             return '???';
             break;
             # -----------------------------------------------------
         # -----------------------------------------------------
         case 'normalizedLength':
             $vn_start = urldecode($pn_row_id);
             if (!($vs_output_units = caGetLengthUnitType($vs_units = caGetOption('units', $va_facet_info, 'm')))) {
                 $vs_output_units = Zend_Measure_Length::METER;
             }
             $vs_increment = caGetOption('increment', $va_facet_info, '1 m');
             $vo_increment = caParseLengthDimension($vs_increment);
             $vn_increment_in_current_units = (double) $vo_increment->convertTo($vs_output_units, 6, 'en_US');
             $vn_end = $vn_start + $vn_increment_in_current_units;
             return "{$vn_start} {$vs_units} - {$vn_end} {$vs_units}";
             break;
             # -----------------------------------------------------
         # -----------------------------------------------------
         case 'normalizedDates':
             return $pn_row_id === 'null' ? _t('Date unknown') : urldecode($pn_row_id);
             break;
             # -----------------------------------------------------
         # -----------------------------------------------------
         case 'fieldList':
             if (!($t_item = $this->opo_datamodel->getInstanceByTableName($this->ops_browse_table_name, true))) {
                 break;
             }
             $vs_field_name = $va_facet_info['field'];
             $va_field_info = $t_item->getFieldInfo($vs_field_name);
             $t_list = new ca_lists();
             if ($vs_list_name = $va_field_info['LIST_CODE']) {
                 $t_list_item = new ca_list_items($pn_row_id);
                 if ($vs_tmp = $t_list_item->getLabelForDisplay()) {
                     return $vs_tmp;
                 }
                 return '???';
             } else {
                 if ($vs_list_name = $va_field_info['LIST']) {
                     if (is_array($va_list_items = $t_list->getItemsForList($vs_list_name))) {
                         $va_list_items = caExtractValuesByUserLocale($va_list_items);
                         foreach ($va_list_items as $vn_id => $va_list_item) {
                             if ($va_list_item['item_value'] == $pn_row_id) {
                                 return $va_list_item['name_plural'];
                             }
                         }
                     }
                 }
             }
             if (isset($va_field_info['BOUNDS_CHOICE_LIST'])) {
                 $va_choice_list = $va_field_info['BOUNDS_CHOICE_LIST'];
                 if (is_array($va_choice_list)) {
                     foreach ($va_choice_list as $vs_val => $vn_id) {
                         if ($vn_id == $pn_row_id) {
                             return $vs_val;
                         }
                     }
                 }
             }
             if ($va_facet_info['table'] && ($t_browse_table = $this->opo_datamodel->getInstanceByTableName($vs_facet_table = $va_facet_info['table'], true))) {
                 if (!($app = AppController::getInstance())) {
                     return '???';
                 }
                 if ($t_browse_table->load($pn_row_id) && $t_browse_table->isReadable($app->getRequest(), 'preferred_labels')) {
                     return $t_browse_table->get("{$vs_facet_table}.preferred_labels");
                 }
             }
             return '???';
             break;
             # -----------------------------------------------------
         # -----------------------------------------------------
         default:
             if ($ps_facet_name == '_search') {
                 return $pn_row_id;
             }
             return 'Invalid type';
             break;
             # -----------------------------------------------------
     }
 }
Example #6
0
 public function getSetsForUser($pa_options)
 {
     if (!is_array($pa_options)) {
         $pa_options = array();
     }
     $pn_user_id = isset($pa_options['user_id']) ? (int) $pa_options['user_id'] : null;
     $pm_table_name_or_num = isset($pa_options['table']) ? $pa_options['table'] : null;
     if ($pm_table_name_or_num && !($vn_table_num = $this->_getTableNum($pm_table_name_or_num))) {
         return null;
     }
     $pm_type = isset($pa_options['setType']) ? $pa_options['setType'] : null;
     $pn_access = isset($pa_options['access']) ? $pa_options['access'] : null;
     $pa_public_access = isset($pa_options['checkAccess']) ? $pa_options['checkAccess'] : null;
     if ($pa_public_access && is_numeric($pa_public_access) && !is_array($pa_public_access)) {
         $pa_public_access = array($pa_public_access);
     }
     for ($vn_i = 0; $vn_i < sizeof($pa_public_access); $vn_i++) {
         $pa_public_access[$vn_i] = intval($pa_public_access[$vn_i]);
     }
     if ($pn_user_id) {
         $va_extra_joins = array();
         $va_sql_wheres = array("(cs.deleted = 0)");
         $va_sql_params = array();
         $o_db = $this->getDb();
         if ($vn_table_num) {
             $va_sql_wheres[] = "(cs.table_num = ?)";
             $va_sql_params[] = (int) $vn_table_num;
         }
         if (!is_null($pa_public_access) && is_array($pa_public_access) && sizeof($pa_public_access)) {
             $va_sql_wheres[] = "(cs.access IN (?))";
             $va_sql_params[] = $pa_public_access;
         }
         if (isset($pm_type) && $pm_type) {
             if (is_numeric($pm_type)) {
                 $va_sql_wheres[] = "(cs.type_id = ?)";
                 $va_sql_params[] = (int) $pm_type;
             } else {
                 # --- look up code of set type
                 $t_list = new ca_lists();
                 $vn_type_id = $t_list->getItemIDFromList("set_types", $pm_type);
                 if ($vn_type_id) {
                     $va_sql_wheres[] = "(cs.type_id = ?)";
                     $va_sql_params[] = (int) $vn_type_id;
                 }
             }
         }
         if ($pa_options["owner"]) {
             $va_sql_wheres[] = "(cs.user_id = " . $pn_user_id . ")";
         } else {
             # --- if owner is not set to true, we're finding all sets the user has access to or is owner of
             # --- we also check the users' access to the set if set
             $t_user = new ca_users();
             $t_user->load($pn_user_id);
             if ($t_user->getPrimaryKey()) {
                 $vs_access_sql = $pn_access > 0 ? " AND (access >= " . intval($pn_access) . ")" : "";
                 if (is_array($va_groups = $t_user->getUserGroups()) && sizeof($va_groups)) {
                     $vs_sql = "(\n\t\t\t\t\t\t\t(cs.user_id = " . intval($pn_user_id) . ") OR \n\t\t\t\t\t\t\t(cs.set_id IN (\n\t\t\t\t\t\t\t\t\tSELECT set_id \n\t\t\t\t\t\t\t\t\tFROM ca_sets_x_user_groups \n\t\t\t\t\t\t\t\t\tWHERE \n\t\t\t\t\t\t\t\t\t\tgroup_id IN (" . join(',', array_keys($va_groups)) . ") {$vs_access_sql}\n\t\t\t\t\t\t\t\t\t\tAND\n\t\t\t\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t\t\t\t (sdatetime IS NULL AND edatetime IS NULL)\n\t\t\t\t\t\t\t\t\t\t\t OR \n\t\t\t\t\t\t\t\t\t\t\t (\n\t\t\t\t\t\t\t\t\t\t\t\tsdatetime <= " . time() . " AND edatetime >= " . time() . "\n\t\t\t\t\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t)";
                 } else {
                     $vs_sql = "(cs.user_id = {$pn_user_id})";
                 }
                 $vs_sql .= " OR (cs.set_id IN (\n\t\t\t\t\t\t\t\t\t\t\tSELECT set_id \n\t\t\t\t\t\t\t\t\t\t\tFROM ca_sets_x_users \n\t\t\t\t\t\t\t\t\t\t\tWHERE \n\t\t\t\t\t\t\t\t\t\t\t\tuser_id = {$pn_user_id} {$vs_access_sql}\n\t\t\t\t\t\t\t\t\t\t\t\tAND\n\t\t\t\t\t\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t\t\t\t\t\t (sdatetime IS NULL AND edatetime IS NULL)\n\t\t\t\t\t\t\t\t\t\t\t\t\t OR \n\t\t\t\t\t\t\t\t\t\t\t\t\t (\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tsdatetime <= " . time() . " AND edatetime >= " . time() . "\n\t\t\t\t\t\t\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t)";
                 $va_sql_wheres[] = "({$vs_sql})";
             }
         }
         $qr_res = $o_db->query("SELECT cs.set_id, cs.user_id, type_id, cu.fname, cu.lname\n\t\t\t\t\t\t\t\t\tFROM ca_sets cs\n\t\t\t\t\t\t\t\t\tINNER JOIN ca_users AS cu ON cs.user_id = cu.user_id\n\t\t\t\t\t\t\t\t\t" . join("\n", $va_extra_joins) . "\n\t\t\t\t\t\t\t\t\t" . (sizeof($va_sql_wheres) ? "WHERE " : "") . " " . join(" AND ", $va_sql_wheres) . "\n\t\t\t\t\t\t\t\t\t", $va_sql_params);
         $va_sets = array();
         $t_list = new ca_lists();
         while ($qr_res->nextRow()) {
             $vn_table_num = $qr_res->get('table_num');
             if (!isset($va_type_name_cache[$vn_table_num]) || !($vs_set_type = $va_type_name_cache[$vn_table_num])) {
                 $vs_set_type = $va_type_name_cache[$vn_table_num] = $this->getSetContentTypeName($vn_table_num, array('number' => 'plural'));
             }
             $vs_type = $t_list->getItemFromListForDisplayByItemID('set_types', $qr_res->get('type_id'));
             $va_sets[$qr_res->get('set_id')] = array_merge($qr_res->getRow(), array('set_content_type' => $vs_set_type, 'set_type' => $vs_type));
         }
         return $va_sets;
     } else {
         return false;
     }
 }
 /**
  * Will return plural value of list item unless useSingular option is set to true, in which case singular version of list item label will be used.
  *
  * @param array Optional array of options. Support options are:
  * 			list_id = if set then the numeric item_id value is translated into label text in the current locale. If not set then the numeric item_id is returned.
  *			useSingular = If list_id is set then by default the returned text is the plural label. Setting this option to true will force use of the singular label.
  *			showHierarchy = If true then hierarchical parents of list item will be returned and hierarchical options described below will be used to control the output
  *			returnIdno = If true list item idno is returned rather than preferred label
  *			HIERARCHICAL OPTIONS: 
  *				direction - For hierarchy specifications (eg. ca_objects.hierarchy) this determines the order in which the hierarchy is returned. ASC will return the hierarchy root first while DESC will return it with the lowest node first. Default is ASC.
  *				top - For hierarchy specifications (eg. ca_objects.hierarchy) this option, if set, will limit the returned hierarchy to the first X nodes from the root down. Default is to not limit.
  *				bottom - For hierarchy specifications (eg. ca_objects.hierarchy) this option, if set, will limit the returned hierarchy to the first X nodes from the lowest node up. Default is to not limit.
  * 				hierarchicalDelimiter - Text to place between items in a hierarchy for a hierarchical specification (eg. ca_objects.hierarchy) when returning as a string
  *				removeFirstItems - If set to a non-zero value, the specified number of items at the top of the hierarchy will be omitted. For example, if set to 2, the root and first child of the hierarchy will be omitted. Default is zero (don't delete anything).
  * @return string The value
  */
 public function getDisplayValue($pa_options = null)
 {
     $vn_list_id = is_array($pa_options) && isset($pa_options['list_id']) ? (int) $pa_options['list_id'] : null;
     if ($vn_list_id > 0) {
         $t_list = new ca_lists();
         $vb_return_idno = isset($pa_options['returnIdno']) && (bool) $pa_options['returnIdno'];
         if ($vb_return_idno) {
             $vs_get_spec = 'idno';
         } else {
             $vs_get_spec = isset($pa_options['useSingular']) && $pa_options['useSingular'] ? 'name_singular' : 'name_plural';
         }
         // do we need to get the hierarchy?
         if ($pa_options['showHierarchy']) {
             $t_item = new ca_list_items($this->ops_text_value);
             return $t_item->get('ca_list_items.hierarchy.' . $vs_get_spec, $pa_options);
         } elseif ($vb_return_idno) {
             $t_item = new ca_list_items($this->ops_text_value);
             return $t_item->get('ca_list_items.' . $vs_get_spec, $pa_options);
         }
         return $t_list->getItemFromListForDisplayByItemID($vn_list_id, $this->ops_text_value, isset($pa_options['useSingular']) && $pa_options['useSingular'] ? false : true);
     }
     return $this->ops_text_value;
 }
 /**
  * Will return plural value of list item unless useSingular option is set to true, in which case singular version of list item label will be used.
  *
  * @param array Optional array of options. Support options are:
  * 			list_id = if set then the numeric item_id value is translated into label text in the current locale. If not set then the numeric item_id is returned.
  *			useSingular = If list_id is set then by default the returned text is the plural label. Setting this option to true will force use of the singular label. [Default is false]
  *			showHierarchy = If true then hierarchical parents of list item will be returned and hierarchical options described below will be used to control the output [Default is false]
  *			returnIdno = If true list item idno is returned rather than preferred label [Default is false]
  *			idsOnly = Return numeric item_id only [Default is false]
  *			HIERARCHICAL OPTIONS: 
  *				direction - For hierarchy specifications (eg. ca_objects.hierarchy) this determines the order in which the hierarchy is returned. ASC will return the hierarchy root first while DESC will return it with the lowest node first. Default is ASC.
  *				top - For hierarchy specifications (eg. ca_objects.hierarchy) this option, if set, will limit the returned hierarchy to the first X nodes from the root down. Default is to not limit.
  *				bottom - For hierarchy specifications (eg. ca_objects.hierarchy) this option, if set, will limit the returned hierarchy to the first X nodes from the lowest node up. Default is to not limit.
  * 				hierarchicalDelimiter - Text to place between items in a hierarchy for a hierarchical specification (eg. ca_objects.hierarchy) when returning as a string
  *				removeFirstItems - If set to a non-zero value, the specified number of items at the top of the hierarchy will be omitted. For example, if set to 2, the root and first child of the hierarchy will be omitted. Default is zero (don't delete anything).
  *				transaction = the transaction to execute database actions within. [Default is null]
  * @return string The value
  */
 public function getDisplayValue($pa_options = null)
 {
     if ($vb_return_idno = isset($pa_options['returnIdno']) && (bool) $pa_options['returnIdno']) {
         return caGetListItemIdno($this->ops_text_value);
     }
     $vb_ids_only = (bool) caGetOption('idsOnly', $pa_options, false);
     if ($vb_ids_only) {
         return (int) $this->ops_text_value;
     }
     $vn_list_id = is_array($pa_options) && isset($pa_options['list_id']) ? (int) $pa_options['list_id'] : null;
     if ($vn_list_id > 0) {
         $t_list = new ca_lists();
         if ($o_trans = caGetOption('transaction', $pa_options, null)) {
             $t_list->setTransaction($o_trans);
         }
         $t_item = new ca_list_items();
         if ($pa_options['showHierarchy'] || $vb_return_idno) {
             if ($o_trans) {
                 $t_item->setTransaction($o_trans);
             }
         }
         $vs_get_spec = isset($pa_options['useSingular']) && $pa_options['useSingular'] ? 'name_singular' : 'name_plural';
         // do we need to get the hierarchy?
         if ($pa_options['showHierarchy']) {
             $t_item->load($this->ops_text_value);
             return $t_item->get('ca_list_items.hierarchy.' . $vs_get_spec, $pa_options);
         }
         return $t_list->getItemFromListForDisplayByItemID($vn_list_id, $this->ops_text_value, isset($pa_options['useSingular']) && $pa_options['useSingular'] ? false : true);
     }
     return $this->ops_text_value;
 }
Example #9
0
 /**
  * Returns list of sets subject to options
  *
  * @param array $pa_options Array of options. Supported options are:
  *			table - if set, list is restricted to sets that can contain the specified item. You can pass a table name or number. If omitted sets containing any content will be returned.
  *			setType - Restricts returned sets to those of the specified type. You can pass a type_id or list item code for the set type. If omitted sets are returned regardless of type.
  *			user_id - Restricts returned sets to those accessible by the current user. If omitted then all sets, regardless of access are returned.
  *			access - Restricts returned sets to those with at least the specified access level for the specified user. If user_id is omitted then this option has no effect. If user_id is set and this option is omitted, then sets where the user has at least read access will be returned. 
  *			checkAccess - Restricts returned sets to those with an public access level with the specified values. If omitted sets are returned regardless of public access (ca_sets.access) value. Can be a single value or array if you wish to filter on multiple public access values.
  *			row_id = if set to an integer only sets containing the specified row are returned
  *			setIDsOnly = if set to true only set_id values are returned, in a simple array
  *			omitCounts = 
  *			all = 
  *			allUsers =
  *			publicUsers =
  *			name = 
  * @return array A list of sets keyed by set_id and then locale_id. Keys for the per-locale value array include: set_id, set_code, status, public access, owner user_id, content table_num, set type_id, set name, number of items in the set (item_count), set type name for display and set content type name for display. If setIDsOnly option is set then a simple array of set_id values is returned instead.
  */
 public function getSets($pa_options = null)
 {
     if (!is_array($pa_options)) {
         $pa_options = array();
     }
     $pm_table_name_or_num = isset($pa_options['table']) ? $pa_options['table'] : null;
     $pm_type = isset($pa_options['setType']) ? $pa_options['setType'] : null;
     $pn_user_id = isset($pa_options['user_id']) ? (int) $pa_options['user_id'] : null;
     $pn_access = isset($pa_options['access']) ? $pa_options['access'] : null;
     $pb_set_ids_only = isset($pa_options['setIDsOnly']) ? (bool) $pa_options['setIDsOnly'] : false;
     $pb_omit_counts = isset($pa_options['omitCounts']) ? (bool) $pa_options['omitCounts'] : false;
     $ps_set_name = isset($pa_options['name']) ? $pa_options['name'] : null;
     $pn_row_id = isset($pa_options['row_id']) && (int) $pa_options['row_id'] ? (int) $pa_options['row_id'] : null;
     $pa_public_access = isset($pa_options['checkAccess']) ? $pa_options['checkAccess'] : null;
     if ($pa_public_access && is_numeric($pa_public_access) && !is_array($pa_public_access)) {
         $pa_public_access = array($pa_public_access);
     }
     for ($vn_i = 0; $vn_i < sizeof($pa_public_access); $vn_i++) {
         $pa_public_access[$vn_i] = intval($pa_public_access[$vn_i]);
     }
     if ($pm_table_name_or_num && !($vn_table_num = $this->_getTableNum($pm_table_name_or_num))) {
         return null;
     }
     $va_extra_joins = array();
     $o_db = $this->getDb();
     $va_sql_wheres = array("(cs.deleted = 0)");
     $va_sql_params = array();
     if ($vn_table_num) {
         $va_sql_wheres[] = "(cs.table_num = ?)";
         $va_sql_params[] = (int) $vn_table_num;
     }
     if ($pb_set_ids_only) {
         $va_sql_selects = array('cs.set_id');
     } else {
         $va_sql_selects = array('cs.set_id', 'cs.set_code', 'cs.status', 'cs.access', 'cs.user_id', 'cs.table_num', 'cs.type_id', 'csl.label_id', 'csl.name', 'csl.locale_id', 'l.language', 'l.country', 'u.fname', 'u.lname', 'u.email');
     }
     if (isset($pa_options['all']) && $pa_options['all']) {
         $va_sql_wheres[] = "(cs.user_id IN (SELECT user_id FROM ca_users WHERE userclass != 255))";
     } elseif (isset($pa_options['allUsers']) && $pa_options['allUsers']) {
         $va_sql_wheres[] = "(cs.user_id IN (SELECT user_id FROM ca_users WHERE userclass = 0))";
     } elseif (isset($pa_options['publicUsers']) && $pa_options['publicUsers']) {
         $va_sql_wheres[] = "(cs.user_id IN (SELECT user_id FROM ca_users WHERE userclass = 1))";
     } else {
         if ($pn_user_id && !$this->getAppConfig()->get('dont_enforce_access_control_for_ca_sets')) {
             $o_dm = $this->getAppDatamodel();
             $t_user = $o_dm->getInstanceByTableName('ca_users', true);
             $t_user->load($pn_user_id);
             if ($t_user->getPrimaryKey()) {
                 $vs_access_sql = $pn_access > 0 ? " AND (access >= " . intval($pn_access) . ")" : "";
                 if (is_array($va_groups = $t_user->getUserGroups()) && sizeof($va_groups)) {
                     $vs_sql = "(\n\t\t\t\t\t\t\t(cs.user_id = " . intval($pn_user_id) . ") OR \n\t\t\t\t\t\t\t(cs.set_id IN (\n\t\t\t\t\t\t\t\t\tSELECT set_id \n\t\t\t\t\t\t\t\t\tFROM ca_sets_x_user_groups \n\t\t\t\t\t\t\t\t\tWHERE \n\t\t\t\t\t\t\t\t\t\tgroup_id IN (" . join(',', array_keys($va_groups)) . ") {$vs_access_sql}\n\t\t\t\t\t\t\t\t\t\tAND\n\t\t\t\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t\t\t\t (sdatetime IS NULL AND edatetime IS NULL)\n\t\t\t\t\t\t\t\t\t\t\t OR \n\t\t\t\t\t\t\t\t\t\t\t (\n\t\t\t\t\t\t\t\t\t\t\t\tsdatetime <= " . time() . " AND edatetime >= " . time() . "\n\t\t\t\t\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t)";
                 } else {
                     $vs_sql = "(cs.user_id = {$pn_user_id})";
                 }
                 $vs_sql .= " OR (cs.set_id IN (\n\t\t\t\t\t\t\t\t\t\t\tSELECT set_id \n\t\t\t\t\t\t\t\t\t\t\tFROM ca_sets_x_users \n\t\t\t\t\t\t\t\t\t\t\tWHERE \n\t\t\t\t\t\t\t\t\t\t\t\tuser_id = {$pn_user_id} {$vs_access_sql}\n\t\t\t\t\t\t\t\t\t\t\t\tAND\n\t\t\t\t\t\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t\t\t\t\t\t (sdatetime IS NULL AND edatetime IS NULL)\n\t\t\t\t\t\t\t\t\t\t\t\t\t OR \n\t\t\t\t\t\t\t\t\t\t\t\t\t (\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tsdatetime <= " . time() . " AND edatetime >= " . time() . "\n\t\t\t\t\t\t\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t)";
                 $va_sql_wheres[] = "({$vs_sql})";
             }
         }
     }
     if (!is_null($pa_public_access) && is_array($pa_public_access) && sizeof($pa_public_access)) {
         $va_sql_wheres[] = "(cs.access IN (?))";
         $va_sql_params[] = $pa_public_access;
     }
     if (isset($pm_type) && $pm_type) {
         if (is_numeric($pm_type)) {
             $va_sql_wheres[] = "(cs.type_id = ?)";
             $va_sql_params[] = (int) $pm_type;
         } else {
             # --- look up code of set type
             $t_list = new ca_lists();
             $vn_type_id = $t_list->getItemIDFromList("set_types", $pm_type);
             if ($vn_type_id) {
                 $va_sql_wheres[] = "(cs.type_id = ?)";
                 $va_sql_params[] = (int) $vn_type_id;
             }
         }
     }
     if ($pn_row_id > 0) {
         $va_sql_wheres[] = "((csi.row_id = ?) AND (csi.table_num = ?))";
         $va_extra_joins[] = "INNER JOIN ca_set_items AS csi ON cs.set_id = csi.set_id";
         $va_sql_selects[] = 'csi.item_id';
         $va_sql_params[] = (int) $pn_row_id;
         $va_sql_params[] = (int) $vn_table_num;
     }
     if ($ps_set_name) {
         $va_sql_wheres[] = "(csl.name = ?)";
         $va_sql_params[] = (string) $ps_set_name;
     }
     if (!$pb_set_ids_only && !$pb_omit_counts) {
         // get set item counts
         $qr_table_nums = $o_db->query("\n\t\t\t\tSELECT DISTINCT cs.table_num \n\t\t\t\tFROM ca_sets cs\n\t\t\t\tINNER JOIN ca_set_items AS csi ON cs.set_id = csi.set_id\n\t\t\t\t" . (sizeof($va_sql_wheres) ? 'WHERE ' : '') . "\n\t\t\t\t" . join(' AND ', $va_sql_wheres) . "\n\t\t\t", $va_sql_params);
         $va_item_counts = array();
         while ($qr_table_nums->nextRow()) {
             $o_dm = $this->getAppDatamodel();
             $t_instance = $o_dm->getInstanceByTableNum($vn_table_num = (int) $qr_table_nums->get('table_num'), true);
             if (!$t_instance) {
                 continue;
             }
             $va_item_wheres = $va_sql_wheres;
             $va_item_wheres[] = "(cs.table_num = {$vn_table_num})";
             if ($t_instance->hasField('deleted')) {
                 $va_item_wheres[] = "(t.deleted = 0)";
             }
             $qr_res = $o_db->query("\n\t\t\t\t\tSELECT cs.set_id, count(distinct row_id) item_count\n\t\t\t\t\tFROM ca_sets cs\n\t\t\t\t\tINNER JOIN ca_set_items AS csi ON cs.set_id = csi.set_id\n\t\t\t\t\tINNER JOIN " . $t_instance->tableName() . " AS t ON t." . $t_instance->primaryKey() . " = csi.row_id\n\t\t\t\t\t" . (sizeof($va_item_wheres) ? 'WHERE ' : '') . "\n\t\t\t\t\t" . join(' AND ', $va_item_wheres) . "\n\t\t\t\t\tGROUP BY cs.set_id\n\t\t\t\t", $va_sql_params);
             while ($qr_res->nextRow()) {
                 $va_item_counts[(int) $qr_res->get('set_id')] = (int) $qr_res->get('item_count');
             }
         }
         // get sets
         $qr_res = $o_db->query("\n\t\t\t\tSELECT " . join(', ', $va_sql_selects) . "\n\t\t\t\tFROM ca_sets cs\n\t\t\t\tLEFT JOIN ca_set_labels AS csl ON cs.set_id = csl.set_id\n\t\t\t\tLEFT JOIN ca_locales AS l ON csl.locale_id = l.locale_id\n\t\t\t\tINNER JOIN ca_users AS u ON cs.user_id = u.user_id\n\t\t\t\t" . join("\n", $va_extra_joins) . "\n\t\t\t\t" . (sizeof($va_sql_wheres) ? 'WHERE ' : '') . "\n\t\t\t\t" . join(' AND ', $va_sql_wheres) . "\n\t\t\t\tORDER BY csl.name\n\t\t\t", $va_sql_params);
         $va_sets = array();
         $o_dm = $this->getAppDatamodel();
         $va_type_name_cache = array();
         $t_list = new ca_lists();
         while ($qr_res->nextRow()) {
             $vn_table_num = $qr_res->get('table_num');
             if (!isset($va_type_name_cache[$vn_table_num]) || !($vs_set_type = $va_type_name_cache[$vn_table_num])) {
                 $vs_set_type = $va_type_name_cache[$vn_table_num] = $this->getSetContentTypeName($vn_table_num, array('number' => 'plural'));
             }
             $vs_type = $t_list->getItemFromListForDisplayByItemID('set_types', $qr_res->get('type_id'));
             $va_sets[$qr_res->get('set_id')][$qr_res->get('locale_id')] = array_merge($qr_res->getRow(), array('item_count' => intval($va_item_counts[$qr_res->get('set_id')]), 'set_content_type' => $vs_set_type, 'set_type' => $vs_type));
         }
         return $va_sets;
     } else {
         if ($pb_set_ids_only) {
             // get sets
             $qr_res = $o_db->query("\n\t\t\t\t\tSELECT " . join(', ', $va_sql_selects) . "\n\t\t\t\t\tFROM ca_sets cs\n\t\t\t\t\tINNER JOIN ca_users AS u ON cs.user_id = u.user_id\n\t\t\t\t\tLEFT JOIN ca_set_labels AS csl ON cs.set_id = csl.set_id\n\t\t\t\t\t" . join("\n", $va_extra_joins) . "\n\t\t\t\t\t" . (sizeof($va_sql_wheres) ? 'WHERE ' : '') . "\n\t\t\t\t\t" . join(' AND ', $va_sql_wheres) . "\n\t\t\t\t", $va_sql_params);
             return $qr_res->getAllFieldValues("set_id");
         } else {
             $qr_res = $o_db->query("\n\t\t\t\t\tSELECT " . join(', ', $va_sql_selects) . "\n\t\t\t\t\tFROM ca_sets cs\n\t\t\t\t\tINNER JOIN ca_users AS u ON cs.user_id = u.user_id\n\t\t\t\t\tLEFT JOIN ca_set_labels AS csl ON cs.set_id = csl.set_id\n\t\t\t\t\tLEFT JOIN ca_locales AS l ON csl.locale_id = l.locale_id\n\t\t\t\t\t" . join("\n", $va_extra_joins) . "\n\t\t\t\t\t" . (sizeof($va_sql_wheres) ? 'WHERE ' : '') . "\n\t\t\t\t\t" . join(' AND ', $va_sql_wheres) . "\n\t\t\t\t", $va_sql_params);
             $t_list = new ca_lists();
             while ($qr_res->nextRow()) {
                 $vn_table_num = $qr_res->get('table_num');
                 if (!isset($va_type_name_cache[$vn_table_num]) || !($vs_set_type = $va_type_name_cache[$vn_table_num])) {
                     $vs_set_type = $va_type_name_cache[$vn_table_num] = $this->getSetContentTypeName($vn_table_num, array('number' => 'plural'));
                 }
                 $vs_type = $t_list->getItemFromListForDisplayByItemID('set_types', $qr_res->get('type_id'));
                 $va_sets[$qr_res->get('set_id')][$qr_res->get('locale_id')] = array_merge($qr_res->getRow(), array('item_count' => intval($va_item_counts[$qr_res->get('set_id')]), 'set_content_type' => $vs_set_type, 'set_type' => $vs_type));
             }
             return $va_sets;
         }
     }
 }
 // Vertebrates
 //
 print "<div class='searchFullTitle'>" . caDetailLink($this->request, "UCM " . ($vs_idno ? $vs_idno : 'not available'), '', 'ca_objects', $vn_id, array("subsite" => $this->request->session->getVar("coloradoSubSite")), array(), array('action' => $this->request->getAction())) . "</div>";
 print "<div class='searchFullText" . ($vs_image ? "Small" : "") . "'>";
 $vs_other = $qr_res->get("ca_objects.other_catalog_number");
 print "<div><b>" . _t('Alternate Catalog Number') . ":</b> " . caReturnDefaultIfBlank($vs_other) . "</div>";
 if ($vn_taxonomy = $qr_res->get('ca_objects.taxonomic_rank', array('idsOnly' => true))) {
     if (isset($va_taxonomy_cache[$vn_taxonomy])) {
         print $va_taxonomy_cache[$vn_taxonomy];
     } else {
         $va_hierarchy = caExtractValuesByUserLocale($t_list_item->getHierarchyAncestors($vn_taxonomy, array("includeSelf" => true, "additionalTableToJoin" => "ca_list_item_labels", "additionalTableSelectFields" => array("name_singular"))));
         $va_hierarchy = array_reverse($va_hierarchy);
         $vs_buf = '';
         foreach ($va_hierarchy as $va_hier_taxonomy) {
             if ($va_hier_taxonomy["parent_id"]) {
                 $vs_buf .= "<div><b>" . $t_lists->getItemFromListForDisplayByItemID("list_item_types", $va_hier_taxonomy["type_id"]) . ": </b>" . $va_hier_taxonomy["name_singular"] . "</div>";
             }
         }
         print $va_taxonomy_cache[$vn_taxonomy] = $vs_buf;
     }
 } else {
     print "<div><b>" . _t('Taxonomy') . ":</b> " . caReturnDefaultIfBlank($qr_res->get('ca_objects.taxonomic_rank')) . "</div>";
 }
 if ($vs_description = $qr_res->get("ca_objects.description")) {
     print "<div><b>" . _t('Description') . ":</b> {$vs_description}</div>";
 }
 print "<div><b>" . _t('Photo') . ":</b> " . ($vs_image ? "Yes" : "No") . "</div>";
 $vs_cast = $qr_res->get("ca_objects.cast_model", array("convertCodesToDisplayText" => true));
 print "<div><b>" . _t('Cast') . ":</b> " . ($vs_cast ? $vs_cast : "No") . "</div>";
 $vs_track_type_status = $qr_res->get('ca_objects.track_type_status', array('convertCodesToDisplayText' => true));
 if (substr($vs_track_type_status, -1) == 's') {
Example #11
0
 /**
  * Returns HTML <select> element containing the specified list, or portion of the list.
  *
  * @param mixed $pm_list_name_or_id
  * @param string $ps_name
  * @param array $pa_attributes 
  * @param array $pa_options Array of options. Valid options include:
  * 	childrenOnlyForItemID = if set only items below item_id in the list item hierarchy are returned. Default (null) is to return all items in the list.
  * 	directChildrenOnly = if set only items with item_id=childrenOnlyForItemID as parent in the list item hierarchy are returned. Default (null) is to return all items in the list.
  *  nullOption = if set then a "null" (no value) option is available labeled with the value passed in this option
  *  additionalOptions = an optional array of options that will be passed through to caHTMLSelect; keys are display labels and values are used as option values
  *  value = if set, the <select> will have default selection set to the item whose *value* matches the option value. If none is set then the first item in the list will be selected
  *  key = ca_list_item field to be used as value for the <select> element list; can be set to either item_id or item_value; default is item_id
  *	width = the display width of the list in characters or pixels
  *  limitToItemsWithID = An optional array of list item_ids. Item_ids not in the array will be omitted from the returned list.
  *  omitItemsWithID = An optional array of list item_ids. Item_ids in the array will be omitted from the returned list.
  *  disableItemsWithID = An optional array of list item_ids. Item_ids in the array will be disabled in the returned list.	
  *
  *	limitToItemsRelatedToCollections = an array of collection_ids or collection idno's; returned items will be restricted to those attached to the specified collections
  *	limitToItemsRelatedToCollectionWithRelationshipTypes = array of collection type names or type_ids; returned items will be restricted to those attached to the specified collectionss with the specified relationship type
  *	limitToListIDs = array of list_ids to restrict returned items to when using "limitToItemsRelatedToCollections"
  *
  *  indentForHierarchy = indicate hierarchy with indentation. [Default is true]
  * 	transaction = transaction to perform database operations within. [Default is null]
  * 
  * @return string - HTML code for the <select> element; empty string if the list is empty
  */
 public static function getListAsHTMLFormElement($pm_list_name_or_id, $ps_name, $pa_attributes = null, $pa_options = null)
 {
     $t_list = new ca_lists();
     if ($o_trans = caGetOption('transaction', $pa_options, null)) {
         $t_list->setTransaction($o_trans);
     }
     if (!is_array($pa_options)) {
         $pa_options = array();
     }
     if (!(isset($pa_options['limitToItemsRelatedToCollection']) && is_array($pa_options['limitToItemsRelatedToCollections']))) {
         $vn_list_id = $t_list->_getListID($pm_list_name_or_id);
         $t_list->load($vn_list_id);
     }
     $vn_root_id = isset($pa_options['childrenOnlyForItemID']) && $pa_options['childrenOnlyForItemID'] ? $pa_options['childrenOnlyForItemID'] : null;
     $va_disabled_item_ids = caGetOption('disableItemsWithID', $pa_options, null);
     $vs_render_as = isset($pa_options['render']) ? $pa_options['render'] : '';
     $vn_sort_type = $t_list->get('default_sort');
     if ($vs_render_as == 'yes_no_checkboxes' && $vn_sort_type == __CA_LISTS_SORT_BY_LABEL__) {
         $vn_sort_type = __CA_LISTS_SORT_BY_IDENTIFIER__;
         // never allow sort-by-label when rendering as yes/no checkbox
     }
     if (!in_array($vs_render_as, array('lookup', 'horiz_hierbrowser', 'vert_hierbrowser'))) {
         if (isset($pa_options['limitToItemsRelatedToCollections']) && is_array($pa_options['limitToItemsRelatedToCollections'])) {
             $t_collection = new ca_collections();
             $va_collection_ids = array();
             foreach ($pa_options['limitToItemsRelatedToCollections'] as $vn_collection_id) {
                 if ($vn_collection_id && !is_numeric($vn_collection_id)) {
                     if ($vn_collection_id = $t_collection->load(array('idno' => $vn_collection_id))) {
                         $va_collection_ids[] = $vn_collection_id;
                     }
                 } else {
                     if ($vn_collection_id) {
                         $va_collection_ids[] = $vn_collection_id;
                     }
                 }
             }
             if (sizeof($va_collection_ids)) {
                 $qr_collections = $t_list->makeSearchResult('ca_collections', $va_collection_ids, array('restrictToRelationshipTypes' => isset($pa_options['limitToItemsRelatedToCollectionWithRelationshipTypes']) ? $pa_options['limitToItemsRelatedToCollectionWithRelationshipTypes'] : null));
                 $va_item_ids = array();
                 while ($qr_collections->nextHit()) {
                     $va_list_items = $qr_collections->get('ca_list_items', array('returnAsArray' => true));
                     foreach ($va_list_items as $vn_rel_id => $va_list_item) {
                         $va_item_ids[$vn_rel_id] = $va_list_item['item_id'];
                     }
                 }
                 if ($va_limit_to_listIDs = isset($pa_options['limitToListIDs']) && is_array($pa_options['limitToListIDs']) ? $pa_options['limitToListIDs'] : null) {
                     // for some reason the option comes back as array(0 => null) if no list is selected in UI
                     // -> have to make sure to catch this case here
                     if (sizeof($va_limit_to_listIDs) == 1 && empty($va_limit_to_listIDs[0])) {
                         $va_limit_to_listIDs = null;
                     }
                 }
                 if (is_array($va_limit_to_listIDs) && sizeof($va_item_ids)) {
                     // filter out items from tables we don't want
                     $qr_list_items = $t_list->makeSearchResult("ca_list_items", array_values($va_item_ids));
                     while ($qr_list_items->nextHit()) {
                         if (!in_array($qr_list_items->get('ca_list_items.list_id'), $va_limit_to_listIDs)) {
                             if (is_array($va_k = array_keys($va_item_ids, $qr_list_items->get('ca_list_items.item_id')))) {
                                 foreach ($va_k as $vs_k) {
                                     unset($va_list_items[$vs_k]);
                                 }
                             }
                         }
                     }
                 }
             }
         } else {
             $va_list_items = $t_list->getItemsForList($pm_list_name_or_id, array_merge($pa_options, array('returnHierarchyLevels' => caGetOption('indentForHierarchy', $pa_options, true), 'item_id' => $vn_root_id, 'extractValuesByUserLocale' => true, 'sort' => $vn_sort_type)));
         }
     }
     if (!is_array($va_list_items)) {
         $va_list_items = array();
     }
     $va_options = array();
     $va_disabled_options = array();
     if (!isset($pa_options['value'])) {
         $pa_options['value'] = null;
     }
     if (!isset($pa_options['key'])) {
         $pa_options['key'] = 'item_id';
     }
     if (!in_array($pa_options['key'], array('item_id', 'item_value'))) {
         $pa_options['key'] = 'item_id';
     }
     if (!isset($pa_options['limitToItemsWithID']) || !is_array($pa_options['limitToItemsWithID']) || !sizeof($pa_options['limitToItemsWithID'])) {
         $pa_options['limitToItemsWithID'] = null;
     }
     if (!isset($pa_options['omitItemsWithID']) || !is_array($pa_options['omitItemsWithID']) || !sizeof($pa_options['omitItemsWithID'])) {
         $pa_options['omitItemsWithID'] = null;
     }
     if (isset($pa_options['nullOption']) && $pa_options['nullOption'] && $vs_render_as != 'checklist') {
         $va_options[''] = $pa_options['nullOption'];
     }
     $va_colors = array();
     $vn_default_val = null;
     foreach ($va_list_items as $vn_item_id => $va_item) {
         if (is_array($pa_options['limitToItemsWithID']) && !in_array($vn_item_id, $pa_options['limitToItemsWithID'])) {
             continue;
         }
         if (is_array($pa_options['omitItemsWithID']) && in_array($vn_item_id, $pa_options['omitItemsWithID'])) {
             continue;
         }
         $va_options[$va_item[$pa_options['key']]] = str_repeat('&nbsp;', intval($va_item['LEVEL']) * 3) . ' ' . $va_item['name_singular'];
         if (!$va_item['is_enabled'] || is_array($va_disabled_item_ids) && in_array($vn_item_id, $va_disabled_item_ids)) {
             $va_disabled_options[$va_item[$pa_options['key']]] = true;
         }
         $va_colors[$vn_item_id] = $va_item['color'];
         if ($va_item['is_default']) {
             $vn_default_val = $va_item[$pa_options['key']];
         }
         // get default value
         if ($va_item['is_default'] && !isset($pa_options['nullOption'])) {
             // set default if needed, but only if there's not a null option set
             if (!is_array($pa_options['value']) && (!isset($pa_options['value']) || !strlen($pa_options['value']))) {
                 $pa_options['value'] = $vn_default_val;
             } else {
                 if (is_array($pa_options['value']) && !sizeof($pa_options['value'])) {
                     $pa_options['value'] = array(0 => $vn_default_val);
                 }
             }
         }
     }
     if (isset($pa_options['additionalOptions']) && is_array($pa_options['additionalOptions'])) {
         $va_options = array_merge($va_options, array_flip($pa_options['additionalOptions']));
     }
     $pa_options['disabledOptions'] = $va_disabled_options;
     switch ($vs_render_as) {
         case 'radio_buttons':
             if (!sizeof($va_options)) {
                 return '';
             }
             // return empty string if list has no values
             $vn_c = 0;
             $vn_i = 0;
             $vs_buf = "<table>\n";
             foreach ($va_options as $vm_value => $vs_label) {
                 if ($vn_c == 0) {
                     $vs_buf .= "<tr>";
                 }
                 $va_attributes = array('value' => $vm_value);
                 if (isset($va_disabled_options[$vm_value]) && $va_disabled_options[$vm_value]) {
                     $va_attributes['disabled'] = 1;
                 }
                 $va_attributes['value'] = $vm_value;
                 $va_attributes['id'] = $ps_name . '_' . $vn_i;
                 if ($pa_options['value'] == $vm_value) {
                     $va_attributes['checked'] = '1';
                 }
                 if (isset($pa_options['readonly']) && $pa_options['readonly']) {
                     $va_attributes['disabled'] = 1;
                 }
                 $vs_buf .= "<td>" . caHTMLRadioButtonInput($ps_name, $va_attributes, $pa_options) . " {$vs_label}</td>";
                 $vn_c++;
                 if ($vn_c >= $pa_options['maxColumns']) {
                     $vn_c = 0;
                     $vs_buf .= "</tr>\n";
                 }
                 $vn_i++;
             }
             if ($vn_c != 0) {
                 $vs_buf .= "</tr>\n";
             }
             $vs_buf .= "</table>";
             return $vs_buf;
             break;
         case 'yes_no_checkboxes':
             if (!sizeof($va_options)) {
                 return '';
             }
             // return empty string if list has no values
             $vn_c = 0;
             $vb_is_checked = false;
             if (!$pa_options['value']) {
                 $pa_options['value'] = (string) $vn_default_val;
             }
             foreach ($va_options as $vm_value => $vs_label) {
                 if (strlen($vm_value) == 0) {
                     continue;
                 }
                 // don't count null values when calculating the first value for the yes/no
                 switch ($vn_c) {
                     case 0:
                         if ($pa_options['value'] === (string) $vm_value) {
                             $vb_is_checked = true;
                         }
                         $pa_attributes['value'] = $pa_options['value'] = $vm_value;
                         $pa_options['label'] = $vs_label;
                         break;
                     case 1:
                         $pa_options['returnValueIfUnchecked'] = $vm_value;
                         break;
                     default:
                         // exit
                         break 2;
                 }
                 $vn_c++;
             }
             if ($vb_is_checked) {
                 $pa_attributes['checked'] = 1;
             }
             if (isset($pa_options['readonly']) && $pa_options['readonly']) {
                 $pa_attributes['disabled'] = 1;
             }
             return caHTMLCheckboxInput($ps_name, $pa_attributes, $pa_options);
             break;
         case 'checklist':
             if (!sizeof($va_options)) {
                 return '';
             }
             // return empty string if list has no values
             $vn_c = 0;
             $vs_buf = "<table>\n";
             foreach ($va_options as $vm_value => $vs_label) {
                 if ($vn_c == 0) {
                     $vs_buf .= "<tr>";
                 }
                 $va_attributes = array('value' => $vm_value);
                 if (isset($va_disabled_options[$vm_value]) && $va_disabled_options[$vm_value]) {
                     $va_attributes['disabled'] = 1;
                 }
                 if (isset($pa_options['readonly']) && $pa_options['readonly']) {
                     $va_attributes['disabled'] = 1;
                 }
                 if (is_array($pa_options['value']) && in_array($vm_value, $pa_options['value'])) {
                     $va_attributes['checked'] = '1';
                 }
                 $vs_buf .= "<td>" . caHTMLCheckboxInput($ps_name . '_' . $vm_value, $va_attributes, $pa_options) . " {$vs_label}</td>";
                 $vn_c++;
                 if ($vn_c >= $pa_options['maxColumns']) {
                     $vn_c = 0;
                     $vs_buf .= "</tr>\n";
                 }
             }
             if ($vn_c != 0) {
                 $vs_buf .= "</tr>\n";
             }
             $vs_buf .= "</table>";
             return $vs_buf;
             break;
         case 'lookup':
             $vs_value = $vs_hidden_value = "";
             if (caGetOption('forSearch', $pa_options)) {
                 if ($vs_val_id = caGetOption('value', $pa_options)) {
                     $vs_value = $t_list->getItemFromListForDisplayByItemID($pm_list_name_or_id, $vs_val_id);
                     $vs_hidden_value = $vs_val_id;
                 }
             } else {
                 $vs_value = "{" . $pa_options['element_id'] . "_label}";
                 $vs_hidden_value = "{" . $pa_options['element_id'] . "}";
             }
             $vs_buf = caHTMLTextInput($ps_name . '_autocomplete', array('width' => isset($pa_options['width']) && $pa_options['width'] > 0 ? $pa_options['width'] : 300, 'height' => isset($pa_options['height']) && $pa_options['height'] > 0 ? $pa_options['height'] : 1, 'value' => $vs_value, 'maxlength' => 512, 'id' => $ps_name . "_autocomplete", 'class' => 'lookupBg')) . caHTMLHiddenInput($ps_name, array('value' => $vs_hidden_value, 'id' => $ps_name));
             if ($pa_options['request']) {
                 $vs_url = caNavUrl($pa_options['request'], 'lookup', 'ListItem', 'Get', array('list' => ca_lists::getListCode($vn_list_id), 'noInline' => 1, 'noSymbols' => 1, 'max' => 100));
             } else {
                 // hardcoded default for testing.
                 $vs_url = '/index.php/lookup/ListItem/Get';
             }
             $vs_buf .= '</div>';
             $vs_buf .= "\n\t\t\t\t\t<script type='text/javascript'>\n\t\t\t\t\t\tjQuery(document).ready(function() {\n\t\t\t\t\t\t\tjQuery('#{$ps_name}_autocomplete').autocomplete({\n\t\t\t\t\t\t\t\t\tsource: '{$vs_url}', minLength: 3, delay: 800, html: true,\n\t\t\t\t\t\t\t\t\tselect: function(event, ui) {\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\tif (parseInt(ui.item.id) > 0) {\n\t\t\t\t\t\t\t\t\t\t\tjQuery('#{$ps_name}').val(ui.item.id);\n\t\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\t\tjQuery('#{$ps_name}_autocomplete').val('');\n\t\t\t\t\t\t\t\t\t\t\tjQuery('#{$ps_name}').val('');\n\t\t\t\t\t\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t});\n\t\t\t\t\t</script>\n\t\t\t\t";
             return $vs_buf;
             break;
         case 'horiz_hierbrowser':
         case 'horiz_hierbrowser_with_search':
         case 'vert_hierbrowser':
             $va_width = caParseFormElementDimension($pa_options['width'] ? $pa_options['width'] : $pa_options['width']);
             if ($va_width['type'] != 'pixels' && $va_width['dimension'] < 250) {
                 $va_width['dimension'] = 500;
             }
             $vn_width = $va_width['dimension'] . 'px';
             $va_height = caParseFormElementDimension($pa_options['height']);
             if ($va_height['type'] != 'pixels' && $va_height['dimension'] < 100) {
                 $va_height['dimension'] = 200;
             }
             $vn_height = $va_height['dimension'] . 'px';
             $t_root_item = new ca_list_items();
             $t_root_item->load(array('list_id' => $vn_list_id, 'parent_id' => null));
             JavascriptLoadManager::register("hierBrowser");
             $vs_buf = "<div style='width: {$vn_width}; height: {$vn_height};'><div id='{$ps_name}_hierarchyBrowser{n}' style='width: 100%; height: 100%;' class='" . ($vs_render_as == 'vert_hierbrowser' ? 'hierarchyBrowserVertical' : 'hierarchyBrowser') . "'>\n\t\t\t\t\t<!-- Content for hierarchy browser is dynamically inserted here by ca.hierbrowser -->\n\t\t\t\t</div><!-- end hierarchyBrowser -->\t</div>";
             $vs_buf .= "\t<script type='text/javascript'>\n\t\tjQuery(document).ready(function() { \n\t\t\tvar oHierBrowser = caUI.initHierBrowser('{$ps_name}_hierarchyBrowser{n}', {\n\t\t\t\tuiStyle: '" . ($vs_render_as == 'vert_hierbrowser' ? 'vertical' : 'horizontal') . "',\n\t\t\t\tlevelDataUrl: '" . caNavUrl($pa_options['request'], 'lookup', 'ListItem', 'GetHierarchyLevel', array('noSymbols' => 1)) . "',\n\t\t\t\tinitDataUrl: '" . caNavUrl($pa_options['request'], 'lookup', 'ListItem', 'GetHierarchyAncestorList') . "',\n\t\t\t\t\n\t\t\t\tselectOnLoad : true,\n\t\t\t\tbrowserWidth: " . (int) $va_width['dimension'] . ",\n\t\t\t\t\n\t\t\t\tclassName: '" . ($vs_render_as == 'vert_hierbrowser' ? 'hierarchyBrowserLevelVertical' : 'hierarchyBrowserLevel') . "',\n\t\t\t\tclassNameContainer: '" . ($vs_render_as == 'vert_hierbrowser' ? 'hierarchyBrowserContainerVertical' : 'hierarchyBrowserContainer') . "',\n\t\t\t\t\n\t\t\t\teditButtonIcon: \"" . caNavIcon($pa_options['request'], __CA_NAV_BUTTON_RIGHT_ARROW__) . "\",\n\t\t\t\tdisabledButtonIcon: \"" . caNavIcon($pa_options['request'], __CA_NAV_BUTTON_DOT__) . "\",\n\t\t\t\tinitItemID: '{" . $pa_options['element_id'] . "}',\n\t\t\t\tdefaultItemID: '" . $t_list->getDefaultItemID() . "',\n\t\t\t\tuseAsRootID: '" . $t_root_item->getPrimaryKey() . "',\n\t\t\t\tindicatorUrl: '" . $pa_options['request']->getThemeUrlPath() . "/graphics/icons/indicator.gif',\n\t\t\t\t\n\t\t\t\tcurrentSelectionDisplayID: '{$ps_name}_browseCurrentSelectionText{n}',\n\t\t\t\tonSelection: function(item_id, parent_id, name, display) {\n\t\t\t\t\tjQuery('#{$ps_name}').val(item_id);\n\t\t\t\t}\n\t\t\t});";
             if ($vs_render_as == 'horiz_hierbrowser_with_search') {
                 $vs_buf .= "jQuery('#{$ps_name}_hierarchyBrowserSearch{n}').autocomplete(\n\t\t\t\t\t{\n\t\t\t\t\t\tsource: '" . caNavUrl($pa_options['request'], 'lookup', 'ListItem', 'Get', array('list' => ca_lists::getListCode($vn_list_id), 'noSymbols' => 1)) . "', \n\t\t\t\t\t\tminLength: 3, delay: 800,\n\t\t\t\t\t\tselect: function(event, ui) {\n\t\t\t\t\t\t\toHierBrowser.setUpHierarchy(ui.item.id);\t// jump browser to selected item\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t);";
             }
             $vs_buf .= "});\n\t</script>";
             if ($vs_render_as == 'horiz_hierbrowser_with_search') {
                 $vs_buf .= "<div class='hierarchyBrowserSearchBar'>" . _t('Search') . ": <input type='text' id='{$ps_name}_hierarchyBrowserSearch{n}' class='hierarchyBrowserSearchBar' name='search' value='' size='20'/></div>";
             }
             if ($vs_render_as != 'vert_hierbrowser') {
                 $vs_buf .= "<div id='{$ps_name}_browseCurrentSelection{n}' class='hierarchyBrowserCurrentSelection'>" . _t("Current selection") . ": <span id='{$ps_name}_browseCurrentSelectionText{n}' class='hierarchyBrowserCurrentSelectionText'>?</span></div>";
             }
             $vs_buf .= caHTMLHiddenInput($ps_name, array('value' => "{" . $pa_options['element_id'] . "}", 'id' => $ps_name));
             return $vs_buf;
             break;
         case 'text':
             return caHTMLTextInput($ps_name, $pa_attributes, $pa_options);
             break;
         case 'options':
             return $va_options;
             break;
         default:
             if (!sizeof($va_options)) {
                 return '';
             }
             // return empty string if list has no values
             if (isset($pa_options['readonly']) && $pa_options['readonly']) {
                 $pa_attributes['disabled'] = 1;
             }
             return caHTMLSelect($ps_name, $va_options, $pa_attributes, array_merge($pa_options, array('contentArrayUsesKeysForValues' => true, 'colors' => $va_colors, 'height' => null)));
             break;
     }
 }
 /**
  * When returning text will return plural value of list item unless useSingular option is set to true, in which case singular version of list item label will be used.
  *
  * @param array Optional array of options. Support options are:
  * 			list_id = if set then the numeric item_id value is translated into label text in the current locale. If not set then the numeric item_id is returned.
  *			useSingular = If list_id is set then by default the returned text is the plural label. Setting this option to true will force use of the singular label. [Default is false]
  *			showHierarchy = If true then hierarchical parents of list item will be returned and hierarchical options described below will be used to control the output [Default is false]
  *			returnIdno = If true list item idno is returned rather than preferred label [Default is false]
  *			idsOnly = Return numeric item_id only [Default is false]
  *			alwaysReturnItemID = Synonym for idsOnly [Default is false]
  *			output = what value for the list to return. Valid values are text [display text], idno [identifier; same as returnIdno option], value [numeric item_id; same as idsOnly option]. [Default is value]
  *
  *			HIERARCHICAL OPTIONS:
  *				direction - For hierarchy specifications (eg. ca_objects.hierarchy) this determines the order in which the hierarchy is returned. ASC will return the hierarchy root first while DESC will return it with the lowest node first. Default is ASC.
  *				top - For hierarchy specifications (eg. ca_objects.hierarchy) this option, if set, will limit the returned hierarchy to the first X nodes from the root down. Default is to not limit.
  *				bottom - For hierarchy specifications (eg. ca_objects.hierarchy) this option, if set, will limit the returned hierarchy to the first X nodes from the lowest node up. Default is to not limit.
  * 				hierarchicalDelimiter - Text to place between items in a hierarchy for a hierarchical specification (eg. ca_objects.hierarchy) when returning as a string
  *				removeFirstItems - If set to a non-zero value, the specified number of items at the top of the hierarchy will be omitted. For example, if set to 2, the root and first child of the hierarchy will be omitted. Default is zero (don't delete anything).
  *				transaction = the transaction to execute database actions within. [Default is null]
  * @return string The value
  */
 public function getDisplayValue($pa_options = null)
 {
     if (isset($pa_options['output'])) {
         switch (strtolower($pa_options['output'])) {
             case 'idno':
                 $pa_options['returnIdno'] = true;
                 break;
             case 'text':
                 $pa_options['returnIdno'] = false;
                 $pa_options['idsOnly'] = false;
                 break;
             default:
                 $pa_options['idsOnly'] = true;
                 break;
         }
     }
     if ($vb_return_idno = isset($pa_options['returnIdno']) && (bool) $pa_options['returnIdno']) {
         return caGetListItemIdno($this->opn_item_id);
     }
     if (is_null($vb_ids_only = isset($pa_options['idsOnly']) ? (bool) $pa_options['idsOnly'] : null)) {
         $vb_ids_only = isset($pa_options['alwaysReturnItemID']) ? (bool) $pa_options['alwaysReturnItemID'] : false;
     }
     if ($vb_ids_only) {
         return (int) $this->opn_item_id;
     }
     $vn_list_id = is_array($pa_options) && isset($pa_options['list_id']) ? (int) $pa_options['list_id'] : null;
     if ($vn_list_id > 0) {
         $t_list = new ca_lists();
         if ($o_trans = isset($pa_options['transaction']) ? $pa_options['transaction'] : null) {
             $t_list->setTransaction($o_trans);
         }
         $t_item = new ca_list_items();
         if ($pa_options['showHierarchy'] || $vb_return_idno) {
             if ($o_trans) {
                 $t_item->setTransaction($o_trans);
             }
         }
         $vs_get_spec = isset($pa_options['useSingular']) && $pa_options['useSingular'] ? 'preferred_labels.name_singular' : 'preferred_labels.name_plural';
         // do we need to get the hierarchy?
         if ($pa_options['showHierarchy']) {
             $t_item->load((int) $this->opn_item_id);
             return $t_item->get('ca_list_items.hierarchy.' . $vs_get_spec, array_merge(array('removeFirstItems' => 1, 'delimiter' => ' ➔ ', $pa_options)));
         }
         return $t_list->getItemFromListForDisplayByItemID($vn_list_id, $this->opn_item_id, isset($pa_options['useSingular']) && $pa_options['useSingular'] ? false : true);
     }
     return $this->ops_text_value;
 }
Example #13
0
    }
    if ($t_object->get("ca_objects.dimensions.dimensions_length")) {
        $va_dimension_pieces[] = $t_object->get("ca_objects.dimensions.dimensions_length");
    }
    if (sizeof($va_dimension_pieces)) {
        print join(" x ", $va_dimension_pieces);
    }
    if ($t_object->get("ca_objects.dimensions.dimensions_weight")) {
        print " " . $t_object->get("ca_objects.dimensions.dimensions_weight");
    }
}
if ($va_materials = $t_object->get("ca_objects.material", array("returnAsArray" => true, "convertCodesToDisplayText" => false))) {
    $i = 0;
    $va_materials_display = array();
    foreach ($va_materials as $vn_material_id => $va_material) {
        $vs_material = $t_lists->getItemFromListForDisplayByItemID("material", $va_material["material"]);
        if (trim($vs_material)) {
            $va_materials_display[] = caNavLink($this->request, $vs_material, "", "", "Browse", "Objects", array("facet" => "material_facet", "id" => $va_material["material"]));
        }
    }
    if (sizeof($va_materials_display)) {
        print "<H6>" . _t("Material") . "</H6>";
        print join(", ", $va_materials_display);
    }
}
?>
		{{{<ifdef code="ca_objects.description"><H6>Description</H6>^ca_objects.description</ifdef>}}}
<?php 
if (trim($t_object->get("ca_objects.dimensions_frame.display_dimensions_frame")) || $t_object->get("ca_objects.dimensions_frame.dimensions_frame_height") || $t_object->get("ca_objects.dimensions.dimensions_height") || trim($t_object->get("ca_objects.dimensions.display_dimensions")) || trim($t_object->get("ca_objects.material")) || trim($t_object->get("description"))) {
    print "<HR/>";
}
    $vs_dob = "";
}
if ($vs_nationality || $vs_dob) {
    print "<H5>(" . $vs_nationality;
    if ($vs_nationality && $vs_dob) {
        print ", ";
    }
    print $vs_dob . ")</H5>";
}
?>
						<HR/>
<?php 
if ($va_styles = $t_item->get("ca_entities.styles_movement", array("returnAsArray" => true, "convertCodesToDisplayText" => false))) {
    $va_style_display = array();
    foreach ($va_styles as $vn_style_id => $va_style) {
        $vs_style_movement = $t_lists->getItemFromListForDisplayByItemID("styles_movement", $va_style["styles_movement"]);
        if (trim($vs_style_movement)) {
            $va_style_display[] = caNavLink($this->request, $vs_style_movement, "", "", "Browse", "Objects", array("facet" => "styles_movement_facet", "id" => $va_style["styles_movement"]));
        }
    }
    if (sizeof($va_style_display)) {
        print "<H6>" . _t("Style/Movement") . "</H6>";
        print join(", ", $va_style_display);
    }
}
?>
									
					{{{<ifdef code="ca_entities.birthplace"><H6>Birthplace</H6>^ca_entities.birthplace</ifdef>}}}
					{{{<ifdef code="ca_entities.entity_bio"><HR/><H6>Biography</H6>^ca_entities.entity_bio</ifdef>}}}
					<HR/>
					<div id="detailTools">
Example #15
0
 /**
  *
  */
 public function getCriterionLabel($ps_facet_name, $pn_row_id)
 {
     if (!($va_facet_info = $this->getInfoForFacet($ps_facet_name))) {
         return null;
     }
     switch ($va_facet_info['type']) {
         # -----------------------------------------------------
         case 'has':
             $vs_yes_text = isset($va_facet_info['label_yes']) && $va_facet_info['label_yes'] ? $va_facet_info['label_yes'] : _t('Yes');
             $vs_no_text = isset($va_facet_info['label_no']) && $va_facet_info['label_no'] ? $va_facet_info['label_no'] : _t('No');
             return (bool) $pn_row_id ? $vs_yes_text : $vs_no_text;
             break;
             # -----------------------------------------------------
         # -----------------------------------------------------
         case 'label':
             if (!($t_table = $this->opo_datamodel->getInstanceByTableName(isset($va_facet_info['relative_to']) && $va_facet_info['relative_to'] ? $va_facet_info['relative_to'] : $this->ops_browse_table_name, true))) {
                 break;
             }
             if (!$t_table->load($pn_row_id)) {
                 return '???';
             }
             return $t_table->getLabelForDisplay();
             break;
             # -----------------------------------------------------
         # -----------------------------------------------------
         case 'authority':
             if (!($t_table = $this->opo_datamodel->getInstanceByTableName($va_facet_info['table'], true))) {
                 break;
             }
             if (!$t_table->load($pn_row_id)) {
                 return '???';
             }
             return $t_table->getLabelForDisplay();
             break;
             # -----------------------------------------------------
         # -----------------------------------------------------
         case 'attribute':
             $t_element = new ca_metadata_elements();
             if (!$t_element->load(array('element_code' => $va_facet_info['element_code']))) {
                 return urldecode($pn_row_id);
             }
             $vn_element_id = $t_element->getPrimaryKey();
             switch ($t_element->get('datatype')) {
                 case 3:
                     // list
                     $t_list = new ca_lists();
                     return $t_list->getItemFromListForDisplayByItemID($t_element->get('list_id'), $pn_row_id, true);
                     break;
                 default:
                     return urldecode($pn_row_id);
                     break;
             }
             break;
             # -----------------------------------------------------
         # -----------------------------------------------------
         case 'field':
             return urldecode($pn_row_id);
             break;
             # -----------------------------------------------------
         # -----------------------------------------------------
         case 'normalizedDates':
             return urldecode($pn_row_id);
             break;
             # -----------------------------------------------------
         # -----------------------------------------------------
         case 'fieldList':
             if (!($t_item = $this->opo_datamodel->getInstanceByTableName($this->ops_browse_table_name, true))) {
                 break;
             }
             $vs_field_name = $va_facet_info['field'];
             $va_field_info = $t_item->getFieldInfo($vs_field_name);
             $t_list = new ca_lists();
             if ($vs_list_name = $va_field_info['LIST_CODE']) {
                 $t_list_item = new ca_list_items($pn_row_id);
                 if ($vs_tmp = $t_list_item->getLabelForDisplay()) {
                     return $vs_tmp;
                 }
                 return '???';
             } else {
                 if ($vs_list_name = $va_field_info['LIST']) {
                     if (is_array($va_list_items = $t_list->getItemsForList($vs_list_name))) {
                         $va_list_items = caExtractValuesByUserLocale($va_list_items);
                         foreach ($va_list_items as $vn_id => $va_list_item) {
                             if ($va_list_item['item_value'] == $pn_row_id) {
                                 return $va_list_item['name_plural'];
                             }
                         }
                     }
                 }
             }
             if (isset($va_field_info['BOUNDS_CHOICE_LIST'])) {
                 $va_choice_list = $va_field_info['BOUNDS_CHOICE_LIST'];
                 if (is_array($va_choice_list)) {
                     foreach ($va_choice_list as $vs_val => $vn_id) {
                         if ($vn_id == $pn_row_id) {
                             return $vs_val;
                         }
                     }
                 }
             }
             return '???';
             break;
             # -----------------------------------------------------
         # -----------------------------------------------------
         default:
             if ($ps_facet_name == '_search') {
                 return $pn_row_id;
             }
             return 'Invalid type';
             break;
             # -----------------------------------------------------
     }
 }
Example #16
0
 /**
  * Returns a display label for a given criterion and facet.
  *
  * @param string $ps_facet_name Name of facet 
  * @param mixed $pm_criterion 
  * @return string
  */
 public function getCriterionLabel($ps_facet_name, $pn_row_id)
 {
     if (!($va_facet_info = $this->getInfoForFacet($ps_facet_name))) {
         return null;
     }
     switch ($va_facet_info['type']) {
         # -----------------------------------------------------
         case 'has':
             $vs_yes_text = isset($va_facet_info['label_yes']) && $va_facet_info['label_yes'] ? $va_facet_info['label_yes'] : _t('Yes');
             $vs_no_text = isset($va_facet_info['label_no']) && $va_facet_info['label_no'] ? $va_facet_info['label_no'] : _t('No');
             return (bool) $pn_row_id ? $vs_yes_text : $vs_no_text;
             break;
             # -----------------------------------------------------
         # -----------------------------------------------------
         case 'label':
             if (!($t_table = $this->opo_datamodel->getInstanceByTableName(isset($va_facet_info['relative_to']) && $va_facet_info['relative_to'] ? $va_facet_info['relative_to'] : $this->ops_browse_table_name, true))) {
                 break;
             }
             if (!$t_table->load($pn_row_id)) {
                 return '???';
             }
             return $t_table->getLabelForDisplay();
             break;
             # -----------------------------------------------------
         # -----------------------------------------------------
         case 'authority':
             if (!($t_table = $this->opo_datamodel->getInstanceByTableName($va_facet_info['table'], true))) {
                 break;
             }
             if (!$t_table->load($pn_row_id)) {
                 return '???';
             }
             return $t_table->getLabelForDisplay();
             break;
             # -----------------------------------------------------
         # -----------------------------------------------------
         case 'attribute':
             $t_element = new ca_metadata_elements();
             if (!$t_element->load(array('element_code' => $va_facet_info['element_code']))) {
                 return urldecode($pn_row_id);
             }
             $vn_element_id = $t_element->getPrimaryKey();
             switch ($vn_element_type = $t_element->get('datatype')) {
                 case __CA_ATTRIBUTE_VALUE_LIST__:
                     $t_list = new ca_lists();
                     return $t_list->getItemFromListForDisplayByItemID($t_element->get('list_id'), $pn_row_id, true);
                     break;
                 case __CA_ATTRIBUTE_VALUE_OBJECTS__:
                 case __CA_ATTRIBUTE_VALUE_ENTITIES__:
                 case __CA_ATTRIBUTE_VALUE_PLACES__:
                 case __CA_ATTRIBUTE_VALUE_OCCURRENCES__:
                 case __CA_ATTRIBUTE_VALUE_COLLECTIONS__:
                 case __CA_ATTRIBUTE_VALUE_LOANS__:
                 case __CA_ATTRIBUTE_VALUE_MOVEMENTS__:
                 case __CA_ATTRIBUTE_VALUE_STORAGELOCATIONS__:
                 case __CA_ATTRIBUTE_VALUE_OBJECTLOTS__:
                     if ($t_rel_item = AuthorityAttributeValue::elementTypeToInstance($vn_element_type)) {
                         return $t_rel_item->load($pn_row_id) ? $t_rel_item->getLabelForDisplay() : "???";
                     }
                     break;
                 default:
                     return urldecode($pn_row_id);
                     break;
             }
             break;
             # -----------------------------------------------------
         # -----------------------------------------------------
         case 'field':
             if (!($t_item = $this->opo_datamodel->getInstanceByTableName($this->ops_browse_table_name, true))) {
                 break;
             }
             if ($vb_is_bit = $t_item->getFieldInfo($va_facet_info['field'], 'FIELD_TYPE') == FT_BIT) {
                 return (bool) $pn_row_id ? caGetOption('label_yes', $va_facet_info, _t('Yes')) : caGetOption('label_no', $va_facet_info, _t('No'));
             }
             return urldecode($pn_row_id);
             break;
             # -----------------------------------------------------
         # -----------------------------------------------------
         case 'location':
             $va_tmp = explode(":", urldecode($pn_row_id));
             $vs_loc_table_name = $this->opo_datamodel->getTableName($va_tmp[0]);
             $va_collapse_map = $this->getCollapseMapForLocationFacet($va_facet_info);
             $t_instance = $this->opo_datamodel->getInstanceByTableName($vs_loc_table_name, true);
             if (($vs_table_name = $vs_loc_table_name) == 'ca_objects_x_storage_locations') {
                 $vs_table_name = 'ca_storage_locations';
             }
             if (isset($va_collapse_map[$vs_table_name][$va_tmp[1]])) {
                 // Class/subclass is collapsable
                 return $va_collapse_map[$vs_table_name][$va_tmp[1]];
             } elseif (isset($va_collapse_map[$vs_table_name]['*'])) {
                 // Class is collapsable
                 return $va_collapse_map[$vs_table_name]['*'];
             } elseif ($va_tmp[2] && ($qr_res = caMakeSearchResult($vs_table_name, array($va_tmp[2]))) && $qr_res->nextHit()) {
                 // Return label for id
                 $va_config = ca_objects::getConfigurationForCurrentLocationType($vs_table_name, $va_tmp[1]);
                 $vs_template = isset($va_config['template']) ? $va_config['template'] : "^{$vs_table_name}.preferred_labels";
                 return caTruncateStringWithEllipsis($qr_res->getWithTemplate($vs_template), 30, 'end');
             }
             return '???';
             break;
             # -----------------------------------------------------
         # -----------------------------------------------------
         case 'normalizedDates':
             return urldecode($pn_row_id);
             break;
             # -----------------------------------------------------
         # -----------------------------------------------------
         case 'fieldList':
             if (!($t_item = $this->opo_datamodel->getInstanceByTableName($this->ops_browse_table_name, true))) {
                 break;
             }
             $vs_field_name = $va_facet_info['field'];
             $va_field_info = $t_item->getFieldInfo($vs_field_name);
             $t_list = new ca_lists();
             if ($vs_list_name = $va_field_info['LIST_CODE']) {
                 $t_list_item = new ca_list_items($pn_row_id);
                 if ($vs_tmp = $t_list_item->getLabelForDisplay()) {
                     return $vs_tmp;
                 }
                 return '???';
             } else {
                 if ($vs_list_name = $va_field_info['LIST']) {
                     if (is_array($va_list_items = $t_list->getItemsForList($vs_list_name))) {
                         $va_list_items = caExtractValuesByUserLocale($va_list_items);
                         foreach ($va_list_items as $vn_id => $va_list_item) {
                             if ($va_list_item['item_value'] == $pn_row_id) {
                                 return $va_list_item['name_plural'];
                             }
                         }
                     }
                 }
             }
             if (isset($va_field_info['BOUNDS_CHOICE_LIST'])) {
                 $va_choice_list = $va_field_info['BOUNDS_CHOICE_LIST'];
                 if (is_array($va_choice_list)) {
                     foreach ($va_choice_list as $vs_val => $vn_id) {
                         if ($vn_id == $pn_row_id) {
                             return $vs_val;
                         }
                     }
                 }
             }
             return '???';
             break;
             # -----------------------------------------------------
         # -----------------------------------------------------
         default:
             if ($ps_facet_name == '_search') {
                 return $pn_row_id;
             }
             return 'Invalid type';
             break;
             # -----------------------------------------------------
     }
 }