瀏覽代碼

Se agrega la entidad Action y se crea el servicio para eventos de Workflow. Se agrega cast string a los métodos __toString()

Maximiliano Schvindt 8 年之前
父節點
當前提交
73400759c8

+ 1 - 1
src/FTTHBundle/Entity/Node.php

@@ -41,7 +41,7 @@ class Node
      */
     public function __toString()
     {
-        return $this->name;
+        return (string) $this->name;
     }
 
     /**

+ 1 - 1
src/FTTHBundle/Entity/OLT.php

@@ -109,7 +109,7 @@ class OLT
      */
     public function __toString()
     {
-        return $this->name;
+        return (string) $this->name;
     }
 
     /**

+ 1 - 1
src/FTTHBundle/Entity/OLTModel.php

@@ -40,7 +40,7 @@ class OLTModel
      */
     public function __toString()
     {
-        return $this->name;
+        return (string) $this->name;
     }
     
     /**

+ 1 - 1
src/FTTHBundle/Entity/ONU.php

@@ -120,7 +120,7 @@ class ONU
      */
     public function __toString()
     {
-        return $this->ponSerialNumber;
+        return (string) $this->ponSerialNumber;
     }
 
     /**

+ 1 - 1
src/FTTHBundle/Entity/ONUModel.php

@@ -46,7 +46,7 @@ class ONUModel
      */
     public function __toString()
     {
-        return $this->name;
+        return (string) $this->name;
     }
     
     /**

+ 1 - 1
src/FTTHBundle/Entity/Profile.php

@@ -56,7 +56,7 @@ class Profile
      */
     public function __toString()
     {
-        return $this->name;
+        return (string) $this->name;
     }
     
     /**

+ 101 - 0
src/WorkflowBundle/Admin/ActionAdmin.php

@@ -0,0 +1,101 @@
+<?php
+
+namespace WorkflowBundle\Admin;
+
+use Base\AdminBundle\Admin\BaseAdmin;
+use Sonata\AdminBundle\Datagrid\DatagridMapper;
+use Sonata\AdminBundle\Datagrid\ListMapper;
+use Sonata\AdminBundle\Form\FormMapper;
+use Sonata\AdminBundle\Show\ShowMapper;
+use Symfony\Component\Yaml\Yaml;
+
+class ActionAdmin extends BaseAdmin
+{
+
+    public function getTemplate($name)
+    {
+        return parent::getTemplate($name);
+    }
+
+    /**
+     * @param DatagridMapper $datagridMapper
+     */
+    protected function configureDatagridFilters(DatagridMapper $datagridMapper)
+    {
+        $datagridMapper
+            ->add('name')
+            ->add('workflowName')
+            ->add('objectClass')
+            ->add('event')
+            ->add('template')
+        ;
+    }
+
+    /**
+     * @param ListMapper $listMapper
+     */
+    protected function configureListFields(ListMapper $listMapper)
+    {
+        $listMapper
+            ->add('name')
+            ->add('workflowName')
+            ->add('objectClass')
+            ->add('event')
+            ->add('eventName')
+            ->add('_action', null, array(
+                'actions' => array(
+                    'show' => array(),
+                    'edit' => array(),
+                    'delete' => array()
+                )
+            ))
+        ;
+    }
+
+    /**
+     * @param FormMapper $formMapper
+     */
+    protected function configureFormFields(FormMapper $formMapper)
+    {
+
+        $formMapper
+            ->add('name')
+            ->add('workflowName')
+            ->add('objectClass')
+            ->add('event')
+            ->add('eventName')
+            ->add('template')
+            // ->add('type', 'choice', array('choices' => array('state_machine' => 'state_machine', 'workflow' => 'workflow')))
+            // ->add('markingType', 'choice', array('choices' => array('single_state' => 'single_state', 'multiple_state' => 'multiple_state')))
+            // ->add('markingName', 'choice', array('choices' => array('currentState' => 'currentState')))
+            // ->add('template', null, array('attr' => array('style' => 'height:500px;')))
+
+            ->setHelps(array(
+               'name' => $this->trans("helps.action_label_name"),
+               'actionName' => $this->trans("helps.action_label_type"),
+               'objectClass' => $this->trans("helps.action_label_marking_type"),
+               'event' => $this->trans("helps.action_label_marking_name"),
+               'eventName' => $this->trans("helps.action_label_marking_name"),
+               'template' => $this->trans("helps.action_label_marking_name"),
+
+            ))
+            ;
+    }
+
+    /**
+     * @param ShowMapper $showMapper
+     */
+    protected function configureShowFields(ShowMapper $showMapper)
+    {
+        $showMapper
+            ->add('id')
+            ->add('name')
+            // ->add('description')
+            // ->add('enable')
+            // ->add('created')
+            // ->add('updated')
+            // ->add('template','string', array('template' => 'WorkflowBundle:Workflow:show_template.html.twig'))
+        ;
+    }
+
+}

