public function run() { parent::run(); $this->getInputJson(); if (!($token = validateToken($this->input['token']))) { throw new \Exception("Invalid token."); } //TODO: delete global somehow global $user; $user = new \User($token['uid']); if (isset($this->input['remove'])) { if (!$user->removeFavorites($this->input['remove'])) { throw new \Exception("Could not remove favorites."); } } if (isset($this->input['add'])) { if (!$user->addFavorites($this->input['add'])) { throw new \Exception("Could not add favorites."); } } $favorites = array(); $user->getFavorites(); foreach ($user->favorites as $favorite) { $favorites[] = $favorite['tid']; } $this->return['favorites'] = $favorites; }