Gazelle/classes/bookmarks.class.php

99 lines
2.0 KiB
PHP
Raw Normal View History

2013-03-29 08:00:08 +00:00
<?
class Bookmarks {
/**
* Check if can bookmark
*
* @param string $Type
* @return boolean
*/
public static function can_bookmark($Type) {
return in_array($Type, array(
'torrent',
'artist',
'collage',
'request'
));
}
/**
* Get the bookmark schema.
* Recommended usage:
* list($Table, $Col) = bookmark_schema('torrent');
*
* @param string $Type the type to get the schema for
*/
public static function bookmark_schema($Type) {
switch ($Type) {
case 'torrent':
return array(
'bookmarks_torrents',
'GroupID'
);
break;
case 'artist':
return array(
'bookmarks_artists',
'ArtistID'
);
break;
case 'collage':
return array(
'bookmarks_collages',
'CollageID'
);
break;
case 'request':
return array(
'bookmarks_requests',
'RequestID'
);
break;
default:
die('HAX');
}
}
/**
* Check if something is bookmarked
*
* @param string $Type
* type of bookmarks to check
* @param int $ID
* bookmark's id
* @return boolean
*/
public static function has_bookmarked($Type, $ID) {
return in_array($ID, self::all_bookmarks($Type));
}
/**
* Fetch all bookmarks of a certain type for a user.
* If UserID is false than defaults to $LoggedUser['ID']
*
* @param string $Type
* type of bookmarks to fetch
* @param int $UserID
* userid whose bookmarks to get
* @return array the bookmarks
*/
public static function all_bookmarks($Type, $UserID = false) {
global $DB, $Cache, $LoggedUser;
if ($UserID === false) {
$UserID = $LoggedUser['ID'];
}
$CacheKey = 'bookmarks_' . $Type . '_' . $UserID;
2013-04-13 08:00:19 +00:00
if (($Bookmarks = $Cache->get_value($CacheKey)) === false) {
2013-03-29 08:00:08 +00:00
list ($Table, $Col) = self::bookmark_schema($Type);
2013-06-06 08:01:03 +00:00
$DB->query("
SELECT $Col
FROM $Table
WHERE UserID = '$UserID'");
2013-03-29 08:00:08 +00:00
$Bookmarks = $DB->collect($Col);
$Cache->cache_value($CacheKey, $Bookmarks, 0);
}
return $Bookmarks;
}
}
?>