/** * @param $auction DbAuction * @param $userIds array * @param int $numWatches */ function addWatches($auction, &$userIds, $numWatches = 1) { global $faker; for ($i = 0; $i < $numWatches; $i++) { $userId = $faker->randomElement($userIds); $auctionWatch = new DbAuctionWatch(array("userId" => $userId, "auctionId" => $auction->getId())); $auctionWatch->create(); $key = array_search($userId, $userIds); unset($userIds[$key]); } }
<?php require_once "../classes/class.helper_operator.php"; require_once "../classes/class.session_operator.php"; require_once "../classes/class.validation_operator.php"; require_once "../classes/class.query_operator.php"; require_once "../classes/class.db_auction_watch.php"; /* @var User $user*/ $user = SessionOperator::getUser(); $auctionId = $_GET["liveAuction"]; if (!is_numeric($auctionId)) { HelperOperator::redirectTo("../views/open_live_auction_view.php?" . $_SERVER['QUERY_STRING']); } // Check user hasn't already watched $alreadyWatching = DbAuctionWatch::withConditions("WHERE userId = " . $user->getUserId() . " AND auctionId =" . $auctionId)->exists() ? true : false; if ($alreadyWatching) { HelperOperator::redirectTo("../views/open_live_auction_view.php?" . $_SERVER['QUERY_STRING']); } // Create an auction_watch $watch = new DbAuctionWatch(array("userId" => $user->getUserId(), "auctionId" => $auctionId)); // Add to watch list $watch->create(); // Set feedback session SessionOperator::setNotification(SessionOperator::CREATED_WATCH); HelperOperator::redirectTo("../views/open_live_auction_view.php?" . $_SERVER['QUERY_STRING']);