forked from seblucas/cops
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrating.php
61 lines (51 loc) · 2.13 KB
/
rating.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
/**
* COPS (Calibre OPDS PHP Server) class file
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Michael Pfitzner
*/
require_once('base.php');
class Rating extends Base {
const ALL_RATING_ID = "cops:rating";
const RATING_COLUMNS = "ratings.id as id, ratings.rating as rating, count(*) as count";
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";
public $id;
public $name;
public function __construct($pid, $pname) {
$this->id = $pid;
$this->name = $pname;
}
public function getUri () {
return "?page=".parent::PAGE_RATING_DETAIL."&id=$this->id";
}
public function getEntryId () {
return self::ALL_RATING_ID.":".$this->id;
}
public static function getCount() {
// str_format (localize("ratings", count(array))
return parent::getCountGeneric ("ratings", self::ALL_RATING_ID, parent::PAGE_ALL_RATINGS, "ratings");
}
public static function getAllRatings() {
return self::getEntryArray (self::SQL_ALL_RATINGS, array ());
}
public static function getEntryArray ($query, $params) {
list (, $result) = parent::executeQuery ($query, self::RATING_COLUMNS, "", $params, -1);
$entryArray = array();
while ($post = $result->fetchObject ())
{
$ratingObj = new Rating ($post->id, $post->rating);
$rating=$post->rating/2;
$rating = str_format (localize("ratingword", $rating), $rating);
array_push ($entryArray, new Entry ($rating, $ratingObj->getEntryId (),
str_format (localize("bookword", $post->count), $post->count), "text",
array ( new LinkNavigation ($ratingObj->getUri ())), "", $post->count));
}
return $entryArray;
}
public static function getRatingById ($ratingId) {
$result = parent::getDb ()->prepare('select rating from ratings where id = ?');
$result->execute (array ($ratingId));
return new Rating ($ratingId, $result->fetchColumn ());
}
}