XpressEngine Core  1.11.2
 All Classes Namespaces Files Functions Variables Pages
point.model.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) NAVER <http://www.navercorp.com> */
8 class pointModel extends point
9 {
10  var $pointList = array();
11 
15  function init()
16  {
17  }
18 
22  function isExistsPoint($member_srl)
23  {
24  $member_srl = abs($member_srl);
25 
26  // Get from instance memory
27  if($this->pointList[$member_srl]) return true;
28 
29  // Get from file cache
30  $path = sprintf(_XE_PATH_ . 'files/member_extra_info/point/%s',getNumberingPath($member_srl));
31  $cache_filename = sprintf('%s%d.cache.txt', $path, $member_srl);
32  if(file_exists($cache_filename))
33  {
34  if(!$this->pointList[$member_srl])
35  $this->pointList[$member_srl] = trim(FileHandler::readFile($cache_filename));
36  return true;
37  }
38 
39  $args =new stdClass();
40  $args->member_srl = $member_srl;
41  $output = executeQuery('point.getPoint', $args);
42  if($output->data->member_srl == $member_srl)
43  {
44  if(!$this->pointList[$member_srl])
45  {
46  $this->pointList[$member_srl] = (int)$output->data->point;
47  FileHandler::makeDir($path);
48  FileHandler::writeFile($cache_filename, (int)$output->data->point);
49  }
50  return true;
51  }
52  return false;
53  }
54 
58  function getPoint($member_srl, $from_db = false)
59  {
60  $member_srl = abs($member_srl);
61 
62  // Get from instance memory
63  if(!$from_db && $this->pointList[$member_srl]) return $this->pointList[$member_srl];
64 
65  // Get from file cache
66  $path = sprintf(_XE_PATH_ . 'files/member_extra_info/point/%s',getNumberingPath($member_srl));
67  $cache_filename = sprintf('%s%d.cache.txt', $path, $member_srl);
68 
69  if(!$from_db && file_exists($cache_filename))
70  return $this->pointList[$member_srl] = trim(FileHandler::readFile($cache_filename));
71 
72  // Get from the DB
73  $args =new stdClass();
74  $args->member_srl = $member_srl;
75  $output = executeQuery('point.getPoint', $args);
76 
77  if(isset($output->data->member_srl))
78  {
79  $point = (int)$output->data->point;
80  $this->pointList[$member_srl] = $point;
81  if(!is_dir($path)) FileHandler::makeDir($path);
82  FileHandler::writeFile($cache_filename, $point);
83  return $point;
84  }
85  return 0;
86  }
87 
91  function getLevel($point, $level_step)
92  {
93  $level_count = count($level_step);
94  for($level=0;$level<=$level_count;$level++) if($point < $level_step[$level]) break;
95  $level --;
96  return $level;
97  }
98 
103  {
104  $member_srls = Context::get('member_srls');
105  $member_srls = array_unique(explode(',', $member_srls));
106  if(!count($member_srls))
107  {
108  return;
109  }
110 
111  $logged_info = Context::get('logged_info');
112  if(!$logged_info->member_srl)
113  {
114  return;
115  }
116 
117  if(!getModel('module')->isSiteAdmin($logged_info))
118  {
119  if(in_array($logged_info->member_srl, $member_srls))
120  {
121  $member_srls = array($logged_info->member_srl);
122  }
123  else
124  {
125  return;
126  }
127  }
128 
129  $oModuleModel = getModel('module');
130  $config = $oModuleModel->getModuleConfig('point');
131 
132  $info = array();
133  foreach($member_srls as $v)
134  {
135  $obj = new stdClass;
136  $obj->point = $this->getPoint($v);
137  $obj->level = $this->getLevel($obj->point, $config->level_step);
138  $obj->member_srl = $v;
139  $info[] = $obj;
140  }
141 
142  $this->add('point_info',$info);
143  }
144 
145 
149  function getMemberList($args = null, $columnList = array())
150  {
151  // Arrange the search options
152  $args->is_admin = Context::get('is_admin')=='Y'?'Y':'';
153  $args->is_denied = Context::get('is_denied')=='Y'?'Y':'';
154  $args->selected_group_srl = Context::get('selected_group_srl');
155 
156  $search_target = trim(Context::get('search_target'));
157  $search_keyword = trim(Context::get('search_keyword'));
158 
159  // if search keyword is emtpy, show all list
160  if(!$search_keyword)
161  {
162  unset($args->is_admin, $args->is_denied, $args->selected_group_srl, $search_target);
163  }
164 
165  if($search_target && $search_keyword)
166  {
167  switch($search_target)
168  {
169  case 'user_id' :
170  if($search_keyword) $search_keyword = str_replace(' ','%',$search_keyword);
171  $args->s_user_id = $search_keyword;
172  break;
173  case 'user_name' :
174  if($search_keyword) $search_keyword = str_replace(' ','%',$search_keyword);
175  $args->s_user_name = $search_keyword;
176  break;
177  case 'nick_name' :
178  if($search_keyword) $search_keyword = str_replace(' ','%',$search_keyword);
179  $args->s_nick_name = $search_keyword;
180  break;
181  case 'email_address' :
182  if($search_keyword) $search_keyword = str_replace(' ','%',$search_keyword);
183  $args->s_email_address = $search_keyword;
184  break;
185  case 'regdate' :
186  $args->s_regdate = $search_keyword;
187  break;
188  case 'last_login' :
189  $args->s_last_login = $search_keyword;
190  break;
191  case 'extra_vars' :
192  $args->s_extra_vars = $search_keyword;
193  break;
194  }
195  }
196  // If there is a selected_group_srl, change the "query id" (for table join)
197  if($args->selected_group_srl)
198  {
199  $query_id = 'point.getMemberListWithinGroup';
200  }
201  else
202  {
203  $query_id = 'point.getMemberList';
204  }
205 
206  $output = executeQuery($query_id, $args, $columnList);
207 
208  if($output->total_count)
209  {
210  $oModuleModel = getModel('module');
211  $config = $oModuleModel->getModuleConfig('point');
212 
213  foreach($output->data as $key => $val)
214  {
215  $output->data[$key]->level = $this->getLevel($val->point, $config->level_step);
216  }
217  }
218 
219  return $output;
220  }
221 }
222 /* End of file point.model.php */
223 /* Location: ./modules/point/point.model.php */
getMemberList($args=null, $columnList=array())
Get a list of points members list.
$oModuleModel
Definition: ko.install.php:236
getNumberingPath($no, $size=3)
Definition: func.inc.php:1081
$obj
Definition: ko.install.php:262
$output
Definition: ko.install.php:193
add($key, $val)
getLevel($point, $level_step)
Get the level.
Definition: point.model.php:91
The model class fo the point module.
Definition: point.model.php:8
writeFile($filename, $buff, $mode="w")
The parent class of the point module.
Definition: point.class.php:8
getMembersPointInfo()
$args
Definition: ko.install.php:185
getPoint($member_srl, $from_db=false)
Get the points.
Definition: point.model.php:58
makeDir($path_string)
const _XE_PATH_
Definition: config.inc.php:49
readFile($filename)
getModel($module_name)
Definition: func.inc.php:145
executeQuery($query_id, $args=NULL, $arg_columns=NULL)
Definition: func.inc.php:203
isExistsPoint($member_srl)
Check if there is points information.
Definition: point.model.php:22
init()
Initialization.
Definition: point.model.php:15