diff options
-rw-r--r-- | lib/class/tag.class.php | 24 | ||||
-rw-r--r-- | lib/class/xmldata.class.php | 34 | ||||
-rw-r--r-- | server/xml.server.php | 12 |
3 files changed, 64 insertions, 6 deletions
diff --git a/lib/class/tag.class.php b/lib/class/tag.class.php index ae1582f8..44d91c9b 100644 --- a/lib/class/tag.class.php +++ b/lib/class/tag.class.php @@ -425,6 +425,30 @@ class Tag extends database_object { } // get_display /** + * count + * This returns the count for the all objects assoicated with this tag + * If a type is specific only counts for said type are returned + */ + public function count($type='') { + + if ($type) { + $filter_sql = " AND `object_type`='" . Dba::escape($type) . "'"; + } + + $results = array(); + + $sql = "SELECT COUNT(`id`) AS `count`,`object_type` FROM `tag_map` WHERE `tag_id`='" . Dba::escape($this->id) . "'" . $filter_sql . " GROUP BY `object_type`"; + $db_results = Dba::read($sql); + + while ($row = Dba::fetch_assoc($db_results)) { + $results[$row['object_type']] = $row['count']; + } + + return $results; + + } // count + + /** * filter_with_prefs * This filters the tags based on the users preference */ diff --git a/lib/class/xmldata.class.php b/lib/class/xmldata.class.php index 62267c4b..c9a11112 100644 --- a/lib/class/xmldata.class.php +++ b/lib/class/xmldata.class.php @@ -170,6 +170,40 @@ class xmlData { } // keyed_array /** + * tags + * This returns tags to the user, in a pretty xml document with the information + */ + public static function tags($tags) { + + if (count($tags) > self::$limit) { + $tags = array_splice($tags,self::$offset,self::$limit); + } + + + $string = ''; + + foreach ($tags as $tag_id) { + $tag = new Tag($tag_id); + $counts = $tag->count(); + $string .= "<tag id=\"$tag_id\">\n" . + "\t<name><![CDATA[$tag->name]]></name>\n" . + "\t<albums>" . intval($counts['album']) . "</albums>\n" . + "\t<artists>" . intval($counts['artist']) . "</artists>\n" . + "\t<songs>" . intval($counts['songs']) . "</songs>\n" . + "\t<videos>" . intval($counts['video']) . "</video>\n" . + "\t<playlists>" . intval($count['playlist']) . "</playlists>\n" . + "\t<stream>" . intval($count['live_stream']) . "</stream>\n" . + "</tag>\n"; + } // end foreach + + + $final = self::_header() . $string . self::_footer(); + + return $final; + + } // tags + + /** * artists * This takes an array of artists and then returns a pretty xml document with the information * we want diff --git a/server/xml.server.php b/server/xml.server.php index 45570dda..1813592e 100644 --- a/server/xml.server.php +++ b/server/xml.server.php @@ -179,28 +179,28 @@ switch ($_REQUEST['action']) { break; case 'tags': Browse::reset_filters(); - Browse::set_type('genre'); + Browse::set_type('tag'); Browse::set_sort('name','ASC'); $method = $_REQUEST['exact'] ? 'exact_match' : 'alpha_match'; Api::set_filter($method,$_REQUEST['filter']); - $genres = Browse::get_objects(); + $tags = Browse::get_objects(); // Set the offset xmlData::set_offset($_REQUEST['offset']); xmlData::set_limit($_REQUEST['limit']); ob_end_clean(); - echo xmlData::genres($genres); + echo xmlData::tags($tags); break; case 'tag': $uid = scrub_in($_REQUEST['filter']); ob_end_clean(); - echo xmlData::genres(array($uid)); + echo xmlData::tags(array($uid)); break; case 'tag_artists': - $genre = new Genre($_REQUEST['filter']); - $artists = $genre->get_artists(); + $tag = new tag($_REQUEST['filter']); + $tags = Tag::get_object_tags('artist',$tag->id); xmlData::set_offset($_REQUEST['offset']); xmlData::set_limit($_REQUEST['limit']); |