ActionRepository.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace WorkflowBundle\Repository;
  3. use \Doctrine\ORM\EntityRepository;
  4. class ActionRepository extends EntityRepository
  5. {
  6. /**
  7. * @param string $eventName
  8. * @param string $objectClass
  9. *
  10. * @return array
  11. */
  12. public function findAllByEventAndObjectClass($eventName, $objectClass)
  13. {
  14. $qb = $this->createQueryBuilder('Action')
  15. ->andWhere('Action.event LIKE :eventName')
  16. ->setParameter('eventName', "%{$eventName}%")
  17. ->andWhere('Action.objectClass LIKE :objectClass')
  18. ->setParameter('objectClass', str_replace('\\', '\\\\', $objectClass))
  19. ;
  20. return $qb->getQuery()->getResult();
  21. }
  22. /**
  23. * @param string $eventName
  24. * @param string $workflowName
  25. * @param string $eventReference
  26. * @param string $objectClass
  27. *
  28. * @return array
  29. */
  30. public function findAllByEventAndWorkflowName($eventName, $workflowName, $eventReference, $objectClass = null)
  31. {
  32. $qb = $this->createQueryBuilder('Action')
  33. ->andWhere('Action.event LIKE :eventName')
  34. ->setParameter('eventName', "%{$eventName}%")
  35. ->andWhere('Action.workflowName = :workflowName')
  36. ->setParameter('workflowName', $workflowName)
  37. ->andWhere('Action.eventReference = :eventReference')
  38. ->setParameter('eventReference', $eventReference)
  39. ;
  40. if ($objectClass) {
  41. $qb->andWhere('Action.objectClass = :objectClass')
  42. ->setParameter('objectClass', $objectClass);
  43. }
  44. return $qb->getQuery()->getResult();
  45. }
  46. /**
  47. * @param string $workflowName Nombre del workflow
  48. * @param string $event Nombre del event
  49. *
  50. * @return array
  51. */
  52. public function findByWorkflowAndEventRef($workflowName, $event)
  53. {
  54. $actions = $this->createQueryBuilder('Action')
  55. ->andWhere('Action.eventReference = :eventReference')
  56. ->setParameter('eventReference', $eventReference)
  57. ->getQuery()->getResult();
  58. $return = [];
  59. foreach ($actions as $action) {
  60. $workflows = array_map('trim', explode(',', $action->getWorkflowName()));
  61. if (in_array($workflowName, $workflows)) {
  62. $return[] = $action;
  63. }
  64. }
  65. return $return;
  66. }
  67. }