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 RATING_COLUMNS = "ratings.id as id, ratings.rating as rating, count(*) as count"; |
15
|
|
|
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"; |
16
|
|
|
public $id; |
17
|
|
|
public $name; |
18
|
|
|
|
19
|
2 |
|
public function __construct($pid, $pname) { |
20
|
2 |
|
$this->id = $pid; |
21
|
2 |
|
$this->name = $pname; |
22
|
2 |
|
} |
23
|
|
|
|
24
|
1 |
|
public function getUri () { |
25
|
1 |
|
return "?page=".parent::PAGE_RATING_DETAIL."&id=$this->id"; |
26
|
|
|
} |
27
|
|
|
|
28
|
2 |
|
public function getEntryId () { |
29
|
2 |
|
return self::ALL_RATING_ID.":".$this->id; |
30
|
|
|
} |
31
|
|
|
|
32
|
19 |
|
public static function getCount() { |
33
|
|
|
// str_format (localize("ratings", count(array)) |
34
|
19 |
|
return parent::getCountGeneric ("ratings", self::ALL_RATING_ID, parent::PAGE_ALL_RATINGS, "ratings"); |
|
|
|
|
35
|
|
|
} |
36
|
|
|
|
37
|
1 |
|
public static function getAllRatings() { |
38
|
1 |
|
return self::getEntryArray (self::SQL_ALL_RATINGS, array ()); |
39
|
|
|
} |
40
|
|
|
|
41
|
1 |
|
public static function getEntryArray ($query, $params) { |
42
|
1 |
|
list (, $result) = parent::executeQuery ($query, self::RATING_COLUMNS, "", $params, -1); |
|
|
|
|
43
|
1 |
|
$entryArray = array(); |
44
|
1 |
|
while ($post = $result->fetchObject ()) |
45
|
|
|
{ |
46
|
1 |
|
$ratingObj = new Rating ($post->id, $post->rating); |
47
|
1 |
|
$rating=$post->rating/2; |
48
|
1 |
|
$rating = str_format (localize("ratingword", $rating), $rating); |
49
|
1 |
|
array_push ($entryArray, new Entry ($rating, $ratingObj->getEntryId (), |
50
|
1 |
|
str_format (localize("bookword", $post->count), $post->count), "text", |
51
|
1 |
|
array ( new LinkNavigation ($ratingObj->getUri ())), "", $post->count)); |
52
|
1 |
|
} |
53
|
1 |
|
return $entryArray; |
54
|
|
|
} |
55
|
|
|
|
56
|
1 |
|
public static function getRatingById ($ratingId) { |
57
|
1 |
|
$result = parent::getDb ()->prepare('select rating from ratings where id = ?'); |
|
|
|
|
58
|
1 |
|
$result->execute (array ($ratingId)); |
59
|
1 |
|
return new Rating ($ratingId, $result->fetchColumn ()); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
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.