|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* COPS (Calibre OPDS PHP Server) class file |
|
4
|
|
|
* |
|
5
|
|
|
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html) |
|
6
|
|
|
* @author Sébastien Lucas <[email protected]> |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
class Tag |
|
|
|
|
|
|
10
|
|
|
{ |
|
11
|
|
|
const ALL_TAGS_ID = "cops:tags"; |
|
|
|
|
|
|
12
|
|
|
const TAG_COLUMNS = "tags.id as id, tags.name as name, count(*) as count"; |
|
|
|
|
|
|
13
|
|
|
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"; |
|
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
public $id; |
|
16
|
|
|
public $name; |
|
17
|
|
|
|
|
18
|
17 |
|
public function __construct($post) { |
|
19
|
17 |
|
$this->id = $post->id; |
|
20
|
17 |
|
$this->name = $post->name; |
|
21
|
17 |
|
} |
|
22
|
|
|
|
|
23
|
8 |
|
public function getUri () { |
|
24
|
8 |
|
return "?page=".Base::PAGE_TAG_DETAIL."&id=$this->id"; |
|
|
|
|
|
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
8 |
|
public function getEntryId () { |
|
28
|
8 |
|
return self::ALL_TAGS_ID.":".$this->id; |
|
|
|
|
|
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
18 |
|
public static function getCount() { |
|
32
|
|
|
// str_format (localize("tags.alphabetical", count(array)) |
|
|
|
|
|
|
33
|
18 |
|
return Base::getCountGeneric ("tags", self::ALL_TAGS_ID, Base::PAGE_ALL_TAGS); |
|
|
|
|
|
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
1 |
View Code Duplication |
public static function getTagById ($tagId) { |
|
|
|
|
|
|
37
|
1 |
|
$result = Base::getDb ()->prepare('select id, name from tags where id = ?'); |
|
38
|
1 |
|
$result->execute (array ($tagId)); |
|
39
|
1 |
|
if ($post = $result->fetchObject ()) { |
|
40
|
1 |
|
return new Tag ($post); |
|
41
|
|
|
} |
|
42
|
|
|
return NULL; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
2 |
|
public static function getAllTags() { |
|
46
|
2 |
|
return Base::getEntryArrayWithBookNumber (self::SQL_ALL_TAGS, self::TAG_COLUMNS, array (), "Tag"); |
|
|
|
|
|
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
23 |
|
public static function getAllTagsByQuery($query, $n, $database = NULL, $numberPerPage = NULL) { |
|
50
|
23 |
|
$columns = "tags.id as id, tags.name as name, (select count(*) from books_tags_link where tags.id = tag) as count"; |
|
|
|
|
|
|
51
|
23 |
|
$sql = 'select {0} from tags where upper (tags.name) like ? {1} order by tags.name'; |
|
52
|
23 |
|
list ($totalNumber, $result) = Base::executeQuery ($sql, $columns, "", array ('%' . $query . '%'), $n, $database, $numberPerPage); |
|
|
|
|
|
|
53
|
23 |
|
$entryArray = array(); |
|
54
|
23 |
|
while ($post = $result->fetchObject ()) |
|
55
|
|
|
{ |
|
56
|
5 |
|
$tag = new Tag ($post); |
|
57
|
5 |
|
array_push ($entryArray, new Entry ($tag->name, $tag->getEntryId (), |
|
58
|
5 |
|
str_format (localize("bookword", $post->count), $post->count), "text", |
|
|
|
|
|
|
59
|
5 |
|
array ( new LinkNavigation ($tag->getUri ())))); |
|
60
|
5 |
|
} |
|
61
|
23 |
|
return array ($entryArray, $totalNumber); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.