Ejemplo n.º 1
0
 /**
  * Action for editing a category's properties
  *
  * Action for route: /adminEditCategory
  *
  * @param Request $request
  * @param Application $app
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  */
 public function editCategoryAction(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');
     }
     $categoryID = $_GET['categoryID'];
     $categoryName = $_GET['categoryName'];
     $categoryImageURL = $_GET['categoryImageURL'];
     $categoryImageURL1 = $_GET['categoryImageURL1'];
     $categoryImageURL2 = $_GET['categoryImageURL2'];
     $categorySummary = $_GET['categorySummary'];
     $connection = open_database_connection();
     $changeCategoryObject = new ChangeCategory();
     $resultMessage = $changeCategoryObject->editCategory($connection, $categoryID, $categoryName, $categoryImageURL1, $categoryImageURL2, $categorySummary);
     $categoriesForSelection = $changeCategoryObject->getCategoriesForSelection($connection, "editCategory");
     close_database_connection($connection);
     if ($resultMessage == "Success!") {
         return $app->redirect("/adminChangeCategory");
     }
     $changeItemURL = $_SERVER['REQUEST_URI'] . $_SERVER['QUERY_STRING'];
     // store username into args array
     $argsArray = array('title' => "Edit category" . $categoryName, 'username' => $username, 'categoryID' => $categoryID, 'categoryName' => $categoryName, 'categoryImageURL' => $categoryImageURL, 'categorySummary' => $categorySummary, 'categoryImageSelection' => $categoriesForSelection, 'resultMessage' => $resultMessage, 'changeItemURL' => $changeItemURL);
     // render (draw) template
     // ------------
     $templateName = 'admin/editCategory';
     return $app['twig']->render($templateName . '.html.twig', $argsArray);
 }