+ 124 - 27
src/WorkflowBundle/Entity/Action.php

@@ -23,30 +23,51 @@ class Action
     /**
      * @var string
      *
-     * @ORM\Column(type="string", length=255)
+     * @ORM\Column(type="string", length=255, nullable=false)
      */
-    private $name;
+    protected $name;
 
     /**
-     * @var Workflow
-     * 
-     * @ORM\ManyToOne(targetEntity="Workflow", inversedBy="actions", fetch="EXTRA_LAZY")
+     * @var string
+     *
+     * @ORM\Column(type="string", length=255, nullable=false)
      */
-    private $workflow;
+    protected $workflowName;
 
     /**
      * @var string
      *
-     * @ORM\Column(type="string", length=255)
+     * @ORM\Column(type="string", length=255, nullable=false)
      */
-    private $event;
+    protected $objectClass;
+    
+    /**
+     * @var string
+     *
+     * @ORM\Column(type="string", length=255, nullable=false)
+     */
+    protected $event;
 
     /**
      * @var string
      *
-     * @ORM\Column(type="string", length=255)
+     * @ORM\Column(type="string", length=255, nullable=false)
+     */
+    protected $eventName;
+
+    /**
+     * @var text
+     *
+     * @ORM\Column(type="text", nullable=false)
      */
-    private $template;
+    protected $template;
+
+    /**
+     * @var int
+     *
+     * @ORM\Column(type="integer", nullable=false, options={"default":1})
+     */
+    protected $tenancyId = 1;
 
     
     /**
@@ -54,7 +75,7 @@ class Action
      */
     public function __toString()
     {
-        return $this->name;
+        return (string) $this->name;
     }
 
     /**
@@ -86,63 +107,139 @@ class Action
     }
 
     /**
-     * @param Workflow $workflow
+     * @param string $event
      *
      * @return Action
      */
-    public function setWorkflow($workflow)
+    public function setEvent($event)
     {
-        $this->workflow = $workflow;
+        $this->event = $event;
 
         return $this;
     }
 
     /**
-     * @return Workflow
+     * @return string
      */
-    public function getWorkflow()
+    public function getEvent()
     {
-        return $this->workflow;
+        return $this->event;
     }
 
     /**
-     * @param string $event
+     * @param text $template
      *
      * @return Action
      */
-    public function setEvent($event)
+    public function setTemplate($template)
     {
-        $this->event = $event;
+        $this->template = $template;
 
         return $this;
     }
 
     /**
+     * @return text
+     */
+    public function getTemplate()
+    {
+        return $this->template;
+    }
+
+
+    /**
+     * Set workflowName
+     *
+     * @param string $workflowName
+     *
+     * @return Action
+     */
+    public function setWorkflowName($workflowName)
+    {
+        $this->workflowName = $workflowName;
+
+        return $this;
+    }
+
+    /**
+     * Get workflowName
+     *
      * @return string
      */
-    public function getEvent()
+    public function getWorkflowName()
     {
-        return $this->event;
+        return $this->workflowName;
     }
 
     /**
-     * @param string $template
+     * Set objectClass
+     *
+     * @param string $objectClass
      *
      * @return Action
      */
-    public function setTemplate($template)
+    public function setObjectClass($objectClass)
     {
-        $this->template = $template;
+        $this->objectClass = $objectClass;
 
         return $this;
     }
 
     /**
+     * Get objectClass
+     *
      * @return string
      */
