<?php
namespace Cms\WorkflowsBundle\Entity;
use Cms\TenantBundle\Entity\TenantedEntity;
use DateTime;
use Platform\SecurityBundle\Entity\Identity\Account;
use Doctrine\ORM\Mapping as ORM;
/**
* Class WorkflowSubmission
* @package Cms\WorkflowsBundle\Entity
*
* @ORM\Entity(
* repositoryClass = "Cms\WorkflowsBundle\Doctrine\WorkflowSubmissionRepository"
* )
* @ORM\Table(
* name = "cms__workflows_workflow_submission"
* )
*/
class WorkflowSubmission extends TenantedEntity {
const SUBMISSION_STATUSES__UNREADY = 0;
const SUBMISSION_STATUSES__APPROVAL = 1;
const SUBMISSION_STATUSES__APPROVED = 2;
const SUBMISSION_STATUSES__REJECTED = 3;
const SUBMISSION_STATUSES__CANCELLED = 4;
/**
* @var WorkflowContent
*
* @ORM\ManyToOne(
* targetEntity = "Cms\WorkflowsBundle\Entity\WorkflowContent",
* )
* @ORM\JoinColumn(
* name = "content",
* referencedColumnName = "id",
* onDelete = "CASCADE"
* )
*/
protected $content;
/**
* @var Workflow
*
* @ORM\ManyToOne(
* targetEntity = "Cms\WorkflowsBundle\Entity\Workflow",
* )
* @ORM\JoinColumn(
* name = "workflow",
* referencedColumnName = "id",
* onDelete = "CASCADE"
* )
*/
protected $workflow;
/**
* @var Account
*
* @ORM\ManyToOne(
* targetEntity = "Platform\SecurityBundle\Entity\Identity\Account",
* )
* @ORM\JoinColumn(
* name = "approvedByAccount",
* referencedColumnName = "id",
* onDelete = "CASCADE"
* )
*/
protected $approvedByAccount;
/**
* @var int
*
* @ORM\Column(
* type = "integer",
* nullable = false
* )
*/
protected $currentStage = 1;
/**
* @var int
*
* @ORM\Column(
* type = "integer",
* nullable = false
* )
*/
protected $status = self::SUBMISSION_STATUSES__APPROVAL;
/**
* @var Datetime
*
* @ORM\Column(
* type = "datetime",
* nullable = true
* )
*/
protected $statusChangedDate;
/**
* @var Datetime
*
* @ORM\Column(
* type = "datetime",
* nullable = true
* )
*/
protected $requestedPublicationDate;
/**
* @var Datetime
*
* @ORM\Column(
* type = "datetime",
* nullable = true
* )
*/
protected $approvalDate;
/**
* @param Account $candidate
* @return bool
*/
public function wasCreatedBy($candidate)
{
return $this->createdBy === $candidate;
}
/**
* @return int
*/
public function getCurrentStage() {
return $this->currentStage;
}
/**
* @return Workflow
*/
public function getWorkflow() {
return $this->workflow;
}
public function setWorkflow($workflow) {
$this->workflow = $workflow;
return $this;
}
public function getContent() {
return $this->content;
}
public function setContent($content) {
$this->content = $content;
return $this;
}
/**
* @return DateTime
*/
public function getRequestedPublicationDate()
{
return $this->requestedPublicationDate;
}
/**
* @param DateTime $requestedDate
* @return $this
*/
public function setRequestedPublicationDate($requestedDate) {
$this->requestedPublicationDate = $requestedDate;
return $this;
}
/**
* @param Account $agent
* @return WorkflowSubmission
*/
public function approve($agent)
{
$dated = new DateTime("now");;
$this->status = WorkflowSubmission::SUBMISSION_STATUSES__APPROVED;
$this->statusChangedDate = $dated;
$this->approvalDate = $dated;
$this->approvedByAccount = $agent;
return $this;
}
/**
* @return WorkflowSubmission
*/
public function reject()
{
$dated = new DateTime("now");;
$this->status = WorkflowSubmission::SUBMISSION_STATUSES__REJECTED;
$this->statusChangedDate = $dated;
return $this;
}
/**
* @return WorkflowSubmission
*/
public function cancel()
{
$dated = new DateTime("now");;
$this->status = WorkflowSubmission::SUBMISSION_STATUSES__CANCELLED;
$this->statusChangedDate = $dated;
return $this;
}
public function getStatus()
{
return $this->status;
}
public function incrementStage()
{
$this->currentStage = $this->currentStage + 1;
}
}