public function clearNotifications(Request $request, Session $session)
 {
     if (!$session->userIsLoggedIn()) {
         return $this->redirectTo('/login');
     }
     Notification::clearForUser($session->activeUser()->id);
     return $this->redirectTo('/dashboard?message=' . urlencode('Notifications cleared'));
 }
示例#2
0
 public function createNewAuction(Request $request, Session $session)
 {
     if (!$session->userIsLoggedIn()) {
         return $this->redirectTo('/login');
     }
     if (!$session->activeUser()->isSeller()) {
         return $this->redirectTo('/dashboard?error=' . urlencode('You must register as a seller to create an auction'));
     }
     $auction_input = $request->post;
     $auction_input['userrole_id'] = $session->activeUser()->sellerID();
     $auction_creator = new AuctionCreator($request);
     $auction_errors = $auction_creator->validateInput($auction_input);
     $errors = [];
     if (count($auction_errors) > 0) {
         $errors[] = 'There was one or more problems with your submission, please go back';
         foreach ($auction_errors as $error) {
             $errors[] = $error;
         }
     }
     if (isset($auction_input['items']) === false) {
         $auction_errors[] = 'Items Missing';
     }
     if (isset($request->files['item_image']['name']) === false || count($request->files['item_image']['name']) !== count($auction_input['items'])) {
         $auction_errors[] = 'Items Images Missing';
     }
     $items = $this->processInput($auction_input['items'], $request->files['item_image']);
     $item_creator = new ItemCreator($request);
     foreach ($items as $key => $item) {
         $item_errors = $item_creator->validateInput($item);
         if (count($item_errors) > 0) {
             foreach ($item_errors as $error) {
                 $errors[] = $error;
             }
         }
     }
     if (count($errors)) {
         return View::renderView('general_error', ['errors' => $errors]);
     }
     $auction_id = $auction_creator->saveInput($auction_input);
     foreach ($items as $key => $item) {
         $item['auction_id'] = $auction_id;
         $item_id = $item_creator->saveInput($item);
     }
     return $this->redirectTo('/dashboard?message=' . urlencode('Auction Created'));
 }
示例#3
0
 public function handleRequest(Request $request)
 {
     $session = new Session($request);
     View::$current_user = $session->activeUser();
     NotificationSender::scanForItemWonNotifications();
     NotificationSender::scanForItemEndedNotifications();
     if ($request->matches('GET', '/test')) {
         $controller = new TestController();
         return $controller->runTest($request, $session);
     } else {
         if ($request->matches('GET', '/dashboard')) {
             $controller = new DashboardController();
             return $controller->getDashboard($request, $session);
         } else {
             if ($request->matches('GET', '/login')) {
                 $controller = new LoginController();
                 return $controller->getLoginPage($request, $session);
             } else {
                 if ($request->matches('POST', '/login')) {
                     $controller = new LoginController();
                     return $controller->processLoginAttempt($request, $session);
                 } else {
                     if ($request->matches('POST', '/signup')) {
                         $controller = new SignupController();
                         return $controller->processSignup($request, $session);
                     } else {
                         if ($request->matches('GET', '/logout')) {
                             $controller = new LoginController();
                             return $controller->logout($request, $session);
                         } else {
                             if ($request->matches('GET', '/auction/create')) {
                                 $controller = new AuctionController();
                                 return $controller->getCreateAuctionPage($request, $session);
                             } else {
                                 if ($request->matches('GET', '/auction/??/edit')) {
                                     return "You are at /auction/id/edit";
                                     //just a dumb placeholder for sanity check
                                 } else {
                                     if ($request->matches('POST', '/auction')) {
                                         $controller = new AuctionController();
                                         return $controller->createNewAuction($request, $session);
                                     } else {
                                         if ($request->matches('GET', '/auction/??')) {
                                             $controller = new AuctionController();
                                             return $controller->getAuction($request, $session);
                                         } else {
                                             if ($request->matches('POST', '/auction/??/bid')) {
                                                 $controller = new AuctionController();
                                                 return $controller->getBidConfirmationPage($request, $session);
                                             } else {
                                                 if ($request->matches('POST', '/auction/??/watch')) {
                                                     $controller = new AuctionController();
                                                     return $controller->getWatchConfirmationPage($request, $session);
                                                 } else {
                                                     if ($request->matches('GET', '/auction/??/feedback/create')) {
                                                         $controller = new FeedbackController();
                                                         return $controller->getFeedbackForm($request, $session, (int) $request->url_array[1]);
                                                     } else {
                                                         if ($request->matches('POST', '/auction/??/feedback/buyer')) {
                                                             $controller = new FeedbackController();
                                                             return $controller->postBuyerFeedback($request, $session, (int) $request->url_array[1]);
                                                         } else {
                                                             if ($request->matches('POST', '/auction/??/feedback/seller')) {
                                                                 $controller = new FeedbackController();
                                                                 return $controller->postSellerFeedback($request, $session, (int) $request->url_array[1]);
                                                             } else {
                                                                 if ($request->matches('GET', '/user/??/feedback')) {
                                                                     $controller = new FeedbackController();
                                                                     return $controller->getFeedbackList($request, $session, (int) $request->url_array[1]);
                                                                 } else {
                                                                     if ($request->matches('GET', '/search')) {
                                                                         $controller = new SearchController();
                                                                         return $controller->getSearch($request, $session);
                                                                     } else {
                                                                         if ($request->matches('GET', '/')) {
                                                                             $controller = new HomeController();
                                                                             return $controller->getHomepage($request, $session);
                                                                         } else {
                                                                             if ($request->matches('GET', '/notifications/clear')) {
                                                                                 $controller = new NotificationController();
                                                                                 return $controller->clearNotifications($request, $session);
                                                                             }
                                                                         }
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return View::renderView('general_error', ['user' => $session->activeUser(), 'message' => 'URL Not Found']);
 }
示例#4
0
 public function getDashboard(Request $request, Session $session)
 {
     if (!$session->userIsLoggedIn()) {
         return $this->redirectTo('/login');
     }
     if ($session->activeUser()->isSeller()) {
         $liveSellerAuctions = Auction::getLiveAuctionsForUser($session->activeUser()->sellerID());
         $completedSellerAuctions = Auction::getCompletedAuctionsForUser($session->activeUser()->sellerID());
         $sellerFeedback = $session->activeUser()->getSellerFeedback();
         $sellerRating = $session->activeUser()->getSellerMeanRating();
     }
     if ($session->activeUser()->isBuyer()) {
         $liveBidBuyerAuctions = Auction::getLiveBidAuctionsForUser($session->activeUser()->buyerID());
         $completedBidBuyerAuctions = Auction::getCompletedBidAuctionsForUser($session->activeUser()->buyerID());
         $liveWatchedBuyerAuctions = Auction::getLiveWatchedAuctionsForUser($session->activeUser()->buyerID());
         $buyerFeedback = $session->activeUser()->getBuyerFeedback();
         $buyerRating = $session->activeUser()->getBuyerMeanRating();
         $recommendations = $session->activeUser()->getRecommendations();
     }
     $view = new View('dashboard', ['liveSellerAuctions' => isset($liveSellerAuctions) ? $liveSellerAuctions : NULL, 'completedSellerAuctions' => isset($completedSellerAuctions) ? $completedSellerAuctions : NULL, 'sellerFeedback' => isset($sellerFeedback) ? $sellerFeedback : NULL, 'sellerRating' => isset($sellerRating) ? $sellerRating : NULL, 'liveBidBuyerAuctions' => isset($liveBidBuyerAuctions) ? $liveBidBuyerAuctions : NULL, 'completedBidBuyerAuctions' => isset($completedBidBuyerAuctions) ? $completedBidBuyerAuctions : NULL, 'liveWatchedBuyerAuctions' => isset($liveWatchedBuyerAuctions) ? $liveWatchedBuyerAuctions : NULL, 'buyerFeedback' => isset($buyerFeedback) ? $buyerFeedback : NULL, 'buyerRating' => isset($buyerRating) ? $buyerRating : NULL, 'recommendations' => isset($recommendations) ? $recommendations : NULL, 'message' => isset($request->get['message']) ? $request->get['message'] : NULL, 'error' => isset($request->get['error']) ? $request->get['error'] : NULL]);
     return $view->render();
 }