|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* COPS (Calibre OPDS PHP Server) class file |
|
4
|
|
|
* |
|
5
|
|
|
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html) |
|
6
|
|
|
* @author Michael Pfitzner |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
class Rating |
|
10
|
|
|
{ |
|
11
|
|
|
const ALL_RATING_ID = "cops:rating"; |
|
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
const RATING_COLUMNS = "ratings.id as id, ratings.rating as rating, count(*) as count"; |
|
|
|
|
|
|
14
|
|
|
const SQL_ALL_RATINGS ="select {0} from ratings, books_ratings_link where books_ratings_link.rating = ratings.id group by ratings.id order by ratings.rating"; |
|
|
|
|
|
|
15
|
|
|
public $id; |
|
16
|
|
|
public $name; |
|
17
|
|
|
|
|
18
|
2 |
|
public function __construct($pid, $pname) { |
|
19
|
2 |
|
$this->id = $pid; |
|
20
|
2 |
|
$this->name = $pname; |
|
21
|
2 |
|
} |
|
22
|
|
|
|
|
23
|
1 |
|
public function getUri () { |
|
24
|
1 |
|
return "?page=".Base::PAGE_RATING_DETAIL."&id=$this->id"; |
|
|
|
|
|
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
2 |
|
public function getEntryId () { |
|
28
|
2 |
|
return self::ALL_RATING_ID.":".$this->id; |
|
|
|
|
|
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
19 |
|
public static function getCount() { |
|
32
|
|
|
// str_format (localize("ratings", count(array)) |
|
|
|
|
|
|
33
|
19 |
|
return Base::getCountGeneric ("ratings", self::ALL_RATING_ID, Base::PAGE_ALL_RATINGS, "ratings"); |
|
|
|
|
|
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
1 |
|
public static function getAllRatings() { |
|
37
|
1 |
|
return self::getEntryArray (self::SQL_ALL_RATINGS, array ()); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
1 |
|
public static function getEntryArray ($query, $params) { |
|
41
|
1 |
|
list (, $result) = Base::executeQuery ($query, self::RATING_COLUMNS, "", $params, -1); |
|
|
|
|
|
|
42
|
1 |
|
$entryArray = array(); |
|
43
|
1 |
|
while ($post = $result->fetchObject ()) |
|
44
|
|
|
{ |
|
45
|
1 |
|
$ratingObj = new Rating ($post->id, $post->rating); |
|
46
|
1 |
|
$rating=$post->rating/2; |
|
47
|
1 |
|
$rating = str_format (localize("ratingword", $rating), $rating); |
|
|
|
|
|
|
48
|
1 |
|
array_push ($entryArray, new Entry ($rating, $ratingObj->getEntryId (), |
|
49
|
1 |
|
str_format (localize("bookword", $post->count), $post->count), "text", |
|
|
|
|
|
|
50
|
1 |
|
array ( new LinkNavigation ($ratingObj->getUri ())), "", $post->count)); |
|
|
|
|
|
|
51
|
1 |
|
} |
|
52
|
1 |
|
return $entryArray; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
1 |
|
public static function getRatingById ($ratingId) { |
|
56
|
1 |
|
$result = Base::getDb ()->prepare('select rating from ratings where id = ?'); |
|
57
|
1 |
|
$result->execute (array ($ratingId)); |
|
58
|
1 |
|
return new Rating ($ratingId, $result->fetchColumn ()); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|
PHP provides two ways to mark string literals. Either with single quotes
'literal'or with double quotes"literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (
\') and the backslash (\\). Every other character is displayed as is.Double quoted string literals may contain other variables or more complex escape sequences.
will print an indented:
Single is ValueIf your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.
For more information on PHP string literals and available escape sequences see the PHP core documentation.