Esempio n. 1
0
 /**
  * Delete all comments for given ids
  *
  * @param  $ids Array of comments ids
  * @return void
  */
 public static function deleteCommentsByIds($ids)
 {
     if (is_array($ids)) {
         if (count($ids)) {
             $db = JFactory::getDbo();
             $db->setQuery("SELECT DISTINCT object_group, object_id FROM #__jcomments WHERE parent IN (" . implode(',', $ids) . ")");
             $objects = $db->loadObjectList();
             if (count($objects)) {
                 require_once JCOMMENTS_LIBRARIES . '/joomlatune/tree.php';
                 $descendants = array();
                 foreach ($objects as $o) {
                     $query = "SELECT id, parent" . "\nFROM #__jcomments" . "\nWHERE `object_group` = " . $db->Quote($o->object_group) . "\nAND `object_id` = " . $db->Quote($o->object_id);
                     $db->setQuery($query);
                     $comments = $db->loadObjectList();
                     $tree = new JoomlaTuneTree($comments);
                     foreach ($ids as $id) {
                         $descendants = array_merge($descendants, $tree->descendants((int) $id));
                     }
                     unset($tree);
                     $descendants = array_unique($descendants);
                 }
                 $ids = array_merge($ids, $descendants);
             }
             unset($descendants);
             $ids = implode(',', $ids);
             $db->setQuery("DELETE FROM #__jcomments WHERE id IN (" . $ids . ")");
             $db->execute();
             $db->setQuery("DELETE FROM #__jcomments_votes WHERE commentid IN (" . $ids . ")");
             $db->execute();
             $db->setQuery("DELETE FROM #__jcomments_reports WHERE commentid IN (" . $ids . ")");
             $db->execute();
         }
     }
 }
Esempio n. 2
0
 public function delete($oid = null)
 {
     $k = $this->_tbl_key;
     $id = $oid ? $oid : $this->{$k};
     $result = parent::delete($oid);
     if ($result) {
         // process nested comments (threaded mode)
         $query = "SELECT id, parent" . "\n FROM #__jcomments" . "\n WHERE `object_group` = " . $this->_db->Quote($this->object_group) . "\n AND `object_id`= " . $this->object_id;
         $this->_db->setQuery($query);
         $rows = $this->_db->loadObjectList();
         require_once JCOMMENTS_LIBRARIES . '/joomlatune/tree.php';
         $tree = new JoomlaTuneTree($rows);
         $descendants = $tree->descendants($id);
         unset($rows);
         if (count($descendants)) {
             $query = "DELETE FROM #__jcomments WHERE id IN (" . implode(',', $descendants) . ')';
             $this->_db->setQuery($query);
             $this->_db->execute();
             $descendants[] = $id;
             $query = "DELETE FROM #__jcomments_votes WHERE commentid IN (" . implode(',', $descendants) . ')';
             $this->_db->setQuery($query);
             $this->_db->execute();
             $query = "DELETE FROM #__jcomments_reports WHERE commentid IN (" . implode(',', $descendants) . ')';
             $this->_db->setQuery($query);
             $this->_db->execute();
         } else {
             // delete comment's vote info
             $query = "DELETE FROM #__jcomments_votes WHERE commentid = " . $id;
             $this->_db->setQuery($query);
             $this->_db->excute();
             // delete comment's reports info
             $query = "DELETE FROM #__jcomments_reports WHERE commentid = " . $id;
             $this->_db->setQuery($query);
             $this->_db->execute();
         }
         unset($descendants);
     }
     return $result;
 }