Skip to content

Commit

Permalink
Merge pull request #214 from wimvds/fix-form-submissions-export
Browse files Browse the repository at this point in the history
fix form submissions export
  • Loading branch information
Wim Vandersmissen committed Mar 19, 2015
2 parents 929c862 + 350be1b commit aa2eb2f
Show file tree
Hide file tree
Showing 17 changed files with 533 additions and 174 deletions.
4 changes: 2 additions & 2 deletions src/Kunstmaan/AdminListBundle/AdminList/AdminList.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ public function getItems()
*
* @return \Iterator
*/
public function getAllIterator()
public function getIterator()
{
return $this->configurator->getAllIterator();
return $this->configurator->getIterator();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
use Symfony\Component\HttpFoundation\Request;

/**
* Abstract admin list configurator, this implements the most common functionality from the AdminListConfiguratorInterface
* Abstract admin list configurator, this implements the most common functionality from the
* AdminListConfiguratorInterface and ExportListConfiguratorInterface
*/
abstract class AbstractAdminListConfigurator implements AdminListConfiguratorInterface
abstract class AbstractAdminListConfigurator implements AdminListConfiguratorInterface, ExportListConfiguratorInterface
{
const SUFFIX_ADD = 'add';
const SUFFIX_EDIT = 'edit';
const SUFFIX_ADD = 'add';
const SUFFIX_EDIT = 'edit';
const SUFFIX_EXPORT = 'export';
const SUFFIX_DELETE = 'delete';

Expand Down Expand Up @@ -139,16 +140,30 @@ public function buildListActions()
{
}

/**
* Configure the export fields
*/
public function buildExportFields()
{
}

/**
* Build iterator (if needed)
*/
public function buildIterator()
{
}

/**
* Reset all built members
*/
public function resetBuilds()
{
$this->fields = array();
$this->exportFields = array();
$this->fields = array();
$this->exportFields = array();
$this->filterBuilder = null;
$this->itemActions = array();
$this->listActions = array();
$this->itemActions = array();
$this->listActions = array();
}

/**
Expand All @@ -162,15 +177,17 @@ public function getAddUrlFor(array $params = array())
{
$params = array_merge($params, $this->getExtraParameters());

$friendlyName = explode("\\", $this->getEntityName());
$friendlyName = array_pop($friendlyName);
$re = '/(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])/';
$a = preg_split($re, $friendlyName);
$friendlyName = explode("\\", $this->getEntityName());
$friendlyName = array_pop($friendlyName);
$re = '/(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])/';
$a = preg_split($re, $friendlyName);
$superFriendlyName = implode(' ', $a);

return array(
$superFriendlyName => array('path' => $this->getPathByConvention($this::SUFFIX_ADD),
'params' => $params)
$superFriendlyName => array(
'path' => $this->getPathByConvention($this::SUFFIX_ADD),
'params' => $params
)
);
}

Expand All @@ -184,7 +201,7 @@ public function getExportUrl()
$params = $this->getExtraParameters();

return array(
'path' => $this->getPathByConvention($this::SUFFIX_EXPORT),
'path' => $this->getPathByConvention($this::SUFFIX_EXPORT),
'params' => array_merge(array('_format' => 'csv'), $params)
);
}
Expand All @@ -199,7 +216,7 @@ public function getIndexUrl()
$params = $this->getExtraParameters();

return array(
'path' => $this->getPathByConvention(),
'path' => $this->getPathByConvention(),
'params' => $params
);
}
Expand All @@ -217,13 +234,14 @@ public function getAdminType($entity)
return $this->type;
}

if (method_exists($entity, "getAdminType")) {
if (method_exists($entity, 'getAdminType')) {
return $entity->getAdminType();
}

throw new InvalidArgumentException("You need to implement the getAdminType method in " . get_class(
$this
) . " or " . get_class($entity));
throw new InvalidArgumentException(
'You need to implement the getAdminType method in ' .
get_class($this) . ' or ' . get_class($entity)
);
}

/**
Expand Down Expand Up @@ -317,8 +335,12 @@ public function addExportField($name, $header, $template = null)
*
* @return AbstractAdminListConfigurator
*/
public function addFilter($columnName, FilterTypeInterface $type = null, $filterName = null, array $options = array())
{
public function addFilter(
$columnName,
FilterTypeInterface $type = null,
$filterName = null,
array $options = array()
) {
$this->getFilterBuilder()->add($columnName, $type, $filterName, $options);

return $this;
Expand Down Expand Up @@ -369,7 +391,8 @@ public function getExportFields()

/**
* @param string $label The label, only used when the template equals null
* @param callable $routeGenerator The generator used to generate the url of an item, when generating the item will be provided
* @param callable $routeGenerator The generator used to generate the url of an item, when generating the item will
* be provided
* @param string $icon The icon, only used when the template equals null
* @param string $template The template, when not specified the label is shown
*
Expand Down Expand Up @@ -663,15 +686,15 @@ public function setFilterBuilder(FilterBuilder $filterBuilder)
*/
public function bindRequest(Request $request)
{
$query = $request->query;
$session = $request->getSession();
$query = $request->query;
$session = $request->getSession();

$adminListName = 'listconfig_' . $request->get('_route');

$this->page = $request->query->getInt('page', 1);
$this->page = $request->query->getInt('page', 1);
// Allow alphanumeric, _ & . in order by parameter!
$this->orderBy = preg_replace('/[^[a-zA-Z0-9\_\.]]/', '', $request->query->get('orderBy', ''));
$this->orderDirection = $request->query->getAlpha('orderDirection', '');
$this->orderBy = preg_replace('/[^[a-zA-Z0-9\_\.]]/', '', $request->query->get('orderBy', ''));
$this->orderDirection = $request->query->getAlpha('orderDirection', '');

// there is a session and the filter param is not set
if ($session->has($adminListName) && !$query->has('filter')) {
Expand All @@ -690,11 +713,14 @@ public function bindRequest(Request $request)
}

// save current parameters
$session->set($adminListName, array(
'page' => $this->page,
'orderBy' => $this->orderBy,
'orderDirection' => $this->orderDirection,
));
$session->set(
$adminListName,
array(
'page' => $this->page,
'orderBy' => $this->orderBy,
'orderDirection' => $this->orderDirection,
)
);


$this->getFilterBuilder()->bindRequest($request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

namespace Kunstmaan\AdminListBundle\AdminList\Configurator;

use Doctrine\DBAL\Statement;
use Traversable;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Query\QueryBuilder;

use Pagerfanta\Pagerfanta;

use Kunstmaan\AdminListBundle\AdminList\Configurator\AbstractAdminListConfigurator;
use Kunstmaan\AdminListBundle\AdminList\FilterType\DBAL\AbstractDBALFilterType;
use Kunstmaan\AdminListBundle\Helper\DoctrineDBALAdapter;
Expand Down Expand Up @@ -93,7 +91,11 @@ public function getDeleteUrlFor($item)
public function getPagerfanta()
{
if (is_null($this->pagerfanta)) {
$adapter = new DoctrineDBALAdapter($this->getQueryBuilder(), $this->getCountField(), $this->getUseDistinctCount());
$adapter = new DoctrineDBALAdapter(
$this->getQueryBuilder(),
$this->getCountField(),
$this->getUseDistinctCount()
);
$this->pagerfanta = new Pagerfanta($adapter);
$this->pagerfanta->setCurrentPage($this->getPage());
$this->pagerfanta->setMaxPerPage($this->getLimit());
Expand All @@ -105,8 +107,11 @@ public function getPagerfanta()
/**
* @param array $params
*/
public function adaptQueryBuilder(QueryBuilder $queryBuilder, /** @noinspection PhpUnusedParameterInspection */ array $params = array())
{
public function adaptQueryBuilder(
QueryBuilder $queryBuilder,
/** @noinspection PhpUnusedParameterInspection */
array $params = array()
) {
$queryBuilder->where('1=1');
}

Expand All @@ -131,9 +136,9 @@ public function getItems()
*
* @return \Iterator
*/
public function getAllIterator()
public function getIterator()
{
/*@var Statement $statement*/
/** @var Statement $statement*/
$statement = $this->getQueryBuilder()->execute();

return $statement;
Expand Down Expand Up @@ -191,7 +196,6 @@ public function getCountField()
return $this->countField;
}


/**
* When doing the count you can turn the distinct on or off.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@
namespace Kunstmaan\AdminListBundle\AdminList\Configurator;

use Traversable;

use Doctrine\ORM\EntityManager;
use Doctrine\ORM\QueryBuilder;
use Doctrine\ORM\Query;

use Kunstmaan\AdminBundle\Helper\Security\Acl\AclHelper;
use Kunstmaan\AdminBundle\Helper\Security\Acl\Permission\PermissionDefinition;
use Kunstmaan\AdminListBundle\AdminList\FilterType\ORM\AbstractORMFilterType;
use Kunstmaan\AdminListBundle\AdminList\Configurator\AbstractAdminListConfigurator;
use Kunstmaan\AdminListBundle\AdminList\Filter;

use Pagerfanta\Pagerfanta;
use Pagerfanta\Adapter\DoctrineORMAdapter;

Expand Down Expand Up @@ -53,7 +50,7 @@ abstract class AbstractDoctrineORMAdminListConfigurator extends AbstractAdminLis
*/
public function __construct(EntityManager $em, AclHelper $aclHelper = null)
{
$this->em = $em;
$this->em = $em;
$this->aclHelper = $aclHelper;
}

Expand All @@ -70,7 +67,7 @@ public function getEditUrlFor($item)
$params = array_merge($params, $this->getExtraParameters());

return array(
'path' => $this->getPathByConvention($this::SUFFIX_EDIT),
'path' => $this->getPathByConvention($this::SUFFIX_EDIT),
'params' => $params
);
}
Expand All @@ -88,7 +85,7 @@ public function getDeleteUrlFor($item)
$params = array_merge($params, $this->getExtraParameters());

return array(
'path' => $this->getPathByConvention($this::SUFFIX_DELETE),
'path' => $this->getPathByConvention($this::SUFFIX_DELETE),
'params' => $params
);
}
Expand All @@ -99,7 +96,7 @@ public function getDeleteUrlFor($item)
public function getPagerfanta()
{
if (is_null($this->pagerfanta)) {
$adapter = new DoctrineORMAdapter($this->getQuery());
$adapter = new DoctrineORMAdapter($this->getQuery());
$this->pagerfanta = new Pagerfanta($adapter);
$this->pagerfanta->setNormalizeOutOfRangePages(true);
$this->pagerfanta->setCurrentPage($this->getPage());
Expand Down Expand Up @@ -138,7 +135,7 @@ public function getItems()
*
* @return \Iterator
*/
public function getAllIterator()
public function getIterator()
{
return $this->getQuery()->iterate();
}
Expand Down Expand Up @@ -190,6 +187,7 @@ protected function getQueryBuilder()
$queryBuilder = $this->em
->getRepository($this->getRepositoryName())
->createQueryBuilder('b');

return $queryBuilder;
}

Expand All @@ -208,7 +206,7 @@ public function getPermissionDefinition()
*
* @param PermissionDefinition $permissionDef
*
* @return AbstractAdminListConfigurator|AbstractDoctrineORMAdminListConfigurator
* @return AbstractDoctrineORMAdminListConfigurator
*/
public function setPermissionDefinition(PermissionDefinition $permissionDef)
{
Expand All @@ -219,10 +217,13 @@ public function setPermissionDefinition(PermissionDefinition $permissionDef)

/**
* @param EntityManager $em
*
* @return AbstractDoctrineORMAdminListConfigurator
*/
public function setEntityManager($em)
{
$this->em = $em;

return $this;
}

Expand All @@ -233,5 +234,4 @@ public function getEntityManager()
{
return $this->em;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,6 @@ public function getCount();
*/
public function getItems();

/**
* Return an iterator for all items that matches the current filtering
*
* @return \Iterator
*/
public function getAllIterator();

/**
* Bind request
*
Expand Down
9 changes: 7 additions & 2 deletions src/Kunstmaan/AdminListBundle/AdminList/ExportList.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@

namespace Kunstmaan\AdminListBundle\AdminList;

use Kunstmaan\AdminListBundle\AdminList\Configurator\ExportListConfiguratorInterface;

class ExportList implements ExportableInterface
{
/**
* @var ExportListConfiguratorInterface
*/
private $configurator;

public function __construct($configurator)
public function __construct(ExportListConfiguratorInterface $configurator)
{
$this->configurator = $configurator;
$this->configurator->buildExportFields();
Expand All @@ -18,7 +23,7 @@ public function getExportColumns()
return $this->configurator->getExportFields();
}

public function getAllIterator()
public function getIterator()
{
return $this->configurator->getIterator();
}
Expand Down
Loading

0 comments on commit aa2eb2f

Please sign in to comment.