1
|
|
|
<?php |
2
|
|
|
/* Copyright (C) NAVER <http://www.navercorp.com> */ |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* @class communicationModel |
6
|
|
|
* @author NAVER ([email protected]) |
7
|
|
|
* communication module of the Model class |
8
|
|
|
*/ |
9
|
|
|
class communicationModel extends communication |
10
|
|
|
{ |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Initialization |
14
|
|
|
* @return void |
15
|
|
|
*/ |
16
|
|
|
function init() |
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* get the configuration |
23
|
|
|
* @return object config of communication module |
24
|
|
|
*/ |
25
|
|
|
function getConfig() |
26
|
|
|
{ |
27
|
|
|
$oModuleModel = getModel('module'); |
28
|
|
|
$communication_config = $oModuleModel->getModuleConfig('communication'); |
29
|
|
|
|
30
|
|
|
if(!is_object($communication_config)) |
31
|
|
|
{ |
32
|
|
|
$communication_config = new stdClass(); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
if(!$communication_config->skin) |
36
|
|
|
{ |
37
|
|
|
$communication_config->skin = 'default'; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
if(!$communication_config->colorset) |
41
|
|
|
{ |
42
|
|
|
$communication_config->colorset = 'white'; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
if(!$communication_config->editor_skin) |
46
|
|
|
{ |
47
|
|
|
$communication_config->editor_skin = 'ckeditor'; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
if(!$communication_config->mskin) |
51
|
|
|
{ |
52
|
|
|
$communication_config->mskin = 'default'; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
if(!$communication_config->grant_write) |
56
|
|
|
{ |
57
|
|
|
$communication_config->grant_write = array('default_grant'=>'member'); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
return $communication_config; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @brief get grant array for insert to database. table module_config's config field |
65
|
|
|
* @param string $default |
66
|
|
|
* @param array $group |
67
|
|
|
* @return array |
68
|
|
|
*/ |
69
|
|
|
function getGrantArray($default, $group) |
70
|
|
|
{ |
71
|
|
|
$grant = array(); |
72
|
|
|
if($default!="") |
73
|
|
|
{ |
74
|
|
|
switch($default) |
75
|
|
|
{ |
76
|
|
|
case "-2": |
77
|
|
|
$grant = array("default_grant"=>"site"); |
78
|
|
|
break; |
79
|
|
|
case "-3": |
80
|
|
|
$grant = array("default_grant"=>"manager"); |
81
|
|
|
break; |
82
|
|
|
default : |
83
|
|
|
$grant = array("default_grant"=>"member"); |
84
|
|
|
break; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
else if(is_array($group)) |
88
|
|
|
{ |
89
|
|
|
$oMemberModel = getModel('member'); |
90
|
|
|
$group_list = $oMemberModel->getGroups($this->site_srl); |
|
|
|
|
91
|
|
|
|
92
|
|
|
$group_grant = array(); |
93
|
|
|
foreach($group as $group_srl) |
94
|
|
|
{ |
95
|
|
|
$group_grant[$group_srl] = $group_list[$group_srl]->title; |
96
|
|
|
} |
97
|
|
|
$grant = array('group_grant'=>$group_grant); |
98
|
|
|
} |
99
|
|
|
return $grant; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @brief check member's grant |
104
|
|
|
* @param object $member_info |
|
|
|
|
105
|
|
|
* @param array $arrGrant |
106
|
|
|
* @return boolean |
107
|
|
|
*/ |
108
|
|
|
function checkGrant($arrGrant) |
109
|
|
|
{ |
110
|
|
|
if(!$arrGrant) |
|
|
|
|
111
|
|
|
return false; |
112
|
|
|
|
113
|
|
|
$logged_info = Context::get('logged_info'); |
114
|
|
|
if(!$logged_info) |
115
|
|
|
return false; |
116
|
|
|
|
117
|
|
|
if($logged_info->is_admin == "Y") |
118
|
|
|
return true; |
119
|
|
|
|
120
|
|
|
if($arrGrant['default_grant']) |
121
|
|
|
{ |
122
|
|
|
if($arrGrant['default_grant'] == "member" && $logged_info) |
123
|
|
|
return true; |
124
|
|
|
|
125
|
|
|
if($arrGrant['default_grant'] == "site" && $this->site_srl == $logged_info->site_srl) |
126
|
|
|
return true; |
127
|
|
|
|
128
|
|
|
if($arrGrant['default_grant'] == "manager" && $logged_info->is_admin == "Y") |
129
|
|
|
return true; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
if($arrGrant['group_grant']) |
133
|
|
|
{ |
134
|
|
|
$group_grant = $arrGrant['group_grant']; |
135
|
|
|
if(!is_array($group_grant)) |
136
|
|
|
return false; |
137
|
|
|
|
138
|
|
|
foreach($logged_info->group_list as $group_srl=>$title) |
139
|
|
|
{ |
140
|
|
|
if(isset($group_grant[$group_srl])&&$group_grant[$group_srl]==$title) |
141
|
|
|
return true; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
return false; |
147
|
|
|
|
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* get the message contents |
152
|
|
|
* @param int $message_srl |
153
|
|
|
* @param array $columnList |
154
|
|
|
* @return object message information |
155
|
|
|
*/ |
156
|
|
|
function getSelectedMessage($message_srl, $columnList = array()) |
157
|
|
|
{ |
158
|
|
|
$logged_info = Context::get('logged_info'); |
159
|
|
|
|
160
|
|
|
$args = new stdClass(); |
161
|
|
|
$args->message_srl = $message_srl; |
162
|
|
|
$output = executeQuery('communication.getMessage', $args, $columnList); |
163
|
|
|
|
164
|
|
|
$message = $output->data; |
165
|
|
|
if(!$message) |
166
|
|
|
{ |
167
|
|
|
return; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
// get recipient's information if it is a sent message |
171
|
|
|
$oMemberModel = getModel('member'); |
172
|
|
|
|
173
|
|
|
if($message->sender_srl == $logged_info->member_srl && $message->message_type == 'S') |
174
|
|
|
{ |
175
|
|
|
$member_info = $oMemberModel->getMemberInfoByMemberSrl($message->receiver_srl); |
176
|
|
|
} |
177
|
|
|
// get sendor's information if it is a received/archived message |
178
|
|
|
else |
179
|
|
|
{ |
180
|
|
|
$member_info = $oMemberModel->getMemberInfoByMemberSrl($message->sender_srl); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
if($member_info) |
184
|
|
|
{ |
185
|
|
|
foreach($member_info as $key => $val) |
186
|
|
|
{ |
187
|
|
|
if($key === 'title') continue; |
188
|
|
|
if($key === 'content') continue; |
189
|
|
|
if($key === 'sender_srl') continue; |
190
|
|
|
if($key === 'password') continue; |
191
|
|
|
if($key === 'regdate') continue; |
192
|
|
|
|
193
|
|
|
$message->{$key} = $val; |
194
|
|
|
} |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
// change the status if is a received and not yet read message |
198
|
|
|
if($message->message_type == 'R' && $message->readed != 'Y') |
199
|
|
|
{ |
200
|
|
|
$oCommunicationController = getController('communication'); |
201
|
|
|
$oCommunicationController->setMessageReaded($message_srl); |
|
|
|
|
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
return $message; |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* get a new message |
209
|
|
|
* @param array $columnList |
210
|
|
|
* @return object message information |
211
|
|
|
*/ |
212
|
|
|
function getNewMessage($columnList = array()) |
213
|
|
|
{ |
214
|
|
|
$logged_info = Context::get('logged_info'); |
215
|
|
|
|
216
|
|
|
$args = new stdClass(); |
217
|
|
|
$args->receiver_srl = $logged_info->member_srl; |
218
|
|
|
$args->readed = 'N'; |
219
|
|
|
|
220
|
|
|
$output = executeQuery('communication.getNewMessage', $args, $columnList); |
221
|
|
|
if(!count($output->data)) |
222
|
|
|
{ |
223
|
|
|
return; |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
$message = array_pop($output->data); |
227
|
|
|
|
228
|
|
|
$oCommunicationController = getController('communication'); |
229
|
|
|
$oCommunicationController->setMessageReaded($message->message_srl); |
|
|
|
|
230
|
|
|
|
231
|
|
|
return $message; |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
/** |
235
|
|
|
* get a message list |
236
|
|
|
* @param string $message_type (R: Received Message, S: Sent Message, T: Archive) |
237
|
|
|
* @param array $columnList |
238
|
|
|
* @return Object |
239
|
|
|
*/ |
240
|
|
|
function getMessages($message_type = "R", $columnList = array()) |
241
|
|
|
{ |
242
|
|
|
$logged_info = Context::get('logged_info'); |
243
|
|
|
$args = new stdClass(); |
244
|
|
|
|
245
|
|
|
switch($message_type) |
246
|
|
|
{ |
247
|
|
|
case 'R' : |
248
|
|
|
$args->member_srl = $logged_info->member_srl; |
249
|
|
|
$args->message_type = 'R'; |
250
|
|
|
$query_id = 'communication.getReceivedMessages'; |
251
|
|
|
break; |
252
|
|
|
|
253
|
|
|
case 'T' : |
254
|
|
|
$args->member_srl = $logged_info->member_srl; |
255
|
|
|
$args->message_type = 'T'; |
256
|
|
|
$query_id = 'communication.getStoredMessages'; |
257
|
|
|
break; |
258
|
|
|
|
259
|
|
|
default : |
260
|
|
|
$args->member_srl = $logged_info->member_srl; |
261
|
|
|
$args->message_type = 'S'; |
262
|
|
|
$query_id = 'communication.getSendedMessages'; |
263
|
|
|
break; |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
// Other variables |
267
|
|
|
$args->sort_index = 'message.list_order'; |
268
|
|
|
$args->page = Context::get('page'); |
269
|
|
|
$args->list_count = 20; |
270
|
|
|
$args->page_count = 10; |
271
|
|
|
|
272
|
|
|
return executeQuery($query_id, $args, $columnList); |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
/** |
276
|
|
|
* Get a list of friends |
277
|
|
|
* @param int $friend_group_srl (default 0) |
278
|
|
|
* @param array $columnList |
279
|
|
|
* @return Object |
280
|
|
|
*/ |
281
|
|
|
function getFriends($friend_group_srl = 0, $columnList = array()) |
282
|
|
|
{ |
283
|
|
|
$logged_info = Context::get('logged_info'); |
284
|
|
|
|
285
|
|
|
$args = new stdClass(); |
286
|
|
|
$args->friend_group_srl = $friend_group_srl; |
287
|
|
|
$args->member_srl = $logged_info->member_srl; |
288
|
|
|
|
289
|
|
|
// Other variables |
290
|
|
|
$args->page = Context::get('page'); |
291
|
|
|
$args->sort_index = 'friend.list_order'; |
292
|
|
|
$args->list_count = 10; |
293
|
|
|
$args->page_count = 10; |
294
|
|
|
|
295
|
|
|
$output = executeQuery('communication.getFriends', $args, $columnList); |
296
|
|
|
|
297
|
|
|
return $output; |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
/** |
301
|
|
|
* check if a friend is already added |
302
|
|
|
* @param int $member_srl |
303
|
|
|
* @return int |
304
|
|
|
*/ |
305
|
|
View Code Duplication |
function isAddedFriend($member_srl) |
|
|
|
|
306
|
|
|
{ |
307
|
|
|
$logged_info = Context::get('logged_info'); |
308
|
|
|
|
309
|
|
|
$args = new stdClass(); |
310
|
|
|
$args->member_srl = $logged_info->member_srl; |
311
|
|
|
$args->target_srl = $member_srl; |
312
|
|
|
|
313
|
|
|
$output = executeQuery('communication.isAddedFriend', $args); |
314
|
|
|
|
315
|
|
|
return $output->data->count; |
316
|
|
|
} |
317
|
|
|
|
318
|
|
|
/** |
319
|
|
|
* Get a group of friends |
320
|
|
|
* @param int $friend_group_srl |
321
|
|
|
* @return object |
322
|
|
|
*/ |
323
|
|
View Code Duplication |
function getFriendGroupInfo($friend_group_srl) |
|
|
|
|
324
|
|
|
{ |
325
|
|
|
$logged_info = Context::get('logged_info'); |
326
|
|
|
|
327
|
|
|
$args = new stdClass(); |
328
|
|
|
$args->member_srl = $logged_info->member_srl; |
329
|
|
|
$args->friend_group_srl = $friend_group_srl; |
330
|
|
|
|
331
|
|
|
$output = executeQuery('communication.getFriendGroup', $args); |
332
|
|
|
|
333
|
|
|
return $output->data; |
334
|
|
|
} |
335
|
|
|
|
336
|
|
|
/** |
337
|
|
|
* Get a list of groups |
338
|
|
|
* @return array |
339
|
|
|
*/ |
340
|
|
View Code Duplication |
function getFriendGroups() |
|
|
|
|
341
|
|
|
{ |
342
|
|
|
$logged_info = Context::get('logged_info'); |
343
|
|
|
|
344
|
|
|
$args = new stdClass(); |
345
|
|
|
$args->member_srl = $logged_info->member_srl; |
346
|
|
|
|
347
|
|
|
$output = executeQueryArray('communication.getFriendGroups', $args); |
348
|
|
|
|
349
|
|
|
$group_list = $output->data; |
350
|
|
|
if(!$group_list) |
351
|
|
|
{ |
352
|
|
|
return; |
353
|
|
|
} |
354
|
|
|
|
355
|
|
|
return $group_list; |
356
|
|
|
} |
357
|
|
|
|
358
|
|
|
/** |
359
|
|
|
* check whether to be added in the friend list |
360
|
|
|
* @param int $target_srl |
361
|
|
|
* @return boolean (true : friend, false : not friend) |
362
|
|
|
*/ |
363
|
|
|
function isFriend($target_srl) |
364
|
|
|
{ |
365
|
|
|
$logged_info = Context::get('logged_info'); |
366
|
|
|
|
367
|
|
|
$args = new stdClass(); |
368
|
|
|
$args->member_srl = $target_srl; |
369
|
|
|
$args->target_srl = $logged_info->member_srl; |
370
|
|
|
|
371
|
|
|
$output = executeQuery('communication.isAddedFriend', $args); |
372
|
|
|
|
373
|
|
|
if($output->data->count) |
374
|
|
|
{ |
375
|
|
|
return TRUE; |
376
|
|
|
} |
377
|
|
|
|
378
|
|
|
return FALSE; |
379
|
|
|
} |
380
|
|
|
|
381
|
|
|
} |
382
|
|
|
/* End of file communication.model.php */ |
383
|
|
|
/* Location: ./modules/comment/communication.model.php */ |
384
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: