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
|
|
|
require_once('base.php'); |
10
|
|
|
|
11
|
|
|
class Rating extends Base { |
12
|
|
|
const ALL_RATING_ID = "cops:rating"; |
13
|
|
|
|
14
|
|
|
const SQL_ALL_RATINGS = |
15
|
|
|
"select ratings.id as id, ratings.rating as rating, count(*) as count |
16
|
|
|
from ratings |
17
|
|
|
inner join books_ratings_link as link on link.rating = ratings.id |
18
|
|
|
inner join ({0}) as filter on filter.id = link.book |
19
|
2 |
|
group by ratings.id |
20
|
2 |
|
order by ratings.rating"; |
21
|
2 |
|
public $id; |
22
|
2 |
|
public $name; |
23
|
|
|
|
24
|
1 |
|
public function __construct($pid, $pname) { |
25
|
1 |
|
$this->id = $pid; |
26
|
|
|
$this->name = $pname; |
27
|
|
|
} |
28
|
2 |
|
|
29
|
2 |
|
public function getUri () { |
30
|
|
|
return "?page=".parent::PAGE_RATING_DETAIL."&id=$this->id"; |
31
|
|
|
} |
32
|
8 |
|
|
33
|
|
|
public function getEntryId () { |
34
|
8 |
|
return self::ALL_RATING_ID.":".$this->id; |
35
|
|
|
} |
36
|
|
|
|
37
|
1 |
|
public static function getCount() { |
38
|
1 |
|
// str_format (localize("ratings", count(array)) |
39
|
|
|
return parent::getCountGeneric ("ratings", self::ALL_RATING_ID, parent::PAGE_ALL_RATINGS, "ratings"); |
|
|
|
|
40
|
|
|
} |
41
|
1 |
|
|
42
|
1 |
|
public static function getAllRatings() { |
43
|
1 |
|
return self::getEntryArray (self::SQL_ALL_RATINGS, array ()); |
44
|
1 |
|
} |
45
|
|
|
|
46
|
1 |
|
public static function getEntryArray ($query, $params) { |
47
|
1 |
|
list (, $result) = parent::executeFilteredQuery($query, $params, -1); |
|
|
|
|
48
|
1 |
|
$entryArray = array(); |
49
|
1 |
|
while ($post = $result->fetchObject ()) |
50
|
1 |
|
{ |
51
|
1 |
|
$ratingObj = new Rating ($post->id, $post->rating); |
52
|
1 |
|
$rating=$post->rating/2; |
53
|
1 |
|
$rating = str_format (localize("ratingword", $rating), $rating); |
54
|
|
|
array_push ($entryArray, new Entry ($rating, $ratingObj->getEntryId (), |
55
|
|
|
str_format (localize("bookword", $post->count), $post->count), "text", |
56
|
1 |
|
array ( new LinkNavigation ($ratingObj->getUri ())), "", $post->count)); |
57
|
1 |
|
} |
58
|
1 |
|
return $entryArray; |
59
|
1 |
|
} |
60
|
|
|
|
61
|
|
|
public static function getRatingById ($ratingId) { |
62
|
|
|
$result = parent::getDb ()->prepare('select rating from ratings where id = ?'); |
|
|
|
|
63
|
|
|
$result->execute (array ($ratingId)); |
64
|
|
|
return new Rating ($ratingId, $result->fetchColumn ()); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()
method in theSon
calls the wrong method in the parent class.