Exemplo n.º 1
0
 /**
  * test for sorting categories based on the category name in ascending order
  * NOTE: By adding a category in the database, this test will no longer work
  *      unless $expectedResult is changed based on AdminSearch::sortCategory's new output
  */
 public function testSortCategory()
 {
     // Arrange
     $adminSearch = new AdminSearch();
     $connection = open_database_connection();
     $expectedResult = '<form id="category_result4" action= "/adminEditCategory" method="get">
 <p><span class="search" onclick="document.getElementById(\'category_result4\').submit();">Desserts</span> - From a range of fresh donuts to a mouth watering pumpkin pie or strawberry cheesecake, there is something for everyone!</p><input type="hidden" name="categoryName" value="Desserts" /><input type="hidden" name="categoryID" value="4" /><input type="hidden" name="categoryImageURL" value="donuts.png" /><input type="hidden" name="categorySummary" value="From a range of fresh donuts to a mouth watering pumpkin pie or strawberry cheesecake, there is something for everyone!" /><input type="hidden" name="categoryImageURL1" value="" /><input type="hidden" name="categoryImageURL2" value="" /></form><br><form id="category_result3" action= "/adminEditCategory" method="get">
 <p><span class="search" onclick="document.getElementById(\'category_result3\').submit();">Drinks</span> - Quench your thirst with our selection of freshly made drinks or warm yourself up with a selection of hot drinks that we offer!</p><input type="hidden" name="categoryName" value="Drinks" /><input type="hidden" name="categoryID" value="3" /><input type="hidden" name="categoryImageURL" value="orange_juice.png" /><input type="hidden" name="categorySummary" value="Quench your thirst with our selection of freshly made drinks or warm yourself up with a selection of hot drinks that we offer!" /><input type="hidden" name="categoryImageURL1" value="" /><input type="hidden" name="categoryImageURL2" value="" /></form><br><form id="category_result5" action= "/adminEditCategory" method="get">
 <p><span class="search" onclick="document.getElementById(\'category_result5\').submit();">Extra Burger Toppings</span> - Try and add a little extra to your burger by adding one of these extra toppings meant to add a special touch to your meal. You will be glad and always come back to it or try a different one next time!</p><input type="hidden" name="categoryName" value="Extra Burger Toppings" /><input type="hidden" name="categoryID" value="5" /><input type="hidden" name="categoryImageURL" value="extra_toppings.png" /><input type="hidden" name="categorySummary" value="Try and add a little extra to your burger by adding one of these extra toppings meant to add a special touch to your meal. You will be glad and always come back to it or try a different one next time!" /><input type="hidden" name="categoryImageURL1" value="" /><input type="hidden" name="categoryImageURL2" value="" /></form><br><form id="category_result2" action= "/adminEditCategory" method="get">
 <p><span class="search" onclick="document.getElementById(\'category_result2\').submit();">Salads</span> - A healthy menu item that can be enjoyed in any season and has the benefit of low calories and a good source of energy. Our range of salads are carefully prepared from fresh leaves on the day it is served.</p><input type="hidden" name="categoryName" value="Salads" /><input type="hidden" name="categoryID" value="2" /><input type="hidden" name="categoryImageURL" value="salad.png" /><input type="hidden" name="categorySummary" value="A healthy menu item that can be enjoyed in any season and has the benefit of low calories and a good source of energy. Our range of salads are carefully prepared from fresh leaves on the day it is served." /><input type="hidden" name="categoryImageURL1" value="" /><input type="hidden" name="categoryImageURL2" value="" /></form><br><form id="category_result1" action= "/adminEditCategory" method="get">
 <p><span class="search" onclick="document.getElementById(\'category_result1\').submit();">Vegetarian Burgers</span> - Freshly made selection of vegetarian burgers and sandwiches using the finest ingredients available today. Try one and you will want more!</p><input type="hidden" name="categoryName" value="Vegetarian Burgers" /><input type="hidden" name="categoryID" value="1" /><input type="hidden" name="categoryImageURL" value="vegetarian_burger.png" /><input type="hidden" name="categorySummary" value="Freshly made selection of vegetarian burgers and sandwiches using the finest ingredients available today. Try one and you will want more!" /><input type="hidden" name="categoryImageURL1" value="" /><input type="hidden" name="categoryImageURL2" value="" /></form><br>';
     // Assert
     $result = $adminSearch->sortCategory($connection, "CategoryName", "ASC");
     close_database_connection($connection);
     // Act
     $this->assertEquals($result, $expectedResult);
 }