-    public function getTemplate()
+    public function getObjectClass()
     {
-        return $this->template;
+        return $this->objectClass;
     }
 
+    /**
+     * Set eventName
+     *
+     * @param string $eventName
+     *
+     * @return Action
+     */
+    public function setEventName($eventName)
+    {
+        $this->eventName = $eventName;
+
+        return $this;
+    }
+
+    /**
+     * Get eventName
+     *
+     * @return string
+     */
+    public function getEventName()
+    {
+        return $this->eventName;
+    }
+
+    /**
+     * Set tenancyId
+     *
+     * @param integer $tenancyId
+     *
+     * @return Action
+     */
+    public function setTenancyId($tenancyId)
+    {
+        $this->tenancyId = $tenancyId;
+
+        return $this;
+    }
+
+    /**
+     * Get tenancyId
+     *
+     * @return integer
+     */
+    public function getTenancyId()
+    {
+        return $this->tenancyId;
+    }
 }

+ 2 - 2
src/WorkflowBundle/Entity/Workflow.php

@@ -107,7 +107,7 @@ class Workflow
     
     public function __construct()
     {
-        $this->actions = new \Doctrine\Common\Collections\ArrayCollection();
+        //$this->actions = new \Doctrine\Common\Collections\ArrayCollection();
     }
 
     /**
@@ -115,7 +115,7 @@ class Workflow
      */
     public function __toString()
     {
-        return $this->name;
+        return (string) $this->name;
     }
     
     /**

+ 62 - 0
src/WorkflowBundle/Event/EventSubscriber.php

@@ -0,0 +1,62 @@
+<?php
+
+namespace WorkflowBundle\Event;
+
+use Symfony\Component\EventDispatcher\EventSubscriberInterface;
+use Symfony\Component\Workflow\Event\Event;
+use Symfony\Component\Workflow\Event\GuardEvent;
+use Symfony\Component\DependencyInjection\ContainerInterface;
+
+# Ayuda:
+# http://blog.eleven-labs.com/en/symfony-workflow-component/
+# https://github.com/lexik/LexikWorkflowBundle
+# https://github.com/fduch/workflow-bundle
+
+
+class EventSubscriber implements EventSubscriberInterface
+{
+
+    private $container;
+
+    /**
+     * @param ContainerInterface $container
+     */
+    public function __construct(ContainerInterface $container)
+    {
+        $this->container = $container;
+    }
+
+    public static function getSubscribedEvents()
+    {
+        return array(
+                'workflow.transition' => array('transition'),
+                'workflow.enter' => array('enter'),
+                'workflow.leave' => array('leave'),
+                'workflow.guard' => array('guard')
+        );
+    }
+
+    public function transition(Event $event)
+    {
+        
+
+    }
+    
+    public function leave(Event $event)
+    {
+
+
+    }
+
+    public function enter(Event $event)
+    {
+
+        
+    }
+    
+    public function guard(GuardEvent $event)
+    {
+       //$event->setBlocked(true);
+    }
+    
+}

+ 8 - 1
src/WorkflowBundle/Resources/config/services.yml

@@ -1,11 +1,18 @@
 services:
-    workflow.admin.onu:
+    workflow.admin.workflow:
         class: WorkflowBundle\Admin\WorkflowAdmin
         arguments: [~, WorkflowBundle\Entity\Workflow, SonataAdminBundle:CRUD]
         tags:
             - { name: sonata.admin, manager_type: orm, group: Workflow, label: Workflow, label_catalogue: WorkflowBundle, label_translator_strategy: sonata.admin.label.strategy.underscore }
         calls:    
             - [setTranslationDomain, [WorkflowBundle]]
+    workflow.admin.action:
+        class: WorkflowBundle\Admin\ActionAdmin
+        arguments: [~, WorkflowBundle\Entity\Action, SonataAdminBundle:CRUD]
+        tags:
+            - { name: sonata.admin, manager_type: orm, group: Workflow, label: Action, label_catalogue: WorkflowBundle, label_translator_strategy: sonata.admin.label.strategy.underscore }
+        calls:    
+            - [setTranslationDomain, [WorkflowBundle]]
     workflow.event.subscriber:
         class: WorkflowBundle\Event\EventSubscriber
         tags: