2012-05-29 21:08:40 +03:00
|
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* COPS (Calibre OPDS PHP Server) class file
|
|
|
|
|
*
|
|
|
|
|
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
|
|
|
|
|
* @author S<EFBFBD>bastien Lucas <sebastien@slucas.fr>
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
require_once('base.php');
|
|
|
|
|
|
|
|
|
|
class tag extends Base {
|
2013-10-25 08:59:27 +03:00
|
|
|
|
const ALL_TAGS_ID = "cops:tags";
|
2013-12-05 11:52:51 +02:00
|
|
|
|
|
2012-05-29 21:08:40 +03:00
|
|
|
|
public $id;
|
|
|
|
|
public $name;
|
2013-12-05 11:52:51 +02:00
|
|
|
|
|
2012-05-29 21:08:40 +03:00
|
|
|
|
public function __construct($pid, $pname) {
|
|
|
|
|
$this->id = $pid;
|
|
|
|
|
$this->name = $pname;
|
|
|
|
|
}
|
2013-12-05 11:52:51 +02:00
|
|
|
|
|
2012-05-29 21:08:40 +03:00
|
|
|
|
public function getUri () {
|
|
|
|
|
return "?page=".parent::PAGE_TAG_DETAIL."&id=$this->id";
|
|
|
|
|
}
|
2013-12-05 11:52:51 +02:00
|
|
|
|
|
2012-05-29 21:08:40 +03:00
|
|
|
|
public function getEntryId () {
|
|
|
|
|
return self::ALL_TAGS_ID.":".$this->id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function getCount() {
|
2014-05-30 07:47:38 +03:00
|
|
|
|
// str_format (localize("tags.alphabetical", count(array))
|
|
|
|
|
return parent::getCountGeneric ("tags", self::ALL_TAGS_ID, parent::PAGE_ALL_TAGS);
|
2012-05-29 21:08:40 +03:00
|
|
|
|
}
|
2013-12-05 11:52:51 +02:00
|
|
|
|
|
2012-05-29 21:08:40 +03:00
|
|
|
|
public static function getTagById ($tagId) {
|
|
|
|
|
$result = parent::getDb ()->prepare('select id, name from tags where id = ?');
|
|
|
|
|
$result->execute (array ($tagId));
|
|
|
|
|
if ($post = $result->fetchObject ()) {
|
|
|
|
|
return new Tag ($post->id, $post->name);
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2013-12-05 11:52:51 +02:00
|
|
|
|
|
2012-05-29 21:08:40 +03:00
|
|
|
|
public static function getAllTags() {
|
|
|
|
|
$result = parent::getDb ()->query('select tags.id as id, tags.name as name, count(*) as count
|
|
|
|
|
from tags, books_tags_link
|
|
|
|
|
where tags.id = tag
|
|
|
|
|
group by tags.id, tags.name
|
|
|
|
|
order by tags.name');
|
|
|
|
|
$entryArray = array();
|
|
|
|
|
while ($post = $result->fetchObject ())
|
|
|
|
|
{
|
|
|
|
|
$tag = new Tag ($post->id, $post->name);
|
2013-12-05 11:52:51 +02:00
|
|
|
|
array_push ($entryArray, new Entry ($tag->name, $tag->getEntryId (),
|
|
|
|
|
str_format (localize("bookword", $post->count), $post->count), "text",
|
2012-05-29 21:08:40 +03:00
|
|
|
|
array ( new LinkNavigation ($tag->getUri ()))));
|
|
|
|
|
}
|
|
|
|
|
return $entryArray;
|
|
|
|
|
}
|
2013-12-05 11:52:51 +02:00
|
|
|
|
|
2013-11-22 15:41:56 +02:00
|
|
|
|
public static function getAllTagsByQuery($query, $n, $database = NULL, $numberPerPage = NULL) {
|
|
|
|
|
$columns = "tags.id as id, tags.name as name, (select count(*) from books_tags_link where tags.id = tag) as count";
|
2014-05-12 22:36:31 +03:00
|
|
|
|
$sql = 'select {0} from tags where upper (tags.name) like ? {1} order by tags.name';
|
2013-11-22 15:41:56 +02:00
|
|
|
|
list ($totalNumber, $result) = parent::executeQuery ($sql, $columns, "", array ('%' . $query . '%'), $n, $database, $numberPerPage);
|
2013-09-27 18:10:07 +03:00
|
|
|
|
$entryArray = array();
|
|
|
|
|
while ($post = $result->fetchObject ())
|
|
|
|
|
{
|
|
|
|
|
$tag = new Tag ($post->id, $post->name);
|
2013-12-05 11:52:51 +02:00
|
|
|
|
array_push ($entryArray, new Entry ($tag->name, $tag->getEntryId (),
|
|
|
|
|
str_format (localize("bookword", $post->count), $post->count), "text",
|
2013-09-27 18:10:07 +03:00
|
|
|
|
array ( new LinkNavigation ($tag->getUri ()))));
|
|
|
|
|
}
|
2013-11-22 15:41:56 +02:00
|
|
|
|
return array ($entryArray, $totalNumber);
|
2013-09-27 18:10:07 +03:00
|
|
|
|
}
|
2012-05-29 21:08:40 +03:00
|
|
|
|
}
|