-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from LIN3S/feature/multiple-persistence-strategy
Feature/multiple persistence strategy
- Loading branch information
Showing
18 changed files
with
258 additions
and
236 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,109 +11,26 @@ | |
|
||
namespace LIN3S\AdminBundle\Configuration\Model; | ||
|
||
use LIN3S\AdminBundle\Repository\QueryBuilder; | ||
use LIN3S\AdminBundle\Repository\AdminRepository; | ||
|
||
/** | ||
* Entity configuration. | ||
* | ||
* @author Gorka Laucirica <[email protected]> | ||
*/ | ||
final class Entity | ||
{ | ||
/** | ||
* Collection of actions. | ||
* | ||
* @var array | ||
*/ | ||
protected $actions; | ||
|
||
/** | ||
* The entity name. | ||
* | ||
* @var string | ||
*/ | ||
protected $name; | ||
|
||
/** | ||
* The class name. | ||
* | ||
* @var string | ||
*/ | ||
protected $className; | ||
|
||
/** | ||
* The list actions. | ||
* | ||
* @var array | ||
*/ | ||
protected $listActions; | ||
|
||
/** | ||
* The list fields. | ||
* | ||
* @var array | ||
*/ | ||
protected $listFields; | ||
|
||
/** | ||
* The list filters. | ||
* | ||
* @var array | ||
*/ | ||
protected $listFilters; | ||
|
||
/** | ||
* The entities per page. | ||
* | ||
* @var int | ||
*/ | ||
protected $listEntitiesPerPage; | ||
|
||
/** | ||
* The list global actions. | ||
* | ||
* @var array | ||
*/ | ||
protected $listGlobalActions; | ||
|
||
/** | ||
* The list order by default. | ||
* | ||
* @var array | ||
*/ | ||
protected $listOrderByDefault; | ||
|
||
/** | ||
* The entity name, for visualization purposes. | ||
* | ||
* It contains the singular and plural cases. | ||
* | ||
* @var array | ||
*/ | ||
private $actions; | ||
private $name; | ||
private $className; | ||
private $listActions; | ||
private $listFields; | ||
private $listFilters; | ||
private $listEntitiesPerPage; | ||
private $listGlobalActions; | ||
private $listOrderByDefault; | ||
private $printNames; | ||
private $repositoryServiceId; | ||
private $repository; | ||
|
||
/** | ||
* The query builder. | ||
* | ||
* @var QueryBuilder | ||
*/ | ||
protected $queryBuilder; | ||
|
||
/** | ||
* EntityConfiguration constructor. | ||
* | ||
* @param string $name The entity name | ||
* @param string $className The class name | ||
* @param array $actions Collection of actions | ||
* @param array $listActions List actions | ||
* @param array $listFields List fields | ||
* @param array $listFilters List filters | ||
* @param array $listGlobalActions List global actions | ||
* @param QueryBuilder $queryBuilder The query builder | ||
* @param array $printNames The entity name, for visualization purposes | ||
* @param int $listEntitiesPerPage The number of entities per page | ||
* @param array $listOrderByDefault The order by default | ||
*/ | ||
public function __construct( | ||
$name, | ||
$className, | ||
|
@@ -122,7 +39,7 @@ public function __construct( | |
array $listFields = [], | ||
array $listFilters = [], | ||
array $listGlobalActions = [], | ||
QueryBuilder $queryBuilder, | ||
$repositoryServiceId, | ||
array $printNames, | ||
$listEntitiesPerPage, | ||
array $listOrderByDefault = [] | ||
|
@@ -135,7 +52,7 @@ public function __construct( | |
$this->actions = $actions; | ||
$this->listActions = $listActions; | ||
$this->listGlobalActions = $listGlobalActions; | ||
$this->queryBuilder = $queryBuilder; | ||
$this->repositoryServiceId = $repositoryServiceId; | ||
$this->printNames = $printNames; | ||
$this->listEntitiesPerPage = $listEntitiesPerPage; | ||
$this->listOrderByDefault = $listOrderByDefault; | ||
|
@@ -365,13 +282,24 @@ public function printNames() | |
return $this->printNames; | ||
} | ||
|
||
/** | ||
* Gets the query builder. | ||
* | ||
* @return QueryBuilder | ||
*/ | ||
public function queryBuilder() | ||
public function repositoryServiceId() | ||
{ | ||
return $this->repositoryServiceId; | ||
} | ||
|
||
public function repository() | ||
{ | ||
if (!$this->repository instanceof AdminRepository) { | ||
throw new \Exception( | ||
sprintf('The repository is not loaded yet') | ||
); | ||
} | ||
|
||
return $this->repository; | ||
} | ||
|
||
public function loadRepository(AdminRepository $repository) | ||
{ | ||
return $this->queryBuilder; | ||
$this->repository = $repository; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,48 +15,15 @@ | |
use Symfony\Component\HttpFoundation\Request; | ||
|
||
/** | ||
* Admin repository. | ||
* | ||
* @author Gorka Laucirica <[email protected]> | ||
*/ | ||
class AdminRepository | ||
interface AdminRepository | ||
{ | ||
/** | ||
* Finds the result about request criteria and given entity configuration. | ||
* | ||
* @param Request $request The request | ||
* @param Entity $config The entity configuration | ||
* | ||
* @return array | ||
*/ | ||
public function findByRequest(Request $request, Entity $config) | ||
{ | ||
$queryBuilder = $config->queryBuilder()->generate($request, $config); | ||
|
||
$postPerPage = $config->listEntitiesPerPage(); | ||
|
||
$offset = ($request->get('page', 1) - 1) * $postPerPage; | ||
$limit = $postPerPage; | ||
|
||
$queryBuilder->setFirstResult($offset); | ||
$queryBuilder->setMaxResults($limit); | ||
public function find(Entity $config, $id); | ||
|
||
return $queryBuilder->getQuery()->getResult(); | ||
} | ||
public function remove($entity); | ||
|
||
/** | ||
* Counts all the result about request criteria and given entity configuration. | ||
* | ||
* @param Request $request The request | ||
* @param Entity $config The entity configuration | ||
* | ||
* @return int | ||
*/ | ||
public function countAll(Request $request, Entity $config) | ||
{ | ||
$queryBuilder = $config->queryBuilder()->generate($request, $config); | ||
$queryBuilder->select($queryBuilder->expr()->count('a')); | ||
public function findByRequest(Request $request, Entity $config); | ||
|
||
return count($queryBuilder->getQuery()->getScalarResult()); | ||
} | ||
public function countAll(Request $request, Entity $config); | ||
} |
Oops, something went wrong.