1
0
Fork 0
mirror of https://github.com/Yetangitu/ampache synced 2025-10-06 03:49:56 +02:00

basic browse concept added to sidebar and start of the browse logic

This commit is contained in:
Karl 'vollmerk' Vollmer 2007-05-06 21:07:03 +00:00
parent b1f2bacf44
commit 691c838e90
9 changed files with 212 additions and 83 deletions

View file

@ -102,10 +102,8 @@ switch($_REQUEST['action']) {
}
break;
case 'song_title':
/* Create the Needed Object */
$song = new Song();
case 'song':
Browse::set_type('song');
/* Setup the View Object */
$view = new View();

View file

@ -27,33 +27,48 @@
class Album {
/* Variables from DB */
var $id;
var $name;
var $year;
var $prefix;
public $id;
public $name;
public $year;
public $prefix;
/* Art Related Fields */
var $art;
var $art_mime;
public $art;
public $art_mime;
public $thumb;
public $thumb_mime;
// cached information
var $_songs=array();
public $_songs=array();
/*!
@function Album
@discussion Album class, for modifing a song.
@param $album_id The ID of the song
/**
* __construct
* Album constructor it loads everything relating
* to this album from the database it does not
* pull the album or thumb art by default or
* get any of the counts.
*/
function Album($album_id = 0) {
function __construct($album_id = 0) {
if (!$album_id) { return false; }
/* Assign id for use in get_info() */
$this->id = $album_id;
$this->id = intval($album_id);
/* Get the information from the db */
if ($info = $this->_get_info()) {
$this->name = trim($info['prefix'] . " " . $info['album_name']);
$info = $this->_get_info();
// Foreach what we've got
foreach ($info as $key=>$value) {
$this->$key = $value;
}
// Little bit of formating here
$this->f_name = trim($info['prefix'] . ' ' . $info['name']);
// Additional data that we are going to need
/*
$this->songs = $info['song_count'];
$this->artist_count = $info['artist_count'];
$this->year = $info['year'];
@ -62,40 +77,40 @@ class Album {
$this->album = $info['album_name'];
$this->has_art = $info['has_art'];
$this->prefix = $info['prefix'];
} // if info
*/
return true;
} //constructor
/*!
@function get_info
@discussion get's the vars for $this out of the database
@param $this->id Taken from the object
*/
/**
* _get_info
* This is a private function that pulls the album
* from the database
*/
private function _get_info() {
$this->id = intval($this->id);
/* Grab the basic information from the catalog and return it */
// Just get the album information
$sql = "SELECT * FROM `album` WHERE `id`='" . $this->id . "'";
/* Grab the basic information from the catalog and return it
$sql = "SELECT COUNT(DISTINCT(song.artist)) as artist_count,album.prefix,album.year,album.name AS album_name,COUNT(song.id) AS song_count," .
"artist.name AS artist_name,artist.id AS art_id,artist.prefix AS artist_prefix,album.art AS has_art ".
"FROM song,artist,album WHERE album.id='$this->id' AND song.album=album.id AND song.artist=artist.id GROUP BY song.album";
*/
$db_results = Dba::query($sql);
$results = Dba::fetch_assoc($db_results);
// If there is art then set it to 1, if not set it to 0, we don't want to cary
// around the full blob with every object because it can be pretty big
$results['has_art'] = strlen($results['has_art']) ? '1' : '0';
return $results;
} // _get_info
/**
* get_songs
* gets the songs for this album
* gets the songs for this album takes an optional limit
* and an optional artist, if artist is passed it only gets
* songs with this album + specified artist
*/
public function get_songs($limit = 0,$artist='') {
@ -117,13 +132,32 @@ class Album {
} // get_songs
/**
* has_art
* This returns true or false depending on if we find any art for this
* album.
*/
public function has_art() {
$sql = "SELECT `album_id` FROM `album_data` WHERE `album_id`='" . $this->id . "' AND art IS NOT NULL";
$db_results = Dba::query($sql);
if (Dba::fetch_assoc($db_results)) {
$this->has_art = true;
return true;
}
return false;
} // has_art
/**
* format
* This is the format function for this object. It sets cleaned up
* album information with the base required
* f_link, f_name
*/
function format() {
public function format() {
$web_path = Config::get('web_path');
@ -147,24 +181,13 @@ class Album {
} // format
/**
* format_album
* DEPRECIATED DO NOT USE!
*/
function format_album() {
// Call the real function
$this->format();
} // format_album
/**
* get_art
* This function only pulls art from the database, if thumb is passed
* it trys to pull the resized art instead, if resized art is found then
* it returns an additional resized=true in the array
*/
function get_art() {
public function get_art() {
// Attempt to get the resized art first
$art = $this->get_resized_db_art();
@ -187,7 +210,7 @@ class Album {
* ['artist'] = STRING
* ['album_name'] = STRING
*/
function find_art($options=array(),$limit='') {
public function find_art($options=array(),$limit='') {
/* Create Base Vars */
$results = array();
@ -365,7 +388,7 @@ class Album {
$id = Dba::escape($this->id);
$sql = "SELECT `thumb` AS `art`,`thumb_mime` AS `art_mime` FROM `album` WHERE `id`='$id'";
$sql = "SELECT `thumb` AS `art`,`thumb_mime` AS `art_mime` FROM `album_data` WHERE `album_id`='$id'";
$db_results = Dba::query($sql);
$results = Dba::fetch_assoc($db_results);
@ -384,7 +407,7 @@ class Album {
*/
public function get_db_art() {
$sql = "SELECT `art`,`art_mime` FROM `album` WHERE `id`='$this->id'";
$sql = "SELECT `art`,`art_mime` FROM `album_data` WHERE `album_id`='$this->id'";
$db_results = Dba::query($sql);
$results = Dba::fetch_assoc($db_results);

View file

@ -0,0 +1,90 @@
<?php
/*
Copyright (c) 2001 - 2007 Ampache.org
All rights reserved.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/**
* Browse Class
* This handles all of the sql/filtering
* on the data before it's thrown out to the templates
* it also handles pulling back the object_ids and then
* calling the correct template for the object we are displaying
*/
class Browse {
/**
* constructor
* This should never be called
*/
private __construct() {
// Rien a faire
} // __construct
/**
* set_filter
* This saves the filter data we pass it into the session
* This is done here so that it's easy to modify where the data
* is saved should I change my mind in the future. It also makes
* a single point for whitelist tweaks etc
*/
public static function set_filter($key,$value) {
switch ($key) {
case 'show_art':
case 'min_count':
case 'unplayed':
case 'rated':
$key = $_REQUEST['key'];
$_SESSION['browse']['filter'][$key] = make_bool($_REQUEST['value']);
break;
default
// Rien a faire
break;
} // end switch
} // set_filter
/**
* set_type
* This sets the type of object that we want to browse by
* we do this here so we only have to maintain a single whitelist
* and if I want to change the location I only have to do it here
*/
public static function set_type($type) {
switch($type) {
case 'song':
case 'album':
case 'artist':
case 'genre':
$_SESSION['browse']['type'] = $type;
break;
default:
// Rien a faire
break;
} // end type whitelist
} // set_type
} // browse

View file

@ -604,6 +604,14 @@ class Update {
$sql = "ALTER TABLE `album` DROP `art`, DROP `art_mime`, DROP `thumb`, DROP `thumb_mime`";
$db_results = Dba::query($sql);
// We need to fix the user_vote table
$sql = "ALTER TABLE `user_vote` CHANGE `user` `user` INT( 11 ) UNSIGNED NOT NULL";
$db_results = Dba::query($sql);
// Remove offset limit from the user
$sql = "ALTER TABLE `user` DROP `offset_limit`";
$db_results = Dba::query($sql);
self::set_version('db_version','340003');
} // update_340003

View file

@ -226,10 +226,7 @@ else {
init_preferences();
/* Add in some variables for ajax done here because we need the user */
$ajax_info['ajax_url'] = $results['web_path'] . '/server/ajax.server.php';
$ajax_info['ajax_info'] = '&amp;user_id=' . $GLOBALS['user']->id;
Config::set_by_array($ajax_info);
unset($ajax_info);
Config::set('ajax_url',Config::get('web_path') . '/server/ajax.server.php',1);
// Load gettext mojo
load_gettext();

View file

@ -141,29 +141,25 @@ function return_referer() {
/**
* show_alphabet_list
* shows the A-Z,0-9 lists for
* albums and artist pages
* shows the A-Z,0-9 lists for albums and artist page
* It takes a selected and an action
*/
function show_alphabet_list ($type,$script="artist.php",$selected="false",$action='match') {
function show_alphabet_list () {
$list = array(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,1,2,3,4,5,6,7,8,9,"0");
$style_name = "style_" . strtolower($selected);
${$style_name} = "style=\"font-weight:bold;\"";
unset($title);
echo "<div class=\"alphabet\">";
foreach ($list as $l) {
$style_name = "style_" . strtolower($l);
echo "<a href=\"". conf('web_path') ."/$script?action=$action&amp;match=$l\" " . ${$style_name} . ">$l</a> | \n";
echo "<span style=\"width:3px;\" onclick=\"ajaxPut('". Config::get('ajax_url') ."?action=browse&amp;key=alpha_match&amp;value=$l');return true;\">" .
$l . "</span>\n";
$i++;
if ($i/11 == intval($i/11)) { echo "<br />"; }
}
echo " <a href=\"". conf('web_path') ."/$script?action=$action&amp;match=Browse\" $style_browse>" . _("Browse") . "</a> | \n";
if ($script == "albums.php") {
echo " <a href=\"". conf('web_path') ."/$script?action=$action&amp;match=Show_missing_art\" $style_show_missing_art>" . _("Show w/o art") . "</a> | \n";
} // if we are on the albums page
echo " <a href=\"". conf('web_path') ."/$script?action=$action&amp;match=Show_all\" $style_show_all>" . _("Show all") . "</a>";
echo "</div>\n";
echo "</div>";
} // show_alphabet_list

View file

@ -193,23 +193,20 @@ switch ($action) {
$xml_doc = xml_from_array($results);
echo $xml_doc;
break;
case 'browse_type':
// Clean up the types
switch ($_REQUEST['type']) {
case 'song':
case 'album':
case 'artist':
case 'genre':
$type = $_REQUEST['type'];
break;
default:
$type = 'song';
break;
} // types
// Used to change filter/settings on browse
case 'browse':
// Set any new filters we've just added
Browse::set_filter($_REQUEST['key'],$_REQUEST['value']);
// Refresh the browse div with our new filter options
$object_ids = Browse::get_objects();
ob_start();
Browse::show_objects($object_ids);
$results['browse_content'] = ob_get_contents();
ob_end_clean();
$xml_doc = xml_from_array($results);
echo $xml_doc;
break;
case 'sidebar':
switch ($_REQUEST['button']) {

View file

@ -1,9 +1,24 @@
<?php $ajax_info = Config::get('ajax_url'); ?>
<h4><?php echo _('Browse By'); ?></h4>
<form id="browse_type" name="browse_type" action="#" method="post">
<select name="type" onchange="ajaxPut('browse_type','<?php echo Config::get('ajax_url'); ?>?action=browse_type');return true;" >
<form id="browse_type" name="browse_type" action="<?php echo Config::get('web_path'); ?>/browse.php" method="post">
<select name="action" onchange="document.getElementById('browse_type').submit();" >
<option value="">-- <?php echo _('Type'); ?> --</option>
<option value="song"><?php echo _('Song Title'); ?></option>
<option value="album"><?php echo _('Albums'); ?></option>
<option value="artist"><?php echo _('Artist'); ?></option>
<option value="genre"><?php echo _('Genre'); ?></option>
</select>
</form>
<hr />
<?php show_alphabet_list($_REQUEST['alpha_match'],$_REQUEST['action']); ?>
<hr />
<h4><?php echo _('Filters'); ?></h4>
<input type="checkbox" onclick="ajaxPut('<?php echo $ajax_info; ?>?action=browse&amp;key=show_art&amp;value=1');return true;" value="1" />
<?php echo _('Show Art'); ?><br />
<input type="checkbox" onclick="ajaxPut('<?php echo $ajax_info; ?>?action=browse&amp;key=min_count&amp;value=1');return true;" value="1" />
<?php echo _('Minimum Count'); ?><br />
<input type="checkbox" onclick="ajaxPut('<?php echo $ajax_info; ?>?action=browse&amp;key=unplayed&amp;value=1');return true;" value="1" />
<?php echo _('Unplayed'); ?><br />
<input type="checkbox" onclick="ajaxPut('<?php echo $ajax_info; ?>?action=browse&amp;key=rated&amp;value=1');return true;" value="1" />
<?php echo _('Rated'); ?><br />
<hr />

View file

@ -619,6 +619,11 @@ td.user_disabled {
font-size:10px;
font-weight:normal;
}
.alphabet span {
cursor: pointer;
color: #003399;
}
#mpdpl td {
padding:0 2px 0 2px;
text-align:left;