Exemplo n.º 2
0
 /**
  * Search action for the admin pages. This function handles all of the possible
  * types of searches that the user might search for.
  *
  * Action for route: /adminSearch
  *
  * @param Request $request
  * @param Application $app
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  */
 public function searchAction(Request $request, Application $app)
 {
     // test if 'username' stored in session ...
     $username = getAuthenticatedUserName($app);
     // check we are authenticated --------
     $isAuthenticated = null != $username;
     if (!$isAuthenticated) {
         // not authenticated, so redirect to LOGIN page
         return $app->redirect('/login');
     }
     $connection = open_database_connection();
     $searchType = $_GET['search_type'];
     if ($searchType == "new") {
         $searchType = "product";
     }
     $searchObject = new AdminSearch();
     $searchResults = "";
     if ($searchType == "category") {
         if (!empty($_GET['keywords'])) {
             if (isset($_GET['name'])) {
                 if ($_GET['name'] == "ascending") {
                     $searchResults = $searchObject->sortCategoryBySearch($connection, "ASC", "CategoryName", $_GET['keywords']);
                 } else {
                     if ($_GET['name'] == "descending") {
                         $searchResults = $searchObject->sortCategoryBySearch($connection, "DESC", "CategoryName", $_GET['keywords']);
                     }
                 }
             } else {
                 $searchResults = $searchObject->makeCategorySearch($connection, $_GET['keywords']);
             }
         } else {
             if (isset($_GET['name'])) {
                 if ($_GET['name'] == "ascending") {
                     $searchResults = $searchObject->sortCategory($connection, "CategoryName", "ASC");
                 } else {
                     $searchResults = $searchObject->sortCategory($connection, "CategoryName", "DESC");
                 }
             } else {
                 if (isset($_GET['summary'])) {
                     if ($_GET['summary'] == "ascending") {
                         $searchResults = $searchObject->sortCategory($connection, "CategorySummary", "ASC");
                     } else {
                         $searchResults = $searchObject->sortCategory($connection, "CategorySummary", "DESC");
                     }
                 }
             }
         }
     } else {
         if ($searchType == "product-category") {
             if (isset($_GET['search'])) {
                 if (isset($_GET['name'])) {
                     if ($_GET['name'] == "ascending") {
                         $searchResults = $searchObject->sortCategoryBySearch($connection, "ASC", "CategoryName", $_GET['keywords']);
                     } else {
                         if ($_GET['name'] == "descending") {
                             $searchResults = $searchObject->sortCategoryBySearch($connection, "DESC", "CategoryName", $_GET['keywords']);
                         }
                     }
                 } else {
                     $searchResults = $searchObject->makeCategorySearch($connection, $_GET['keywords']);
                 }
             } else {
                 if (isset($_GET['name'])) {
                     if ($_GET['name'] == "ascending") {
                         $searchResults = $searchObject->sortCategory($connection, "CategoryName", "ASC");
                     } else {
                         $searchResults = $searchObject->sortCategory($connection, "CategoryName", "DESC");
                     }
                 } else {
                     if ($_GET['summary'] == "ascending") {
                         $searchResults = $searchObject->sortCategory($connection, "CategorySummary", "ASC");
                     } else {
                         $searchResults = $searchObject->sortCategory($connection, "CategorySummary", "DESC");
                     }
                 }
             }
         } else {
             if ($searchType == "product") {
                 if (isset($_GET['keywords'])) {
                     if (isset($_GET['name'])) {
                         if ($_GET['name'] == "ascending") {
                             $searchResults = $searchObject->sortProductBySearch($connection, "ASC", "ProductName", $_GET['keywords']);
                         } else {
                             if ($_GET['name'] == "descending") {
                                 $searchResults = $searchObject->sortProductBySearch($connection, "DESC", "ProductName", $_GET['keywords']);
                             }
                         }
                     } else {
                         if (isset($_GET['calories'])) {
                             if ($_GET['calories'] == "ascending") {
                                 $searchResults = $searchObject->sortProductBySearch($connection, "ASC", "ProductCalories", $_GET['keywords']);
                             } else {
                                 if ($_GET['calories'] == "descending") {
                                     $searchResults = $searchObject->sortProductBySearch($connection, "DESC", "ProductCalories", $_GET['keywords']);
                                 }
                             }
                         } else {
                             if (isset($_GET['price'])) {
                                 if ($_GET['price'] == "ascending") {
                                     $searchResults = $searchObject->sortProductBySearch($connection, "ASC", "ProductPrice", $_GET['keywords']);
                                 } else {
                                     if ($_GET['price'] == "descending") {
                                         $searchResults = $searchObject->sortProductBySearch($connection, "DESC", "ProductPrice", $_GET['keywords']);
                                     }
                                 }
                             } else {
                                 if (isset($_GET['description'])) {
                                     if ($_GET['description'] == "ascending") {
                                         $searchResults = $searchObject->sortProductBySearch($connection, "ASC", "ProductDescription", $_GET['keywords']);
                                     } else {
                                         if ($_GET['description'] == "descending") {
                                             $searchResults = $searchObject->sortProductBySearch($connection, "DESC", "ProductDescription", $_GET['keywords']);
                                         }
                                     }
                                 } else {
                                     $searchResults = $searchObject->makeProductSearch($connection, $_GET['keywords']);
                                 }
                             }
                         }
                     }
                 } else {
                     if (isset($_GET['name'])) {
                         if ($_GET['name'] == "ascending") {
                             $searchResults = $searchObject->sortProduct($connection, "ProductName", "ASC");
                         } else {
                             $searchResults = $searchObject->sortProduct($connection, "ProductName", "DESC");
                         }
                     } else {
                         if (isset($_GET['calories'])) {
                             if ($_GET['calories'] == "ascending") {
                                 $searchResults = $searchObject->sortProduct($connection, "ProductCalories", "ASC");
                             } else {
                                 $searchResults = $searchObject->sortProduct($connection, "ProductCalories", "DESC");
                             }
                         } else {
                             if (isset($_GET['description'])) {
                                 if ($_GET['description'] == "ascending") {
                                     $searchResults = $searchObject->sortProduct($connection, "ProductDescription", "ASC");
                                 } else {
                                     $searchResults = $searchObject->sortProduct($connection, "ProductDescription", "DESC");
                                 }
                             } else {
                                 if (isset($_GET['price'])) {
                                     if ($_GET['price'] == "ascending") {
                                         $searchResults = $searchObject->sortProduct($connection, "ProductPrice", "ASC");
                                     } else {
                                         $searchResults = $searchObject->sortProduct($connection, "ProductPrice", "DESC");
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     close_database_connection($connection);
     // store username into args array
     $argsArray = array('title' => $_GET['keywords'] . " search results", 'username' => $username, 'searchType' => $searchType, 'searchResults' => $searchResults, 'search' => $_GET['keywords']);
     // render (draw) template
     // ------------
     $templateName = 'admin/adminSearch';
     return $app['twig']->render($templateName . '.html.twig', $argsArray);
 }