Skip to content
This repository has been archived by the owner on Apr 11, 2018. It is now read-only.

Commit

Permalink
[#APOLLO-3238] Case has BusinessRule
Browse files Browse the repository at this point in the history
  • Loading branch information
eddiejaoude committed Jun 19, 2014
1 parent 8020d3b commit f6eb47d
Show file tree
Hide file tree
Showing 4 changed files with 334 additions and 46 deletions.
150 changes: 150 additions & 0 deletions src/Opg/Core/Model/Entity/CaseItem/BusinessRule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
<?php
namespace Opg\Core\Model\Entity\CaseItem;

use Opg\Common\Model\Entity\EntityInterface;
use Opg\Common\Model\Entity\Traits\ExchangeArray;
use Opg\Common\Model\Entity\Traits\ToArray;
use Doctrine\ORM\Mapping as ORM;
use \Zend\InputFilter\InputFilter;
use \Zend\InputFilter\Factory as InputFactory;
use JMS\Serializer\Annotation\Exclude;
use JMS\Serializer\Annotation\ReadOnly;
use JMS\Serializer\Annotation\Type;
use JMS\Serializer\Annotation\Accessor;
use Zend\InputFilter\InputFilterInterface;

/**
* @ORM\Entity
* @ORM\Table(name = "business_rules")
* @ORM\ChangeTrackingPolicy("DEFERRED_EXPLICIT")
* @ORM\entity(repositoryClass="Application\Model\Repository\BusinessRuleRepository")
*
* @package Opg Core
*/
class BusinessRule implements EntityInterface, \IteratorAggregate
{
use \Opg\Common\Model\Entity\Traits\Time;
use \Opg\Common\Model\Entity\Traits\InputFilter;
use \Opg\Common\Model\Entity\Traits\IteratorAggregate;
use ToArray;
use ExchangeArray;

/**
* @ORM\Column(type = "integer", options = {"unsigned": true}) @ORM\GeneratedValue(strategy = "AUTO") @ORM\Id
* @var int $id
*/
protected $id;

/**
* @ORM\Column(type = "string", nullable = true)
* @var string key
*/
protected $key;

/**
* @ORM\Column(type = "string", nullable = true)
* @var string value
*/
protected $value;

/**
* @ORM\ManyToOne(targetEntity="Opg\Core\Model\Entity\PowerOfAttorney\PowerOfAttorney", inversedBy="business_rules")
* @ORM\JoinColumn(name="case_id", referencedColumnName="id")
* @var \Opg\Core\Model\Entity\CaseItem\CaseItem
*/
protected $case;

/**
* @return int
*/
public function getId()
{
return $this->id;
}

/**
* @param int $id
*
* @return BusinessRule
*/
public function setId($id)
{
$this->id = $id;

return $this;
}

/**
* @return \Opg\Common\Model\Entity\Traits\InputFilter|InputFilterInterface
*/
public function getInputFilter()
{
if (!$this->inputFilter) {
$this->inputFilter = new InputFilter();
}

return $this->inputFilter;
}

/**
* @return string
*/
public function getKey()
{
return $this->key;
}

/**
* @param string $key
*
* @return BusinessRule
*/
public function setKey($key)
{
$this->key = $key;

return $this;
}

/**
* @return string
*
* @return BusinessRule
*/
public function getValue()
{
return $this->value;
}

/**
* @param string $value
*
* @return BusinessRule
*/
public function setValue($value)
{
$this->value = $value;

return $this;
}

/**
* @return CaseItem
*/
public function getCase()
{
return $this->case;
}

/**
* @param CaseItem $case
*
* @return BusinessRule
*/
public function setCase(CaseItem $case)
{
$this->case = $case;

return $this;
}
}
123 changes: 77 additions & 46 deletions src/Opg/Core/Model/Entity/CaseItem/CaseItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
use JMS\Serializer\Annotation\Groups;
use JMS\Serializer\Annotation\Type;
use Opg\Common\Model\Entity\DateFormat as OPGDateFormat;
use Opg\Core\Validation\InputFilter\IdentifierFilter;
use Opg\Core\Validation\InputFilter\UidFilter;

/**
* @ORM\MappedSuperclass
Expand All @@ -47,15 +45,15 @@ abstract class CaseItem implements EntityInterface, \IteratorAggregate, CaseItem
use HasCorrespondence;

const APPLICATION_TYPE_CLASSIC = 0;
const APPLICATION_TYPE_ONLINE = 1;
const APPLICATION_TYPE_ONLINE = 1;

/**
* Constants below are for payment types radio buttons, we use 0
* as default
*/
const PAYMENT_OPTION_NOT_SET = 0;
const PAYMENT_OPTION_FALSE = 1;
const PAYMENT_OPTION_TRUE = 2;
const PAYMENT_OPTION_FALSE = 1;
const PAYMENT_OPTION_TRUE = 2;


/**
Expand Down Expand Up @@ -96,7 +94,6 @@ abstract class CaseItem implements EntityInterface, \IteratorAggregate, CaseItem
* @var string
* @Type("string")
* @Serializer\Groups({"api-poa-list","api-task-list"})
* @Accessor(getter="getCaseType", setter="setCaseType")
*/
protected $caseType;

Expand Down Expand Up @@ -216,12 +213,19 @@ abstract class CaseItem implements EntityInterface, \IteratorAggregate, CaseItem
*/
protected $ragTotal;

/**
* @ORM\OneToMany(targetEntity="Opg\Core\Model\Entity\CaseItem\BusinessRule", mappedBy="case_item", cascade={"all"}, fetch="EAGER")
* @var \Opg\Core\Model\Entity\CaseItem\BusinessRule
*/
protected $businessRules;

public function __construct()
{
$this->tasks = new ArrayCollection();
$this->notes = new ArrayCollection();
$this->documents = new ArrayCollection();
$this->caseItems = new ArrayCollection();
$this->tasks = new ArrayCollection();
$this->notes = new ArrayCollection();
$this->documents = new ArrayCollection();
$this->caseItems = new ArrayCollection();
$this->businessRules = new ArrayCollection();
}

/**
Expand Down Expand Up @@ -279,18 +283,15 @@ public function setDueDateString($dueDate)
*/
public function getCaseType()
{
return strtoupper($this->caseType);
return $this->caseType;
}

/**
* @param string $caseType
* @return CaseItem
*/
public function setCaseType($caseType)
{
$this->caseType = strtoupper($caseType);

return $this;
$this->caseType = $caseType;
}

/**
Expand All @@ -303,13 +304,10 @@ public function getCaseSubtype()

/**
* @param string $caseSubtype
* @return CaseItem
*/
public function setCaseSubtype($caseSubtype)
{
$this->caseSubtype = $caseSubtype;

return $this;
}

/**
Expand All @@ -330,13 +328,10 @@ public function getAssignedUser()

/**
* @param string $status
* @return CaseItem
*/
public function setStatus($status)
{
$this->status = $status;

return $this;
}

/**
Expand Down Expand Up @@ -557,22 +552,10 @@ public function addCaseItem(CaseItem $item)
*/
public function getInputFilter()
{
$this->inputFilter = new \Zend\InputFilter\InputFilter();

$caseItemFilter = new CaseItemFilter();
foreach($caseItemFilter->getInputs() as $name=>$input) {
$this->inputFilter->add($input, $name);
if (!$this->inputFilter) {
$this->inputFilter = new CaseItemFilter();
}

$uidFilter = new UidFilter();
foreach($uidFilter->getInputs() as $name=>$input) {
$this->inputFilter->add($input, $name);
}

$idFilter = new IdentifierFilter();
foreach($idFilter->getInputs() as $name=>$input) {
$this->inputFilter->add($input, $name);
}
return $this->inputFilter;
}

Expand Down Expand Up @@ -760,9 +743,9 @@ public function getRagRating()
'3' => 0
);

if(!empty($this->tasks)) {
if (!empty($this->tasks)) {
foreach ($this->tasks as $taskItem) {
if($taskItem->getStatus() !== 'Completed') {
if ($taskItem->getStatus() !== 'Completed') {
$rag[$taskItem->getRagRating()]++;
}
}
Expand All @@ -771,10 +754,10 @@ public function getRagRating()
//Apply rules
if (($rag['3'] >= 1) || $rag['2'] > 2) {
return 3;
}
elseif ($rag['2'] >= 1) {
} elseif ($rag['2'] >= 1) {
return 2;
}

return 1;
}

Expand All @@ -785,9 +768,9 @@ public function getRagTotal()
{
$total = 0;

if(!empty($this->tasks)) {
if (!empty($this->tasks)) {
foreach ($this->filterTasks() as $taskItem) {
if($taskItem->getStatus() !== 'Completed') {
if ($taskItem->getStatus() !== 'Completed') {
$total += $taskItem->getRagRating();
}
}
Expand All @@ -803,21 +786,69 @@ public function filterTasks()
{
$activeTasks = new ArrayCollection();

if(!empty($this->tasks)) {
if (!empty($this->tasks)) {
foreach ($this->tasks as $taskItem) {
if($taskItem->getActiveDate() !== null) {
$now = time();
if ($taskItem->getActiveDate() !== null) {
$now = time();
$taskTime = $taskItem->getActiveDate()->getTimestamp();

if ($now >= $taskTime) {
$activeTasks->add($taskItem);
}
}
else {
} else {
$activeTasks->add($taskItem);
}
}
}

return $activeTasks;
}

/**
* @return ArrayCollection
*/
public function getBusinessRules()
{
return $this->businessRules;
}

/**
* @param ArrayCollection $businessRules
*
* @return CaseItem
*/
public function setBusinessRules(ArrayCollection $businessRules)
{
$this->businessRules = $businessRules;

return $this;
}

/**
* @param BusinessRule $businessRule
*
* @return CaseItem
*/
public function addBusinessRules(BusinessRule $businessRule)
{
$this->businessRules[] = $businessRule;

return $this;
}

/**
* @param string $key
*
* @return BusinessRule|null
*/
public function getBusinessRule($key)
{
foreach ($this->getBusinessRules() as $rule) {
if ($rule->getKey() == $key) {
return $rule;
}
}

return null;
}
}
Loading

0 comments on commit f6eb47d

Please sign in to comment.