mirror of
https://github.com/Yetangitu/ampache
synced 2025-10-06 03:49:56 +02:00
Add Label entity
This commit is contained in:
parent
3016b8f138
commit
0a1b46f437
23 changed files with 1194 additions and 5 deletions
|
@ -85,6 +85,14 @@ class Artist extends database_object implements library_item
|
|||
* @var string $f_tags
|
||||
*/
|
||||
public $f_tags;
|
||||
/**
|
||||
* @var array $labels
|
||||
*/
|
||||
public $labels;
|
||||
/**
|
||||
* @var string $f_labels
|
||||
*/
|
||||
public $f_labels;
|
||||
/**
|
||||
* @var int $object_cnt
|
||||
*/
|
||||
|
@ -331,7 +339,7 @@ class Artist extends database_object implements library_item
|
|||
if (AmpConfig::get('catalog_disable')) {
|
||||
$sql .= "AND `catalog`.`enabled` = '1' ";
|
||||
}
|
||||
$sql .= "ORDER BY album, track";
|
||||
$sql .= "ORDER BY `song`.`album`, `song`.`track`";
|
||||
$db_results = Dba::read($sql, array($this->id));
|
||||
|
||||
$results = array();
|
||||
|
@ -454,6 +462,11 @@ class Artist extends database_object implements library_item
|
|||
$this->tags = Tag::get_top_tags('artist', $this->id);
|
||||
$this->f_tags = Tag::get_display($this->tags, true, 'artist');
|
||||
|
||||
if (AmpConfig::get('label')) {
|
||||
$this->labels = Label::get_labels($this->id);
|
||||
$this->f_labels = Label::get_display($this->labels, true);
|
||||
}
|
||||
|
||||
$this->object_cnt = $extra_info['object_cnt'];
|
||||
}
|
||||
|
||||
|
@ -789,6 +802,10 @@ class Artist extends database_object implements library_item
|
|||
$this->update_tags($data['edit_tags'], $override_childs, $add_to_childs, $current_id, true);
|
||||
}
|
||||
|
||||
if (AmpConfig::get('label') && isset($data['edit_labels'])) {
|
||||
Label::update_label_list($data['edit_labels'], $this->id, true);
|
||||
}
|
||||
|
||||
return $current_id;
|
||||
|
||||
} // update
|
||||
|
|
|
@ -326,6 +326,10 @@ class Browse extends Query
|
|||
$video_type = $type;
|
||||
$box_req = AmpConfig::get('prefix') . '/templates/show_videos.inc.php';
|
||||
break;
|
||||
case 'label':
|
||||
$box_title = T_('Labels');
|
||||
$box_req = AmpConfig::get('prefix') . '/templates/show_labels.inc.php';
|
||||
break;
|
||||
default:
|
||||
// Rien a faire
|
||||
break;
|
||||
|
|
475
lib/class/label.class.php
Normal file
475
lib/class/label.class.php
Normal file
|
@ -0,0 +1,475 @@
|
|||
<?php
|
||||
/* vim:set softtabstop=4 shiftwidth=4 expandtab: */
|
||||
/**
|
||||
*
|
||||
* LICENSE: GNU General Public License, version 2 (GPLv2)
|
||||
* Copyright 2001 - 2015 Ampache.org
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License v2
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Label class
|
||||
*
|
||||
* This is the class responsible for handling the Label object
|
||||
* it is related to the label table in the database.
|
||||
*/
|
||||
class Label extends database_object implements library_item
|
||||
{
|
||||
/* Variables from DB */
|
||||
|
||||
/**
|
||||
* @var int $id
|
||||
*/
|
||||
public $id;
|
||||
/**
|
||||
* @var string $name
|
||||
*/
|
||||
public $name;
|
||||
/**
|
||||
* @var string $category
|
||||
*/
|
||||
public $category;
|
||||
/**
|
||||
* @var string $address
|
||||
*/
|
||||
public $address;
|
||||
/**
|
||||
* @var string $email
|
||||
*/
|
||||
public $email;
|
||||
/**
|
||||
* @var string $website
|
||||
*/
|
||||
public $website;
|
||||
/**
|
||||
* @var string $summary
|
||||
*/
|
||||
public $summary;
|
||||
/**
|
||||
* @var int $user
|
||||
*/
|
||||
public $user;
|
||||
|
||||
/**
|
||||
* @var string $f_name
|
||||
*/
|
||||
public $f_name;
|
||||
/**
|
||||
* @var string $link
|
||||
*/
|
||||
public $link;
|
||||
/**
|
||||
* @var string $f_link
|
||||
*/
|
||||
public $f_link;
|
||||
/**
|
||||
* @var int $artists
|
||||
*/
|
||||
public $artists;
|
||||
|
||||
/**
|
||||
* __construct
|
||||
*/
|
||||
public function __construct($id=null)
|
||||
{
|
||||
if (!$id) { return false; }
|
||||
|
||||
$info = $this->get_info($id);
|
||||
foreach ($info as $key=>$value) {
|
||||
$this->$key = $value;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function display_art($thumb)
|
||||
{
|
||||
if (Art::has_db($this->id, 'label')) {
|
||||
Art::display('label', $this->id, $this->get_fullname(), $thumb, $this->link);
|
||||
}
|
||||
}
|
||||
|
||||
public function format($details = true)
|
||||
{
|
||||
$this->f_name = scrub_out($this->name);
|
||||
$this->link = AmpConfig::get('web_path') . '/labels.php?action=show&label=' . scrub_out($this->id);
|
||||
$this->f_link = "<a href=\"" . $this->link . "\" title=\"" . $this->f_name . "\">" . $this->f_name;
|
||||
$this->artists = count($this->get_artists());
|
||||
}
|
||||
|
||||
public function get_catalogs()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
public function get_childrens()
|
||||
{
|
||||
$medias = array();
|
||||
$artists = $this->get_artists();
|
||||
foreach ($artists as $artist_id) {
|
||||
$medias[] = array(
|
||||
'object_type' => 'artist',
|
||||
'object_id' => $album_id
|
||||
);
|
||||
}
|
||||
return array('artist' => $medias);
|
||||
}
|
||||
|
||||
public function get_default_art_kind()
|
||||
{
|
||||
return 'default';
|
||||
}
|
||||
|
||||
public function get_description()
|
||||
{
|
||||
return $this->summary;
|
||||
}
|
||||
|
||||
public function get_fullname()
|
||||
{
|
||||
return $this->f_name;
|
||||
}
|
||||
|
||||
public function get_keywords()
|
||||
{
|
||||
$keywords = array();
|
||||
$keywords['label'] = array('important' => true,
|
||||
'label' => T_('Label'),
|
||||
'value' => $this->f_name);
|
||||
return $keywords;
|
||||
}
|
||||
|
||||
public function get_medias($filter_type = null)
|
||||
{
|
||||
$medias = array();
|
||||
if (!$filter_type || $filter_type == 'song') {
|
||||
$songs = $this->get_songs();
|
||||
foreach ($songs as $song_id) {
|
||||
$medias[] = array(
|
||||
'object_type' => 'song',
|
||||
'object_id' => $song_id
|
||||
);
|
||||
}
|
||||
}
|
||||
return $medias;
|
||||
}
|
||||
|
||||
public function get_parent()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function get_user_owner()
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
public function search_childrens($name)
|
||||
{
|
||||
$search['type'] = "artist";
|
||||
$search['rule_0_input'] = $name;
|
||||
$search['rule_0_operator'] = 4;
|
||||
$search['rule_0'] = "title";
|
||||
$artists = Search::run($search);
|
||||
|
||||
$childrens = array();
|
||||
foreach ($artists as $artist) {
|
||||
$childrens[] = array(
|
||||
'object_type' => 'artist',
|
||||
'object_id' => $artist
|
||||
);
|
||||
}
|
||||
return $childrens;
|
||||
}
|
||||
|
||||
public function can_edit($user = null)
|
||||
{
|
||||
if (!$user) {
|
||||
$user = $GLOBALS['user']->id;
|
||||
}
|
||||
|
||||
if (!$user)
|
||||
return false;
|
||||
|
||||
if (AmpConfig::get('upload_allow_edit')) {
|
||||
if ($this->user !== null && $user == $this->user)
|
||||
return true;
|
||||
}
|
||||
|
||||
return Access::check('interface', 50, $user);
|
||||
}
|
||||
|
||||
public function update(array $data)
|
||||
{
|
||||
if (self::lookup($data, $this->id) !== 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$name = isset($data['name']) ? $data['name'] : $this->name;
|
||||
$category = isset($data['category']) ? $data['category'] : $this->category;
|
||||
$summary = isset($data['summary']) ? $data['summary'] : $this->summary;
|
||||
$address = isset($data['address']) ? $data['address'] : $this->address;
|
||||
$email = isset($data['email']) ? $data['email'] : $this->email;
|
||||
$website = isset($data['website']) ? $data['website'] : $this->website;
|
||||
|
||||
$sql = "UPDATE `label` SET `name` = ?, `category` = ?, `summary` = ?, `address` = ?, `email` = ?, `website` = ? WHERE `id` = ?";
|
||||
Dba::write($sql, array($name, $category, $summary, $address, $email, $website, $this->id));
|
||||
|
||||
$this->name = $name;
|
||||
$this->category = $category;
|
||||
$this->summary = $summary;
|
||||
$this->address = $address;
|
||||
$this->email = $email;
|
||||
$this->website = $website;
|
||||
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public static function create(array $data)
|
||||
{
|
||||
if (self::lookup($data) !== 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$name = $data['name'];
|
||||
$category = $data['category'];
|
||||
$summary = $data['summary'];
|
||||
$address = $data['address'];
|
||||
$email = $data['email'];
|
||||
$website = $data['website'];
|
||||
$user = $data['user'] ?: $GLOBALS['user']->id;
|
||||
$creation_date = $data['creation_date'] ?: time();
|
||||
|
||||
$sql = "INSERT INTO `label` (`name`, `category`, `summary`, `address`, `email`, `website`, `user`, `creation_date`) " .
|
||||
"VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
Dba::write($sql, array($name, $category, $summary, $address, $email, $website, $user, $creation_date));
|
||||
|
||||
$id = Dba::insert_id();
|
||||
return $id;
|
||||
}
|
||||
|
||||
public static function lookup(array $data, $id = 0)
|
||||
{
|
||||
$ret = -1;
|
||||
$name = trim($data['name']);
|
||||
if (!empty($name)) {
|
||||
$ret = 0;
|
||||
$sql = "SELECT `id` FROM `label` WHERE `name` = ?";
|
||||
$params = array($name);
|
||||
if ($id > 0) {
|
||||
$sql .= " AND `id` != ?";
|
||||
$params[] = $id;
|
||||
}
|
||||
$db_results = Dba::read($sql, $params);
|
||||
if ($row = Dba::fetch_assoc($db_results)) {
|
||||
$ret = $row['id'];
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public static function gc()
|
||||
{
|
||||
// Don't remove labels, it could still be used as description in a search
|
||||
}
|
||||
|
||||
public function get_artists()
|
||||
{
|
||||
$sql = "SELECT `artist` FROM `label_asso` WHERE `label` = ?";
|
||||
$db_results = Dba::read($sql, array($this->id));
|
||||
$results = array();
|
||||
while ($row = Dba::fetch_assoc($db_results)) {
|
||||
$results[] = $row['artist'];
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
public function add_artist_assoc($artist_id)
|
||||
{
|
||||
$sql = "INSERT INTO `label_asso` (`label`, `artist`, `creation_date`) VALUES (?, ?, ?)";
|
||||
return Dba::write($sql, array($this->id, $artist_id, time()));
|
||||
}
|
||||
|
||||
public function remove_artist_assoc($artist_id)
|
||||
{
|
||||
$sql = "DELETE FROM `label_asso` WHERE `label` = ? AND `artist` = ?";
|
||||
return Dba::write($sql, array($this->id, $artist_id));
|
||||
}
|
||||
|
||||
/**
|
||||
* get_songs
|
||||
* gets the songs for this label
|
||||
* @return int[]
|
||||
*/
|
||||
public function get_songs()
|
||||
{
|
||||
$sql = "SELECT `song`.`id` FROM `song` " .
|
||||
"LEFT JOIN `label_asso` ON `label_asso`.`artist` = `song`.`artist` ";
|
||||
if (AmpConfig::get('catalog_disable')) {
|
||||
$sql .= "LEFT JOIN `catalog` ON `catalog`.`id` = `song`.`catalog` ";
|
||||
}
|
||||
$sql .= "WHERE `label_asso`.`label` = ? ";
|
||||
if (AmpConfig::get('catalog_disable')) {
|
||||
$sql .= "AND `catalog`.`enabled` = '1' ";
|
||||
}
|
||||
$sql .= "ORDER BY `song`.`album`, `song`.`track`";
|
||||
$db_results = Dba::read($sql, array($this->id));
|
||||
|
||||
$results = array();
|
||||
while ($r = Dba::fetch_assoc($db_results)) {
|
||||
$results[] = $r['id'];
|
||||
}
|
||||
|
||||
return $results;
|
||||
|
||||
} // get_songs
|
||||
|
||||
public static function get_all_labels()
|
||||
{
|
||||
$sql = "SELECT `id`, `name` FROM `label`";
|
||||
$db_results = Dba::read($sql);
|
||||
$results = array();
|
||||
while ($row = Dba::fetch_assoc($db_results)) {
|
||||
$results[$row['id']] = $row['name'];
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
|
||||
public static function get_labels($artist_id)
|
||||
{
|
||||
$sql = "SELECT `label`.`id`, `label`.`name` FROM `label` " .
|
||||
"LEFT JOIN `label_asso` ON `label_asso`.`label` = `label`.`id` " .
|
||||
"WHERE `label_asso`.`artist` = ?";
|
||||
$db_results = Dba::read($sql, array($artist_id));
|
||||
$results = array();
|
||||
while ($row = Dba::fetch_assoc($db_results)) {
|
||||
$results[$row['id']] = $row['name'];
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* get_display
|
||||
* This returns a csv formated version of the labels that we are given
|
||||
*/
|
||||
public static function get_display($labels, $link=false)
|
||||
{
|
||||
if (!is_array($labels)) { return ''; }
|
||||
|
||||
$results = '';
|
||||
|
||||
// Iterate through the labels, format them according to type and element id
|
||||
foreach ($labels as $label_id=>$value) {
|
||||
if ($link) {
|
||||
$results .= '<a href="' . AmpConfig::get('web_path') . '/labels.php?action=show&label=' . $label_id . '" title="' . $value . '">';
|
||||
}
|
||||
$results .= $value;
|
||||
if ($link) {
|
||||
$results .= '</a>';
|
||||
}
|
||||
$results .= ', ';
|
||||
}
|
||||
|
||||
$results = rtrim($results, ', ');
|
||||
|
||||
return $results;
|
||||
|
||||
} // get_display
|
||||
|
||||
/**
|
||||
* update_label_list
|
||||
* Update the labels list based on commated list (ex. label1,label2,label3,..)
|
||||
*/
|
||||
public static function update_label_list($labels_comma, $artist_id, $overwrite)
|
||||
{
|
||||
debug_event('label.class', 'Updating labels for values {'.$labels_comma.'} artist {'.$artist_id.'}', '5');
|
||||
|
||||
$clabels = Label::get_labels($artist_id);
|
||||
$editedLabels = explode(",", $labels_comma);
|
||||
|
||||
if (is_array($clabels)) {
|
||||
foreach ($clabels as $clid => $clv) {
|
||||
if ($clid) {
|
||||
$clabel = new Label($clid);
|
||||
debug_event('label.class', 'Processing label {'.$clabel->name.'}...', '5');
|
||||
$found = false;
|
||||
|
||||
foreach ($editedLabels as $lk => $lv) {
|
||||
if ($clabel->name == $lv) {
|
||||
$found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($found) {
|
||||
debug_event('label.class', 'Already found. Do nothing.', '5');
|
||||
unset($editedLabels[$lk]);
|
||||
} else if ($overwrite) {
|
||||
debug_event('label.class', 'Not found in the new list. Delete it.', '5');
|
||||
$clabel->remove_artist_assoc($artist_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Look if we need to add some new labels
|
||||
foreach ($editedLabels as $lk => $lv) {
|
||||
if ($lv != '') {
|
||||
debug_event('label.class', 'Adding new label {'.$lv.'}', '5');
|
||||
$label_id = Label::lookup(array('name' => $lv));
|
||||
if ($label_id === 0) {
|
||||
debug_event('label.class', 'Creating a label directly from artist editing is not allowed.', '5');
|
||||
//$label_id = Label::create(array('name' => $lv));
|
||||
}
|
||||
if ($label_id > 0) {
|
||||
$clabel = new Label($label_id);
|
||||
$clabel->add_artist_assoc($artist_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
} // update_tag_list
|
||||
|
||||
/**
|
||||
* clean_to_existing
|
||||
* Clean label list to existing label list only
|
||||
* @param array|string $labels
|
||||
* @return array|string
|
||||
*/
|
||||
public static function clean_to_existing($labels)
|
||||
{
|
||||
if (is_array($labels)) {
|
||||
$ar = $labels;
|
||||
} else {
|
||||
$ar = explode(",", $labels);
|
||||
}
|
||||
|
||||
$ret = array();
|
||||
foreach ($ar as $label) {
|
||||
$label = trim($label);
|
||||
if (!empty($label)) {
|
||||
if (Label::lookup(array('name' => $label)) > 0) {
|
||||
$ret[] = $label;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (is_array($labels) ? $ret : implode(",", $ret));
|
||||
}
|
||||
}
|
|
@ -213,6 +213,12 @@ class Query
|
|||
),
|
||||
'user' => array(
|
||||
'starts_with'
|
||||
),
|
||||
'label' => array(
|
||||
'alpha_match',
|
||||
'regex_match',
|
||||
'regex_not_match',
|
||||
'starts_with'
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -356,6 +362,11 @@ class Query
|
|||
'length',
|
||||
'codec',
|
||||
'release_date'
|
||||
),
|
||||
'label' => array(
|
||||
'name',
|
||||
'category',
|
||||
'user'
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -675,6 +686,7 @@ class Query
|
|||
case 'movie':
|
||||
case 'personal_video':
|
||||
case 'clip':
|
||||
case 'label':
|
||||
// Set it
|
||||
$this->_state['type'] = $type;
|
||||
$this->set_base_sql(true, $custom_base);
|
||||
|
@ -1018,6 +1030,10 @@ class Query
|
|||
$this->set_select("`personal_video`.`id`");
|
||||
$sql = "SELECT %%SELECT%% FROM `personal_video` ";
|
||||
break;
|
||||
case 'label':
|
||||
$this->set_select("`label`.`id`");
|
||||
$sql = "SELECT %%SELECT%% FROM `label` ";
|
||||
break;
|
||||
case 'playlist_song':
|
||||
case 'song':
|
||||
default:
|
||||
|
@ -1635,6 +1651,25 @@ class Query
|
|||
break;
|
||||
} // end filter
|
||||
break;
|
||||
case 'label':
|
||||
switch ($filter) {
|
||||
case 'alpha_match':
|
||||
$filter_sql = " `label`.`name` LIKE '%" . Dba::escape($value) . "%' AND ";
|
||||
break;
|
||||
case 'regex_match':
|
||||
if (!empty($value)) $filter_sql = " `label`.`name` REGEXP '" . Dba::escape($value) . "' AND ";
|
||||
break;
|
||||
case 'regex_not_match':
|
||||
if (!empty($value)) $filter_sql = " `label`.`name` NOT REGEXP '" . Dba::escape($value) . "' AND ";
|
||||
break;
|
||||
case 'starts_with':
|
||||
$filter_sql = " `label`.`name` LIKE '" . Dba::escape($value) . "%' AND ";
|
||||
break;
|
||||
default:
|
||||
// Rien a faire
|
||||
break;
|
||||
} // end filter
|
||||
break;
|
||||
} // end switch on type
|
||||
|
||||
return $filter_sql;
|
||||
|
@ -1956,6 +1991,19 @@ class Query
|
|||
break;
|
||||
}
|
||||
break;
|
||||
case 'label':
|
||||
switch ($field) {
|
||||
case 'name':
|
||||
$sql = "`label`.`name`";
|
||||
break;
|
||||
case 'category':
|
||||
$sql = "`label`.`category`";
|
||||
break;
|
||||
case 'user':
|
||||
$sql = "`label`.`user`";
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// Rien a faire
|
||||
break;
|
||||
|
|
|
@ -238,6 +238,13 @@ class Search extends playlist_object
|
|||
'widget' => array('input', 'text')
|
||||
);
|
||||
|
||||
$this->types[] = array(
|
||||
'name' => 'label',
|
||||
'label' => T_('Label'),
|
||||
'type' => 'text',
|
||||
'widget' => array('input', 'text')
|
||||
);
|
||||
|
||||
|
||||
$this->types[] = array(
|
||||
'name' => 'tag',
|
||||
|
@ -498,6 +505,20 @@ class Search extends playlist_object
|
|||
'widget' => array('input', 'text')
|
||||
);
|
||||
break;
|
||||
case 'label':
|
||||
$this->types[] = array(
|
||||
'name' => 'name',
|
||||
'label' => T_('Name'),
|
||||
'type' => 'text',
|
||||
'widget' => array('input', 'text')
|
||||
);
|
||||
$this->types[] = array(
|
||||
'name' => 'category',
|
||||
'label' => T_('Category'),
|
||||
'type' => 'text',
|
||||
'widget' => array('input', 'text')
|
||||
);
|
||||
break;
|
||||
} // end switch on searchtype
|
||||
|
||||
} // end constructor
|
||||
|
@ -1112,7 +1133,7 @@ class Search extends playlist_object
|
|||
|
||||
switch ($rule[0]) {
|
||||
case 'anywhere':
|
||||
$where[] = "(`artist`.`name` $sql_match_operator '$input' OR `album`.`name` $sql_match_operator '$input' OR `song_data`.`comment` $sql_match_operator '$input' OR `song`.`file` $sql_match_operator '$input' OR `song`.`title` $sql_match_operator '$input')";
|
||||
$where[] = "(`artist`.`name` $sql_match_operator '$input' OR `album`.`name` $sql_match_operator '$input' OR `song_data`.`comment` $sql_match_operator '$input' OR `song_data`.`label` $sql_match_operator '$input' OR `song`.`file` $sql_match_operator '$input' OR `song`.`title` $sql_match_operator '$input')";
|
||||
$join['album'] = true;
|
||||
$join['artist'] = true;
|
||||
$join['song_data'] = true;
|
||||
|
@ -1150,6 +1171,10 @@ class Search extends playlist_object
|
|||
$where[] = "`song_data`.`comment` $sql_match_operator '$input'";
|
||||
$join['song_data'] = true;
|
||||
break;
|
||||
case 'label':
|
||||
$where[] = "`song_data`.`label` $sql_match_operator '$input'";
|
||||
$join['song_data'] = true;
|
||||
break;
|
||||
case 'played':
|
||||
$where[] = " `song`.`played` = '$input'";
|
||||
break;
|
||||
|
@ -1405,4 +1430,54 @@ class Search extends playlist_object
|
|||
'having_sql' => $having_sql
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* label_to_sql
|
||||
*
|
||||
* Handles the generation of the SQL for label searches.
|
||||
*/
|
||||
private function label_to_sql()
|
||||
{
|
||||
$sql_logic_operator = $this->logic_operator;
|
||||
$where = array();
|
||||
$table = array();
|
||||
|
||||
foreach ($this->rules as $rule) {
|
||||
$type = $this->name_to_basetype($rule[0]);
|
||||
$operator = array();
|
||||
foreach ($this->basetypes[$type] as $op) {
|
||||
if ($op['name'] == $rule[1]) {
|
||||
$operator = $op;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$input = $this->_mangle_data($rule[2], $type, $operator);
|
||||
$sql_match_operator = $operator['sql'];
|
||||
|
||||
switch ($rule[0]) {
|
||||
case 'name':
|
||||
$where[] = "`label`.`name` $sql_match_operator '$input'";
|
||||
break;
|
||||
case 'category':
|
||||
$where[] = "`label`.`category` $sql_match_operator '$input'";
|
||||
break;
|
||||
default:
|
||||
// Nihil
|
||||
break;
|
||||
} // switch on ruletype
|
||||
} // foreach rule
|
||||
|
||||
$where_sql = implode(" $sql_logic_operator ", $where);
|
||||
|
||||
return array(
|
||||
'base' => 'SELECT DISTINCT(`label`.`id`) FROM `label`',
|
||||
'join' => $join,
|
||||
'where' => $where,
|
||||
'where_sql' => $where_sql,
|
||||
'table' => $table,
|
||||
'table_sql' => '',
|
||||
'group_sql' => '',
|
||||
'having_sql' => ''
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -497,6 +497,9 @@ class Update
|
|||
$update_string = " - Add WebDAV backend preference.<br />";
|
||||
$version[] = array('version' => '370032','description' => $update_string);
|
||||
|
||||
$update_string = " - Add Label tables.<br />";
|
||||
$version[] = array('version' => '370033','description' => $update_string);
|
||||
|
||||
return $version;
|
||||
}
|
||||
|
||||
|
@ -3407,4 +3410,37 @@ class Update
|
|||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* update_370033
|
||||
*
|
||||
* Add Label tables.
|
||||
*/
|
||||
public static function update_370033()
|
||||
{
|
||||
$retval = true;
|
||||
|
||||
$sql = "CREATE TABLE `label` (" .
|
||||
"`id` int(11) unsigned NOT NULL AUTO_INCREMENT," .
|
||||
"`name` varchar(80) NOT NULL," .
|
||||
"`category` varchar(40) NULL," .
|
||||
"`summary` TEXT CHARACTER SET utf8 NULL," .
|
||||
"`address` varchar(256) NULL," .
|
||||
"`email` varchar(128) NULL," .
|
||||
"`website` varchar(256) NULL," .
|
||||
"`user` int(11) unsigned NULL," .
|
||||
"`creation_date` int(11) unsigned NULL," .
|
||||
"PRIMARY KEY (`id`)) ENGINE = MYISAM";
|
||||
$retval = Dba::write($sql) ? $retval : false;
|
||||
|
||||
$sql = "CREATE TABLE `label_asso` (" .
|
||||
"`id` int(11) unsigned NOT NULL AUTO_INCREMENT," .
|
||||
"`label` int(11) unsigned NOT NULL," .
|
||||
"`artist` int(11) unsigned NOT NULL," .
|
||||
"`creation_date` int(11) unsigned NULL," .
|
||||
"PRIMARY KEY (`id`)) ENGINE = MYISAM";
|
||||
$retval = Dba::write($sql) ? $retval : false;
|
||||
|
||||
return $retval;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue