src/Cms/WorkflowsBundle/Entity/WorkflowSubmission.php line 19

Open in your IDE?
  1. <?php
  2. namespace Cms\WorkflowsBundle\Entity;
  3. use Cms\TenantBundle\Entity\TenantedEntity;
  4. use DateTime;
  5. use Platform\SecurityBundle\Entity\Identity\Account;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * Class WorkflowSubmission
  9.  * @package Cms\WorkflowsBundle\Entity
  10.  *
  11.  * @ORM\Entity(
  12.  *     repositoryClass = "Cms\WorkflowsBundle\Doctrine\WorkflowSubmissionRepository"
  13.  * )
  14.  * @ORM\Table(
  15.  *     name = "cms__workflows_workflow_submission"
  16.  * )
  17.  */
  18. class WorkflowSubmission extends TenantedEntity {
  19.     const SUBMISSION_STATUSES__UNREADY 0;
  20.     const SUBMISSION_STATUSES__APPROVAL 1;
  21.     const SUBMISSION_STATUSES__APPROVED 2;
  22.     const SUBMISSION_STATUSES__REJECTED 3;
  23.     const SUBMISSION_STATUSES__CANCELLED 4;
  24.     /**
  25.      * @var WorkflowContent
  26.      *
  27.      * @ORM\ManyToOne(
  28.      *     targetEntity = "Cms\WorkflowsBundle\Entity\WorkflowContent",
  29.      * )
  30.      * @ORM\JoinColumn(
  31.      *     name = "content",
  32.      *     referencedColumnName = "id",
  33.      *     onDelete = "CASCADE"
  34.      * )
  35.      */
  36.     protected $content;
  37.     /**
  38.      * @var Workflow
  39.      *
  40.      * @ORM\ManyToOne(
  41.      *     targetEntity = "Cms\WorkflowsBundle\Entity\Workflow",
  42.      * )
  43.      * @ORM\JoinColumn(
  44.      *     name = "workflow",
  45.      *     referencedColumnName = "id",
  46.      *     onDelete = "CASCADE"
  47.      * )
  48.      */
  49.     protected $workflow;
  50.     /**
  51.      * @var Account
  52.      *
  53.      * @ORM\ManyToOne(
  54.      *     targetEntity = "Platform\SecurityBundle\Entity\Identity\Account",
  55.      * )
  56.      * @ORM\JoinColumn(
  57.      *     name = "approvedByAccount",
  58.      *     referencedColumnName = "id",
  59.      *     onDelete = "CASCADE"
  60.      * )
  61.      */
  62.     protected $approvedByAccount;
  63.     /**
  64.      * @var int
  65.      *
  66.      * @ORM\Column(
  67.      *     type = "integer",
  68.      *     nullable = false
  69.      * )
  70.      */
  71.     protected $currentStage 1;
  72.     /**
  73.      * @var int
  74.      *
  75.      * @ORM\Column(
  76.      *     type = "integer",
  77.      *     nullable = false
  78.      * )
  79.      */
  80.     protected $status self::SUBMISSION_STATUSES__APPROVAL;
  81.     /**
  82.      * @var Datetime
  83.      *
  84.      * @ORM\Column(
  85.      *     type = "datetime",
  86.      *     nullable = true
  87.      * )
  88.      */
  89.     protected $statusChangedDate;
  90.     /**
  91.      * @var Datetime
  92.      *
  93.      * @ORM\Column(
  94.      *     type = "datetime",
  95.      *     nullable = true
  96.      * )
  97.      */
  98.     protected $requestedPublicationDate;
  99.     /**
  100.      * @var Datetime
  101.      *
  102.      * @ORM\Column(
  103.      *     type = "datetime",
  104.      *     nullable = true
  105.      * )
  106.      */
  107.     protected $approvalDate;
  108.     /**
  109.      * @param Account $candidate
  110.      * @return bool
  111.      */
  112.     public function wasCreatedBy($candidate)
  113.     {
  114.         return $this->createdBy === $candidate;
  115.     }
  116.     /**
  117.      * @return int
  118.      */
  119.     public function getCurrentStage() {
  120.         return $this->currentStage;
  121.     }
  122.     /**
  123.      * @return Workflow
  124.      */
  125.     public function getWorkflow() {
  126.         return $this->workflow;
  127.     }
  128.     public function setWorkflow($workflow) {
  129.         $this->workflow $workflow;
  130.         return $this;
  131.     }
  132.     public function getContent() {
  133.         return $this->content;
  134.     }
  135.     public function setContent($content) {
  136.         $this->content $content;
  137.         return $this;
  138.     }
  139.     /**
  140.      * @return DateTime
  141.      */
  142.     public function getRequestedPublicationDate()
  143.     {
  144.         return $this->requestedPublicationDate;
  145.     }
  146.     /**
  147.      * @param DateTime $requestedDate
  148.      * @return $this
  149.      */
  150.     public function setRequestedPublicationDate($requestedDate) {
  151.         $this->requestedPublicationDate $requestedDate;
  152.         return $this;
  153.     }
  154.     /**
  155.      * @param Account $agent
  156.      * @return WorkflowSubmission
  157.      */
  158.     public function approve($agent)
  159.     {
  160.         $dated = new DateTime("now");;
  161.         $this->status WorkflowSubmission::SUBMISSION_STATUSES__APPROVED;
  162.         $this->statusChangedDate $dated;
  163.         $this->approvalDate $dated;
  164.         $this->approvedByAccount $agent;
  165.         return $this;
  166.     }
  167.     /**
  168.      * @return WorkflowSubmission
  169.      */
  170.     public function reject()
  171.     {
  172.         $dated = new DateTime("now");;
  173.         $this->status WorkflowSubmission::SUBMISSION_STATUSES__REJECTED;
  174.         $this->statusChangedDate $dated;
  175.         return $this;
  176.     }
  177.     /**
  178.      * @return WorkflowSubmission
  179.      */
  180.     public function cancel()
  181.     {
  182.         $dated = new DateTime("now");;
  183.         $this->status WorkflowSubmission::SUBMISSION_STATUSES__CANCELLED;
  184.         $this->statusChangedDate $dated;
  185.         return $this;
  186.     }
  187.     public function getStatus()
  188.     {
  189.         return $this->status;
  190.     }
  191.     public function incrementStage()
  192.     {
  193.         $this->currentStage $this->currentStage 1;
  194.     }
  195. }