$value) { $where_sql .= self::sql_filter($key,$value); } // end foreach $where_sql = rtrim($where_sql,'AND '); $sql .= $where_sql; // Now Add the Order $order_sql = "ORDER BY "; // If we don't have a sort, then go ahead and return it now if (!is_array($_SESSION['browse']['sort'])) { return $sql; } foreach ($_SESSION['browse']['sort'] as $key=>$value) { $order_sql .= self::sql_sort($key,$value); } // Clean her up $order_sql = rtrim($order_sql,"ORDER BY "); $order_sql = rtrim($order_sql,","); $sql = $sql . $order_sql; return $sql; } // get_sql /** * sql_filter * This takes a filter name and value and if it is possible * to filter by this name on this type returns the approiate sql * if not returns nothing */ private static function sql_filter($filter,$value) { $filter_sql = ''; if ($_SESSION['browse']['type'] == 'song') { switch($filter) { case 'alpha_match': $filter_sql = " `song`.`title` LIKE '" . Dba::escape($value) . "%' AND "; break; case 'unplayed': $filter_sql = " `song`.`played`='0' AND "; break; default: // Rien a faire break; } // end list of sqlable filters } // if it is a song elseif ($_SESSION['browse']['type'] == 'album') { switch($filter) { case 'alpha_match': $filter_sql = " `album`.`name` LIKE '" . Dba::escape($value) . "%' AND "; break; case 'min_count': break; default: // Rien a faire break; } } // end album elseif ($_SESSION['browse']['type'] == 'artist') { switch($filter) { case 'alpha_match': $filter_sql = " `artist`.`name` LIKE '" . Dba::escape($value) . "%' AND "; break; default: // Rien a faire break; } // end filter } // end artist elseif ($_SESSION['browse']['type'] == 'live_stream') { switch ($filter) { case 'alpha_match': $filter_sql = " `live_stream`.`name` LIKE '" . Dba::escape($value) . "%' AND "; break; default: // Rien a faire break; } // end filter } // end live_stream return $filter_sql; } // sql_filter /** * logic_filter * This runs the filters that we can't easily apply * to the sql so they have to be done after the fact * these should be limited as they are often intensive and * require additional queries per object... :( */ private static function logic_filter($object_id) { return true; } // logic_filter /** * sql_sort * This builds any order bys we need to do * to sort the results as best we can, there is also * a logic based sort that will come later as that's * a lot more complicated */ private static function sql_sort($field,$order) { if ($order != 'DESC') { $order == 'ASC'; } switch ($_SESSION['browse']['type']) { case 'song': switch($field) { case 'title'; $sql = "`song`.`title`"; break; case 'year': $sql = "`song`.`year`"; break; default: // Rien a faire break; } // end switch break; case 'album': switch($field) { case 'name': $sql = "`album`.`name`"; break; case 'year': $sql = "`album`.`year`"; break; } // end switch default: // Rien a faire break; } // end switch if ($sql) { $sql_sort = "$sql $order,"; } return $sql_sort; } // sql_sort /** * show_objects * This takes an array of objects * and requires the correct template based on the * type that we are currently browsing */ public static function show_objects($object_ids='') { $object_ids = $object_ids ? $object_ids : self::get_saved(); // Reset the total items self::$total_objects = count($object_ids); // Limit is based on the users preferences $limit = $GLOBALS['user']->prefs['offset_limit'] ? $GLOBALS['user']->prefs['offset_limit'] : '25'; $object_ids = array_slice($object_ids,self::$start,$limit); switch ($_SESSION['browse']['type']) { case 'song': show_box_top(_('Songs')); require_once Config::get('prefix') . '/templates/show_songs.inc.php'; show_box_bottom(); break; case 'album': show_box_top(_('Albums')); require_once Config::get('prefix') . '/templates/show_albums.inc.php'; show_box_bottom(); break; case 'genre': show_box_top(_('Genres')); require_once Config::get('prefix') . '/templates/show_genres.inc.php'; show_box_bottom(); break; case 'user': show_box_top(_('Manage Users')); require_once Config::get('prefix') . '/templates/show_users.inc.php'; show_box_bottom(); break; case 'artist': show_box_top(_('Artists')); require_once Config::get('prefix') . '/templates/show_artists.inc.php'; show_box_bottom(); break; case 'live_stream': show_box_top(_('Radion Stations')); require_once Config::get('prefix') . '/templates/show_live_streams.inc.php'; show_box_bottom(); break; default: // Rien a faire break; } // end switch on type } // show_object /** * save_objects * This takes the full array of object ides, often passed into show and then * if nessecary it saves them into the session */ public static function save_objects($object_ids) { // save these objects $_SESSION['browse']['save'] = $object_ids; self::$total_objects = count($object_ids); return true; } // save_objects } // browse