From 8ff428bf5b9fc02ee8429d5737ac814ad910f506 Mon Sep 17 00:00:00 2001 From: Portugao Date: Sat, 4 Nov 2017 22:38:11 +0100 Subject: [PATCH] typo --- .../Controller/FieldController.php | 197 +++++++++++------- 1 file changed, 127 insertions(+), 70 deletions(-) diff --git a/MU/TransportModule/Controller/FieldController.php b/MU/TransportModule/Controller/FieldController.php index 4860bc2..0d4c3ef 100644 --- a/MU/TransportModule/Controller/FieldController.php +++ b/MU/TransportModule/Controller/FieldController.php @@ -15,6 +15,8 @@ use MU\TransportModule\Controller\Base\AbstractFieldController; use RuntimeException; +use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache; +use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Security\Core\Exception\AccessDeniedException; @@ -36,6 +38,7 @@ class FieldController extends AbstractFieldController * defaults = {"sort" = "", "sortdir" = "asc", "pos" = 1, "num" = 10, "_format" = "html"}, * methods = {"GET"} * ) + * @Cache(expires="+2 hours", public=false) * @Theme("admin") * * @param Request $request Current request instance @@ -61,6 +64,7 @@ public function adminViewAction(Request $request, $sort, $sortdir, $pos, $num) * defaults = {"sort" = "", "sortdir" = "asc", "pos" = 1, "num" = 10, "_format" = "html"}, * methods = {"GET"} * ) + * @Cache(expires="+2 hours", public=false) * * @param Request $request Current request instance * @param string $sort Sorting field @@ -84,6 +88,8 @@ public function viewAction(Request $request, $sort, $sortdir, $pos, $num) * defaults = {"_format" = "html"}, * methods = {"GET", "POST"} * ) + * @ParamConverter("field", class="MUTransportModule:FieldEntity", options = {"repository_method" = "selectById", "mapping": {"id": "id"}, "map_method_signature" = true}) + * @Cache(lastModified="field.getUpdatedDate()", ETag="'Field' ~ field.getid() ~ field.getUpdatedDate().format('U')") * @Theme("admin") * * @param Request $request Current request instance @@ -108,6 +114,8 @@ public function adminDeleteAction(Request $request, FieldEntity $field) * defaults = {"_format" = "html"}, * methods = {"GET", "POST"} * ) + * @ParamConverter("field", class="MUTransportModule:FieldEntity", options = {"repository_method" = "selectById", "mapping": {"id": "id"}, "map_method_signature" = true}) + * @Cache(lastModified="field.getUpdatedDate()", ETag="'Field' ~ field.getid() ~ field.getUpdatedDate().format('U')") * * @param Request $request Current request instance * @param FieldEntity $field Treated field instance @@ -122,6 +130,98 @@ public function deleteAction(Request $request, FieldEntity $field) { return parent::deleteAction($request, $field); } + + + /** + * @inheritDoc + * + * @Route("/admin/field/edit/{id}.{_format}", + * requirements = {"id" = "\d+", "_format" = "html"}, + * defaults = {"id" = "0", "_format" = "html"}, + * methods = {"GET", "POST"} + * ) + * @Cache(expires="+30 minutes", public=false) + * @Theme("admin") + * + * @param Request $request Current request instance + * + * @return Response Output + * + * @throws AccessDeniedException Thrown if the user doesn't have required permissions + * @throws NotFoundHttpException Thrown by form handler if field to be edited isn't found + * @throws RuntimeException Thrown if another critical error occurs (e.g. workflow actions not available) + */ + public function adminEditAction(Request $request) + { + return parent::adminEditAction($request); + } + + /** + * @inheritDoc + * + * @Route("/field/edit/{id}.{_format}", + * requirements = {"id" = "\d+", "_format" = "html"}, + * defaults = {"id" = "0", "_format" = "html"}, + * methods = {"GET", "POST"} + * ) + * @Cache(expires="+30 minutes", public=false) + * + * @param Request $request Current request instance + * + * @return Response Output + * + * @throws AccessDeniedException Thrown if the user doesn't have required permissions + * @throws NotFoundHttpException Thrown by form handler if field to be edited isn't found + * @throws RuntimeException Thrown if another critical error occurs (e.g. workflow actions not available) + */ + public function editAction(Request $request) + { + return parent::editAction($request); + } + + /** + * Process status changes for multiple items. + * + * This function processes the items selected in the admin view page. + * Multiple items may have their state changed or be deleted. + * + * @Route("/admin/fields/handleSelectedEntries", + * methods = {"POST"} + * ) + * @Theme("admin") + * + * @param Request $request Current request instance + * + * @return RedirectResponse + * + * @throws RuntimeException Thrown if executing the workflow action fails + */ + public function adminHandleSelectedEntriesAction(Request $request) + { + return parent::adminHandleSelectedEntriesAction($request); + } + + /** + * Process status changes for multiple items. + * + * This function processes the items selected in the admin view page. + * Multiple items may have their state changed or be deleted. + * + * @Route("/fields/handleSelectedEntries", + * methods = {"POST"} + * ) + * + * @param Request $request Current request instance + * + * @return RedirectResponse + * + * @throws RuntimeException Thrown if executing the workflow action fails + */ + public function handleSelectedEntriesAction(Request $request) + { + return parent::handleSelectedEntriesAction($request); + } + /** * @inheritDoc * @@ -138,7 +238,7 @@ public function deleteAction(Request $request, FieldEntity $field) */ public function adminGetFieldsAction(Request $request) { - return parent::adminGetFieldsAction($request); + return parent::adminGetFieldsAction($request); } /** @@ -156,7 +256,7 @@ public function adminGetFieldsAction(Request $request) */ public function getFieldsAction(Request $request) { - return parent::getFieldsAction($request); + return parent::getFieldsAction($request); } /** @@ -174,59 +274,59 @@ protected function getFieldsInternal(Request $request, $isAdmin = false) $templateParameters = [ 'routeArea' => $isAdmin ? 'admin' : '' ]; - + $controllerHelper = $this->get('mu_transport_module.controller_helper'); $modelHelper = $this->get('mu_transport_module.model_helper'); - + $tableId = $controllerHelper->getParameter('table'); - + $tableRepository = $modelHelper->getRepository('table'); $table = $tableRepository->findOneBy(array('id' => $tableId)); $database = $table['database']; - + $conn = new \PDO('mysql:dbname=' . $database['dbName'] . ';host=' . $database['host'], $database['dbUser'], $database['dbPassword']); $statement = $conn->query('DESCRIBE ' . $table['name']); $result = $statement->fetchAll(PDO::FETCH_ASSOC); - + $entityManager = $this->container->get('doctrine.entitymanager'); - + $count = 0; - + foreach ($result as $field) { $newField = new FieldEntity(); $newField->setFieldName($field['Field']); - if ($field['Key'] != '') { - $newField->setFieldKey($field['Key']); + if ($field['Key'] != '') { + $newField->setFieldKey($field['Key']); } else { $newField->setFieldKey(''); } $pos = strpos($field['Type'], '('); if ($pos != false) { - $length = strstr($field['Type'], '('); - $length = str_replace('(', '', $length); - $length = str_replace(')', '', $length); - if ($length != '') { - $newField->setFieldLength($length); - } else { - $newField->setFieldLength(''); - } - $type = explode('(', $field['Type']); - $newField->setFieldType($type[0]); + $length = strstr($field['Type'], '('); + $length = str_replace('(', '', $length); + $length = str_replace(')', '', $length); + if ($length != '') { + $newField->setFieldLength($length); + } else { + $newField->setFieldLength(''); + } + $type = explode('(', $field['Type']); + $newField->setFieldType($type[0]); } else { $newField->setFieldType($field['Type']); } if ($field['Default'] != '') { - $newField->setFieldDefault($field['Default']); + $newField->setFieldDefault($field['Default']); } else { $newField->setFieldDefault(''); } if ($field['Null'] != '') { - $newField->setFieldNull($field['Null']); + $newField->setFieldNull($field['Null']); } else { $newField->setFieldNull(''); } if ($field['Extra'] != '') { - $newField->setFieldExtra($field['Extra']); + $newField->setFieldExtra($field['Extra']); } else { $newField->setFieldExtra(''); } @@ -234,7 +334,7 @@ protected function getFieldsInternal(Request $request, $isAdmin = false) $newField->setWorkflowState('approved'); $entityManager->persist($newField); $entityManager->flush(); - + $count++; $fieldList[] = $field; } @@ -261,7 +361,7 @@ protected function getFieldsInternal(Request $request, $isAdmin = false) */ public function adminCopyValuesFromDatabaseToDatabaseAction(Request $request) { - return parent::adminCopyValuesFromDatabaseToDatabaseAction($request); + return parent::adminCopyValuesFromDatabaseToDatabaseAction($request); } /** @@ -279,50 +379,7 @@ public function adminCopyValuesFromDatabaseToDatabaseAction(Request $request) */ public function copyValuesFromDatabaseToDatabaseAction(Request $request) { - return parent::copyValuesFromDatabaseToDatabaseAction($request); - } - - /** - * Process status changes for multiple items. - * - * This function processes the items selected in the admin view page. - * Multiple items may have their state changed or be deleted. - * - * @Route("/admin/fields/handleSelectedEntries", - * methods = {"POST"} - * ) - * @Theme("admin") - * - * @param Request $request Current request instance - * - * @return RedirectResponse - * - * @throws RuntimeException Thrown if executing the workflow action fails - */ - public function adminHandleSelectedEntriesAction(Request $request) - { - return parent::adminHandleSelectedEntriesAction($request); - } - - /** - * Process status changes for multiple items. - * - * This function processes the items selected in the admin view page. - * Multiple items may have their state changed or be deleted. - * - * @Route("/fields/handleSelectedEntries", - * methods = {"POST"} - * ) - * - * @param Request $request Current request instance - * - * @return RedirectResponse - * - * @throws RuntimeException Thrown if executing the workflow action fails - */ - public function handleSelectedEntriesAction(Request $request) - { - return parent::handleSelectedEntriesAction($request); + return parent::copyValuesFromDatabaseToDatabaseAction($request); } // feel free to add your own controller methods here