function watch($id = null) { if (is_null($id)) { $this->Session->setFlash('Repository not found'); $this->redirect('/'); } if (!$this->isLoggedIn()) { $this->redirect(array('controller' => 'login', 'action' => 'index')); } $user = $this->getConnectedUser(); $repo = $this->RepositoriesUser->find('first', array('conditions' => array('user_id' => $user['User']['id'], 'repository_id' => $id), 'recursive' => -1)); if (empty($repo)) { $this->Session->setFlash('Repository not found'); $this->redirect('/'); } $watching = $repo['RepositoriesUser']['watching']; $this->RepositoriesUser->read(null, $repo['RepositoriesUser']['id']); $this->RepositoriesUser->set('watching', !$watching); $this->RepositoriesUser->save(); if ($watching) { $msg = "Repository removed from watchlist"; } else { $msg = "Repository added to watchlist"; } $this->Session->setFlash($msg); $this->redirect(array('action' => 'set_repository_by_id', $id)); }
/** * discount user points * anon doesn't need this * neither if action == 'earn' */ function _pay() { if ($this->Session->check('Points.proceed') && !$this->Session->read('Points.proceed')) { $this->_cancel_everything($this->Session->read('Points.status')); } $user = $this->getConnectedUser(); if ($user == $this->anonymous) { return; } if ($this->_get_action() == $this->earn) { return; } $repo = $this->getCurrentRepository(); $action = $this->_get_action(); if ($action == $this->upload) { $cost = $repo['Repository']['upload_cost']; } else { if ($action == $this->download) { if (!$this->Session->check('Search.count')) { $this->_cancel_everything('Document search results not found'); } $count = $this->Session->read('Search.count'); $cost = $repo['Repository']['download_cost'] * $count; } else { $this->_cancel_everything('Action not recognized'); } } if ($this->RepositoriesUser->discountPoints($user['User']['id'], $repo['Repository']['id'], $cost)) { $this->Session->write("Points.status", "Spent {$cost} points"); } else { $this->Session->write("Points.status", "An error occurred subtracting points. Please blame to the administrator or the developer"); $this->Session->write("Points.proceed", false); } }