use GW2Spidy\DB\WatchlistQuery; use GW2Spidy\DB\ItemQuery; use Symfony\Component\HttpFoundation\Request; /** * ---------------------- * route /watchlistadd POST * ---------------------- */ $app->get("/watchlist/add/{dataId}", function (Request $request, $dataId) use($app) { if (!($user = $app['user'])) { return $app->redirect($app['url_generator']->generate('login')); } if ($item = ItemQuery::create()->findPk($dataId)) { // check unique if (!WatchlistQuery::create()->filterByUser($user)->filterByItem($item)->count()) { $w = new Watchlist(); $w->setUser($user); $w->setItemId($dataId); $w->save(); } } $uri = $request->headers->get('referer'); if ($uri && preg_match('/\\/login/', $uri)) { $uri = null; } return $app->redirect($uri ?: $app['url_generator']->generate('watchlist')); })->assert('dataId', '\\d+')->bind('watchlistaddpost'); /** * ---------------------- * route /watchlistremove POST * ----------------------
/** * @param Item $item The item object to add. */ protected function doAddItem($item) { $watchlist = new Watchlist(); $watchlist->setItem($item); $this->addWatchlist($watchlist); }
/** * Exclude object from result * * @param Watchlist $watchlist Object to remove from the list of results * * @return WatchlistQuery The current query, for fluid interface */ public function prune($watchlist = null) { if ($watchlist) { $this->addUsingAlias(WatchlistPeer::ID, $watchlist->getId(), Criteria::NOT_EQUAL); } return $this; }
/** * Filter the query by a related Watchlist object * * @param Watchlist|PropelObjectCollection $watchlist the related object to use as filter * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return UserQuery The current query, for fluid interface * @throws PropelException - if the provided filter is invalid. */ public function filterByWatchlist($watchlist, $comparison = null) { if ($watchlist instanceof Watchlist) { return $this->addUsingAlias(UserPeer::ID, $watchlist->getUserId(), $comparison); } elseif ($watchlist instanceof PropelObjectCollection) { return $this->useWatchlistQuery()->filterByPrimaryKeys($watchlist->getPrimaryKeys())->endUse(); } else { throw new PropelException('filterByWatchlist() only accepts arguments of type Watchlist or PropelCollection'); } }
/** * @param User $user The user object to add. */ protected function doAddUser($user) { $watchlist = new Watchlist(); $watchlist->setUser($user); $this->addWatchlist($watchlist); }
/** * Adds an object to the instance pool. * * Propel keeps cached copies of objects in an instance pool when they are retrieved * from the database. In some cases -- especially when you override doSelect*() * methods in your stub classes -- you may need to explicitly add objects * to the cache in order to ensure that the same objects are always returned by doSelect*() * and retrieveByPK*() calls. * * @param Watchlist $obj A Watchlist object. * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). */ public static function addInstanceToPool($obj, $key = null) { if (Propel::isInstancePoolingEnabled()) { if ($key === null) { $key = (string) $obj->getId(); } // if key === null WatchlistPeer::$instances[$key] = $obj; } }