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

Commit

Permalink
[APOLLO-2316] - merging master
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyquinton committed May 15, 2014
2 parents 06b9ca6 + e348087 commit 7125f25
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 12 deletions.
2 changes: 1 addition & 1 deletion build/build.xml
Expand Up @@ -2,7 +2,7 @@

<project name="opg-core-back-end" default="build">

<target name="build" depends="clean,prepare,lint,phpunit,phpmd-ci,phpcs-ci,phpcpd,phpcb"/>
<target name="build" depends="clean,prepare,phpunit,phpmd-ci,phpcs-ci,phpcpd,phpcb,phpdocs"/>

<target name="clean">
<delete dir="${basedir}/output"/>
Expand Down
10 changes: 10 additions & 0 deletions src/Opg/Common/Model/Entity/DateFormat.php
Expand Up @@ -15,6 +15,7 @@ final class DateFormat

const REGEXP_DATE_TIME = '/^[0-9]{1,2}\/[0-9]{1,2}\/[0-9]{4} [0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}$/';

const REGEXP_MYSQL_DATE_TIME = '/[0-9]{4}-[0-9]{1,2}-[0-9]{1,2} [0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}$/';
/**
* @var string
*/
Expand All @@ -25,6 +26,11 @@ final class DateFormat
*/
protected static $DateTimeFormat = 'd/m/Y H:i:s';

/**
* @var string
*/
protected static $DateTimeMysqlExport = 'Y-d-m H:i:s';

/**
* @return string
*/
Expand Down Expand Up @@ -57,6 +63,10 @@ public static function createDateTime($strDateTime)
return \DateTime::createFromFormat(self::getDateTimeFormat(), $strDateTime);
}

if (preg_match(self::REGEXP_MYSQL_DATE_TIME, trim($strDateTime))) {
return \DateTime::createFromFormat(self::$DateTimeMysqlExport, $strDateTime);
}

throw new InvalidDateFormatException(
"'{$strDateTime}' was not in the expected format " . self::getDateTimeFormat()
);
Expand Down
12 changes: 12 additions & 0 deletions src/Opg/Common/Model/Entity/HasRagRating.php
@@ -0,0 +1,12 @@
<?php

namespace Opg\Common\Model\Entity;


interface HasRagRating
{
/**
* @return int
*/
public function getRagRating();
}
59 changes: 58 additions & 1 deletion src/Opg/Core/Model/Entity/CaseItem/CaseItem.php
Expand Up @@ -7,6 +7,7 @@
use Opg\Common\Model\Entity\EntityInterface;
use Opg\Common\Model\Entity\HasNotesInterface;
use Opg\Common\Model\Entity\HasCorrespondenceInterface;
use Opg\Common\Model\Entity\HasRagRating;
use Opg\Common\Model\Entity\HasUidInterface;
use Opg\Common\Model\Entity\Traits\ExchangeArray;
use Opg\Common\Model\Entity\Traits\InputFilter;
Expand All @@ -32,7 +33,8 @@
* @ORM\MappedSuperclass
* @package Opg\Core\Model\Entity\CaseItem
*/
abstract class CaseItem implements EntityInterface, \IteratorAggregate, CaseItemInterface, HasUidInterface, HasNotesInterface, HasCorrespondenceInterface
abstract class CaseItem implements EntityInterface, \IteratorAggregate, CaseItemInterface, HasUidInterface,
HasNotesInterface, HasCorrespondenceInterface, HasRagRating
{
use ToArray;
use HasNotes;
Expand Down Expand Up @@ -196,6 +198,22 @@ abstract class CaseItem implements EntityInterface, \IteratorAggregate, CaseItem
*/
protected $taskStatus = [];

/**
* Non persistable entity
* @var int
* @ReadOnly
* @Accessor(getter="getRagRating")
*/
protected $ragRating;

/**
* Non persistable entity
* @var int
* @ReadOnly
* @Accessor(getter="getRagTotal")
*/
protected $ragTotal;

public function __construct()
{
$this->tasks = new ArrayCollection();
Expand Down Expand Up @@ -707,4 +725,43 @@ public function getRegistrationDateString()

return '';
}

/**
* @return int
*/
public function getRagRating()
{
$rag = array(
'1' => 0,
'2' => 0,
'3' => 0
);

foreach ($this->tasks as $taskItem) {
$rag[$taskItem->getRagRating()]++;
}

//Apply rules
if (($rag['3'] >= 1) || $rag['2'] > 2) {
return 3;
}
elseif ($rag['2'] >= 1) {
return 2;
}
return 1;
}

/**
* @return int
*/
public function getRagTotal()
{
$total = 0;

foreach ($this->tasks as $taskItem) {
$total += $taskItem->getRagRating();
}

return $total;
}
}
37 changes: 34 additions & 3 deletions src/Opg/Core/Model/Entity/CaseItem/Task/Task.php
@@ -1,6 +1,7 @@
<?php
namespace Opg\Core\Model\Entity\CaseItem\Task;

