cops/rating.php

62 lines
2.1 KiB
PHP

2014-02-27 01:33:40 +02:00
<?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";
2014-02-27 12:44:11 +02:00
const RATING_COLUMNS = "ratings.id as id, ratings.rating as rating, count(*) as count";
2014-02-27 01:33:40 +02:00
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() {
2014-05-30 07:47:38 +03:00
// str_format (localize("ratings", count(array))
return parent::getCountGeneric ("ratings", self::ALL_RATING_ID, parent::PAGE_ALL_RATINGS, "ratings");
2014-02-27 01:33:40 +02:00
}
public static function getAllRatings() {
return self::getEntryArray (self::SQL_ALL_RATINGS, array ());
}
public static function getEntryArray ($query, $params) {
2014-03-10 18:59:57 +02:00
list (, $result) = parent::executeQuery ($query, self::RATING_COLUMNS, "", $params, -1);
2014-02-27 01:33:40 +02:00
$entryArray = array();
while ($post = $result->fetchObject ())
{
2014-02-27 12:44:11 +02:00
$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 (),
2014-02-27 01:33:40 +02:00
str_format (localize("bookword", $post->count), $post->count), "text",
array ( new LinkNavigation ($ratingObj->getUri ())), "", $post->count));
2014-02-27 01:33:40 +02:00
}
return $entryArray;
}
public static function getRatingById ($ratingId) {
$result = parent::getDb ()->prepare('select rating from ratings where id = ?');
$result->execute (array ($ratingId));
2014-03-27 15:06:26 +02:00
return new Rating ($ratingId, $result->fetchColumn ());
2014-02-27 01:33:40 +02:00
}
}