Guillermo Espinoza пре 8 година
родитељ
комит
4c19690cb3
3 измењених фајлова са 28 додато и 6 уклоњено
  1. 1 1
      Entity/Action.php
  2. 26 0
      Repository/ActionRepository.php
  3. 1 5
      Services/ProducerService.php

+ 1 - 1
Entity/Action.php

@@ -7,7 +7,7 @@ use Symfony\Component\Validator\Constraints as Assert;
 
 /**
  * @ORM\Table
- * @ORM\Entity
+ * @ORM\Entity(repositoryClass="WorkflowBundle\Repository\ActionRepository")
  */
 class Action
 {

+ 26 - 0
Repository/ActionRepository.php

@@ -0,0 +1,26 @@
+<?php
+
+namespace WorkflowBundle\Repository;
+
+use \Doctrine\ORM\EntityRepository;
+
+class ActionRepository extends EntityRepository
+{
+
+    /**
+     * @param string $eventName
+     * @param string $objectClass
+     * 
+     * @return array
+     */
+    public function findAllByEventAndObjectClass($eventName, $objectClass)
+    {
+        $qb = $this->createQueryBuilder('Action')
+                   ->andWhere('Action.event LIKE :eventName')->setParameter('eventName', "%{$eventName}%")
+                   ->andWhere('Action.objectClass = :objectClass')->setParameter('objectClass', $objectClass)
+                ;
+        
+        return $qb->getQuery()->getResult();
+    }
+
+}

+ 1 - 5
Services/ProducerService.php

@@ -51,11 +51,7 @@ class ProducerService
         // la $entity esta dentro de las entidades con workflow
         if (in_array($entityClass, WorkFlowEntityClasses::getConstants())) {
             $actionRepository = $this->getEntityManager()->getRepository('WorkflowBundle:Action');
-            
-            /* @todo Refactorizar */
-            $actions = $actionRepository->findBy(array(
-                'objectClass' => $entityClass,
-            ));
+            $actions = $actionRepository->findAllByEventAndObjectClass($eventName, $entityClass);
             foreach ($actions as $action) {
                 $this->publishMessage($action, $entity);
             }