Esempio n. 1
0
 /**
  * test for sorting products from the search
  * NOTE: By changing the the products "Cappuccino", "Lemon Tea", or
  *      "Mineral Water" in the database or adding any products with
  *      similar names this test will no longer work unless $expectedResult
  *      is changed based on AdminSearch::sortProductBySearch's new output
  */
 public function testSortProductBySearch()
 {
     // Arrange
     $adminSearch = new AdminSearch();
     $connection = open_database_connection();
     $expectedResult = '<h3>Search results for Cappuccino</h3><form id="productResult13" action= "/adminEditProduct" method="get">
 <p><span class="search" onclick="document.getElementById(\'productResult13\').submit();">Cappuccino</span> - This creamy, delicious, rich flavoured coffee specialty is made from 1/3 Espresso, 1/3 steamed milk and 1/3 foamed milk and garnished with your choice of Cinnamon or powder chocolate. We use  high altitude(above 3000 ft) grown Arabica coffee beans.</p><p>Calories: 115</p><p>Price: 3.45</p><input type="hidden" name="product_ID" value="13" /><input type="hidden" name="product_name" value="Cappuccino" /><input type="hidden" name="product_image_URL" value="cappuccino.png" /><input type="hidden" name="product_description" value="This creamy, delicious, rich flavoured coffee specialty is made from 1/3 Espresso, 1/3 steamed milk and 1/3 foamed milk and garnished with your choice of Cinnamon or powder chocolate. We use  high altitude(above 3000 ft) grown Arabica coffee beans." /><input type="hidden" name="product_calories" value="115" /><input type="hidden" name="product_allergy_info" value="no allergens are present on this drink product but consideration for those with low toleration to milk products should be given." /><input type="hidden" name="product_price" value="3.45" /><input type="hidden" name="category_ID" value="3" /><input type="hidden" name="category_name" value="Drinks" /><input type="hidden" name="category_summary" 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="productImageURL1" value="" /><input type="hidden" name="productImageURL2" value="cappuccino.png" /></form><h3>Search results for Water</h3><form id="productResult10" action= "/adminEditProduct" method="get">
 <p><span class="search" onclick="document.getElementById(\'productResult10\').submit();">Lemon Tea</span> - KBK lemon tea is inspired from the Indian cuisine and it is a very refreshing drink which could be served at any time of the day indulging yourself or when meeting with your next door neighbor. It is made of aromatic Indian black tea, lemon, and spring water. Best served with a slice of lemon and some ice!</p><p>Calories: 40</p><p>Price: 2.95</p><input type="hidden" name="product_ID" value="10" /><input type="hidden" name="product_name" value="Lemon Tea" /><input type="hidden" name="product_image_URL" value="lemon_tea.png" /><input type="hidden" name="product_description" value="KBK lemon tea is inspired from the Indian cuisine and it is a very refreshing drink which could be served at any time of the day indulging yourself or when meeting with your next door neighbor. It is made of aromatic Indian black tea, lemon, and spring water. Best served with a slice of lemon and some ice!" /><input type="hidden" name="product_calories" value="40" /><input type="hidden" name="product_allergy_info" value="no allergens are present on this product." /><input type="hidden" name="product_price" value="2.95" /><input type="hidden" name="category_ID" value="3" /><input type="hidden" name="category_name" value="Drinks" /><input type="hidden" name="category_summary" 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="productImageURL1" value="" /><input type="hidden" name="productImageURL2" value="lemon_tea.png" /></form><form id="productResult14" action= "/adminEditProduct" method="get">
 <p><span class="search" onclick="document.getElementById(\'productResult14\').submit();">Mineral Water</span> - This mineral water is bottled fresh at its source in the French Alps. You are what you drink, so hydration is very important, so do not leave out this vital supplement in any meal.</p><p>Calories: 10</p><p>Price: 1.49</p><input type="hidden" name="product_ID" value="14" /><input type="hidden" name="product_name" value="Mineral Water" /><input type="hidden" name="product_image_URL" value="mineral_water.png" /><input type="hidden" name="product_description" value="This mineral water is bottled fresh at its source in the French Alps. You are what you drink, so hydration is very important, so do not leave out this vital supplement in any meal." /><input type="hidden" name="product_calories" value="10" /><input type="hidden" name="product_allergy_info" value="None" /><input type="hidden" name="product_price" value="1.49" /><input type="hidden" name="category_ID" value="3" /><input type="hidden" name="category_name" value="Drinks" /><input type="hidden" name="category_summary" 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="productImageURL1" value="" /><input type="hidden" name="productImageURL2" value="mineral_water.png" /></form>';
     // Assert
     $result = $adminSearch->sortProductBySearch($connection, "ASC", "ProductName", "Cappuccino Water");
     close_database_connection($connection);
     // Act
     $this->assertEquals($result, $expectedResult);
 }
Esempio 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);
 }