Add the number of elements to the tags. re #79
This commit is contained in:
parent
f095e9426e
commit
20359c7306
29
tag.php
29
tag.php
|
@ -10,13 +10,17 @@ require_once('base.php');
|
||||||
|
|
||||||
class tag extends Base {
|
class tag extends Base {
|
||||||
const ALL_TAGS_ID = "cops:tags";
|
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 $id;
|
||||||
public $name;
|
public $name;
|
||||||
|
|
||||||
public function __construct($pid, $pname) {
|
public function __construct($post) {
|
||||||
$this->id = $pid;
|
$this->id = $post->id;
|
||||||
$this->name = $pname;
|
$this->name = $post->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getUri () {
|
public function getUri () {
|
||||||
|
@ -36,26 +40,13 @@ class tag extends Base {
|
||||||
$result = parent::getDb ()->prepare('select id, name from tags where id = ?');
|
$result = parent::getDb ()->prepare('select id, name from tags where id = ?');
|
||||||
$result->execute (array ($tagId));
|
$result->execute (array ($tagId));
|
||||||
if ($post = $result->fetchObject ()) {
|
if ($post = $result->fetchObject ()) {
|
||||||
return new Tag ($post->id, $post->name);
|
return new Tag ($post);
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getAllTags() {
|
public static function getAllTags() {
|
||||||
$result = parent::getDb ()->query('select tags.id as id, tags.name as name, count(*) as count
|
return Base::getEntryArrayWithBookNumber (self::SQL_ALL_TAGS, self::TAG_COLUMNS, array (), "Tag");
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getAllTagsByQuery($query, $n, $database = NULL, $numberPerPage = NULL) {
|
public static function getAllTagsByQuery($query, $n, $database = NULL, $numberPerPage = NULL) {
|
||||||
|
@ -65,7 +56,7 @@ order by tags.name');
|
||||||
$entryArray = array();
|
$entryArray = array();
|
||||||
while ($post = $result->fetchObject ())
|
while ($post = $result->fetchObject ())
|
||||||
{
|
{
|
||||||
$tag = new Tag ($post->id, $post->name);
|
$tag = new Tag ($post);
|
||||||
array_push ($entryArray, new Entry ($tag->name, $tag->getEntryId (),
|
array_push ($entryArray, new Entry ($tag->name, $tag->getEntryId (),
|
||||||
str_format (localize("bookword", $post->count), $post->count), "text",
|
str_format (localize("bookword", $post->count), $post->count), "text",
|
||||||
array ( new LinkNavigation ($tag->getUri ()))));
|
array ( new LinkNavigation ($tag->getUri ()))));
|
||||||
|
|
Loading…
Reference in a new issue