755 lines
16 KiB
PHP
755 lines
16 KiB
PHP
<?php
|
|
|
|
namespace Trinity\Bundle\AdminBundle\Configuration;
|
|
|
|
use Trinity\Bundle\AdminBundle\Exception as BaseAdminException;
|
|
|
|
class CrudConfiguration
|
|
{
|
|
protected $modelNamespace = null;
|
|
protected $model = null;
|
|
protected $modelPeer = null;
|
|
protected $modelQuery = null;
|
|
|
|
protected $routePrefix = null;
|
|
|
|
protected $formNamespace = null;
|
|
protected $formEdit = null;
|
|
protected $formNew = null;
|
|
protected $formFilter = null;
|
|
|
|
protected $formEditOptions = array();
|
|
protected $formNewOptions = array();
|
|
protected $formFilterOptions = array();
|
|
|
|
protected $fieldsTemplates = array();
|
|
protected $fieldsHelpers = array();
|
|
protected $displayFields = array();
|
|
protected $displayFieldsAttrs = array();
|
|
protected $fieldsets = array();
|
|
protected $fieldsetsView = 'fieldset';
|
|
protected $fieldsnames = array();
|
|
|
|
protected $filterDisplayFields = array();
|
|
protected $filtersMethods = array();
|
|
protected $filtersTemplates = array();
|
|
protected $filterNamespace = null;
|
|
protected $filter = null;
|
|
protected $filterValue = null;
|
|
|
|
protected $listTitle = null;
|
|
protected $editTitle = null;
|
|
protected $newTitle = null;
|
|
|
|
protected $maxPerPage = 10;
|
|
protected $currentPage = 1;
|
|
protected $sort = null;
|
|
protected $sortOrder = \Criteria::ASC;
|
|
|
|
protected $highlighting = 'edit';
|
|
|
|
protected $rankable = false;
|
|
|
|
protected $i18nCultures = array();
|
|
protected $i18n = false;
|
|
|
|
protected $storageNamespace = null;
|
|
|
|
protected $batchActions = true;
|
|
|
|
protected $contextMenu = true;
|
|
|
|
protected $collections = array();
|
|
|
|
protected $export = false;
|
|
|
|
protected $exportFormats = array();
|
|
|
|
protected $redirectIfOneResult = true;
|
|
|
|
protected $indexListActions = array(
|
|
'edit' => 'TrinityAdminBundle:BaseAdmin:listEdit.html.twig',
|
|
'remove' => 'TrinityAdminBundle:BaseAdmin:listRemove.html.twig',
|
|
);
|
|
|
|
protected $indexActions = array(
|
|
'new' => 'TrinityAdminBundle:BaseAdmin:indexNew.html.twig',
|
|
);
|
|
|
|
public function setExport($export, array $formats = array('XML', 'CSV', 'JSON', 'YAML'))
|
|
{
|
|
$this->export = (bool) $export;
|
|
$this->exportFormats = $formats;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getExport()
|
|
{
|
|
return $this->export;
|
|
}
|
|
|
|
public function setExportFormats(array $exportFormats)
|
|
{
|
|
$this->exportFormats = $exportFormats;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getExportFormats()
|
|
{
|
|
return $this->exportFormats;
|
|
}
|
|
|
|
private function formatNamespace($namespace)
|
|
{
|
|
if (substr($namespace, strlen($namespace)-1) !== '\\') {
|
|
$namespace .= '\\';
|
|
}
|
|
|
|
return $namespace;
|
|
}
|
|
|
|
public function setIndexListAction($actionName, $template = 'TrinityAdminBundle:BaseAdmin:listDefault.html.twig')
|
|
{
|
|
$this->indexListActions[$actionName] = $template;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function setIndexListActions(array $actions)
|
|
{
|
|
$this->indexListActions = $actions;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function removeIndexAction($action)
|
|
{
|
|
if (isset($this->indexActions[$action])) {
|
|
unset($this->indexActions[$action]);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function removeIndexListAction($action)
|
|
{
|
|
if (isset($this->indexListActions[$action])) {
|
|
unset($this->indexListActions[$action]);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getIndexListActions()
|
|
{
|
|
return $this->indexListActions;
|
|
}
|
|
|
|
public function getIndexListAction($action)
|
|
{
|
|
return isset($this->indexListActions[$action]) ? $this->indexListActions[$action] : null;
|
|
}
|
|
|
|
public function setIndexAction($actionName,$template)
|
|
{
|
|
$this->indexActions[$actionName] = $template;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function setIndexActions(array $actions)
|
|
{
|
|
$this->indexActions = $actions;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getIndexActions()
|
|
{
|
|
return $this->indexActions;
|
|
}
|
|
|
|
public function getIndexAction($action)
|
|
{
|
|
return isset($this->indexActions[$action]) ? $this->indexActions[$action] : null;
|
|
}
|
|
|
|
public function setContextMenu($contextMenu)
|
|
{
|
|
$this->contextMenu = (bool) $contextMenu;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getContextMenu()
|
|
{
|
|
return $this->contextMenu;
|
|
}
|
|
|
|
public function setModelNamespace($modelNamespace)
|
|
{
|
|
$this->modelNamespace = $this->formatNamespace($modelNamespace);
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function setFormNamespace($formNamespace)
|
|
{
|
|
$this->formNamespace = $this->formatNamespace($formNamespace);
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getFormNamespace()
|
|
{
|
|
return $this->formNamespace;
|
|
}
|
|
|
|
public function setFilterNamespace($filterNamespace)
|
|
{
|
|
$this->filterNamespace = $this->formatNamespace($filterNamespace);
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getFiltersTemplates()
|
|
{
|
|
return $this->filtersTemplates;
|
|
}
|
|
|
|
public function setBatchActions($batchActions)
|
|
{
|
|
$this->batchActions = (bool) $batchActions;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getBatchActions()
|
|
{
|
|
return $this->batchActions;
|
|
}
|
|
|
|
public function getFilterNamespace()
|
|
{
|
|
return $this->filterNamespace ? $this->filterNamespace : $this->formNamespace;
|
|
}
|
|
|
|
public function setFieldsets(array $fieldsets, array $i18nFieldsets = array())
|
|
{
|
|
$this->fieldsets = $fieldsets;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getFieldsets()
|
|
{
|
|
return $this->fieldsets;
|
|
}
|
|
|
|
public function setFieldsetsView($fieldsetsView)
|
|
{
|
|
$this->fieldsetsView = $fieldsetsView;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getFieldsetsView()
|
|
{
|
|
return $this->fieldsetsView;
|
|
}
|
|
|
|
public function getFieldsnames()
|
|
{
|
|
return $this->fieldsnames;
|
|
}
|
|
|
|
public function setFieldname($fieldname, $name)
|
|
{
|
|
$this->fieldsnames[$fieldname] = $name;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function setMaxPerPage($maxPerPage)
|
|
{
|
|
if (is_integer($maxPerPage)) {
|
|
$this->maxPerPage = $maxPerPage;
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getMaxPerPage()
|
|
{
|
|
return $this->maxPerPage;
|
|
}
|
|
|
|
public function setCurrentPage($currentPage)
|
|
{
|
|
$this->currentPage = $currentPage;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getCurrentPage()
|
|
{
|
|
return $this->currentPage;
|
|
}
|
|
|
|
public function setFilter($method, $value)
|
|
{
|
|
$this->filter = $method;
|
|
$this->filterValue = $value;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getFilter()
|
|
{
|
|
return $this->filter;
|
|
}
|
|
|
|
public function getFilterValue()
|
|
{
|
|
return $this->filterValue;
|
|
}
|
|
|
|
public function setSort($method, $order = 'asc')
|
|
{
|
|
$order = strtoupper($order);
|
|
|
|
if (!in_array($order, array(\Criteria::ASC, \Criteria::DESC))) {
|
|
throw new \InvalidArgumentException(sprintf('"%s" is not a valid order: %s.', $order, implode(', ', array(\Criteria::ASC, \Criteria::DESC))));
|
|
}
|
|
|
|
$this->sort = $method;
|
|
$this->sortOrder = $order;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getSort()
|
|
{
|
|
return $this->sort;
|
|
}
|
|
|
|
public function getSortOrder()
|
|
{
|
|
return $this->sortOrder;
|
|
}
|
|
|
|
public function setDisplayFieldAttrs($field, array $attr)
|
|
{
|
|
$this->displayFieldsAttrs[$field] = $attr;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function setDisplayFieldsAttrs(array $attrs)
|
|
{
|
|
foreach ($attrs as $key => $value) {
|
|
$this->setDisplayFieldAttrs($key, $value);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getDisplayFieldsAttrs()
|
|
{
|
|
return $this->displayFieldsAttrs;
|
|
}
|
|
|
|
public function setDisplayFields(array $displayFields)
|
|
{
|
|
$this->displayFields = $displayFields;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getDisplayFields()
|
|
{
|
|
return $this->displayFields;
|
|
}
|
|
|
|
public function setFilterDisplayFields(array $filterDisplayFields)
|
|
{
|
|
$this->filterDisplayFields = $filterDisplayFields;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getFilterDisplayFields()
|
|
{
|
|
return $this->filterDisplayFields;
|
|
}
|
|
|
|
public function setFieldTemplate($field, $template)
|
|
{
|
|
$this->fieldsTemplates[$field] = $template;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function setFilterTemplate($field, $template)
|
|
{
|
|
$this->filtersTemplates[$field] = $template;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function setFieldHelper($field, $helper)
|
|
{
|
|
$this->fieldsHelpers[$field] = $helper;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function setRedirectIfOneResult($redirectIfOneResult)
|
|
{
|
|
$this->redirectIfOneResult = (bool) $redirectIfOneResult;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getRedirectIfOneResult()
|
|
{
|
|
return $this->redirectIfOneResult;
|
|
}
|
|
|
|
public function setFilterMethod($field, $method, $criteria = null, $value = null)
|
|
{
|
|
$this->filtersMethods[$field] = array(
|
|
'method' => $method,
|
|
'criteria' => $criteria,
|
|
'value' => $value,
|
|
);
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getFiltersMethods()
|
|
{
|
|
return $this->filtersMethods;
|
|
}
|
|
|
|
public function getFieldsTemplates()
|
|
{
|
|
return $this->fieldsTemplates;
|
|
}
|
|
|
|
public function getFieldsHelpers()
|
|
{
|
|
return $this->fieldsHelpers;
|
|
}
|
|
|
|
public function setModel($model, $useDefaultNamespace = true)
|
|
{
|
|
if (!$useDefaultNamespace) {
|
|
$this->model = $model;
|
|
|
|
return $this;
|
|
}
|
|
|
|
if (!class_exists($this->modelNamespace.$model)) {
|
|
$this->modelNotFoundAdminException($this->modelNamespace.$model);
|
|
}
|
|
|
|
$this->model = $this->modelNamespace.$model;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getModel()
|
|
{
|
|
return $this->model;
|
|
}
|
|
|
|
public function setModelPeer($modelPeer, $useDefaultNamespace = true)
|
|
{
|
|
if (!$useDefaultNamespace) {
|
|
$this->modelPeer = $modelPeer;
|
|
|
|
return $this;
|
|
}
|
|
|
|
if (!class_exists($this->modelNamespace.$modelPeer)) {
|
|
$this->modelNotFoundAdminException($this->modelNamespace.$modelPeer);
|
|
}
|
|
|
|
$this->modelPeer = $this->modelNamespace.$modelPeer;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getModelPeer()
|
|
{
|
|
return $this->modelPeer;
|
|
}
|
|
|
|
public function setModelQuery($modelQuery, $useDefaultNamespace = true)
|
|
{
|
|
if (!$useDefaultNamespace) {
|
|
$this->modelQuery = $modelQuery;
|
|
|
|
return $this;
|
|
}
|
|
|
|
if (!class_exists($this->modelNamespace.$modelQuery)) {
|
|
$this->modelNotFoundAdminException($this->modelNamespace.$modelQuery);
|
|
}
|
|
|
|
$this->modelQuery = $this->modelNamespace.$modelQuery;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getRoutePrefix()
|
|
{
|
|
if (null === $this->routePrefix) {
|
|
throw new \RuntimeException('You must set the route_prefix in the configuration of your admin bundle.');
|
|
}
|
|
|
|
return $this->routePrefix;
|
|
}
|
|
|
|
public function setRoutePrefix($routePrefix)
|
|
{
|
|
$this->routePrefix = $routePrefix;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getModelQuery()
|
|
{
|
|
return $this->modelQuery;
|
|
}
|
|
|
|
public function setFormEdit($formEdit, $useDefaultNamespace = true)
|
|
{
|
|
if (!$useDefaultNamespace) {
|
|
$this->formEdit = $formEdit;
|
|
|
|
return $this;
|
|
}
|
|
|
|
if (!class_exists($this->getFormNamespace().$formEdit)) {
|
|
$this->modelNotFoundAdminException($this->getFormNamespace().$formEdit);
|
|
}
|
|
|
|
$this->formEdit = $this->getFormNamespace().$formEdit;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getFormEdit()
|
|
{
|
|
return $this->formEdit;
|
|
}
|
|
|
|
public function setFormNew($formNew, $useDefaultNamespace = true)
|
|
{
|
|
if (!$useDefaultNamespace) {
|
|
$this->formNew = $formNew;
|
|
|
|
return $this;
|
|
}
|
|
|
|
if (!class_exists($this->getFormNamespace().$formNew)) {
|
|
$this->modelNotFoundAdminException($this->getFormNamespace().$formNew);
|
|
}
|
|
|
|
$this->formNew = $this->getFormNamespace().$formNew;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getFormNew()
|
|
{
|
|
return $this->formNew;
|
|
}
|
|
|
|
public function setFormFilter($formFilter, $useDefaultNamespace = true)
|
|
{
|
|
if (!$useDefaultNamespace) {
|
|
$this->formFilter = $formFilter;
|
|
|
|
return $this;
|
|
}
|
|
|
|
if (!class_exists($this->getFilterNamespace().$formFilter)) {
|
|
$this->modelNotFoundAdminException($this->getFilterNamespace().$formFilter);
|
|
}
|
|
|
|
$this->formFilter = $this->getFilterNamespace().$formFilter;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getFormFilter()
|
|
{
|
|
return $this->formFilter;
|
|
}
|
|
|
|
public function setEditTitle($editTitle)
|
|
{
|
|
$this->editTitle = $editTitle;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function setListTitle($listTitle)
|
|
{
|
|
$this->listTitle = $listTitle;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function setNewTitle($newTitle)
|
|
{
|
|
$this->newTitle = $newTitle;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getEditTitle($object)
|
|
{
|
|
return $this->editTitle;
|
|
}
|
|
|
|
public function getListTitle()
|
|
{
|
|
return $this->listTitle;
|
|
}
|
|
|
|
public function getNewTitle()
|
|
{
|
|
return $this->newTitle;
|
|
}
|
|
|
|
public function setFormEditOptions($formEditOptions)
|
|
{
|
|
$this->formEditOptions = $formEditOptions;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getFormEditOptions()
|
|
{
|
|
return $this->formEditOptions;
|
|
}
|
|
|
|
public function setFormNewOptions($formNewOptions)
|
|
{
|
|
$this->formNewOptions = $formNewOptions;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getFormNewOptions()
|
|
{
|
|
return $this->formNewOptions;
|
|
}
|
|
|
|
public function setFormFilterOptions($formFilterOptions)
|
|
{
|
|
$this->formFilterOptions = $formFilterOptions;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getFormFilterOptions()
|
|
{
|
|
return $this->formFilterOptions;
|
|
}
|
|
|
|
public function getCopyBatchAction()
|
|
{
|
|
return $this->copyBatchAction;
|
|
}
|
|
|
|
public function getDefaultFieldTemplate()
|
|
{
|
|
return 'TrinityAdminBundle:BaseAdmin:default.html.twig';
|
|
}
|
|
|
|
public function modelNotFoundAdminException($model)
|
|
{
|
|
throw new BaseAdminException\ModelNotFoundAdminException(sprintf('Model "%s" is not found.', $model));
|
|
}
|
|
|
|
public function setStorageNamespace($storageNamespace)
|
|
{
|
|
$this->storageNamespace = $storageNamespace;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getStorageNamespace()
|
|
{
|
|
return $this->storageNamespace;
|
|
}
|
|
|
|
public function setRankable($bool)
|
|
{
|
|
$this->rankable = (bool) $bool;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getRankable()
|
|
{
|
|
return $this->rankable;
|
|
}
|
|
|
|
public function setI18n($i18n, array $cultures)
|
|
{
|
|
$this->i18n = (bool) $i18n;
|
|
$this->i18nCultures = $cultures;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function setI18nCultures(array $cultures)
|
|
{
|
|
$this->i18nCultures = $cultures;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getI18n()
|
|
{
|
|
return $this->i18n;
|
|
}
|
|
|
|
public function getI18nCultures()
|
|
{
|
|
return $this->i18nCultures;
|
|
}
|
|
|
|
public function setCollections(array $collections)
|
|
{
|
|
$this->collections = $collections;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getCollections()
|
|
{
|
|
return $this->collections;
|
|
}
|
|
|
|
public function setHighlighting($highlighting)
|
|
{
|
|
$this->highlighting = $highlighting;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getHighlighting()
|
|
{
|
|
return $this->highlighting;
|
|
}
|
|
}
|