/
tag.php
executable file
·82 lines (75 loc) · 1.78 KB
/
tag.php
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
<?php
class shareTagController extends ezcMvcController
{
public function createResult()
{
switch( $this->action )
{
case 'list':
case 'display':
return $this->{$this->action}();
}
}
private function list()
{
// select last 25 updates with a tag
$q->select( 'DISTINCT message.id as id, user_id, date, status, fullname, source' )
->from( 'message' )->leftJoin( 'message_tag', 'message.id', 'message_tag.message_id' )
->innerJoin( 'user', 'message.user_id', 'user.id' )
->orderBy( 'date', ezcQuerySelect::DESC )->limit( 25 );
$s = $q->prepare();
$s->execute();
$r = $s->fetchAll();
// collect all IDs
$ids = array();
$msgs = array();
foreach( $r as $message )
{
$ids[] = $message['id'];
$msgs[$message['id']] = $message;
}
// select tags per message
$q = ezcDbInstance::get()->createSelectQuery();
$q->select( '*' )
->from( 'message_tag' )
->innerJoin( 'message', 'message.id', 'message_tag.message_id' )
->where( $q->expr->in( 'message_id', $ids ) );
$s = $q->prepare();
$s->execute();
// massage tags
$tagIndex = array();
$tags = array();
foreach( $s->fetchAll() as $res )
{
$tagIndex[$res['message_id']][$res['tag']] = true;
$tags[strtolower($res['tag'])] = $res['tag'];
}
sort( $tags );
// loop over all messages and build the tag lists.
$tagList = array();
foreach( $msgs as $msg )
{
foreach( $tags as $tag )
{
if ( isset( $tagIndex[$msg['id']][$tag] ) )
{
if ( !isset( $tagList[$tag] ) )
{
$tagList[$tag] = array( $msg );
}
else
{
$tagList[$tag][] = $msg;
}
}
}
}
foreach( $tagList as &$perTag )
{
$perTag = shareFormat::formatMessages( $perTag );
}
$res = new ezcMvcResult;
$res->variables['updates'] = $tagList;
}
}
?>