Add the number of elements to the tags. re #79

This commit is contained in:
Sébastien Lucas 2014-06-03 21:27:44 +02:00
parent f095e9426e
commit 20359c7306

29
tag.php
View file

@ -10,13 +10,17 @@ require_once('base.php');
class tag extends Base {
const ALL_TAGS_ID = "cops:tags";
const TAG_COLUMNS = "tags.id as id, tags.name as name, count(*) as count";
const SQL_ALL_TAGS = "select {0} from tags, books_tags_link where tags.id = tag group by tags.id, tags.name order by tags.name";
const SQL_TAGS_FOR_SEARCH = "select {0} from tags, books_tags_link where tags.id = tag group by tags.id, tags.name order by tags.name";
public $id;
public $name;
public function __construct($pid, $pname) {
$this->id = $pid;
$this->name = $pname;
public function __construct($post) {
$this->id = $post->id;
$this->name = $post->name;
}
public function getUri () {
@ -36,26 +40,13 @@ class tag extends Base {
$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 new Tag ($post);
}
return NULL;
}
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);
array_push ($entryArray, new Entry ($tag->name, $tag->getEntryId (),
str_format (localize("bookword", $post->count), $post->count), "text",
array ( new LinkNavigation ($tag->getUri ()))));
}
return $entryArray;
return Base::getEntryArrayWithBookNumber (self::SQL_ALL_TAGS, self::TAG_COLUMNS, array (), "Tag");
}
public static function getAllTagsByQuery($query, $n, $database = NULL, $numberPerPage = NULL) {
@ -65,7 +56,7 @@ order by tags.name');
$entryArray = array();
while ($post = $result->fetchObject ())
{
$tag = new Tag ($post->id, $post->name);
$tag = new Tag ($post);
array_push ($entryArray, new Entry ($tag->name, $tag->getEntryId (),
str_format (localize("bookword", $post->count), $post->count), "text",
array ( new LinkNavigation ($tag->getUri ()))));