示例#1
0
 /**
  * Deletes the tag relation specified by $pn_relation_id (a ca_items_x_tags.relation_id value) from the currently loaded row. Will only delete 
  * tags attached to the currently loaded row. If you attempt to delete a ca_items_x_tags.relation_id not attached to the current row 
  * removeTag() will return false and post an error. If you attempt to call removeTag() with no row loaded null will be returned.
  * If $pn_user_id is specified then only tags created by the specified user will be deleted; if the tag being
  * deleted is not created by the user then false is returned and an error posted.
  *
  * @param $pn_relation_id [integer] a valid ca_items_x_tags.relation_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 tag relations added by the specified user will be deleted (optional - default is null)
  */
 public function removeTag($pn_relation_id, $pn_user_id = null)
 {
     if (!($vn_row_id = $this->getPrimaryKey())) {
         return null;
     }
     $t_ixt = new ca_items_x_tags($pn_relation_id);
     if (!$t_ixt->getPrimaryKey()) {
         $this->postError(2800, _t('Tag relation id is invalid'), 'BaseModel->removeTag()', 'ca_item_tags');
         return false;
     }
     if ($t_ixt->get('table_num') != $this->tableNum() || $t_ixt->get('row_id') != $vn_row_id) {
         $this->postError(2810, _t('Tag is not part of the current row'), 'BaseModel->removeTag()', 'ca_item_tags');
         return false;
     }
     if ($pn_user_id) {
         if ($t_ixt->get('user_id') != $pn_user_id) {
             $this->postError(2820, _t('Tag was not created by specified user'), 'BaseModel->removeTag()', 'ca_item_tags');
             return false;
         }
     }
     $t_ixt->setMode(ACCESS_WRITE);
     $t_ixt->delete();
     if ($t_ixt->numErrors()) {
         $this->errors = $t_ixt->errors;
         return false;
     }
     return true;
 }
 public function Delete()
 {
     $va_errors = array();
     $pa_tag_relation_ids = $this->request->getParameter('tag_relation_id', pArray);
     $ps_mode = $this->request->getParameter('mode', pString);
     if (is_array($pa_tag_relation_ids) && sizeof($pa_tag_relation_ids) > 0) {
         foreach ($pa_tag_relation_ids as $vn_relation_id) {
             $t_item_x_tag = new ca_items_x_tags($vn_relation_id);
             if (!$t_item_x_tag->getPrimaryKey()) {
                 $va_errors[] = _t("The tag does not exist");
                 break;
             }
             $t_item_x_tag->setMode(ACCESS_WRITE);
             if (!$t_item_x_tag->delete()) {
                 $va_errors[] = _t("Could not delete tag");
                 break;
             }
         }
         if (sizeof($va_errors) > 0) {
             $this->notification->addNotification(implode("; ", $va_errors), __NOTIFICATION_TYPE_ERROR__);
         } else {
             $this->notification->addNotification(_t("Your tags have been deleted"), __NOTIFICATION_TYPE_INFO__);
         }
     } else {
         $this->notification->addNotification(_t("Please use the checkboxes to select tags for deletion"), __NOTIFICATION_TYPE_WARNING__);
     }
     switch ($ps_mode) {
         case "dashboard":
             $this->response->setRedirect(caNavUrl($this->request, "", "Dashboard", "Index"));
             break;
             # -----------------------
         # -----------------------
         default:
             $this->ListUnmoderated();
             break;
             # -----------------------
     }
 }