浏览代码

fix repository

Guillermo Espinoza 8 年之前
父节点
当前提交
521e90e501

+ 10 - 10
src/WorkflowBundle/Admin/Doctrine2WorkFlowActionAdmin.php

@@ -9,7 +9,7 @@ use Sonata\AdminBundle\Form\FormMapper;
 use Sonata\AdminBundle\Show\ShowMapper;
 use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
 use \WorkflowBundle\Utils\DoctrineEvents;
-use \WorkflowBundle\Utils\WorkFlowEntities;
+use \WorkflowBundle\Utils\WorkFlowEntityClasses;
 
 class Doctrine2WorkFlowActionAdmin extends BaseAdmin
 {
@@ -21,8 +21,8 @@ class Doctrine2WorkFlowActionAdmin extends BaseAdmin
     {
         $datagridMapper
             ->add('name')
-            ->add('event')
-            ->add('entity')
+            ->add('eventName')
+            ->add('entityClass')
         ;
     }
 
@@ -33,8 +33,8 @@ class Doctrine2WorkFlowActionAdmin extends BaseAdmin
     {
         $listMapper
             ->add('name')
-            ->add('event')
-            ->add('entity')
+            ->add('eventName')
+            ->add('entityClass')
             ->add('actions')
             ->add('_action', null, array(
                 'actions' => array(
@@ -53,11 +53,11 @@ class Doctrine2WorkFlowActionAdmin extends BaseAdmin
     {
         $formMapper
             ->add('name')
-            ->add('event', ChoiceType::class, array(
+            ->add('eventName', ChoiceType::class, array(
                 'choices' => DoctrineEvents::getChoices(),
             ))
-            ->add('entity', ChoiceType::class, array(
-                'choices' => WorkFlowEntities::getChoices(),
+            ->add('entityClass', ChoiceType::class, array(
+                'choices' => WorkFlowEntityClasses::getChoices(),
             ))
             ->add('actions', null, array(
                 'multiple' => true,
@@ -74,8 +74,8 @@ class Doctrine2WorkFlowActionAdmin extends BaseAdmin
     {
         $showMapper
             ->add('name')
-            ->add('event')
-            ->add('entity')
+            ->add('eventName')
+            ->add('entityClass')
             ->add('actions')
         ;
     }

+ 13 - 13
src/WorkflowBundle/Entity/Doctrine2WorkFlowAction.php

@@ -33,14 +33,14 @@ class Doctrine2WorkFlowAction
      * 
      * @ORM\Column(type="string", length=255) 
      */
-    protected $event;
+    protected $eventName;
 
     /**
      * @var string
      * 
      * @ORM\Column(type="string", length=255) 
      */
-    protected $entity;
+    protected $entityClass;
     
     /**
      * @var ArrayCollection
@@ -55,7 +55,7 @@ class Doctrine2WorkFlowAction
      */
     public function __toString()
     {
-        return $this->name;
+        return (string) $this->name;
     }
 
     public function __construct()
@@ -96,19 +96,19 @@ class Doctrine2WorkFlowAction
     /**
      * @return string
      */
-    public function getEvent()
+    public function getEventName()
     {
-        return $this->event;
+        return $this->eventName;
     }
 
     /**
-     * @param string $event
+     * @param string $eventName
      * 
      * @return $this
      */
-    public function setEvent($event)
+    public function setEventName($eventName)
     {
-        $this->event = $event;
+        $this->eventName = $eventName;
 
         return $this;
     }
@@ -116,19 +116,19 @@ class Doctrine2WorkFlowAction
     /**
      * @return string
      */
-    public function getEntity()
+    public function getEntityClass()
     {
-        return $this->entity;
+        return $this->entityClass;
     }
 
     /**
-     * @param string $entity
+     * @param string $entityClass
      * 
      * @return $this
      */
-    public function setEntity($entity)
+    public function setEntityClass($entityClass)
     {
-        $this->entity = $entity;
+        $this->entityClass = $entityClass;
         
         return $this;
     }

+ 5 - 2
src/WorkflowBundle/EventListener/DoctrineEventSubscriber.php

@@ -68,11 +68,14 @@ class DoctrineEventSubscriber implements EventSubscriber
     /**
      * @param LifecycleEventArgs $args
      */
-    public function execute(LifecycleEventArgs $args)
+    public function execute(LifecycleEventArgs $args, $eventName = 'prePersist')
     {
         $entity = $args->getEntity();
         $entityManager = $args->getEntityManager();
-        $class = get_class($entity);
+        $entityClass = get_class($entity);
+        
+        $doctrine2WorkFlowActionRepository = $entityManager->getRepository('WorkflowBundle:Doctrine2WorkFlowAction');
+        $doctrine2WorkFlowActions = $doctrine2WorkFlowActionRepository->findAllByEventAndEntityClass($eventName, $entityClass);
     }
 
 }

+ 5 - 5
src/WorkflowBundle/Repository/Doctrine2WorkFlowActionRepository.php

@@ -17,21 +17,21 @@ class Doctrine2WorkFlowActionRepository extends EntityRepository
         $qb = $this->createQueryBuilder('Doctrine2WorkFlowAction');
 
         foreach ($criteria as $field => $value) {
-            $qb->andWhere("{$field} = :{$field}")->setParameter($field, $value);
+            $qb->andWhere("Doctrine2WorkFlowAction.{$field} = :{$field}")->setParameter($field, $value);
         }
 
         return $qb->getQuery()->getResult();
     }
 
     /**
-     * @param string $event
-     * @param string $entity
+     * @param string $eventName
+     * @param string $entityClass
      * 
      * @return array
      */
-    public function findAllByEventAndEntity($event, $entity)
+    public function findAllByEventAndEntityClass($eventName, $entityClass)
     {
-        return $this->findAllBy(compact('event', 'entity'));
+        return $this->findAllBy(compact('eventName', 'entityClass'));
     }
 
 }

+ 8 - 4
src/WorkflowBundle/Resources/translations/WorkflowBundle.es.yml

@@ -8,8 +8,9 @@ filter:
     label_updated: Actualizado
     label_enable : Habilitado
     label_event: Evento
+    label_event_name: Evento
     label_actions: Actions
-    label_entity: Entidad
+    label_entity_class: Entidad
 breadcrumb:
     link_workflow_list: Listado Workflows
     link_workflow_create: Crear Workflow
@@ -30,8 +31,9 @@ form:
     label_marking_type : Tipo de marcador
     label_marking_name : Nombre de marcador
     label_event: Evento
+    label_event_name: Evento
     label_actions: Actions
-    label_entity: Entidad
+    label_entity_class: Entidad
 list:
     label_id: Id
     label_name: Nombre
@@ -45,8 +47,9 @@ list:
     label_marking_type : Tipo de marcador
     label_marking_name : Nombre de marcador
     label_event: Evento
+    label_event_name: Evento
     label_actions: Actions
-    label_entity: Entidad
+    label_entity_class: Entidad
 show:
     label_id: Id
     label_name: Nombre
@@ -60,8 +63,9 @@ show:
     label_marking_type : Tipo de marcador
     label_marking_name : Nombre de marcador
     label_event: Evento
+    label_event_name: Evento
     label_actions: Actions
-    label_entity: Entidad
+    label_entity_class: Entidad
 helps:
     workflow_label_name: Nombre con el que se identificará el workflow. Se convertirá a minúscula y los espacios se reemplazarán por "_"
     workflow_label_type: "Tipo de Workflow: state_machine o workflow"

+ 1 - 1
src/WorkflowBundle/Utils/WorkFlowEntities.php

@@ -8,7 +8,7 @@ namespace WorkflowBundle\Utils;
  * const <NOMBRE_CONSTANTE> = '<Namespace\Entidad>';
  */
 
-class WorkFlowEntities
+class WorkFlowEntityClasses
 {
 
     use ChoiceTrait;