XOOPS  2.6.0
comment.php
Go to the documentation of this file.
1 <?php
2 /*
3  You may not change or alter any portion of this comment or credits
4  of supporting developers from this source code or any supporting source code
5  which is considered copyrighted (c) material of the original comment or credit authors.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 */
11 
22 
30 {
31 
35  public function __construct()
36  {
37  $this->initVar('id', XOBJ_DTYPE_INT, 0, false);
38  $this->initVar('pid', XOBJ_DTYPE_INT, 0, false);
39  $this->initVar('modid', XOBJ_DTYPE_INT, null, false);
40  $this->initVar('icon', XOBJ_DTYPE_OTHER, '', false);
41  $this->initVar('title', XOBJ_DTYPE_TXTBOX, null, true, 255, true);
42  $this->initVar('text', XOBJ_DTYPE_TXTAREA, '', true, null, true);
43  $this->initVar('created', XOBJ_DTYPE_INT, 0, false);
44  $this->initVar('modified', XOBJ_DTYPE_INT, 0, false);
45  $this->initVar('uid', XOBJ_DTYPE_INT, 0, true);
46  $this->initVar('ip', XOBJ_DTYPE_OTHER, null, false);
47  $this->initVar('sig', XOBJ_DTYPE_INT, 0, false);
48  $this->initVar('itemid', XOBJ_DTYPE_INT, 0, false);
49  $this->initVar('rootid', XOBJ_DTYPE_INT, 0, false);
50  $this->initVar('status', XOBJ_DTYPE_INT, 0, false);
51  $this->initVar('exparams', XOBJ_DTYPE_OTHER, null, false, 255);
52  $this->initVar('dohtml', XOBJ_DTYPE_INT, 0, false);
53  $this->initVar('dosmiley', XOBJ_DTYPE_INT, 1, false);
54  $this->initVar('doxcode', XOBJ_DTYPE_INT, 1, false);
55  $this->initVar('doimage', XOBJ_DTYPE_INT, 1, false);
56  $this->initVar('dobr', XOBJ_DTYPE_INT, 1, false);
57  }
58 
62  public function isRoot()
63  {
64  return ($this->getVar('id') == $this->getVar('rootid'));
65  }
66 }
67 
75 {
81  public function __construct(Connection $db = null)
82  {
83  parent::__construct($db, 'comments', 'CommentsComment', 'id', 'title');
84  }
85 
98  public function getByItemId($module_id, $item_id, $order = null, $status = null, $limit = null, $start = 0)
99  {
100  $criteria = new CriteriaCompo(new Criteria('modid', intval($module_id)));
101  $criteria->add(new Criteria('itemid', intval($item_id)));
102  if (isset($status)) {
103  $criteria->add(new Criteria('status', intval($status)));
104  }
105  if (isset($order)) {
106  $criteria->setOrder($order);
107  }
108  if (isset($limit)) {
109  $criteria->setLimit($limit);
110  $criteria->setStart($start);
111  }
112  return $this->getObjects($criteria);
113  }
114 
124  public function getCountByItemId($module_id, $item_id, $status = null)
125  {
126  $criteria = new CriteriaCompo(new Criteria('modid', intval($module_id)));
127  $criteria->add(new Criteria('itemid', intval($item_id)));
128  if (isset($status)) {
129  $criteria->add(new Criteria('status', intval($status)));
130  }
131  return $this->getCount($criteria);
132  }
133 
139  public function getCountByModuleId($module_id, $item_id = null)
140  {
141  $criteria = new CriteriaCompo(new Criteria('modid', intval($module_id)));
142  if (isset($item_id)) {
143  $criteria->add(new Criteria('itemid', intval($item_id)));
144  }
145  return $this->getCount($criteria);
146  }
147 
158  public function getTopComments($module_id, $item_id, $order, $status = null)
159  {
160  $criteria = new CriteriaCompo(new Criteria('modid', intval($module_id)));
161  $criteria->add(new Criteria('itemid', intval($item_id)));
162  $criteria->add(new Criteria('pid', 0));
163  if (isset($status)) {
164  $criteria->add(new Criteria('status', intval($status)));
165  }
166  $criteria->setOrder($order);
167  return $this->getObjects($criteria);
168  }
169 
179  public function getThread($comment_rootid, $comment_id, $status = null)
180  {
181  $criteria = new CriteriaCompo(new Criteria('rootid', intval($comment_rootid)));
182  $criteria->add(new Criteria('id', intval($comment_id), '>='));
183  if (isset($status)) {
184  $criteria->add(new Criteria('status', intval($status)));
185  }
186  return $this->getObjects($criteria);
187  }
188 
198  public function updateByField(CommentsComment $comment, $field_name, $field_value)
199  {
200  $comment->unsetNew();
201  $comment->setVar($field_name, $field_value);
202  return $this->insert($comment);
203  }
204 
211  public function deleteByModule($module_id)
212  {
213  return $this->deleteAll(new Criteria('modid', intval($module_id)));
214  }
215 
221  function deleteByItemId($module_id, $item_id)
222  {
223  $module_id = intval($module_id);
224  $item_id = intval($item_id);
225  if ($module_id > 0 && $item_id > 0) {
226  $comments = $this->getByItemId($module_id, $item_id);
227  if (is_array($comments)) {
228  $count = count($comments);
229  $deleted_num = array();
230  for ($i = 0; $i < $count; ++$i) {
231  if (false != $this->delete($comments[$i])) {
232  // store poster ID and deleted post number into array for later use
233  $poster_id = $comments[$i]->getVar('uid');
234  if ($poster_id != 0) {
235  $deleted_num[$poster_id] = !isset($deleted_num[$poster_id]) ? 1
236  : ($deleted_num[$poster_id] + 1);
237  }
238  }
239  }
240 
241  $member_handler = Xoops::getInstance()->getHandlerMember();
242  foreach ($deleted_num as $user_id => $post_num) {
243  // update user posts
244  /* @var $member_handler XoopsMemberHandler */
245  $poster = $member_handler->getUser($user_id);
246  if (is_object($poster)) {
247  $member_handler->updateUserByField($poster, 'posts', $poster->getVar('posts') - $post_num);
248  }
249  }
250  return true;
251  }
252  }
253  return false;
254  }
255 }
getTopComments($module_id, $item_id, $order, $status=null)
Definition: comment.php:158
if($uname== ''||$pass== '') $member_handler
Definition: checklogin.php:44
__construct(Connection $db=null)
Definition: comment.php:81
deleteByItemId($module_id, $item_id)
Definition: comment.php:221
$i
Definition: dialog.php:68
static getInstance()
Definition: Xoops.php:160
$module_id
Definition: update.php:56
deleteByModule($module_id)
Definition: comment.php:211
getCountByModuleId($module_id, $item_id=null)
Definition: comment.php:139
getThread($comment_rootid, $comment_id, $status=null)
Definition: comment.php:179
getVar($key, $format= 's')
$status
getObjects(CriteriaElement $criteria=null, $id_as_key=false, $as_object=true)
const XOBJ_DTYPE_TXTAREA
Definition: XoopsObject.php:21
getByItemId($module_id, $item_id, $order=null, $status=null, $limit=null, $start=0)
Definition: comment.php:98
$comments
Definition: main.php:48
deleteAll(CriteriaElement $criteria, $force=true, $asObject=false)
$limit
Definition: findusers.php:202
$criteria
$start
setVar($key, $value, $not_gpc=false)
initVar($key, $data_type, $value=null, $required=false, $maxlength=null, $options= '')
updateByField(CommentsComment $comment, $field_name, $field_value)
Definition: comment.php:198
$user_id
Definition: update.php:57
getCountByItemId($module_id, $item_id, $status=null)
Definition: comment.php:124