1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @property integer $uid |
4
|
|
|
* @property array $posts |
5
|
|
|
* @property string $content_type |
6
|
|
|
*/ |
7
|
|
|
class Wall extends CModel |
8
|
|
|
{ |
9
|
|
|
const TYPE_DUEL = 'duel'; |
|
|
|
|
10
|
|
|
const TYPE_LEVEL = 'level'; |
|
|
|
|
11
|
|
|
const TYPE_NEW_COUNTY = 'new_county'; |
|
|
|
|
12
|
|
|
const TYPE_CLUB_FIRE = 'club_fire'; |
|
|
|
|
13
|
|
|
const TYPE_CLUB_APPROVE = 'club_approve'; |
14
|
|
|
const TYPE_CLUB_DELETE = 'club_delete'; |
|
|
|
|
15
|
|
|
const TYPE_CLUB_CLOSE = 'club_close'; |
|
|
|
|
16
|
|
|
const TYPE_BADGE = 'badge'; |
|
|
|
|
17
|
|
|
const TYPE_NEW_AWARD = 'new_award'; |
|
|
|
|
18
|
|
|
|
19
|
|
|
private $uid; |
20
|
|
|
private $content_type = '?'; |
21
|
|
|
private $posts = []; |
|
|
|
|
22
|
|
|
|
23
|
|
|
public function attributeNames() |
24
|
|
|
{ |
25
|
|
|
return []; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function getPosts() |
29
|
|
|
{ |
30
|
|
|
return $this->posts; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function setUid($uid) |
34
|
|
|
{ |
35
|
|
|
$this->uid = (int)$uid; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function setContent_type($type) |
39
|
|
|
{ |
40
|
|
|
$this->content_type = $type; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function add($data) |
44
|
|
|
{ |
45
|
|
|
$data['type'] = $this->content_type; |
46
|
|
|
$body = CJSON::encode($data); |
|
|
|
|
47
|
|
|
|
48
|
|
|
Yii::app()->db->createCommand() |
49
|
|
|
->insert('wall', [ |
50
|
|
|
'uid'=>$this->uid, |
51
|
|
|
'body'=>$body |
52
|
|
|
]); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function fetchPosts() |
56
|
|
|
{ |
57
|
|
|
$res = Yii::app()->db->createCommand() |
58
|
|
|
->select('*') |
59
|
|
|
->from('wall') |
60
|
|
|
->where('uid=:uid', [':uid'=>$this->uid]) |
61
|
|
|
->order('created DESC') |
62
|
|
|
->limit(10) |
63
|
|
|
->queryAll(); |
64
|
|
|
|
65
|
|
|
$lastDay = ''; |
66
|
|
|
foreach ($res as $post) { |
67
|
|
|
//separator |
68
|
|
|
$day = date('Y. m. d.', strtotime($post['created'])); |
69
|
|
|
if ($day != $lastDay) { |
70
|
|
|
$lastDay = $day; |
|
|
|
|
71
|
|
|
$this->posts[$post['created']] = [ |
72
|
|
|
'content_type' => 'date_separator', |
73
|
|
|
'body'=>[], |
74
|
|
|
'created'=>$day |
75
|
|
|
]; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
$post['body'] = CJSON::decode($post['body']); |
|
|
|
|
79
|
|
|
$post['content_type'] = $post['body']['type']; |
80
|
|
|
|
81
|
|
|
$post['created'] = date('H:i', strtotime($post['created'])); |
82
|
|
|
|
83
|
|
|
$this->posts[$post['id']] = $post; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
} |
|
|
|
|
87
|
|
|
|
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.