/** * Delete a comment * * @return void */ public function deletereplyTask() { // Incoming $row = new Comment(Request::getInt('replyid', 0)); // Do we have a reply ID? if (!$row->exists()) { $this->setError(Lang::txt('COM_WISHLIST_ERROR_REPLY_NOT_FOUND')); return; } if ($row->get('added_by') != User::get('id')) { App::redirect(Request::getVar('HTTP_REFERER', NULL, 'server'), Lang::txt('COM_WISHLIST_ERROR_CANNOT_DELETE_REPLY'), 'error'); return; } // Delete the comment $row->set('state', 4); if (!$row->store()) { throw new Exception($row->getError(), 500); } // Go back to the page App::redirect(Request::getVar('HTTP_REFERER', NULL, 'server')); }
/** * Get a list or count of comments * * @param string $rtrn Data format to return * @param array $filters Filters to apply to data fetch * @param boolean $clear Clear cached data? * @return mixed */ public function comments($rtrn = 'list', $filters = array(), $clear = false) { if (!isset($filters['item_id'])) { $filters['item_id'] = $this->get('id'); } if (!isset($filters['item_type'])) { $filters['item_type'] = 'wish'; } if (!isset($filters['parent'])) { $filters['parent'] = 0; } if (!isset($filters['state'])) { $filters['state'] = array(static::APP_STATE_PUBLISHED, static::APP_STATE_FLAGGED); } switch (strtolower($rtrn)) { case 'count': if (!is_numeric($this->_cache['comments.count']) || $clear) { $this->_cache['comments.count'] = Comment::all()->whereEquals('item_id', $filters['item_id'])->whereEquals('item_type', $filters['item_type'])->whereIn('state', $filters['state'])->total(); } return $this->_cache['comments.count']; break; case 'authors': if (!is_array($this->_cache['comments.authors']) || $clear) { $this->_cache['comments.authors'] = array(); if (!$this->_cache['comments.authors']) { $c = $this->comments('list', $filters); } foreach ($c as $com) { $this->_cache['comments.authors'][] = $com->get('created_by'); foreach ($com->replies(array('state' => $filters['state'])) as $rep) { $this->_cache['comments.authors'][] = $rep->get('created_by'); foreach ($rep->replies(array('state' => $filters['state'])) as $res) { $this->_cache['comments.authors'][] = $res->get('created_by'); } } } $this->_cache['comments.authors'] = array_unique($this->_cache['comments.authors']); } return $this->_cache['comments.authors']; break; case 'list': case 'results': default: if (!$this->_cache['comments.list'] || $clear) { $results = Comment::all()->whereEquals('parent', $filters['parent'])->whereEquals('item_id', $filters['item_id'])->whereEquals('item_type', $filters['item_type'])->whereIn('state', $filters['state'])->ordered()->rows(); $this->_cache['comments.list'] = $results; } return $this->_cache['comments.list']; break; } }
/** * Delete a comment * * @return void */ public function deletereplyTask() { // Incoming $row = Comment::oneOrFail(Request::getInt('replyid', 0)); // Do we have a reply ID? if (!$row->get('id')) { $this->setError(Lang::txt('COM_WISHLIST_ERROR_REPLY_NOT_FOUND')); return; } if ($row->get('created_by') != User::get('id')) { App::redirect(Request::getVar('HTTP_REFERER', NULL, 'server'), Lang::txt('COM_WISHLIST_ERROR_CANNOT_DELETE_REPLY'), 'error'); return; } // Delete the comment $row->set('state', $row::STATE_DELETED); if (!$row->save()) { throw new Exception($row->getError(), 500); } // Log activity $wishlist = Wishlist::getInstance(Request::getInt('listid', 0)); if (!$wishlist->exists()) { throw new Exception(Lang::txt('COM_WISHLIST_ERROR_WISHLIST_NOT_FOUND'), 404); } $wish = new Wish(Request::getInt('wishid', 0)); Event::trigger('system.logActivity', ['activity' => ['action' => 'deleted', 'scope' => 'wishlist.comment', 'scope_id' => $row->get('id'), 'description' => Lang::txt('COM_WISHLIST_ACTIVITY_COMMENT_DELETED', $row->get('id'), '<a href="' . Route::url($wish->link()) . '">' . $wish->get('subject') . '</a>'), 'details' => array('id' => $row->get('id'), 'url' => Route::url($wish->link()))], 'recipients' => array(['wishlist.' . $wishlist->get('category'), $wishlist->get('referenceid')], ['user', $row->get('created_by')])]); // Go back to the page App::redirect(Request::getVar('HTTP_REFERER', NULL, 'server')); }