/**
  * 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()));
     }
 }
예제 #2
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;
             # -----------------------------
     }
 }