cops/rating.php

66 lines
2.3 KiB
PHP
Raw Normal View History

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";
const AUTHOR_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 $sort;
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() {
$nAuthors = parent::getDb ()->query('select count(*) from ratings')->fetchColumn();
$entry = new Entry (localize("rating.title"), self::ALL_RATING_ID,
str_format (localize("ratings", $nAuthors), $nAuthors), "text",
array ( new LinkNavigation ("?page=".parent::PAGE_ALL_RATINGS)));
return $entry;
}
public static function getAllRatings() {
return self::getEntryArray (self::SQL_ALL_RATINGS, array ());
}
public static function getEntryArray ($query, $params) {
list ($totalNumber, $result) = parent::executeQuery ($query, self::AUTHOR_COLUMNS, "", $params, -1);
$entryArray = array();
while ($post = $result->fetchObject ())
{
$rating = new Rating ($post->id, $post->rating);
$bewertung=$post->rating/2;
$bewertung.=" Sterne";
array_push ($entryArray, new Entry ($bewertung, $rating->getEntryId (),
str_format (localize("bookword", $post->count), $post->count), "text",
array ( new LinkNavigation ($rating->getUri ()))));
}
return $entryArray;
}
public static function getRatingById ($ratingId) {
$result = parent::getDb ()->prepare('select rating from ratings where id = ?');
$result->execute (array ($ratingId));
return new Author ($ratingId, $result->fetchColumn ());
}
}