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

Commit

Permalink
[APOLLO-2953] - Added completed date to domain model
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyquinton committed Jun 17, 2014
1 parent 0a92a31 commit 4826524
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 0 deletions.
71 changes: 71 additions & 0 deletions src/Opg/Core/Model/Entity/CaseItem/Task/Task.php
Expand Up @@ -31,6 +31,9 @@
*/
class Task implements EntityInterface, \IteratorAggregate, HasRagRating
{

const STATUS_COMPLETED = 'completed';

use \Opg\Common\Model\Entity\Traits\Time;
use \Opg\Common\Model\Entity\Traits\InputFilter;
use ToArray;
Expand Down Expand Up @@ -109,6 +112,14 @@ class Task implements EntityInterface, \IteratorAggregate, HasRagRating
*/
protected $description;

/**
* @ORM\Column(type="datetime", nullable=true)
* @var \DateTime
* @Type("string")
* @Accessor(getter="getCompletedDateString",setter="setCompletedDateString")
*/
protected $completedDate;

/**
* Non persistable entity, used for validation of create
*
Expand Down Expand Up @@ -339,6 +350,9 @@ public function setAssignedUser(User $assignedUser = null)
public function setStatus($status)
{
$this->status = $status;
if((strtolower($this->status)) == self::STATUS_COMPLETED) {
$this->setCompletedDate(new \DateTime());
}

return $this;
}
Expand Down Expand Up @@ -500,6 +514,10 @@ public function exchangeArray(array $data)
$this->setActiveDate($data['activeDate']);
}

if (!empty($data['completedDate'])) {
$this->setCompletedDate($data['completedDate']);
}

if (!empty($data['priority'])) {
$this->setPriority($data['priority']);
}
Expand Down Expand Up @@ -627,4 +645,57 @@ public function getSystemType()
{
return $this->systemType;
}

/**
* @param \DateTime $completedDate
*
* @return $this
*/
public function setCompletedDate(\DateTime $completedDate = null)
{
if (is_null($completedDate)) {
$completedDate = new \DateTime();
}
$this->completedDate = $completedDate;

return $this;
}

/**
* @param string $completedDate
*
* @return $this
*/
public function setCompletedDateString($completedDate)
{
if (!empty($completedDate)) {
$completedDate = OPGDateFormat::createDateTime($completedDate);

if ($completedDate) {
return $this->setCompletedDate($completedDate);
}
}
return $this->setCompletedDate(new \DateTime());
}

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

/**
* @return string
*/
public function getCompletedDateString()
{
if (!empty($this->completedDate)) {
return $this->completedDate->format(OPGDateFormat::getDateTimeFormat());
}

return '';
}

}
45 changes: 45 additions & 0 deletions tests/OpgTest/Core/Model/Entity/CaseItem/Task/TaskTest.php
Expand Up @@ -44,6 +44,7 @@ protected function setUp()
$this->data['createdTime'] = new \DateTime();
$this->data['dueDate'] = new \DateTime();
$this->data['activeDate'] = new \DateTime();
$this->data['completedDate'] = new \DateTime();
$this->task = new Task();
}

Expand Down Expand Up @@ -414,4 +415,48 @@ public function testGetRagRatingError()
{
$this->assertEquals(3, $this->task->getRagRating());
}

public function testGetSetCompletedDateNulls()
{
$expectedDate = new \DateTime();
$this->assertEmpty($this->task->getCompletedDate());
$this->task->setCompletedDate();
$this->assertEquals(
$expectedDate->format(OPGDateFormat::getDateTimeFormat()),
$this->task->getCompletedDate()->format(OPGDateFormat::getDateTimeFormat())
);
}

public function testGetSetCompletedDateString()
{
$expected = date(OPGDateFormat::getDateTimeFormat());
$this->task->setCompletedDateString($expected);
$this->assertEquals($expected, $this->task->getCompletedDateString());
}


public function testGetSetCompletedDateEmptyString()
{
$expectedDate = new \DateTime();
$this->task->setCompletedDateString(null);
$returnedDate = $this->task->getCompletedDate();

$this->assertEquals(
$expectedDate->format(OPGDateFormat::getDateTimeFormat()),
$returnedDate->format(OPGDateFormat::getDateTimeFormat())
);
}

public function testSetCompletedDateIsSetWhenCaseStatusSetToCompleted()
{
$this->task->setStatus('completed');
$this->assertNotEmpty($this->task->getCompletedDate());
$this->assertEquals($this->task->getCompletedDate(), new \DateTime());
}

public function testClassConstantsExist()
{
$this->assertEquals(task::STATUS_COMPLETED,'completed');
}

}

0 comments on commit 4826524

Please sign in to comment.