use Opg\Common\Model\Entity\HasRagRating;
use Opg\Common\Model\Entity\Traits\ToArray;
use Opg\Common\Model\Entity\EntityInterface;
use Opg\Core\Model\Entity\User\User;
Expand All @@ -12,6 +13,7 @@
use JMS\Serializer\Annotation\Exclude;
use JMS\Serializer\Annotation\Groups;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\ReadOnly;
use Opg\Common\Model\Entity\DateFormat as OPGDateFormat;

use Opg\Core\Model\Entity\CaseItem\CaseItem;
Expand All @@ -26,7 +28,7 @@
* @author Chris Moreton
*
*/
class Task implements EntityInterface, \IteratorAggregate
class Task implements EntityInterface, \IteratorAggregate, HasRagRating
{
use \Opg\Common\Model\Entity\Traits\Time;
use \Opg\Common\Model\Entity\Traits\InputFilter;
Expand Down Expand Up @@ -89,9 +91,17 @@ class Task implements EntityInterface, \IteratorAggregate
*/
protected $case;

/**
* Non persistable entity
* @var int
* @Groups({"api-poa-list","api-task-list"})
* @ReadOnly
* @Accessor(getter="getRagRating")
*/
protected $ragRating;

public function __construct()
{
$now = new \DateTime();
$this->setCreatedTime();
}

Expand Down Expand Up @@ -150,7 +160,7 @@ public function setDueDateString($dueDate)
}

/**
* @return string $dueDate
* @return \DateTime $dueDate
*/
public function getDueDate()
{
Expand Down Expand Up @@ -430,4 +440,25 @@ public function setCase(CaseItem $case)

return $this;
}

/**
* @return int
*/
public function getRagRating()
{
$dateDiff = $this->getDueDate()->diff(new \DateTime);

$daysOffset = $dateDiff->days;
if($dateDiff->invert == 1) {
$daysOffset *= -1;
}

if ($daysOffset > 0) {
return 3;
}
elseif ($daysOffset < 0) {
return 1;
}
return 2;
}
}
14 changes: 8 additions & 6 deletions tests/OpgTest/Core/Model/Entity/CaseItem/Lpa/LpaTest.php
Expand Up @@ -481,10 +481,10 @@ public function testArrayRecursive()
'attorneyDeclarationSignatoryFullName' => null,
'correspondentComplianceAssertion' => 1,
'certificateProviders' => array(),
'paymentByDebitCreditCard' => false,
'paymentByCheque' => false,
'feeExemptionAppliedFor' => false,
'feeRemissionAppliedFor' => false,
'paymentByDebitCreditCard' => 0,
'paymentByCheque' => 0,
'feeExemptionAppliedFor' => 0,
'feeRemissionAppliedFor' => 0,
'caseAttorneySingular' => false,
'caseAttorneyJointlyAndSeverally' => false,
'caseAttorneyJointly' => false,
Expand All @@ -495,12 +495,14 @@ public function testArrayRecursive()
'applicationType' => 0,
'registrationDate' => null,
'closedDate' => null,
'lifeSustainingTreatment' => false,
'lifeSustainingTreatment' => null,
'lifeSustainingTreatmentSignatureDate' => null,
'notificationDate' => null,
'dispatchDate' => null,
'noticeGivenDate' => null,
'correspondence' => null
'correspondence' => null,
'ragRating' => null,
'ragTotal' => null
),
$lpa->toArrayRecursive()
);
Expand Down
3 changes: 2 additions & 1 deletion tests/OpgTest/Core/Model/Entity/CaseItem/Task/TaskTest.php
Expand Up @@ -27,7 +27,8 @@ class TaskTest extends \PHPUnit_Framework_TestCase
'assignedUser' => null,
'priority' => 'high',
'errorMessages' => array(),
'case' => null
'case' => null,
'ragRating' => null
);

/**
Expand Down

0 comments on commit 7125f25

Please sign in to comment.