Skip to content

Commit

Permalink
typo
Browse files Browse the repository at this point in the history
  • Loading branch information
Portugao committed Nov 4, 2017
1 parent 78c5c6a commit 8ff428b
Showing 1 changed file with 127 additions and 70 deletions.
197 changes: 127 additions & 70 deletions MU/TransportModule/Controller/FieldController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
*
Expand All @@ -138,7 +238,7 @@ public function deleteAction(Request $request, FieldEntity $field)
*/
public function adminGetFieldsAction(Request $request)
{
return parent::adminGetFieldsAction($request);
return parent::adminGetFieldsAction($request);
}

/**
Expand All @@ -156,7 +256,7 @@ public function adminGetFieldsAction(Request $request)
*/
public function getFieldsAction(Request $request)
{
return parent::getFieldsAction($request);
return parent::getFieldsAction($request);
}

/**
Expand All @@ -174,67 +274,67 @@ 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('');
}
$newField->setTable($table);
$newField->setWorkflowState('approved');
$entityManager->persist($newField);
$entityManager->flush();

$count++;
$fieldList[] = $field;
}
Expand All @@ -261,7 +361,7 @@ protected function getFieldsInternal(Request $request, $isAdmin = false)
*/
public function adminCopyValuesFromDatabaseToDatabaseAction(Request $request)
{
return parent::adminCopyValuesFromDatabaseToDatabaseAction($request);
return parent::adminCopyValuesFromDatabaseToDatabaseAction($request);
}

/**
Expand All @@ -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
Expand Down

0 comments on commit 8ff428b

Please sign in to comment.