/** * Permanently deletes the comment specified by $pn_comment_id. * If $pn_user_id is specified then only comments created by the specified user will be deleted; if the comment being * deleted is not created by the user then false is returned and an error posted. * * @param $pn_comment_id [integer] a valid comment_id to be removed; must be related to the currently loaded row (mandatory) * @param $pn_user_id [integer] a valid ca_users.user_id value; if specified then only comments by the specified user will be deleted (optional - default is null) */ public function removeComment($pn_comment_id, $pn_user_id = null) { $t_comment = new ca_item_comments($pn_comment_id); if (!$t_comment->getPrimaryKey()) { $this->postError(2800, _t('Comment id is invalid'), 'BaseModel->removeComment()'); return false; } if ($pn_user_id) { if ($t_comment->get('user_id') != $pn_user_id) { $this->postError(2820, _t('Comment was not created by specified user'), 'BaseModel->removeComment()'); return false; } } $t_comment->setMode(ACCESS_WRITE); $t_comment->delete(); if ($t_comment->numErrors()) { $this->errors = $t_comment->errors; return false; } return true; }
/** * Permanently deletes the comment specified by $pn_comment_id. Will only delete comments attached to the * currently loaded row. If you attempt to delete a comment_id not attached to the current row removeComment() * will return false and post an error. If you attempt to call removeComment() with no row loaded null will be returned. * If $pn_user_id is specified then only comments created by the specified user will be deleted; if the comment being * deleted is not created by the user then false is returned and an error posted. * * @param $pn_comment_id [integer] a valid comment_id to be removed; must be related to the currently loaded row (mandatory) * @param $pn_user_id [integer] a valid ca_users.user_id value; if specified then only comments by the specified user will be deleted (optional - default is null) */ public function removeComment($pn_comment_id, $pn_user_id = null) { if (!($vn_row_id = $this->getPrimaryKey())) { return null; } $t_comment = new ca_item_comments($pn_comment_id); if (!$t_comment->getPrimaryKey()) { $this->postError(2800, _t('Comment id is invalid'), 'BaseModel->removeComment()', 'ca_item_comments'); return false; } if ($t_comment->get('table_num') != $this->tableNum() || $t_comment->get('row_id') != $vn_row_id) { $this->postError(2810, _t('Comment is not part of the current row'), 'BaseModel->removeComment()', 'ca_item_comments'); return false; } if ($pn_user_id) { if ($t_comment->get('user_id') != $pn_user_id) { $this->postError(2820, _t('Comment was not created by specified user'), 'BaseModel->removeComment()', 'ca_item_comments'); return false; } } $t_comment->setMode(ACCESS_WRITE); $t_comment->delete(); if ($t_comment->numErrors()) { $this->errors = $t_comment->errors; return false; } return true; }
public function Delete() { $va_errors = array(); $pa_comment_ids = $this->request->getParameter('comment_id', pArray); $ps_mode = $this->request->getParameter('mode', pString); if (is_array($pa_comment_ids) && sizeof($pa_comment_ids) > 0) { foreach ($pa_comment_ids as $vn_comment_id) { $t_comment = new ca_item_comments($vn_comment_id); if (!$t_comment->getPrimaryKey()) { $va_errors[] = _t("The comment does not exist"); break; } $t_comment->setMode(ACCESS_WRITE); if (!$t_comment->delete()) { $va_errors[] = _t("Could not delete comment"); break; } } if (sizeof($va_errors) > 0) { $this->notification->addNotification(implode("; ", $va_errors), __NOTIFICATION_TYPE_ERROR__); } else { $this->notification->addNotification(_t("Your comments have been deleted"), __NOTIFICATION_TYPE_INFO__); } } else { $this->notification->addNotification(_t("Please use the checkboxes to select comments for deletion"), __NOTIFICATION_TYPE_WARNING__); } switch ($ps_mode) { case "list": $this->ListUnmoderated(); break; # ----------------------- # ----------------------- case "search": $this->Index(); break; # ----------------------- # ----------------------- case "dashboard": $this->response->setRedirect(caNavUrl($this->request, "", "Dashboard", "Index")); break; # ----------------------- } }