/**
  * Add comment to specified item
  * 
  * @param string $type can be one of: ["ca_objects", "ca_entities", "ca_places", "ca_occurrences", "ca_collections", "ca_list_items", "ca_object_representations", "ca_storage_locations", "ca_movements", "ca_loans", "ca_tours", "ca_tour_stops"]
  * @param int $item_id primary key
  * @param array $comment_info_array
  * @return boolean
  * @throws SoapFault
  */
 public function addComment($type, $item_id, $comment_info_array)
 {
     if (!($t_subject_instance = $this->getTableInstance($type, $item_id))) {
         throw new SoapFault("Server", "Invalid type or item_id");
     }
     $t_comment = new ca_item_comments();
     $t_comment->setMode(ACCESS_WRITE);
     $t_comment->set($comment_info_array);
     $t_comment->set('table_num', $t_subject_instance->tableNum());
     $t_comment->set('row_id', $t_subject_instance->getPrimaryKey());
     $t_comment->set('user_id', $this->getUserID());
     $vn_id = $t_comment->insert();
     if ($t_comment->numErrors() == 0) {
         return $vn_id;
     } else {
         throw new SoapFault("Server", "There were errors while adding the comment: " . join(";", $t_comment->getErrors()));
     }
 }
Esempio n. 2
0
 /**
  * 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;
 }
Esempio n. 3
0
 function deleteComment()
 {
     if (!$this->request->isLoggedIn()) {
         $this->response->setRedirect(caNavUrl($this->request, '', 'LoginReg', 'loginForm'));
         return;
     }
     $o_datamodel = new Datamodel();
     if (!($t_set = $this->_getSet(__CA_SET_READ_ACCESS__))) {
         $this->Index();
         return;
     }
     $pn_comment_id = $this->request->getParameter("comment_id", pInteger);
     $t_comment = new ca_item_comments($pn_comment_id);
     if ($t_comment->get("comment_id")) {
         # --- check if user is owner of comment or has edit access to set comment was made on
         if ($this->request->getUserID() != $t_comment->get("user_id") && !$t_set->haveAccessToSet($this->request->getUserID(), __CA_SET_EDIT_ACCESS__)) {
             $this->Index();
             return;
         }
         $t_comment->setMode(ACCESS_WRITE);
         $t_comment->delete(true);
         if ($t_comment->numErrors()) {
             $this->notification->addNotification(_t("There were errors:" . join("; ", $t_comment->getErrors())), __NOTIFICATION_TYPE_ERROR__);
         } else {
             $this->notification->addNotification(_t("Removed comment"), __NOTIFICATION_TYPE_INFO__);
         }
     } else {
         $this->notification->addNotification(_t("Invalid comment_id"), __NOTIFICATION_TYPE_ERROR__);
     }
     $ps_reload = $this->request->getParameter("reload", pString);
     switch ($ps_reload) {
         case "detail":
             $this->response->setRedirect(caNavUrl($this->request, '', 'Sets', 'setDetail'));
             return;
             break;
             # -----------------------------
         # -----------------------------
         default:
             $this->response->setRedirect(caNavUrl($this->request, '', 'Sets', 'Index'));
             return;
             break;
             # -----------------------------
     }
 }
Esempio n. 4
0
 /**
  * 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;
 }
 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;
             # -----------------------
     }
 }