Beispiel #1
0
 /**
  * Set and get a specific wish
  *
  * @param   integer  $id  Wish ID
  * @return  object
  */
 public function wish($id = null)
 {
     if (!$this->_cache['wish'] instanceof Wish || $id !== null && (int) $this->_cache['wish']->get('id') != $id) {
         $this->_cache['wish'] = null;
         if ($this->_cache['wishes.list'] instanceof ItemList) {
             foreach ($this->_cache['wishes.list'] as $key => $wish) {
                 if ((int) $wish->get('id') == $id || (string) $wish->get('alias') == $id) {
                     $this->_cache['wish'] = $wish;
                     break;
                 }
             }
         }
         if (!$this->_cache['wish']) {
             $this->_cache['wish'] = Wish::getInstance($id, $this->get('scope'), $this->get('scope_id'));
         }
         if (!$this->_cache['wish']->exists()) {
             $this->_cache['wish']->set('scope', $this->get('scope'));
             $this->_cache['wish']->set('scope_id', $this->get('scope_id'));
         }
     }
     return $this->_cache['wish'];
 }
Beispiel #2
0
 /**
  * Save a vote for a wish
  *
  * @return     void
  */
 public function savevoteTask()
 {
     Request::checkToken();
     $refid = Request::getInt('rid', 0);
     $category = Request::getVar('category', '');
     $wishlist = Wishlist::getInstance($refid, $category);
     if (!$wishlist->exists()) {
         throw new Exception(Lang::txt('COM_WISHLIST_ERROR_WISHLIST_NOT_FOUND'), 404);
     }
     $wishid = Request::getInt('wishid', 0);
     $wish = Wish::getInstance($wishid);
     if (!$wish->exists()) {
         throw new Exception(Lang::txt('COM_WISHLIST_ERROR_WISH_NOT_FOUND_ON_LIST'), 404);
     }
     //$objWishlist = new Tables\Wishlist($this->database);
     //$objWish = new Tables\Wish($this->database);
     //$objR = new Tables\Wish\Rank($this->database);
     // figure list id
     /*if ($category && $refid)
     		{
     			$listid = $objWishlist->get_wishlistID($refid, $category);
     		}
     
     		// cannot rank a wish if list/wish is not found
     		if (!$listid or !$wishid)
     		{
     			throw new Exception(Lang::txt('COM_WISHLIST_ERROR_WISHLIST_NOT_FOUND'), 404);
     		}
     
     		$wishlist = $objWishlist->get_wishlist($listid);
     		$item = $objWish->get_wish($wishid, User::get('id'));
     
     		// cannot proceed if wish id is not found
     		if (!$wishlist or !$item)
     		{
     			throw new Exception(Lang::txt('COM_WISHLIST_ERROR_WISHLIST_NOT_FOUND'), 404);
     		}
     
     		// is this wish on correct list?
     		if ($listid != $wishlist->id)
     		{
     			throw new Exception(Lang::txt('COM_WISHLIST_ERROR_WISH_NOT_FOUND_ON_LIST'), 404);
     		}*/
     // get vote
     $effort = Request::getVar('effort', '', 'post');
     $importance = Request::getVar('importance', '', 'post');
     // Login required
     if (User::isGuest()) {
         // Set page title
         if (!$wishlist->isPublic() && !$wishlist->access('manage')) {
             $this->_list_title = '';
         }
         $this->_buildTitle();
         // Set the pathway
         $this->_buildPathway($wishlist);
         $this->_msg = Lang::txt('COM_WISHLIST_WARNING_LOGIN_TO_RANK');
         $this->loginTask();
         return;
     }
     // Need to be list admin
     if (!$wishlist->access('manage') || $wishlist->get('admin') == 1) {
         throw new Exception(Lang::txt('COM_WISHLIST_ALERTNOTAUTH_ACTION'), 403);
     }
     // did user make selections?
     if (!$effort or !$importance) {
         App::redirect(Route::url($wish->link()), Lang::txt('Please be sure to provide both an importance and an effort'), 'error');
         return;
     }
     // is the wish ranked already?
     if (!$wish->rank($effort, $importance)) {
         App::redirect(Route::url($wish->link()), $wish->getError(), 'error');
         return;
     }
     // update priority on all wishes
     if (!$wishlist->rank()) {
         throw new Exception($wishlist->getError(), 500);
     }
     App::redirect(Route::url($wish->link()));
 }