From 5bd82180f5470c4ce255d02b7aa36c476db1cd99 Mon Sep 17 00:00:00 2001 From: Karl 'vollmerk' Vollmer Date: Sun, 17 May 2009 15:51:29 +0000 Subject: some incomplete work cleaning up the api a bit --- lib/class/tag.class.php | 24 ++++++++++++++++++++++++ lib/class/xmldata.class.php | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) (limited to 'lib/class') 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 @@ -424,6 +424,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 @@ -169,6 +169,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 .= "\n" . + "\tname]]>\n" . + "\t" . intval($counts['album']) . "\n" . + "\t" . intval($counts['artist']) . "\n" . + "\t" . intval($counts['songs']) . "\n" . + "\t" . intval($counts['video']) . "\n" . + "\t" . intval($count['playlist']) . "\n" . + "\t" . intval($count['live_stream']) . "\n" . + "\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 -- cgit