|
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
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.