forked from fossar/selfoss
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTags.php
More file actions
100 lines (82 loc) · 2.24 KB
/
Tags.php
File metadata and controls
100 lines (82 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?PHP
namespace controllers;
/**
* Controller for tag access
*
* @package controllers
* @copyright Copyright (c) Tobias Zeising (http://www.aditu.de)
* @license GPLv3 (http://www.gnu.org/licenses/gpl-3.0.html)
* @author Tobias Zeising <tobias.zeising@aditu.de>
*/
class Tags extends BaseController {
/**
* returns all tags
* html
*
* @return void
*/
public function tagslist() {
echo $this->tagsListAsString();
}
/**
* returns all tags
* html
*
* @return void
*/
public function tagsListAsString() {
$tagsDao = new \daos\Tags();
return $this->renderTags($tagsDao->get());
}
/**
* returns all tags
* html
*
* @return void
*/
public function renderTags($tags) {
$html = "";
$itemsDao = new \daos\Items();
foreach($tags as $tag) {
$this->view->tag = $tag['tag'];
$this->view->color = $tag['color'];
$this->view->unread = $itemsDao->numberOfUnreadForTag($tag['tag']);
$html .= $this->view->render('templates/tag.phtml');
}
return $html;
}
/**
* set tag color
*
* @return void
*/
public function color() {
// read data
parse_str(\F3::get('BODY'),$data);
$tag = $data['tag'];
$color = $data['color'];
if(!isset($tag) || strlen(trim($tag))==0)
$this->view->error('invalid or no tag given');
if(!isset($color) || strlen(trim($color))==0)
$this->view->error('invalid or no color given');
$tagsDao = new \daos\Tags();
$tagsDao->saveTagColor($tag, $color);
$this->view->jsonSuccess(array(
'success' => true
));
}
/**
* returns all tags
* html
*
* @return void
*/
public function listTags() {
$tagsDao = new \daos\Tags();
$tags = $tagsDao->get();
$itemsDao = new \daos\Items();
for($i=0; $i<count($tags); $i++)
$tags[$i]['unread'] = $itemsDao->numberOfUnreadForTag($tags[$i]['tag']);
$this->view->jsonSuccess($tags);
}
}