コード例 #1
0
 public function Delete()
 {
     $ps_mode = $this->request->getParameter('mode', pString);
     $va_errors = array();
     $pa_watch_ids = $this->request->getParameter('watch_id', pArray);
     $va_errors = array();
     if (is_array($pa_watch_ids) && sizeof($pa_watch_ids) > 0) {
         $t_watch_list = new ca_watch_list();
         foreach ($pa_watch_ids as $vn_watch_id) {
             if ($t_watch_list->load(array('watch_id' => $vn_watch_id))) {
                 $t_watch_list->setMode(ACCESS_WRITE);
                 $t_watch_list->delete();
                 if ($t_watch_list->numErrors()) {
                     $va_errors = $t_item->errors;
                 }
             }
         }
         if (sizeof($va_errors) > 0) {
             $this->notification->addNotification(implode("; ", $va_errors), __NOTIFICATION_TYPE_ERROR__);
         } else {
             $this->notification->addNotification(_t("Your watched items have been deleted"), __NOTIFICATION_TYPE_INFO__);
         }
     } else {
         $this->notification->addNotification(_t("Please use the checkboxes to select items to remove from your watch list"), __NOTIFICATION_TYPE_WARNING__);
     }
     if ($ps_mode == "dashboard") {
         $this->response->setRedirect(caNavUrl($this->request, "", "Dashboard", "Index"));
     } else {
         $this->ListItems();
     }
 }
コード例 #2
0
 /**
  * Add item to user's watch list. Intended to be called via ajax, and JSON response is returned in the current view inherited from ActionController
  */
 public function toggleWatch()
 {
     list($vn_subject_id, $t_subject) = $this->_initView();
     require_once __CA_MODELS_DIR__ . '/ca_watch_list.php';
     if (!$this->_checkAccess($t_subject)) {
         return false;
     }
     $va_errors = array();
     $t_watch_list = new ca_watch_list();
     $vn_user_id = $this->request->user->get("user_id");
     if ($t_watch_list->isItemWatched($vn_subject_id, $t_subject->tableNum(), $vn_user_id)) {
         if ($t_watch_list->load(array('row_id' => $vn_subject_id, 'user_id' => $vn_user_id, 'table_num' => $t_subject->tableNum()))) {
             $t_watch_list->setMode(ACCESS_WRITE);
             $t_watch_list->delete();
             if ($t_watch_list->numErrors()) {
                 $va_errors = $t_item->errors;
                 $this->view->setVar('state', 'watched');
             } else {
                 $this->view->setVar('state', 'unwatched');
             }
         }
     } else {
         $t_watch_list->setMode(ACCESS_WRITE);
         $t_watch_list->set('user_id', $vn_user_id);
         $t_watch_list->set('table_num', $t_subject->tableNum());
         $t_watch_list->set('row_id', $vn_subject_id);
         $t_watch_list->insert();
         if ($t_watch_list->numErrors()) {
             $this->view->setVar('state', 'unwatched');
             $va_errors = $t_item->errors;
         } else {
             $this->view->setVar('state', 'watched');
         }
     }
     $this->view->setVar('errors', $va_errors);
     $this->render('../generic/ajax_toggle_item_watch_json.php');
 }