Skip to content

Instantly share code, notes, and snippets.

Created September 21, 2012 11:56
Show Gist options
  • Save anonymous/3761072 to your computer and use it in GitHub Desktop.
Save anonymous/3761072 to your computer and use it in GitHub Desktop.
Ejemplo de uso
<?php
namespace Proyecto\AlmazaraBundle\Controller;
// sistema CRUD
use Jcr\SystemBundle\Controller\CrudController;
/**
* FormatoCrudController
*
*/
class FormatoCrudController extends CrudController
{
/**
* Constructor y asignación mínima para el funcionamiento del CRUD
*
*/
public function __construct()
{
// defaults settings
parent::__construct();
$this->userRoles[] = 'ROLE_ALMAZARA';
$this->sessionName = 'crud_panel_almazara_formato';
$this->menuSection = 'auxiliares';
// basic config
$this->title = 'Mantenimiento de Formatos de envases';
$this->entity = 'Proyecto\ComunBundle\Entity\AlmazaraMarcaFormato';
$this->routePrefix = 'panel_almazara_formato';
$this->setOrder('titulo', 'asc');
// solo mis regitros
$this->userIdField = 'almazara';
// codigo unico dentro del formato
$this->setFieldPosition('codigo');
}
/**
* Configuración de las plantillas usadas en las diferentes vistas
*
*/
protected function configureViews()
{
$this->setView('table' ,'AlmazaraBundle:Crud:table_view.html.twig');
$this->setView('record' ,'AlmazaraBundle:Crud:record_view.html.twig');
$this->setView('new' ,'AlmazaraBundle:Crud:new_view.html.twig');
$this->setView('edit' ,'AlmazaraBundle:Crud:edit_view.html.twig');
$this->setView('delete' ,'AlmazaraBundle:Crud:delete_view.html.twig');
}
/**
* Configuramos los campos que se usaran
*
*/
protected function configureFields()
{
// fields
$this->setField(array(
'title' => 'Id',
'name' => 'id',
'type' => 'integer',
'showIn' => array(
'table' => true,
'record' => true,
'order' => true,
'filter' => false,
'new' => false,
'edit' => false,
'delete' => false,
),
'css' => array(
'required' => false,
'class' => 'span2',
'view-table-witdh' => '5%',
),
));
$this->setField(array(
'title' => 'Marca',
'name' => 'almazara_marca',
'type' => 'entity',
'join' => array(
'id' => 'z',
'entity' => 'Proyecto\ComunBundle\Entity\AlmazaraMarca',
'field' => 'titulo',
'alias' => 'almazara_marca_titulo',
'query_builder' => array(
array(
'action' => 'where',
'condition' => '=',
'field' => 'almazara',
'value' => $this->container->get('security.context')->getToken()->getUser()->getId(),
),
),
),
'showIn' => array(
'table' => true,
'record' => true,
'order' => true,
'filter' => true,
'new' => true,
'edit' => true,
'delete' => true,
),
'css' => array(
'required' => false,
'class' => 'span4',
'view-table-witdh' => '40%',
),
));
$this->setField(array(
'title' => 'Nombre',
'name' => 'titulo',
'type' => 'text',
'showIn' => array(
'table' => true,
'record' => true,
'order' => true,
'filter' => true,
'new' => true,
'edit' => true,
'delete' => true,
),
'css' => array(
'required' => true,
'class' => 'span6',
'view-table-witdh' => '',
),
));
$this->setField(array(
'title' => 'Formato',
'name' => 'formato',
'type' => 'text',
'showIn' => array(
'table' => true,
'record' => true,
'order' => true,
'filter' => true,
'new' => true,
'edit' => true,
'delete' => true,
),
'css' => array(
'required' => true,
'class' => 'span4',
'view-table-witdh' => '10%',
),
));
$this->setField(array(
'title' => 'Capacidad',
'name' => 'capacidad',
'type' => 'text',
'showIn' => array(
'table' => true,
'record' => true,
'order' => true,
'filter' => true,
'new' => true,
'edit' => true,
'delete' => true,
),
'css' => array(
'required' => true,
'class' => 'span2',
'view-table-witdh' => '5%',
),
));
$this->setField(array(
'title' => 'Etiqueta',
'name' => 'fichero_etiqueta',
'type' => 'file',
'params' => array(
'type' => 'image',
'folder' => 'formatos',
'width_record_view' => 48,
'width_table_view' => 32,
'msg_edit' => 'Si NO desea cambia la imagen, deje el campo en blanco',
),
'showIn' => array(
'table' => true,
'record' => true,
'order' => false,
'filter' => false,
'new' => true,
'edit' => true,
'delete' => true,
),
'css' => array(
'required' => false,
'class' => 'span6',
'view-table-witdh' => '7%',
),
));
}
/**
* Cuando insertarmos un formato, creamos su contador de etiquetas
*
*/
protected function afterCreate($em, $entity) {
$tabla = 'Proyecto\ComunBundle\Entity\AlmazaraMarcaFormatoContadorEtiqueta';
$contador = new $tabla;
$contador->setAlmazara($entity->getAlmazara());
$contador->setAlmazaraMarca($entity->getAlmazaraMarca());
$contador->setAlmazaraMarcaFormato($entity);
$contador->setContador(1);
$em->persist($contador);
$em->flush();
return array('ok' => true, 'msg' => '');
}
/**
* Cuando borramos un formato, borramos su contador de etiquetas
*
*/
protected function beforeErase($em, $entity, $id) {
$tabla = 'Proyecto\ComunBundle\Entity\AlmazaraMarcaFormatoContadorEtiqueta';
$contador = $em->getRepository($tabla)->findOneBy(array('almazara_marca_formato' => $id));
$em->remove($contador);
$em->flush();
return array('ok' => true, 'msg' => '');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment