diff --git a/application/libraries/Librivox_search.php b/application/libraries/Librivox_search.php index 5da8e6ec..9b53b7b4 100644 --- a/application/libraries/Librivox_search.php +++ b/application/libraries/Librivox_search.php @@ -183,7 +183,7 @@ function advanced_title_search($params) $sql .= ' - SELECT DISTINCT "title" AS blade, ' . implode(',' , $cols) . ' + SELECT "title" AS blade, ' . implode(',' , $cols) . ' FROM search_table st @@ -227,7 +227,7 @@ function advanced_title_search($params) $sql .= ' UNION - SELECT DISTINCT "title" AS blade, ' . implode(',' , $cols) . ' + SELECT "title" AS blade, ' . implode(',' , $cols) . ' FROM search_table st @@ -272,7 +272,7 @@ function advanced_title_search($params) $sql .= ' UNION - SELECT DISTINCT "group" AS blade,' . implode(',' , $cols) . ' + SELECT "group" AS blade,' . implode(',' , $cols) . ' FROM search_table st @@ -452,4 +452,4 @@ private function _get_projects_by_reader($reader, $exact_match) } -} \ No newline at end of file +} diff --git a/application/libraries/Librivox_simple_search.php b/application/libraries/Librivox_simple_search.php index da5ef833..17319f1c 100644 --- a/application/libraries/Librivox_simple_search.php +++ b/application/libraries/Librivox_simple_search.php @@ -63,7 +63,7 @@ function simple_search($params) // q is in the title, and not in a group. Joins language & author for fields. $sql .= ' - SELECT DISTINCT "title" AS blade, ' . implode(',' , $cols) . ' + SELECT "title" AS blade, ' . implode(',' , $cols) . ' FROM search_table st @@ -114,7 +114,7 @@ function simple_search($params) UNION - SELECT DISTINCT "group" AS blade,' . implode(',' , $cols) . ' + SELECT "group" AS blade,' . implode(',' , $cols) . ' FROM search_table st @@ -337,4 +337,4 @@ function simple_search($params) } -} \ No newline at end of file +} diff --git a/application/models/Project_model.php b/application/models/Project_model.php index 6e276363..117643c3 100644 --- a/application/models/Project_model.php +++ b/application/models/Project_model.php @@ -59,7 +59,7 @@ function get_projects($params) OR p.person_mc_id = '.$user_projects.' OR p.person_pl_id = '.$user_projects.' OR reader_data.reader_id = '.$user_projects.')'; - } + } $sql .= ' ORDER BY p.title '. $limit; @@ -70,7 +70,7 @@ function get_projects($params) function get_lastest_releases($limit=10) { - $sql = 'SELECT DISTINCT p.id, p.title_prefix, p.title, p.url_librivox, p.description, p.project_type, p.coverart_thumbnail, p.date_catalog, COALESCE(l.two_letter_code, l.three_letter_code) AS language_code, language + $sql = 'SELECT p.id, p.title_prefix, p.title, p.url_librivox, p.description, p.project_type, p.coverart_thumbnail, p.date_catalog, COALESCE(l.two_letter_code, l.three_letter_code) AS language_code, language FROM projects p JOIN languages l ON (l.id = p.language_id) WHERE p.status = "complete" @@ -154,7 +154,7 @@ function get_project_authors($project_id) function get_project_readers($project_id) { - $sql = 'SELECT DISTINCT u.id AS reader_id, u.display_name + $sql = 'SELECT u.id AS reader_id, u.display_name FROM users u JOIN section_readers sr ON (sr.reader_id = u.id) JOIN sections s ON (s.id = sr.section_id) @@ -168,7 +168,7 @@ function get_project_readers($project_id) function create_project_reader_list($project_id) { - $sql = 'SELECT DISTINCT u.display_name + $sql = 'SELECT u.display_name FROM users u JOIN section_readers sr ON (sr.reader_id = u.id) JOIN sections s ON (s.id = sr.section_id) @@ -221,7 +221,7 @@ function get_projects_by_author($params) $sql = ' - SELECT DISTINCT "project" AS primary_type, p.id AS primary_key, p.id, p.project_type, p.title_prefix, p.title, + SELECT "project" AS primary_type, p.id AS primary_key, p.id, p.project_type, p.title_prefix, p.title, COALESCE(p.date_catalog, "2001-01-01" ), p.url_librivox, p.status, p.coverart_thumbnail, p.zip_url, p.zip_size, l.language , p.url_forum FROM projects p JOIN project_authors pa ON (pa.project_id = p.id) @@ -253,7 +253,7 @@ function get_projects_by_author($params) $sql .= ' UNION - SELECT DISTINCT "section" AS primary_type, s.id AS primary_key, p.id, p.project_type, "", CONCAT(s.title, " (in ", COALESCE(p.title_prefix, "" ), " ", p.title, ")") as title, + SELECT "section" AS primary_type, s.id AS primary_key, p.id, p.project_type, "", CONCAT(s.title, " (in ", COALESCE(p.title_prefix, "" ), " ", p.title, ")") as title, COALESCE(p.date_catalog, "2001-01-01" ), p.url_librivox, p.status, p.coverart_thumbnail, p.zip_url, p.zip_size, l.language , p.url_forum FROM projects p JOIN sections s ON (p.id = s.project_id) @@ -318,7 +318,7 @@ function get_projects_for_title_menu($params) } $sql = ' - SELECT DISTINCT "project" AS primary_type, p.id AS primary_key, p.id, p.project_type, p.title_prefix, p.title, + SELECT "project" AS primary_type, p.id AS primary_key, p.id, p.project_type, p.title_prefix, p.title, COALESCE(p.date_catalog, "2001-01-01" ), p.url_librivox, p.status, p.coverart_thumbnail, p.zip_url, p.zip_size, l.language, p.url_forum FROM projects p @@ -351,7 +351,7 @@ function get_projects_for_title_menu($params) function get_projects_by_reader($params) { - $sql = 'SELECT DISTINCT p.id, p.project_type, p.title_prefix, p.title, p.date_catalog, p.url_librivox, p.status, p.coverart_thumbnail, p.zip_url, p.zip_size, + $sql = 'SELECT p.id, p.project_type, p.title_prefix, p.title, p.date_catalog, p.url_librivox, p.status, p.coverart_thumbnail, p.zip_url, p.zip_size, l.two_letter_code, l.language , p.url_forum FROM projects p JOIN project_readers pr ON (pr.project_id = p.id) @@ -388,7 +388,7 @@ function get_projects_by_reader($params) function get_projects_by_group($params) { - $sql = 'SELECT DISTINCT p.id, p.project_type, p.title_prefix, p.title, p.url_librivox, p.status, p.coverart_thumbnail, p.zip_url, p.zip_size, + $sql = 'SELECT p.id, p.project_type, p.title_prefix, p.title, p.url_librivox, p.status, p.coverart_thumbnail, p.zip_url, p.zip_size, l.two_letter_code, l.language, p.url_forum FROM projects p JOIN group_projects gp ON (gp.project_id = p.id) diff --git a/application/models/Project_reader_model.php b/application/models/Project_reader_model.php index 27a8b83e..b0436d0e 100644 --- a/application/models/Project_reader_model.php +++ b/application/models/Project_reader_model.php @@ -4,7 +4,7 @@ class Project_reader_model extends MY_Model { function get_all_distinct($offset=0, $limit=CATALOG_RESULT_COUNT){ - $sql = "SELECT DISTINCT reader_id, display_name, username, COALESCE(NULLIF(display_name,''), username) + $sql = "SELECT reader_id, display_name, username, COALESCE(NULLIF(display_name,''), username) FROM project_readers ORDER BY 4 ASC "; @@ -15,4 +15,4 @@ function get_all_distinct($offset=0, $limit=CATALOG_RESULT_COUNT){ } -} \ No newline at end of file +} diff --git a/application/models/User_model.php b/application/models/User_model.php index 7facaa01..e8cd32f8 100644 --- a/application/models/User_model.php +++ b/application/models/User_model.php @@ -12,11 +12,19 @@ function get_users($params=array()) //$limit = 'LIMIT 0, 500'; $limit = ''; - $sql = 'SELECT DISTINCT u.* - FROM ' . $this->_table . ' u - LEFT OUTER JOIN users_groups ug ON (ug.user_id = u.id) - LEFT OUTER JOIN roles r ON (ug.group_id = r.id) - WHERE u.id NOT IN (1,2) AND u.active = 1 '; //set these to constants + if (!empty($params['user_type']) and $params['user_type'] != 'all') + { + $sql = 'SELECT DISTINCT u.id, u.username, u.display_name, u.email, u.website + FROM ' . $this->_table . ' u + LEFT OUTER JOIN users_groups ug ON (ug.user_id = u.id) + LEFT OUTER JOIN roles r ON (ug.group_id = r.id) + WHERE u.id NOT IN (1,2) AND u.active = 1 + AND r.name = '. $this->db->escape($params['user_type']) .' '; + } else { + $sql = 'SELECT u.id, u.username, u.display_name, u.email, u.website + FROM ' . $this->_table . ' u + WHERE u.id NOT IN (1,2) AND u.active = 1 '; //set these to constants + } if (!empty($params['user_search'])) { @@ -24,16 +32,10 @@ function get_users($params=array()) $sql .= ' AND (u.username LIKE ' . $user_like . ' OR u.email LIKE ' . $user_like . ') ' ; } - if (!empty($params['user_type'])) - { - if ($params['user_type'] == 'all') - $limit = ''; - else - $sql .= ' AND r.name = '. $this->db->escape($params['user_type']) .' '; - } - $sql .= ' ORDER BY u.username '. $limit; + log_message('error', $sql); + $query = $this->db->query($sql); return $query->result(); }