XpressEngine Core  1.11.2
 All Classes Namespaces Files Functions Variables Pages
point.admin.controller.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) NAVER <http://www.navercorp.com> */
9 {
13  function init()
14  {
15  }
16 
21  {
22  // Get the configuration information
23  $oModuleModel = getModel('module');
24  $config = $oModuleModel->getModuleConfig('point');
25  // Arrange variables
27 
28  //if module IO config is off
29  if($args->able_module == 'Y')
30  {
31  // Re-install triggers, if it was disabled.
32  if($config->able_module == 'N')
33  {
34  $this->moduleUpdate();
35  }
36 
37  //module IO config is on
38  $config->able_module = 'Y';
39 
40  // Check the point name
41  $config->point_name = $args->point_name;
42  if(!$config->point_name) $config->point_name = 'point';
43  // Specify the default points
44  $config->signup_point = (int)$args->signup_point;
45  $config->login_point = (int)$args->login_point;
46  $config->insert_document = (int)$args->insert_document;
47  $config->read_document = (int)$args->read_document;
48  $config->insert_comment = (int)$args->insert_comment;
49  $config->upload_file = (int)$args->upload_file;
50  $config->download_file = (int)$args->download_file;
51  $config->voted = (int)$args->voted;
52  $config->blamed = (int)$args->blamed;
53  // The highest level
54  $config->max_level = $args->max_level;
55  if($config->max_level>1000) $config->max_level = 1000;
56  if($config->max_level<1) $config->max_level = 1;
57  // Set the level icon
58  $config->level_icon = $args->level_icon;
59  // Check if downloads are not allowed
60  if($args->disable_download == 'Y') $config->disable_download = 'Y';
61  else $config->disable_download = 'N';
62  // Check if reading a document is not allowed
63  if($args->disable_read_document == 'Y') $config->disable_read_document = 'Y';
64  else $config->disable_read_document = 'N';
65 
66  $oMemberModel = getModel('member');
67  $group_list = $oMemberModel->getGroups();
68  $config->point_group = array();
69 
70  // Per-level group configurations
71  foreach($group_list as $group)
72  {
73  // Admin group should not be connected to point.
74  if($group->is_admin == 'Y' || $group->is_default == 'Y') continue;
75 
76  $group_srl = $group->group_srl;
77 
78  if(isset($args->{'point_group_'.$group_srl}))
79  {
80  //if group level is higher than max level, change to max level
81  if($args->{'point_group_'.$group_srl} > $args->max_level)
82  {
83  $args->{'point_group_'.$group_srl} = $args->max_level;
84  }
85 
86  //if group level is lower than 1, change to 1
87  if($args->{'point_group_'.$group_srl} < 1)
88  {
89  $args->{'point_group_'.$group_srl} = 1;
90  }
91  $config->point_group[$group_srl] = $args->{'point_group_'.$group_srl};
92  }
93  }
94 
95  $config->group_reset = $args->group_reset;
96  // Per-level point configurations
97  unset($config->level_step);
98  for($i=1;$i<=$config->max_level;$i++)
99  {
100  $key = "level_step_".$i;
101  $config->level_step[$i] = (int)$args->{$key};
102  }
103  // A function to calculate per-level points
104  $config->expression = $args->expression;
105  }
106  else
107  {
108  //module IO config is OFF, Other settings will not be modified.
109  $config->able_module = 'N';
110 
111  // Delete Triggers
112  $oModuleController = getController('module');
113  $oModuleController->deleteModuleTriggers('point');
114  }
115  // Save
116  $oModuleController = getController('module');
117  $oModuleController->insertModuleConfig('point', $config);
118 
119  $this->setMessage('success_updated');
120 
121  $returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispPointAdminConfig');
122  $this->setRedirectUrl($returnUrl);
123  }
124 
129  {
131 
132  $configTypeList = array('insert_document', 'insert_comment', 'upload_file', 'download_file', 'read_document', 'voted', 'blamed');
133  foreach($configTypeList AS $config)
134  {
135  if(is_array($args->{$config}))
136  {
137  foreach($args->{$config} AS $key=>$value)
138  {
139  $module_config[$key][$config] = $value;
140  }
141  }
142  }
143 
144  $oModuleController = getController('module');
145  if(count($module_config))
146  {
147  foreach($module_config as $module_srl => $config)
148  {
149  $oModuleController->insertModulePartConfig('point',$module_srl,$config);
150  }
151  }
152 
153  $this->setMessage('success_updated');
154  if(!in_array(Context::getRequestMethod(),array('XMLRPC','JSON')))
155  {
156  $returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispPointAdminModuleConfig');
157  header('location:'.$returnUrl);
158  return;
159  }
160  }
161 
166  {
167  $module_srl = Context::get('target_module_srl');
168  if(!$module_srl) return new BaseObject(-1, 'msg_invalid_request');
169  // In case of batch configuration of several modules
170  if(preg_match('/^([0-9,]+)$/',$module_srl)) $module_srl = explode(',',$module_srl);
171  else $module_srl = array($module_srl);
172  // Save configurations
173  $oModuleController = getController('module');
174  for($i=0;$i<count($module_srl);$i++)
175  {
176  $srl = trim($module_srl[$i]);
177  if(!$srl) continue;
178  unset($config);
179  $config['insert_document'] = (int)Context::get('insert_document');
180  $config['insert_comment'] = (int)Context::get('insert_comment');
181  $config['upload_file'] = (int)Context::get('upload_file');
182  $config['download_file'] = (int)Context::get('download_file');
183  $config['read_document'] = (int)Context::get('read_document');
184  $config['voted'] = (int)Context::get('voted');
185  $config['blamed'] = (int)Context::get('blamed');
186  $oModuleController->insertModulePartConfig('point', $srl, $config);
187  }
188 
189  $this->setError(-1);
190  $this->setMessage('success_updated', 'info');
191 
192  $returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispBoardAdminContent');
193  $this->setRedirectUrl($returnUrl);
194  }
195 
200  {
201  $member_srl = Context::get('member_srl');
202  $point = Context::get('point');
203 
204  preg_match('/^(\+|-)?([1-9][0-9]*)$/', $point, $m);
205 
206  $action = '';
207  switch($m[1])
208  {
209  case '+':
210  $action = 'add';
211  break;
212  case '-':
213  $action = 'minus';
214  break;
215  default:
216  $action = 'update';
217  break;
218  }
219  $point = $m[2];
220 
221  $oPointController = getController('point');
222  $output = $oPointController->setPoint($member_srl, (int)$point, $action);
223 
224  $this->setError(-1);
225  $this->setMessage('success_updated', 'info');
226 
227  $returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispPointAdminPointList');
228  return $this->setRedirectUrl($returnUrl, $output);
229  }
230 
235  {
236  @set_time_limit(0);
237  // Get per-module points information
238  $oModuleModel = getModel('module');
239  $config = $oModuleModel->getModuleConfig('point');
240 
241  $module_config = $oModuleModel->getModulePartConfigs('point');
242  // A variable to store member's points
243  $member = array();
244 
245  // Get member infomation
246  $output = executeQueryArray('point.getMemberCount');
247  if(!$output->toBool()) return $output;
248 
249  if($output->data)
250  {
251  foreach($output->data as $key => $val)
252  {
253  if(!$val->member_srl) continue;
254  $member[$val->member_srl] = 0;
255  }
256  }
257 
258  // Get post information
259  $output = executeQueryArray('point.getDocumentPoint');
260  if(!$output->toBool()) return $output;
261 
262  if($output->data)
263  {
264  foreach($output->data as $key => $val)
265  {
266  if($module_config[$val->module_srl]['insert_document']) $insert_point = $module_config[$val->module_srl]['insert_document'];
267  else $insert_point = $config->insert_document;
268 
269  if(!$val->member_srl) continue;
270  $point = $insert_point * $val->count;
271  $member[$val->member_srl] += $point;
272  }
273  }
274 
275  $output = null;
276  // Get comments information
277  $output = executeQueryArray('point.getCommentPoint');
278  if(!$output->toBool()) return $output;
279 
280  if($output->data)
281  {
282  foreach($output->data as $key => $val)
283  {
284  if($module_config[$val->module_srl]['insert_comment']) $insert_point = $module_config[$val->module_srl]['insert_comment'];
285  else $insert_point = $config->insert_comment;
286 
287  if(!$val->member_srl) continue;
288  $point = $insert_point * $val->count;
289  $member[$val->member_srl] += $point;
290  }
291  }
292  $output = null;
293  // Get the attached files' information
294  $output = executeQueryArray('point.getFilePoint');
295  if(!$output->toBool()) return $output;
296 
297  if($output->data)
298  {
299  foreach($output->data as $key => $val)
300  {
301  if($module_config[$val->module_srl]['upload_file']) $insert_point = $module_config[$val->module_srl]['upload_file'];
302  else $insert_point = $config->upload_file;
303 
304  if(!$val->member_srl) continue;
305  $point = $insert_point * $val->count;
306  $member[$val->member_srl] += $point;
307  }
308  }
309  $output = null;
310  // Set all members' points to 0
311  $output = executeQuery("point.initMemberPoint");
312  if(!$output->toBool()) return $output;
313  // Save the file temporarily
314 
315  $str = '';
316  foreach($member as $key => $val)
317  {
318  $val += (int)$config->signup_point;
319  $str .= $key.','.$val."\r\n";
320  }
321 
322  @file_put_contents('./files/cache/pointRecal.txt', $str, LOCK_EX);
323 
324  $this->add('total', count($member));
325  $this->add('position', 0);
326  $this->setMessage( sprintf(Context::getLang('point_recal_message'), 0, $this->get('total')) );
327  }
328 
333  {
334  $position = (int)Context::get('position');
335  $total = (int)Context::get('total');
336 
337  if(!file_exists('./files/cache/pointRecal.txt')) return new BaseObject(-1, 'msg_invalid_request');
338 
339  $idx = 0;
340  $f = fopen("./files/cache/pointRecal.txt","r");
341  while(!feof($f))
342  {
343  $str = trim(fgets($f, 1024));
344  $idx ++;
345  if($idx > $position)
346  {
347  list($member_srl, $point) = explode(',',$str);
348 
349  $args = new stdClass();
350  $args->member_srl = $member_srl;
351  $args->point = $point;
352  $output = executeQuery('point.insertPoint',$args);
353  if($idx%5000==0) break;
354  }
355  }
356 
357  if(feof($f))
358  {
359  FileHandler::removeFile('./files/cache/pointRecal.txt');
360  $idx = $total;
361 
362  FileHandler::rename('./files/member_extra_info/point','./files/member_extra_info/point.old');
363 
364  FileHandler::removeDir('./files/member_extra_info/point.old');
365  }
366  fclose($f);
367 
368  $this->add('total', $total);
369  $this->add('position', $idx);
370  $this->setMessage(sprintf(Context::getLang('point_recal_message'), $idx, $total));
371 
372  }
373 
378  {
379  $module_srl = Context::get('module_srls');
380  if(!$module_srl) return new BaseObject(-1, 'msg_invalid_request');
381  // In case of batch configuration of several modules
382  if(preg_match('/^([0-9,]+)$/',$module_srl)) $module_srl = explode(',',$module_srl);
383  else $module_srl = array($module_srl);
384  // Save configurations
385  $oModuleController = getController('module');
386  for($i=0;$i<count($module_srl);$i++)
387  {
388  $srl = trim($module_srl[$i]);
389  if(!$srl) continue;
390  $args = new stdClass();
391  $args->module = 'point';
392  $args->module_srl = $srl;
393  executeQuery('module.deleteModulePartConfig', $args);
394  }
395 
396  $oCacheHandler = CacheHandler::getInstance('object', null, true);
397  if($oCacheHandler->isSupport())
398  {
399  $oCacheHandler->invalidateGroupKey('site_and_module');
400  }
401 
402  $this->setMessage('success_updated');
403  }
404 
409  function cacheActList()
410  {
411  return;
412  }
413 }
414 /* End of file point.admin.controller.php */
415 /* Location: ./modules/point/point.admin.controller.php */
$oModuleModel
Definition: ko.install.php:236
The admin controller class of the point module.
getController($module_name)
Definition: func.inc.php:90
removeFile($filename)
procPointAdminInsertConfig()
Save the default configurations.
$output
Definition: ko.install.php:193
& getInstance($target= 'object', $info=null, $always_use_file=false)
getNotEncodedUrl()
Definition: func.inc.php:316
procPointAdminReset()
Reset points for each module.
procPointAdminUpdatePoint()
Change members points.
The parent class of the point module.
Definition: point.class.php:8
rename($source, $target)
$args
Definition: ko.install.php:185
procPointAdminInsertPointModuleConfig()
Save individual points per module.
procPointAdminInsertModuleConfig()
Save per-module configurations.
getLang($code)
procPointAdminApplyPoint()
Apply member points saved by file to units of 5,000 people.
cacheActList()
Save the cache files.
getModel($module_name)
Definition: func.inc.php:145
executeQueryArray($query_id, $args=NULL, $arg_columns=NULL)
Definition: func.inc.php:219
$module_srl
Definition: ko.install.php:254
executeQuery($query_id, $args=NULL, $arg_columns=NULL)
Definition: func.inc.php:203
$oModuleController
Definition: ko.install.php:287
procPointAdminReCal()
Recalculate points based on the list/comment/attachment and registration information. Granted only once a first-time login score.
moduleUpdate()
Execute update.