Skip to content
Permalink
Browse files

Fix CRUD-module title-ordering on multi-lang-content sites

  • Loading branch information...
chrisgraham committed May 15, 2019
1 parent b2e806c commit dbbc06070f1f9b4cf2da83ec0473021f2783c696
@@ -28,7 +28,6 @@ class Module_cms_calendar extends Standard_crud_module
public $lang_type = 'CALENDAR_EVENT';
public $select_name = 'TITLE';
public $orderer = 'id';
public $orderer_is_multi_lang = false;
public $array_key = 'id';
public $title_is_multi_lang = true;
public $non_integer_id = false;
@@ -40,7 +40,6 @@ class Module_cms_quiz extends Standard_crud_module
public $menu_label = 'QUIZZES';
public $table = 'quizzes';
public $orderer = 'q_add_date';
public $orderer_is_multi_lang = false;
public $donext_type = null;
public $donext_entry_content_type = 'quiz';
@@ -27,7 +27,6 @@ class Module_cms_booking extends Standard_crud_module
public $user_facing = false;
public $menu_label = 'BOOKINGS';
public $orderer = 'sort_order';
public $orderer_is_multi_lang = false;
public $title_is_multi_lang = true;
public $table = 'bookable';
public $bookings_crud_module;
@@ -412,7 +411,6 @@ class Module_cms_booking_supplements extends Standard_crud_module
public $user_facing = false;
public $menu_label = 'BOOKINGS';
public $orderer = 'sort_order';
public $orderer_is_multi_lang = false;
public $title_is_multi_lang = true;
public $table = 'bookable_supplement';
@@ -612,7 +610,6 @@ class Module_cms_booking_blacks extends Standard_crud_module
public $user_facing = false;
public $menu_label = 'BOOKINGS';
public $orderer = 'id';
public $orderer_is_multi_lang = false;
public $title_is_multi_lang = true;
public $table = 'bookable_blacked';
@@ -29,7 +29,6 @@ class Module_cms_tutorials extends Standard_crud_module
public $menu_label = 'TUTORIALS';
public $select_name = 'TUTORIALS';
public $orderer = 't_title';
public $orderer_is_multi_lang = false;
public $table = 'tutorials_external';
public $do_preview = null;
@@ -32,7 +32,6 @@ class Module_warnings extends Standard_crud_module
public $menu_label = 'MODULE_TRANS_NAME_warnings';
public $table = 'f_warnings';
public $orderer = 'w_time';
public $orderer_is_multi_lang = false;
public $title_is_multi_lang = true;
/**
@@ -110,7 +110,6 @@ abstract class Standard_crud_module
public $table_prefix = '';
public $array_key = 'id';
public $title_is_multi_lang = true;
public $orderer_is_multi_lang = null;
public $orderer = null;
public $table = null; // Actually, this is used by choose_feedback_fields_statistically also
@@ -1106,32 +1105,32 @@ public function get_entry_rows($recache = false, $orderer = null, $where = null,
}
}
$orderer_is_multi_lang = $this->orderer_is_multi_lang;
if (is_null($orderer_is_multi_lang)) {
$orderer_is_multi_lang = $this->title_is_multi_lang;
}
$select_field = !is_null($this->orderer) ? $this->orderer : ($this->table_prefix . strtolower($this->select_name));
if (is_null($orderer)) {
$orderer = $select_field;
}
$table_raw = (is_null($this->table) ? $this->module_type : $this->table);
$table = $table_raw . ' r';
$db = ((substr($table, 0, 2) == 'f_') && ($table != 'f_welcome_emails r') && (!$force_site_db) && (get_forum_type() == 'cns')) ? $GLOBALS['FORUM_DB'] : $GLOBALS['SITE_DB'];
if (($orderer_is_multi_lang) && (preg_replace('# (ASC|DESC)$#', '', $orderer) == $select_field)) {
if (is_null($orderer)) {
$orderer = $select_field;
}
$orderer_is_multi_lang = isset($GLOBALS['TABLE_LANG_FIELDS_CACHE'][$table_raw][preg_replace('# (ASC|DESC)$#', '', $orderer)]);
if ($orderer_is_multi_lang) {
$_orderer = $GLOBALS['SITE_DB']->translate_field_ref(preg_replace('# (ASC|DESC)$#', '', $orderer));
if (substr($orderer, -5) == ' DESC') {
$_orderer .= ' DESC';
}
$orderer = $_orderer;
} elseif (substr($orderer, 0, 1) != '(') { // If not a subquery
} elseif ((substr($orderer, 0, 1) != '(') && (strpos($orderer, '.') === false)) { // If not a subquery and not already dotted
$orderer = 'r.' . $orderer;
}
if ($force_site_db) {
$dbs_bak = $GLOBALS['NO_DB_SCOPE_CHECK'];
$GLOBALS['NO_DB_SCOPE_CHECK'] = true;
}
$max_rows = $db->query_select_value($table . $join, 'COUNT(*)', $where, '', false, isset($GLOBALS['TABLE_LANG_FIELDS_CACHE'][$table_raw]) ? $GLOBALS['TABLE_LANG_FIELDS_CACHE'][$table_raw] : null);
if ($max_rows == 0) {
return array(array(), 0);
@@ -1141,13 +1140,15 @@ public function get_entry_rows($recache = false, $orderer = null, $where = null,
$max = get_param_integer('max', 20);
}
$rows = $db->query_select($table . $join, array('r.*'), $where, 'ORDER BY ' . $orderer, $max, $start, false, isset($GLOBALS['TABLE_LANG_FIELDS_CACHE'][$table_raw]) ? $GLOBALS['TABLE_LANG_FIELDS_CACHE'][$table_raw] : null);
if ($force_site_db) {
$GLOBALS['NO_DB_SCOPE_CHECK'] = $dbs_bak;
}
$_entries = array();
foreach ($rows as $row) {
$key = $row[$this->array_key];
$readable = $orderer_is_multi_lang ? get_translated_text($row[$select_field], $db) : $row[$select_field];
$readable = $row[$select_field];
if (is_integer($readable)) {
$readable = '#' . strval($readable);
}

0 comments on commit dbbc060

Please sign in to comment.
You can’t perform that action at this time.