XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
comment.php
Go to the documentation of this file.
1 <?php
19 defined('XOOPS_ROOT_PATH') or die('Restricted access');
20 
30 {
31 
35  function XoopsComment()
36  {
37  $this->XoopsObject();
38  $this->initVar('com_id', XOBJ_DTYPE_INT, null, false);
39  $this->initVar('com_pid', XOBJ_DTYPE_INT, 0, false);
40  $this->initVar('com_modid', XOBJ_DTYPE_INT, null, false);
41  $this->initVar('com_icon', XOBJ_DTYPE_OTHER, null, false);
42  $this->initVar('com_title', XOBJ_DTYPE_TXTBOX, null, true, 255, true);
43  $this->initVar('com_text', XOBJ_DTYPE_TXTAREA, null, true, null, true);
44  $this->initVar('com_created', XOBJ_DTYPE_INT, 0, false);
45  $this->initVar('com_modified', XOBJ_DTYPE_INT, 0, false);
46  $this->initVar('com_uid', XOBJ_DTYPE_INT, 0, true);
47  // Start Add by voltan
48  $this->initVar('com_user', XOBJ_DTYPE_TXTBOX, null, false, 60);
49  $this->initVar('com_email', XOBJ_DTYPE_TXTBOX, null, false, 60);
50  $this->initVar('com_url', XOBJ_DTYPE_TXTBOX, null, false, 60);
51  // End Add by voltan
52  $this->initVar('com_ip', XOBJ_DTYPE_OTHER, null, false);
53  $this->initVar('com_sig', XOBJ_DTYPE_INT, 0, false);
54  $this->initVar('com_itemid', XOBJ_DTYPE_INT, 0, false);
55  $this->initVar('com_rootid', XOBJ_DTYPE_INT, 0, false);
56  $this->initVar('com_status', XOBJ_DTYPE_INT, 0, false);
57  $this->initVar('com_exparams', XOBJ_DTYPE_OTHER, null, false, 255);
58  $this->initVar('dohtml', XOBJ_DTYPE_INT, 0, false);
59  $this->initVar('dosmiley', XOBJ_DTYPE_INT, 0, false);
60  $this->initVar('doxcode', XOBJ_DTYPE_INT, 0, false);
61  $this->initVar('doimage', XOBJ_DTYPE_INT, 0, false);
62  $this->initVar('dobr', XOBJ_DTYPE_INT, 0, false);
63  }
64 
68  function id($format = 'N')
69  {
70  return $this->getVar('com_id', $format);
71  }
72 
76  function com_id($format = '')
77  {
78  return $this->getVar('com_id', $format);
79  }
80 
84  function com_pid($format = '')
85  {
86  return $this->getVar('com_pid', $format);
87  }
88 
92  function com_modid($format = '')
93  {
94  return $this->getVar('com_modid', $format);
95  }
96 
100  function com_icon($format = '')
101  {
102  return $this->getVar('com_icon', $format);
103  }
104 
108  function com_title($format = '')
109  {
110  return $this->getVar('com_title', $format);
111  }
112 
116  function com_text($format = '')
117  {
118  return $this->getVar('com_text', $format);
119  }
120 
124  function com_created($format = '')
125  {
126  return $this->getVar('com_created', $format);
127  }
128 
132  function com_modified($format = ''){
133  return $this->getVar('com_modified', $format);
134  }
135 
139  function com_uid($format = '')
140  {
141  return $this->getVar('com_uid', $format);
142  }
143 
144  // Start Add by voltan
148  function com_user($format = '')
149  {
150  return $this->getVar('com_user', $format);
151  }
155  function com_email($format = '')
156  {
157  return $this->getVar('com_email', $format);
158  }
162  function com_url($format = '')
163  {
164  return $this->getVar('com_url', $format);
165  }
166  // End Add by voltan
167 
171  function com_ip($format = '')
172  {
173  return $this->getVar('com_ip', $format);
174  }
175 
179  function com_sig($format = '')
180  {
181  return $this->getVar('com_sig', $format);
182  }
183 
187  function com_itemid($format = '')
188  {
189  return $this->getVar('com_itemid', $format);
190  }
191 
195  function com_rootid($format = '')
196  {
197  return $this->getVar('com_rootid', $format);
198  }
199 
203  function com_status($format = '')
204  {
205  return $this->getVar('com_status', $format);
206  }
207 
211  function com_exparams($format = '')
212  {
213  return $this->getVar('com_exparams', $format);
214  }
215 
219  function dohtml($format = '')
220  {
221  return $this->getVar('dohtml', $format);
222  }
223 
227  function dosmiley($format = '')
228  {
229  return $this->getVar('dosmiley', $format);
230  }
231 
235  function doxcode($format = '')
236  {
237  return $this->getVar('doxcode', $format);
238  }
239 
243  function doimage($format = '')
244  {
245  return $this->getVar('doimage', $format);
246  }
247 
251  function dobr($format = '')
252  {
253  return $this->getVar('dobr', $format);
254  }
255 
261  function isRoot()
262  {
263  return ($this->getVar('com_id') == $this->getVar('com_rootid'));
264  }
265 }
266 
281 {
289  function &create($isNew = true)
290  {
291  $comment = new XoopsComment();
292  if ($isNew) {
293  $comment->setNew();
294  }
295  return $comment;
296  }
297 
305  function &get($id)
306  {
307  $comment = false;
308  $id = intval($id);
309  if ($id > 0) {
310  $sql = 'SELECT * FROM ' . $this->db->prefix('xoopscomments') . ' WHERE com_id=' . $id;
311  if (!$result = $this->db->query($sql)) {
312  return $comment;
313  }
314  $numrows = $this->db->getRowsNum($result);
315  if ($numrows == 1) {
316  $comment = new XoopsComment();
317  $comment->assignVars($this->db->fetchArray($result));
318  }
319  }
320  return $comment;
321  }
322 
330  function insert(&$comment)
331  {
335  if (!is_a($comment, 'xoopscomment')) {
336  return false;
337  }
338  if (!$comment->isDirty()) {
339  return true;
340  }
341  if (!$comment->cleanVars()) {
342  return false;
343  }
344  foreach($comment->cleanVars as $k => $v) {
345  ${$k} = $v;
346  }
347  // Start edit by voltan
348  if ($comment->isNew()) {
349  $com_id = $this->db->genId('xoopscomments_com_id_seq');
350  $sql = sprintf("INSERT INTO %s (com_id, com_pid, com_modid, com_icon, com_title, com_text, com_created, com_modified, com_uid, com_user, com_email, com_url, com_ip, com_sig, com_itemid, com_rootid, com_status, com_exparams, dohtml, dosmiley, doxcode, doimage, dobr) VALUES (%u, %u, %u, %s, %s, %s, %u, %u, %u, %s, %s, %s, %s, %u, %u, %u, %u, %s, %u, %u, %u, %u, %u)", $this->db->prefix('xoopscomments'), $com_id, $com_pid, $com_modid, $this->db->quoteString($com_icon), $this->db->quoteString($com_title), $this->db->quoteString($com_text), $com_created, $com_modified, $com_uid, $this->db->quoteString($com_user), $this->db->quoteString($com_email), $this->db->quoteString($com_url), $this->db->quoteString($com_ip), $com_sig, $com_itemid, $com_rootid, $com_status, $this->db->quoteString($com_exparams), $dohtml, $dosmiley, $doxcode, $doimage, $dobr);
351  } else {
352  $sql = sprintf("UPDATE %s SET com_pid = %u, com_icon = %s, com_title = %s, com_text = %s, com_created = %u, com_modified = %u, com_uid = %u, com_user = %s, com_email = %s, com_url = %s, com_ip = %s, com_sig = %u, com_itemid = %u, com_rootid = %u, com_status = %u, com_exparams = %s, dohtml = %u, dosmiley = %u, doxcode = %u, doimage = %u, dobr = %u WHERE com_id = %u", $this->db->prefix('xoopscomments'), $com_pid, $this->db->quoteString($com_icon), $this->db->quoteString($com_title), $this->db->quoteString($com_text), $com_created, $com_modified, $com_uid, $this->db->quoteString($com_user), $this->db->quoteString($com_email), $this->db->quoteString($com_url), $this->db->quoteString($com_ip), $com_sig, $com_itemid, $com_rootid, $com_status, $this->db->quoteString($com_exparams), $dohtml, $dosmiley, $doxcode, $doimage, $dobr, $com_id);
353  }
354  // End edit by voltan
355  if (!$result = $this->db->query($sql)) {
356  return false;
357  }
358  if (empty($com_id)) {
359  $com_id = $this->db->getInsertId();
360  }
361  $comment->assignVar('com_id', $com_id);
362  return true;
363  }
364 
372  function delete(&$comment)
373  {
377  if (!is_a($comment, 'xoopscomment')) {
378  return false;
379  }
380  $sql = sprintf("DELETE FROM %s WHERE com_id = %u", $this->db->prefix('xoopscomments'), $comment->getVar('com_id'));
381  if (!$result = $this->db->query($sql)) {
382  return false;
383  }
384  return true;
385  }
386 
395  function getObjects($criteria = null, $id_as_key = false)
396  {
397  $ret = array();
398  $limit = $start = 0;
399  $sql = 'SELECT * FROM ' . $this->db->prefix('xoopscomments');
400  if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
401  $sql .= ' ' . $criteria->renderWhere();
402  $sort = ($criteria->getSort() != '') ? $criteria->getSort() : 'com_id';
403  $sql .= ' ORDER BY ' . $sort . ' ' . $criteria->getOrder();
404  $limit = $criteria->getLimit();
405  $start = $criteria->getStart();
406  }
407  $result = $this->db->query($sql, $limit, $start);
408  if (!$result) {
409  return $ret;
410  }
411  while ($myrow = $this->db->fetchArray($result)) {
412  $comment = new XoopsComment();
413  $comment->assignVars($myrow);
414  if (!$id_as_key) {
415  $ret[] =& $comment;
416  } else {
417  $ret[$myrow['com_id']] = & $comment;
418  }
419  unset($comment);
420  }
421  return $ret;
422  }
423 
431  function getCount($criteria = null)
432  {
433  $sql = 'SELECT COUNT(*) FROM ' . $this->db->prefix('xoopscomments');
434  if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
435  $sql .= ' ' . $criteria->renderWhere();
436  }
437  if (!$result = & $this->db->query($sql)) {
438  return 0;
439  }
440  list ($count) = $this->db->fetchRow($result);
441  return $count;
442  }
443 
451  function deleteAll($criteria = null)
452  {
453  $sql = 'DELETE FROM ' . $this->db->prefix('xoopscomments');
454  if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
455  $sql .= ' ' . $criteria->renderWhere();
456  }
457  if (!$result = $this->db->query($sql)) {
458  return false;
459  }
460  return true;
461  }
462 
470  function getList($criteria = null)
471  {
472  $comments = $this->getObjects($criteria, true);
473  $ret = array();
474  foreach(array_keys($comments) as $i) {
475  $ret[$i] = $comments[$i]->getVar('com_title');
476  }
477  return $ret;
478  }
479 
492  function getByItemId($module_id, $item_id, $order = null, $status = null, $limit = null, $start = 0)
493  {
494  $criteria = new CriteriaCompo(new Criteria('com_modid', intval($module_id)));
495  $criteria->add(new Criteria('com_itemid', intval($item_id)));
496  if (isset($status)) {
497  $criteria->add(new Criteria('com_status', intval($status)));
498  }
499  if (isset($order)) {
500  $criteria->setOrder($order);
501  }
502  if (isset($limit)) {
503  $criteria->setLimit($limit);
504  $criteria->setStart($start);
505  }
506  return $this->getObjects($criteria);
507  }
508 
518  function getCountByItemId($module_id, $item_id, $status = null)
519  {
520  $criteria = new CriteriaCompo(new Criteria('com_modid', intval($module_id)));
521  $criteria->add(new Criteria('com_itemid', intval($item_id)));
522  if (isset($status)) {
523  $criteria->add(new Criteria('com_status', intval($status)));
524  }
525  return $this->getCount($criteria);
526  }
527 
538  function getTopComments($module_id, $item_id, $order, $status = null)
539  {
540  $criteria = new CriteriaCompo(new Criteria('com_modid', intval($module_id)));
541  $criteria->add(new Criteria('com_itemid', intval($item_id)));
542  $criteria->add(new Criteria('com_pid', 0));
543  if (isset($status)) {
544  $criteria->add(new Criteria('com_status', intval($status)));
545  }
546  $criteria->setOrder($order);
547  return $this->getObjects($criteria);
548  }
549 
559  function getThread($comment_rootid, $comment_id, $status = null)
560  {
561  $criteria = new CriteriaCompo(new Criteria('com_rootid', intval($comment_rootid)));
562  $criteria->add(new Criteria('com_id', intval($comment_id), '>='));
563  if (isset($status)) {
564  $criteria->add(new Criteria('com_status', intval($status)));
565  }
566  return $this->getObjects($criteria);
567  }
568 
578  function updateByField(&$comment, $field_name, $field_value)
579  {
580  $comment->unsetNew();
581  $comment->setVar($field_name, $field_value);
582  return $this->insert($comment);
583  }
584 
592  {
593  return $this->deleteAll(new Criteria('com_modid', intval($module_id)));
594  }
595 }
596 ?>