本文整理汇总了PHP中Attribute::getSortFieldForDatatype方法的典型用法代码示例。如果您正苦于以下问题:PHP Attribute::getSortFieldForDatatype方法的具体用法?PHP Attribute::getSortFieldForDatatype怎么用?PHP Attribute::getSortFieldForDatatype使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Attribute
的用法示例。
在下文中一共展示了Attribute::getSortFieldForDatatype方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: find
//.........这里部分代码省略.........
$va_joins[] = " INNER JOIN ca_attributes ON ca_attributes.row_id = {$vs_table}.{$vs_table_pk} AND ca_attributes.table_num = {$vn_table_num} ";
$va_joins[] = " INNER JOIN ca_attribute_values ON ca_attribute_values.attribute_id = ca_attributes.attribute_id ";
foreach ($pa_values as $vs_field => $vm_value) {
if (($vn_element_id = array_search($vs_field, $va_element_codes)) !== false) {
$vs_q = " (ca_attribute_values.element_id = {$vn_element_id}) AND ";
switch ($vn_datatype = $t_instance->_getElementDatatype($vs_field)) {
case 0:
// continue
// continue
case 15:
// media
// media
case 16:
// file
// SKIP
continue 2;
break;
case 2:
// date
if (is_array($va_date = caDateToHistoricTimestamps($vm_value))) {
$vs_q .= "((ca_attribute_values.value_decimal1 BETWEEN ? AND ?) OR (ca_attribute_values.value_decimal2 BETWEEN ? AND ?))";
array_push($va_sql_params, $va_date['start'], $va_date['end'], $va_date['start'], $va_date['end']);
} else {
continue 2;
}
break;
case 3:
// list
$vn_item_id = is_numeric($vm_value) ? (int) $vm_value : (int) caGetListItemID($vm_value);
$vs_q .= "(ca_attribute_values.item_id = ?)";
$va_sql_params[] = $vn_item_id;
break;
default:
if (!($vs_fld = Attribute::getSortFieldForDatatype($vn_datatype))) {
$vs_fld = 'value_longtext1';
}
if (caGetOption('allowWildcards', $pa_options, false) && strpos($vm_value, '%') !== false) {
$vs_q .= "(ca_attribute_values.{$vs_fld} LIKE ?)";
} else {
$vs_q .= "(ca_attribute_values.{$vs_fld} = ?)";
}
$va_sql_params[] = (string) $vm_value;
break;
}
$va_label_sql[] = "({$vs_q})";
}
}
}
if (!sizeof($va_label_sql)) {
return null;
}
$vs_deleted_sql = $t_instance->hasField('deleted') ? "({$vs_table}.deleted = 0) AND " : '';
$vs_sql = "SELECT * FROM {$vs_table}";
$vs_sql .= join("\n", $va_joins);
$vs_sql .= " WHERE {$vs_deleted_sql} " . join(" {$ps_boolean} ", $va_label_sql);
$vs_orderby = '';
if ($vs_sort_proc) {
$vs_sort_direction = caGetOption('sortDirection', $pa_options, 'ASC', array('validValues' => array('ASC', 'DESC')));
$va_tmp = explode(".", $vs_sort_proc);
if (sizeof($va_tmp) == 2) {
switch ($va_tmp[0]) {
case $vs_table:
if ($t_instance->hasField($va_tmp[1])) {
$vs_orderby = " ORDER BY {$vs_sort_proc} {$vs_sort_direction}";
}
break;
示例2: sortHits
/**
* @param $pa_hits Array of row_ids to sort. *MUST HAVE row_ids AS KEYS, NOT VALUES*
*/
public function sortHits($pa_hits, $ps_field, $ps_direction = 'asc', $pa_options = null)
{
if (!in_array(strtolower($ps_direction), array('asc', 'desc'))) {
$ps_direction = 'asc';
}
if (!is_array($pa_hits) || !sizeof($pa_hits)) {
return $pa_hits;
}
$vs_search_tmp_table = $this->loadListIntoTemporaryResultTable($pa_hits, $pa_options['search']);
$t_table = $this->opo_datamodel->getInstanceByTableNum($this->opn_tablenum, true);
$vs_table_pk = $t_table->primaryKey();
$vs_table_name = $this->ops_tablename;
$va_fields = explode(';', $ps_field);
$va_sorted_hits = array();
$vn_num_locales = ca_locales::numberOfCataloguingLocales();
foreach ($va_fields as $vs_field) {
$va_joins = $va_orderbys = array();
$vs_locale_where = $vs_is_preferred_sql = '';
$va_tmp = explode('.', $vs_field);
// Rewrite for <table>.preferred_labels.* syntax
if ($va_tmp[1] == 'preferred_labels') {
if ($t_labeled_item_table = $this->opo_datamodel->getInstanceByTableName($va_tmp[0], true)) {
if ($t_label_table = $t_labeled_item_table->getLabelTableInstance()) {
$va_tmp2 = array($t_label_table->tableName());
if (isset($va_tmp[2]) && $t_label_table->hasField($va_tmp[2])) {
$va_tmp2[] = $va_tmp[2];
} else {
$va_tmp2[] = $t_labeled_item_table->getLabelDisplayField();
}
$va_tmp = $va_tmp2;
$vs_field = join(".", $va_tmp);
}
}
}
if ($va_tmp[0] == $vs_table_name) {
//
// sort field is in search table
//
if (!$t_table->hasField($va_tmp[1])) {
//
// is it an attribute?
//
$t_element = new ca_metadata_elements();
$vs_sort_element_code = array_pop($va_tmp);
if ($t_element->load(array('element_code' => $vs_sort_element_code))) {
$vn_element_id = $t_element->getPrimaryKey();
if (!($vs_sortable_value_fld = Attribute::getSortFieldForDatatype($t_element->get('datatype')))) {
return $pa_hits;
}
if ((int) $t_element->get('datatype') == 3) {
$vs_sortable_value_fld = 'lil.name_plural';
$vs_sort_field = array_pop(explode('.', $vs_sortable_value_fld));
$vs_locale_where = $vn_num_locales > 1 ? ', lil.locale_id' : '';
$vs_sql = "\n\t\t\t\t\t\t\t\tSELECT attr.row_id, lil.locale_id, lower({$vs_sortable_value_fld}) {$vs_sort_field}\n\t\t\t\t\t\t\t\tFROM ca_attributes attr\n\t\t\t\t\t\t\t\tINNER JOIN ca_attribute_values AS attr_vals ON attr_vals.attribute_id = attr.attribute_id\n\t\t\t\t\t\t\t\tINNER JOIN ca_list_item_labels AS lil ON lil.item_id = attr_vals.item_id\n\t\t\t\t\t\t\t\tINNER JOIN {$vs_browse_tmp_table} ON {$vs_browse_tmp_table}.row_id = attr.row_id\n\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t(attr_vals.element_id = ?) AND (attr.table_num = ?) AND (lil.{$vs_sort_field} IS NOT NULL)\n\t\t\t\t\t\t\t\tORDER BY lil.{$vs_sort_field}\n\t\t\t\t\t\t\t";
} else {
$vs_sortable_value_fld = 'attr_vals.' . $vs_sortable_value_fld;
$vs_sort_field = array_pop(explode('.', $vs_sortable_value_fld));
$vs_locale_where = $vn_num_locales > 1 ? 'attr.locale_id' : '';
$vs_sql = "\n\t\t\t\t\t\t\t\tSELECT attr.row_id, attr.locale_id, lower({$vs_sortable_value_fld}) {$vs_sort_field}\n\t\t\t\t\t\t\t\tFROM ca_attributes attr\n\t\t\t\t\t\t\t\tINNER JOIN ca_attribute_values AS attr_vals ON attr_vals.attribute_id = attr.attribute_id\n\t\t\t\t\t\t\t\tINNER JOIN {$vs_search_tmp_table} ON {$vs_search_tmp_table}.row_id = attr.row_id\n\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t(attr_vals.element_id = ?) AND (attr.table_num = ?) AND (attr_vals.{$vs_sort_field} IS NOT NULL)\n\t\t\t\t\t\t\t\tORDER BY attr_vals.{$vs_sort_field}\n\t\t\t\t\t\t\t";
//print $vs_sql." ; $vn_element_id/; ".$this->opn_tablenum."<br>";
}
$qr_sort = $this->opo_db->query($vs_sql, (int) $vn_element_id, (int) $this->opn_tablenum);
while ($qr_sort->nextRow()) {
$va_row = $qr_sort->getRow();
if (!$va_row['row_id']) {
continue;
}
if ($vn_num_locales > 1) {
$va_sorted_hits[$va_row['row_id']][$va_row['locale_id']] .= trim(str_replace(array("'", '"'), array('', ''), $va_row[$vs_sort_field]));
} else {
$va_sorted_hits[$va_row['row_id']] .= trim(str_replace(array("'", '"'), array('', ''), $va_row[$vs_sort_field]));
}
unset($pa_hits[$va_row['row_id']]);
}
// Add on hits that aren't sorted because they don't have an attribute associated
foreach ($pa_hits as $vn_id => $va_row) {
if (!is_array($va_row)) {
$va_row = array();
}
if ($vn_num_locales > 1) {
$va_sorted_hits[$vn_id][1] = $va_row;
} else {
$va_sorted_hits[$vn_id] = $va_row;
}
}
}
continue;
} else {
$va_field_info = $t_table->getFieldInfo($va_tmp[1]);
if ($va_field_info['START'] && $va_field_info['END']) {
$va_orderbys[] = $va_field_info['START'] . ' ' . $ps_direction;
$va_orderbys[] = $va_field_info['END'] . ' ' . $ps_direction;
} else {
$va_orderbys[] = $vs_field . ' ' . $ps_direction;
}
if ($t_table->hasField('locale_id')) {
$vs_locale_where = ", " . $vs_table_name . ".locale_id";
//.........这里部分代码省略.........
示例3: _getSortKeysForElement
/**
* Get sort keys for list of hits from a given table
*
* @param string $ps_element_code
* @param int $pn_table_num
* @param array $pa_hits
* @return array|bool
*/
private function _getSortKeysForElement($ps_element_code, $pn_table_num, $pa_hits)
{
if (!($t_element = ca_metadata_elements::getInstance($ps_element_code))) {
return false;
}
// is metadata element
$vn_element_id = $t_element->getPrimaryKey();
if (!($vs_sortable_value_fld = Attribute::getSortFieldForDatatype($t_element->get('datatype')))) {
return false;
}
$vs_sql = null;
switch ($vn_datatype = (int) $t_element->get('datatype')) {
case __CA_ATTRIBUTE_VALUE_LIST__:
$vs_sql = "\n\t\t\t\t\t\t\tSELECT attr.row_id, lower(lil.name_plural) name_plural\n\t\t\t\t\t\t\tFROM ca_attributes attr\n\t\t\t\t\t\t\tINNER JOIN ca_attribute_values AS attr_vals ON attr_vals.attribute_id = attr.attribute_id\n\t\t\t\t\t\t\tINNER JOIN ca_list_item_labels AS lil ON lil.item_id = attr_vals.item_id\n\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t(attr_vals.element_id = ?) AND\n\t\t\t\t\t\t\t\t(attr.table_num = ?) AND\n\t\t\t\t\t\t\t\t(lil.name_plural IS NOT NULL) AND\n\t\t\t\t\t\t\t\t(attr.row_id IN (?))\n\t\t\t\t\t\t";
break;
case __CA_ATTRIBUTE_VALUE_OBJECTS__:
case __CA_ATTRIBUTE_VALUE_ENTITIES__:
case __CA_ATTRIBUTE_VALUE_PLACES__:
case __CA_ATTRIBUTE_VALUE_OCCURRENCES__:
case __CA_ATTRIBUTE_VALUE_COLLECTIONS__:
case __CA_ATTRIBUTE_VALUE_LOANS__:
case __CA_ATTRIBUTE_VALUE_MOVEMENTS__:
case __CA_ATTRIBUTE_VALUE_STORAGELOCATIONS__:
case __CA_ATTRIBUTE_VALUE_OBJECTLOTS__:
if (!($vs_sortable_value_fld = Attribute::getSortFieldForDatatype($vn_datatype))) {
break;
}
if (!($t_auth_instance = AuthorityAttributeValue::elementTypeToInstance($vn_datatype))) {
break;
}
$vs_sql = "\n\t\t\t\t\t\t\tSELECT attr.row_id, lower(lil.{$vs_sortable_value_fld}) {$vs_sortable_value_fld}\n\t\t\t\t\t\t\tFROM ca_attributes attr\n\t\t\t\t\t\t\tINNER JOIN ca_attribute_values AS attr_vals ON attr_vals.attribute_id = attr.attribute_id\n\t\t\t\t\t\t\tINNER JOIN " . $t_auth_instance->getLabelTableName() . " AS lil ON lil.value_integer1 = attr_vals.item_id\n\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t(attr_vals.element_id = ?) AND\n\t\t\t\t\t\t\t\t(attr.table_num = ?) AND\n\t\t\t\t\t\t\t\t(lil.{$vs_sortable_value_fld} IS NOT NULL) AND\n\t\t\t\t\t\t\t\t(attr.row_id IN (?))\n\t\t\t\t\t\t";
break;
case __CA_ATTRIBUTE_VALUE_DATERANGE__:
$vs_sortable_value_fld = 'attr_vals.' . $vs_sortable_value_fld;
$vs_sort_field = array_pop(explode('.', $vs_sortable_value_fld));
$vs_sql = "\n\t\t\t\t\t\t\tSELECT attr.row_id, {$vs_sortable_value_fld}\n\t\t\t\t\t\t\tFROM ca_attributes attr\n\t\t\t\t\t\t\tINNER JOIN ca_attribute_values AS attr_vals ON attr_vals.attribute_id = attr.attribute_id\n\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t(attr_vals.element_id = ?) AND\n\t\t\t\t\t\t\t\t(attr.table_num = ?) AND\n\t\t\t\t\t\t\t\t(attr_vals.{$vs_sort_field} IS NOT NULL) AND\n\t\t\t\t\t\t\t(attr.row_id IN (?))\n\t\t\t\t\t\t";
break;
default:
$vs_sortable_value_fld = 'attr_vals.' . $vs_sortable_value_fld;
$vs_sort_field = array_pop(explode('.', $vs_sortable_value_fld));
$vs_sql = "\n\t\t\t\t\t\t\tSELECT attr.row_id, lower({$vs_sortable_value_fld}) {$vs_sort_field}\n\t\t\t\t\t\t\tFROM ca_attributes attr\n\t\t\t\t\t\t\tINNER JOIN ca_attribute_values AS attr_vals ON attr_vals.attribute_id = attr.attribute_id\n\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t(attr_vals.element_id = ?) AND\n\t\t\t\t\t\t\t\t(attr.table_num = ?) AND\n\t\t\t\t\t\t\t\t(attr_vals.{$vs_sort_field} IS NOT NULL) AND\n\t\t\t\t\t\t\t\t(attr.row_id IN (?))\n\t\t\t\t\t\t";
break;
}
if (!$vs_sql) {
return false;
}
$qr_sort = $this->opo_db->query($vs_sql, array((int) $vn_element_id, (int) $pn_table_num, $pa_hits));
$va_sort_keys = array();
while ($qr_sort->nextRow()) {
$va_row = $qr_sort->getRow();
$va_sort_keys[$va_row['row_id']] = $va_row[$vs_sort_field];
}
return $va_sort_keys;
}
示例4: sortHits
/**
*
*/
public function sortHits(&$pa_hits, $ps_table, $ps_field, $ps_key, $ps_direction = 'asc', $pa_options = null)
{
//$t= new Timer();
$vs_browse_tmp_table = $this->loadListIntoTemporaryResultTable($pa_hits, $ps_key);
if (!in_array(strtolower($ps_direction), array('asc', 'desc'))) {
$ps_direction = 'asc';
}
if (!is_array($pa_hits) || !sizeof($pa_hits)) {
return $pa_hits;
}
$t_table = $this->opo_datamodel->getInstanceByTableName($ps_table, true);
$vs_table_pk = $t_table->primaryKey();
$vn_table_num = $t_table->tableNum();
$va_sort_tmp = explode('/', $ps_field);
$ps_field = $va_sort_tmp[0];
$vs_rel_type = sizeof($va_sort_tmp) > 1 ? $va_sort_tmp[1] : null;
$va_fields = explode(';', $ps_field);
$va_sorted_hits = array();
$va_joins = array();
$vs_locale_where = $vs_is_preferred_sql = '';
$vs_primary_sort_field = array_shift($va_fields);
$va_primary_sort_field = explode('.', $vs_primary_sort_field);
$va_additional_sort_fields = array();
foreach ($va_fields as $vs_additional_sort_field) {
$va_tmp = explode('.', $vs_additional_sort_field);
if ($va_tmp[0] == $va_primary_sort_field[0]) {
$va_additional_sort_fields[] = $va_tmp;
}
}
if ($va_primary_sort_field[0] == $ps_table) {
//
// sort field is in search table
//
if (!$t_table->hasField($va_primary_sort_field[1])) {
//
// is it an attribute?
//
$t_element = new ca_metadata_elements();
$vs_sort_element_code = array_pop($va_primary_sort_field);
if ($t_element->load(array('element_code' => $vs_sort_element_code))) {
$vn_element_id = $t_element->getPrimaryKey();
if (!($vs_sortable_value_fld = Attribute::getSortFieldForDatatype($t_element->get('datatype')))) {
return $pa_hits;
}
if ((int) $t_element->get('datatype') == __CA_ATTRIBUTE_VALUE_LIST__) {
$vs_sortable_value_fld = 'lil.name_plural';
$vs_sort_field = array_pop(explode('.', $vs_sortable_value_fld));
$vs_sql = "\n\t\t\t\t\t\t\t\tSELECT attr.row_id, lil.locale_id, lower({$vs_sortable_value_fld}) {$vs_sort_field}\n\t\t\t\t\t\t\t\tFROM ca_attributes attr\n\t\t\t\t\t\t\t\tINNER JOIN ca_attribute_values AS attr_vals ON attr_vals.attribute_id = attr.attribute_id\n\t\t\t\t\t\t\t\tINNER JOIN ca_list_item_labels AS lil ON lil.item_id = attr_vals.item_id\n\t\t\t\t\t\t\t\tINNER JOIN {$vs_browse_tmp_table} ON {$vs_browse_tmp_table}.row_id = attr.row_id\n\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t(attr_vals.element_id = ?) AND (attr.table_num = ?) AND (lil.{$vs_sort_field} IS NOT NULL)\n\t\t\t\t\t\t\t\tORDER BY lil.{$vs_sort_field} {$ps_direction}\n\t\t\t\t\t\t\t";
} elseif ((int) $t_element->get('datatype') == __CA_ATTRIBUTE_VALUE_DATERANGE__) {
$vs_sortable_value_fld = 'attr_vals.' . $vs_sortable_value_fld;
$vs_sort_field = array_pop(explode('.', $vs_sortable_value_fld));
$vs_sql = "\n\t\t\t\t\t\t\t\tSELECT attr.row_id, attr.locale_id, {$vs_sortable_value_fld}\n\t\t\t\t\t\t\t\tFROM ca_attributes attr\n\t\t\t\t\t\t\t\tINNER JOIN ca_attribute_values AS attr_vals ON attr_vals.attribute_id = attr.attribute_id\n\t\t\t\t\t\t\t\tINNER JOIN {$vs_browse_tmp_table} ON {$vs_browse_tmp_table}.row_id = attr.row_id\n\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t(attr_vals.element_id = ?) AND (attr.table_num = ?) AND (attr_vals.{$vs_sort_field} IS NOT NULL)\n\t\t\t\t\t\t\t\tORDER BY attr_vals.{$vs_sort_field} {$ps_direction}, attr.row_id\n\t\t\t\t\t\t\t";
} else {
$vs_sortable_value_fld = 'attr_vals.' . $vs_sortable_value_fld;
$vs_sort_field = array_pop(explode('.', $vs_sortable_value_fld));
$vs_sql = "\n\t\t\t\t\t\t\t\tSELECT attr.row_id, attr.locale_id, lower({$vs_sortable_value_fld}) {$vs_sort_field}\n\t\t\t\t\t\t\t\tFROM ca_attributes attr\n\t\t\t\t\t\t\t\tINNER JOIN ca_attribute_values AS attr_vals ON attr_vals.attribute_id = attr.attribute_id\n\t\t\t\t\t\t\t\tINNER JOIN {$vs_browse_tmp_table} ON {$vs_browse_tmp_table}.row_id = attr.row_id\n\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t(attr_vals.element_id = ?) AND (attr.table_num = ?) AND (attr_vals.{$vs_sort_field} IS NOT NULL)\n\t\t\t\t\t\t\t\tORDER BY attr_vals.{$vs_sort_field} {$ps_direction}, attr.row_id\n\t\t\t\t\t\t\t";
}
$qr_sort = $this->opo_db->query($vs_sql, (int) $vn_element_id, (int) $vn_table_num);
$va_sorted_hits = $qr_sort->getAllFieldValues('row_id');
// Add on hits that aren't sorted because they don't have an attribute associated
$va_missing_items = array_diff($pa_hits, $va_sorted_hits);
$va_sorted_hits = array_merge($va_sorted_hits, $va_missing_items);
}
return $va_sorted_hits;
} else {
$va_field_info = $t_table->getFieldInfo($va_primary_sort_field[1]);
if ($va_field_info['START'] && $va_field_info['END']) {
$vs_sortable_value_fld = $vs_primary_sort_field;
$va_additional_sort_fields[] = $va_field_info['END'];
} else {
$vs_sortable_value_fld = $vs_primary_sort_field;
}
}
} else {
// sort field is in related table
$va_path = $this->opo_datamodel->getPath($ps_table, $va_primary_sort_field[0]);
if (sizeof($va_path) > 2) {
// many-many
$vs_last_table = null;
// generate related joins
foreach ($va_path as $vs_table => $va_info) {
$t_table = $this->opo_datamodel->getInstanceByTableName($vs_table, true);
$vs_rel_type_sql = null;
if ($t_table->isRelationship() && $vs_rel_type) {
if (is_array($va_rel_types = caMakeRelationshipTypeIDList($vs_table, array($vs_rel_type))) && sizeof($va_rel_types)) {
$vs_rel_type_sql = " AND {$vs_table}.type_id IN (" . join(",", $va_rel_types) . ")";
}
}
if ($vs_last_table) {
$va_rels = $this->opo_datamodel->getOneToManyRelations($vs_last_table, $vs_table);
if (!sizeof($va_rels)) {
$va_rels = $this->opo_datamodel->getOneToManyRelations($vs_table, $vs_last_table);
}
if ($vs_table == $va_rels['one_table']) {
$va_joins[$vs_table] = "INNER JOIN " . $va_rels['one_table'] . " ON " . $va_rels['one_table'] . "." . $va_rels['one_table_field'] . " = " . $va_rels['many_table'] . "." . $va_rels['many_table_field'] . $vs_rel_type_sql;
} else {
$va_joins[$vs_table] = "INNER JOIN " . $va_rels['many_table'] . " ON " . $va_rels['many_table'] . "." . $va_rels['many_table_field'] . " = " . $va_rels['one_table'] . "." . $va_rels['one_table_field'] . $vs_rel_type_sql;
//.........这里部分代码省略.........
示例5: sortHits
/**
*
* @param array $pa_hits
* @param string $ps_table The table being sorted
* @param string $ps_field A semicolon-delimited string of fully qualified bundle names (Eg. ca_objects.idno;ca_objects.due_date)
* @param string $ps_key Key to use for temporary storage
* @param string $ps_direction Direction to sort
* @param array $pa_options
*
* @return array
*/
public function sortHits(&$pa_hits, $ps_table, $ps_field, $ps_direction = 'asc', $pa_options = null)
{
if (!($t_table = $this->opo_datamodel->getInstanceByTableName($ps_table, true))) {
return null;
}
// invalid table
$vs_table_pk = $t_table->primaryKey();
$vn_table_num = $t_table->tableNum();
// TODO: allow override of this with field-specific directions
// Default direction
if (!in_array(strtolower($ps_direction), array('asc', 'desc'))) {
$ps_direction = 'asc';
}
// Don't try to sort empty results
if (!is_array($pa_hits) || !sizeof($pa_hits)) {
return $pa_hits;
}
// Get field list
//$va_sort_tmp = explode('/', $ps_field); // strip any relationship type
//$ps_field = $va_sort_tmp[0];
//$vs_rel_type = (sizeof($va_sort_tmp) > 1) ? $va_sort_tmp[1] : null;
$va_bundles = explode(';', $ps_field);
// $va_sort_tmp[0]);
$va_sorted_hits = array();
$vs_sort_tmp_table = null;
$va_sort_key_values = array();
foreach ($va_bundles as $vs_bundle) {
$va_sort_tmp = explode('/', $vs_bundle);
// strip any relationship type
$vs_rel_type = sizeof($va_sort_tmp) > 1 ? $va_sort_tmp[1] : null;
$vs_bundle = $va_sort_tmp[0];
list($vs_field_table, $vs_field, $vs_subfield) = explode(".", $vs_bundle);
if (!($t_instance = $this->opo_datamodel->getInstanceByTableName($vs_field_table, true))) {
break;
}
// Transform preferred_labels
if ($vs_field == 'preferred_labels') {
$vs_field_table = $t_instance->getLabelTableName();
$vs_field = $vs_subfield ? $vs_subfield : $t_instance->getLabelDisplayField();
$vs_subfield = null;
}
if ($vs_field_table === $ps_table) {
// sort in primary table
if (!$t_table->hasField($vs_field)) {
if ($t_element = ca_metadata_elements::getInstance($vs_subfield ? $vs_subfield : $vs_field)) {
// is metadata element
$vn_element_id = $t_element->getPrimaryKey();
if (!($vs_sortable_value_fld = Attribute::getSortFieldForDatatype($t_element->get('datatype')))) {
break;
}
switch ($vn_datatype = (int) $t_element->get('datatype')) {
case __CA_ATTRIBUTE_VALUE_LIST__:
$vs_sql = "\n\t\t\t\t\t\t\t\t\t\tSELECT attr.row_id, lower(lil.name_plural) name_plural\n\t\t\t\t\t\t\t\t\t\tFROM ca_attributes attr\n\t\t\t\t\t\t\t\t\t\tINNER JOIN ca_attribute_values AS attr_vals ON attr_vals.attribute_id = attr.attribute_id\n\t\t\t\t\t\t\t\t\t\tINNER JOIN ca_list_item_labels AS lil ON lil.item_id = attr_vals.item_id\n\t\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\t\t(attr_vals.element_id = ?) AND \n\t\t\t\t\t\t\t\t\t\t\t(attr.table_num = ?) AND \n\t\t\t\t\t\t\t\t\t\t\t(lil.name_plural IS NOT NULL) AND\n\t\t\t\t\t\t\t\t\t\t\t(attr.row_id IN (?))\n\t\t\t\t\t\t\t\t\t";
break;
case __CA_ATTRIBUTE_VALUE_OBJECTS__:
case __CA_ATTRIBUTE_VALUE_ENTITIES__:
case __CA_ATTRIBUTE_VALUE_PLACES__:
case __CA_ATTRIBUTE_VALUE_OCCURRENCES__:
case __CA_ATTRIBUTE_VALUE_COLLECTIONS__:
case __CA_ATTRIBUTE_VALUE_LOANS__:
case __CA_ATTRIBUTE_VALUE_MOVEMENTS__:
case __CA_ATTRIBUTE_VALUE_STORAGELOCATIONS__:
case __CA_ATTRIBUTE_VALUE_OBJECTLOTS__:
if (!($vs_sortable_value_fld = Attribute::getSortFieldForDatatype($vn_datatype))) {
break;
}
if (!($t_auth_instance = AuthorityAttributeValue::elementTypeToInstance($vn_datatype))) {
break;
}
$vs_sql = "\n\t\t\t\t\t\t\t\t\t\tSELECT attr.row_id, lower(lil.{$vs_sortable_value_fld}) {$vs_sortable_value_fld}\n\t\t\t\t\t\t\t\t\t\tFROM ca_attributes attr\n\t\t\t\t\t\t\t\t\t\tINNER JOIN ca_attribute_values AS attr_vals ON attr_vals.attribute_id = attr.attribute_id\n\t\t\t\t\t\t\t\t\t\tINNER JOIN " . $t_auth_instance->getLabelTableName() . " AS lil ON lil.value_integer1 = attr_vals.item_id\n\t\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\t\t(attr_vals.element_id = ?) AND \n\t\t\t\t\t\t\t\t\t\t\t(attr.table_num = ?) AND \n\t\t\t\t\t\t\t\t\t\t\t(lil.{$vs_sortable_value_fld} IS NOT NULL) AND\n\t\t\t\t\t\t\t\t\t\t\t(attr.row_id IN (?))\n\t\t\t\t\t\t\t\t\t";
break;
case __CA_ATTRIBUTE_VALUE_DATERANGE__:
$vs_sortable_value_fld = 'attr_vals.' . $vs_sortable_value_fld;
$vs_sort_field = array_pop(explode('.', $vs_sortable_value_fld));
$vs_sql = "\n\t\t\t\t\t\t\t\t\t\tSELECT attr.row_id, {$vs_sortable_value_fld}\n\t\t\t\t\t\t\t\t\t\tFROM ca_attributes attr\n\t\t\t\t\t\t\t\t\t\tINNER JOIN ca_attribute_values AS attr_vals ON attr_vals.attribute_id = attr.attribute_id\n\t\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\t\t(attr_vals.element_id = ?) AND \n\t\t\t\t\t\t\t\t\t\t\t(attr.table_num = ?) AND \n\t\t\t\t\t\t\t\t\t\t\t(attr_vals.{$vs_sort_field} IS NOT NULL) AND\n\t\t\t\t\t\t\t\t\t\t\t(attr.row_id IN (?))\n\t\t\t\t\t\t\t\t\t";
break;
default:
$vs_sortable_value_fld = 'attr_vals.' . $vs_sortable_value_fld;
$vs_sort_field = array_pop(explode('.', $vs_sortable_value_fld));
$vs_sql = "\n\t\t\t\t\t\t\t\t\t\tSELECT attr.row_id, lower({$vs_sortable_value_fld}) {$vs_sort_field}\n\t\t\t\t\t\t\t\t\t\tFROM ca_attributes attr\n\t\t\t\t\t\t\t\t\t\tINNER JOIN ca_attribute_values AS attr_vals ON attr_vals.attribute_id = attr.attribute_id\n\t\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\t\t(attr_vals.element_id = ?) AND \n\t\t\t\t\t\t\t\t\t\t\t(attr.table_num = ?) AND \n\t\t\t\t\t\t\t\t\t\t\t(attr_vals.{$vs_sort_field} IS NOT NULL) AND\n\t\t\t\t\t\t\t\t\t\t\t(attr.row_id IN (?))\n\t\t\t\t\t\t\t\t\t";
break;
}
$qr_sort = $this->opo_db->query($vs_sql, array((int) $vn_element_id, (int) $vn_table_num, $pa_hits));
$va_sort_keys = array();
while ($qr_sort->nextRow()) {
$va_row = $qr_sort->getRow();
$va_sort_keys[$va_row['row_id']] = $va_row[$vs_sort_field];
}
$va_sort_key_values[] = $va_sort_keys;
//.........这里部分代码省略.........