602 lines
13 KiB
Plaintext
602 lines
13 KiB
Plaintext
<?php
|
|
|
|
namespace Trinity\Bundle\AdminBundle\Configuration;
|
|
|
|
use Trinity\Bundle\AdminBundle\Exception as BaseAdminException;
|
|
|
|
class CrudConfiguration
|
|
{
|
|
protected $model_namespace = null;
|
|
protected $model = null;
|
|
protected $model_peer = null;
|
|
protected $model_query = null;
|
|
|
|
protected $route_prefix = null;
|
|
|
|
protected $form_namespace = null;
|
|
protected $form_edit = null;
|
|
protected $form_new = null;
|
|
protected $form_filter = null;
|
|
|
|
protected $form_edit_options = array();
|
|
protected $form_new_options = array();
|
|
protected $form_filter_options = array();
|
|
|
|
protected $fields_templates = array();
|
|
protected $fields_helpers = array();
|
|
protected $display_fields = array();
|
|
protected $fieldsets = array();
|
|
protected $fieldsnames = array();
|
|
|
|
protected $filter_display_fields = array();
|
|
protected $filters_methods = array();
|
|
protected $filters_templates = array();
|
|
protected $filter_namespace = null;
|
|
|
|
protected $list_title = null;
|
|
protected $edit_title = null;
|
|
protected $new_title = null;
|
|
|
|
protected $max_per_page = 10;
|
|
protected $current_page = 1;
|
|
protected $sort = null;
|
|
protected $sort_order = \Criteria::ASC;
|
|
|
|
protected $rankable = false;
|
|
|
|
protected $i18n_cultures = array();
|
|
protected $i18n = false;
|
|
|
|
protected $storage_namespace = null;
|
|
|
|
protected $batch_actions = true;
|
|
|
|
protected $collections = array();
|
|
|
|
protected $export = false;
|
|
|
|
protected $index_list_actions = array(
|
|
'edit' => 'TrinityAdminBundle:BaseAdmin:listEdit.html.twig',
|
|
'remove' => 'TrinityAdminBundle:BaseAdmin:listRemove.html.twig',
|
|
);
|
|
|
|
protected $index_actions = array(
|
|
'new' => 'TrinityAdminBundle:BaseAdmin:indexNew.html.twig',
|
|
);
|
|
|
|
public function setExport($export)
|
|
{
|
|
$this->export = (bool) $export;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getExport()
|
|
{
|
|
return $this->export;
|
|
}
|
|
|
|
private function formatNamespace($namespace)
|
|
{
|
|
if (substr($namespace, strlen($namespace)-1) !== '\\') {
|
|
$namespace .= '\\';
|
|
}
|
|
|
|
return $namespace;
|
|
}
|
|
|
|
public function setIndexListAction($action_name, $template = 'TrinityAdminBundle:BaseAdmin:listDefault.html.twig')
|
|
{
|
|
$this->index_list_actions[$action_name] = $template;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function setIndexListActions(array $actions)
|
|
{
|
|
$this->index_list_actions = $actions;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function removeIndexAction($action)
|
|
{
|
|
if (isset($this->index_actions[$action])) {
|
|
unset($this->index_actions[$action]);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function removeIndexListAction($action)
|
|
{
|
|
if (isset($this->index_list_actions[$action])) {
|
|
unset($this->index_list_actions[$action]);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getIndexListActions()
|
|
{
|
|
return $this->index_list_actions;
|
|
}
|
|
|
|
public function getIndexListAction($action)
|
|
{
|
|
return isset($this->index_list_actions[$action]) ? $this->index_list_actions[$action] : null;
|
|
}
|
|
|
|
public function setIndexAction($action_name,$template)
|
|
{
|
|
$this->index_actions[$action_name] = $template;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function setIndexActions(array $actions)
|
|
{
|
|
$this->index_actions = $actions;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getIndexActions()
|
|
{
|
|
return $this->index_actions;
|
|
}
|
|
|
|
public function getIndexAction($action)
|
|
{
|
|
return isset($this->index_actions[$action]) ? $this->index_actions[$action] : null;
|
|
}
|
|
|
|
public function setModelNamespace($model_namespace)
|
|
{
|
|
$this->model_namespace = $this->formatNamespace($model_namespace);
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function setFormNamespace($form_namespace)
|
|
{
|
|
$this->form_namespace = $this->formatNamespace($form_namespace);
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function setFilterNamespace($filter_namespace)
|
|
{
|
|
$this->filter_namespace = $this->formatNamespace($filter_namespace);
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getFiltersTemplates()
|
|
{
|
|
return $this->filters_templates;
|
|
}
|
|
|
|
public function setBatchActions($batch_actions)
|
|
{
|
|
$this->batch_actions = (bool) $batch_actions;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getBatchActions()
|
|
{
|
|
return $this->batch_actions;
|
|
}
|
|
|
|
public function getFilterNamespace()
|
|
{
|
|
return $this->filter_namespace ? $this->filter_namespace : $this->form_namespace;
|
|
}
|
|
|
|
public function setFieldsets(array $fieldsets, array $i18n_fieldsets = array())
|
|
{
|
|
$this->fieldsets = $fieldsets;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getFieldsets()
|
|
{
|
|
return $this->fieldsets;
|
|
}
|
|
|
|
public function getFieldsnames()
|
|
{
|
|
return $this->fieldsnames;
|
|
}
|
|
|
|
public function setFieldname($fieldname, $name)
|
|
{
|
|
$this->fieldsnames[$fieldname] = $name;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function setMaxPerPage($max_per_page)
|
|
{
|
|
if (is_integer($max_per_page)) {
|
|
$this->max_per_page = $max_per_page;
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getMaxPerPage()
|
|
{
|
|
return $this->max_per_page;
|
|
}
|
|
|
|
public function setCurrentPage($current_page)
|
|
{
|
|
$this->current_page = $current_page;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getCurrentPage()
|
|
{
|
|
return $this->current_page;
|
|
}
|
|
|
|
public function setSort($column, $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 = $column;
|
|
$this->sort_order = $order;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getSort()
|
|
{
|
|
return $this->sort;
|
|
}
|
|
|
|
public function getSortOrder()
|
|
{
|
|
return $this->sort_order;
|
|
}
|
|
|
|
public function setDisplayFields(array $display_fields)
|
|
{
|
|
$this->display_fields = $display_fields;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getDisplayFields()
|
|
{
|
|
return $this->display_fields;
|
|
}
|
|
|
|
public function setFilterDisplayFields(array $filter_display_fields)
|
|
{
|
|
$this->filter_display_fields = $filter_display_fields;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getFilterDisplayFields()
|
|
{
|
|
return $this->filter_display_fields;
|
|
}
|
|
|
|
public function setFieldTemplate($field, $template)
|
|
{
|
|
$this->fields_templates[$field] = $template;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function setFilterTemplate($field, $template)
|
|
{
|
|
$this->filters_templates[$field] = $template;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function setFieldHelper($field, $helper)
|
|
{
|
|
$this->fields_helpers[$field] = $helper;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function setFilterMethod($field, $method, $criteria = null, $params = array())
|
|
{
|
|
$this->filters_methods[$field] = array(
|
|
'method' => $method,
|
|
'criteria' => $criteria,
|
|
'params' => $params,
|
|
);
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getFiltersMethods()
|
|
{
|
|
return $this->filters_methods;
|
|
}
|
|
|
|
public function getFieldsTemplates()
|
|
{
|
|
return $this->fields_templates;
|
|
}
|
|
|
|
public function getFieldsHelpers()
|
|
{
|
|
return $this->fields_helpers;
|
|
}
|
|
|
|
public function setModel($model)
|
|
{
|
|
if (!class_exists($this->model_namespace.$model)) {
|
|
$this->modelNotFoundAdminException($this->model_namespace.$model);
|
|
}
|
|
|
|
$this->model = $this->model_namespace.$model;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getModel()
|
|
{
|
|
return $this->model;
|
|
}
|
|
|
|
public function setModelPeer($model_peer)
|
|
{
|
|
if (!class_exists($this->model_namespace.$model_peer)) {
|
|
$this->modelNotFoundAdminException($this->model_namespace.$model_peer);
|
|
}
|
|
|
|
$this->model_peer = $this->model_namespace.$model_peer;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getModelPeer()
|
|
{
|
|
return $this->model_peer;
|
|
}
|
|
|
|
public function setModelQuery($model_query)
|
|
{
|
|
if (!class_exists($this->model_namespace.$model_query)) {
|
|
$this->modelNotFoundAdminException($this->model_namespace.$model_query);
|
|
}
|
|
|
|
$this->model_query = $this->model_namespace.$model_query;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getRoutePrefix()
|
|
{
|
|
if (null === $this->route_prefix) {
|
|
throw new \RuntimeException('You must set the route_prefix in the configuration of your admin bundle.');
|
|
}
|
|
|
|
return $this->route_prefix;
|
|
}
|
|
|
|
public function setRoutePrefix($route_prefix)
|
|
{
|
|
$this->route_prefix = $route_prefix;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getModelQuery()
|
|
{
|
|
return $this->model_query;
|
|
}
|
|
|
|
public function setFormEdit($form_edit)
|
|
{
|
|
if (!class_exists($this->form_namespace.$form_edit)) {
|
|
$this->modelNotFoundAdminException($this->form_namespace.$form_edit);
|
|
}
|
|
|
|
$this->form_edit = $this->form_namespace.$form_edit;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getFormEdit()
|
|
{
|
|
return $this->form_edit;
|
|
}
|
|
|
|
public function setFormNew($form_new)
|
|
{
|
|
if (!class_exists($this->form_namespace.$form_new)) {
|
|
$this->modelNotFoundAdminException($this->form_namespace.$form_new);
|
|
}
|
|
|
|
$this->form_new = $this->form_namespace.$form_new;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getFormNew()
|
|
{
|
|
return $this->form_new;
|
|
}
|
|
|
|
public function setFormFilter($form_filter)
|
|
{
|
|
if (!class_exists($this->getFilterNamespace().$form_filter)) {
|
|
$this->modelNotFoundAdminException($this->getFilterNamespace().$form_filter);
|
|
}
|
|
|
|
$this->form_filter = $this->getFilterNamespace().$form_filter;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getFormFilter()
|
|
{
|
|
return $this->form_filter;
|
|
}
|
|
|
|
public function setEditTitle($edit_title)
|
|
{
|
|
$this->edit_title = $edit_title;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function setListTitle($list_title)
|
|
{
|
|
$this->list_title = $list_title;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function setNewTitle($new_title)
|
|
{
|
|
$this->new_title = $new_title;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getEditTitle($object)
|
|
{
|
|
return $this->edit_title;
|
|
}
|
|
|
|
public function getListTitle()
|
|
{
|
|
return $this->list_title;
|
|
}
|
|
|
|
public function getNewTitle()
|
|
{
|
|
return $this->new_title;
|
|
}
|
|
|
|
public function setFormEditOptions($form_edit_options)
|
|
{
|
|
$this->form_edit_options = $form_edit_options;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getFormEditOptions()
|
|
{
|
|
return $this->form_edit_options;
|
|
}
|
|
|
|
public function setFormNewOptions($form_new_options)
|
|
{
|
|
$this->form_new_options = $form_new_options;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getFormNewOptions()
|
|
{
|
|
return $this->form_new_options;
|
|
}
|
|
|
|
public function setFormFilterOptions($form_filter_options)
|
|
{
|
|
$this->form_filter_options = $form_filter_options;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getFormFilterOptions()
|
|
{
|
|
return $this->form_filter_options;
|
|
}
|
|
|
|
public function getCopyBatchAction()
|
|
{
|
|
return $this->copy_batch_action;
|
|
}
|
|
|
|
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($storage_namespace)
|
|
{
|
|
$this->storage_namespace = $storage_namespace;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getStorageNamespace()
|
|
{
|
|
return $this->storage_namespace;
|
|
}
|
|
|
|
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->i18n_cultures = $cultures;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function setI18nCultures(array $cultures)
|
|
{
|
|
$this->i18n_cultures = $cultures;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getI18n()
|
|
{
|
|
return $this->i18n;
|
|
}
|
|
|
|
public function getI18nCultures()
|
|
{
|
|
return $this->i18n_cultures;
|
|
}
|
|
|
|
public function setCollections(array $collections)
|
|
{
|
|
$this->collections = $collections;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getCollections()
|
|
{
|
|
return $this->collections;
|
|
}
|
|
}
|