예제 #1
0
 /**
  * Subscribe
  *
  * @return  string  HTML
  */
 private function _subscribe()
 {
     $url = Route::url($this->publication->link());
     // Incoming
     $confirm = Request::getInt('confirm', 0);
     $email = Request::getVar('email', '');
     // Login required
     if (User::isGuest() || !$this->publication->exists()) {
         App::redirect($url);
     }
     // Save subscription
     if (!$confirm) {
         return;
     }
     $watch = \Hubzero\Item\Watch::oneByScope($this->publication->get('id'), 'publication', User::get('id'), $email);
     if ($this->action == 'unsubscribe' && !$watch->get('id')) {
         App::redirect($url, Lang::txt('PLG_PUBLICATIONS_WATCH_FAIL_UNSUBSCRIBE'), 'error');
     }
     $watch->set('item_id', $this->publication->get('id'));
     $watch->set('item_type', 'publication');
     $watch->set('created_by', User::get('id'));
     $watch->set('state', $this->action == 'subscribe' ? 1 : 2);
     $watch->save();
     if ($err = $watch->getError()) {
         App::redirect($url, $err, 'error');
     }
     // Log the activity
     Event::trigger('system.logActivity', ['activity' => ['action' => $this->action . 'd', 'scope' => 'publication', 'scope_id' => $this->publication->get('id'), 'description' => Lang::txt('PLG_PUBLICATIONS_WATCH_' . strtoupper($this->action) . 'D', '<a href="' . $url . '">' . $this->publication->get('title') . '</a>'), 'details' => array('title' => $this->publication->get('title'), 'url' => $url)], 'recipients' => [User::get('id')]]);
     // Redirect back to the publication
     $msg = $this->action == 'subscribe' ? Lang::txt('PLG_PUBLICATIONS_WATCH_SUCCESS_SUBSCRIBED') : Lang::txt('PLG_PUBLICATIONS_WATCH_SUCCESS_UNSUBSCRIBED');
     App::redirect($url, $msg);
 }
예제 #2
0
 /**
  * Subscribe
  *
  * @return  void
  */
 private function _save()
 {
     // Check for request forgeries
     Request::checkToken();
     // Login required
     if (User::isGuest() || !$this->project->exists()) {
         App::redirect(Route::url($this->project->link()));
     }
     // Incoming
     $email = User::get('email');
     $categories = Request::getVar('category', array());
     $frequency = Request::getWord('frequency', 'immediate');
     // Save subscription
     $watch = \Hubzero\Item\Watch::oneByScope($this->project->get('id'), 'project', User::get('id'), $email);
     $watch->set('item_id', $this->project->get('id'));
     $watch->set('item_type', 'project');
     $watch->set('created_by', User::get('id'));
     $watch->set('state', empty($categories) ? 2 : 1);
     $cats = array('blog' => 0, 'quote' => 0, 'team' => 0, 'files' => 0, 'publications' => 0, 'todo' => 0, 'notes' => 0);
     $params = new \Hubzero\Config\Registry($watch->get('params', ''));
     $params->set('frequency', $frequency);
     foreach ($cats as $param => $value) {
         if (isset($categories[$param])) {
             $value = intval($categories[$param]);
         }
         if ($param == 'quote' && isset($categories['blog'])) {
             $value = 1;
         }
         $params->set($param, $value);
     }
     $watch->set('params', $params->toString());
     $watch->save();
     if ($err = $watch->getError()) {
         Notify::error($err);
     } else {
         Notify::message(Lang::txt('PLG_PROJECTS_WATCH_SUCCESS_SAVED'), 'success', 'projects');
     }
     App::redirect(Route::url($this->project->link()));
 }