Permalink
Browse files

Task constructior has separated parameters now

  • Loading branch information...
AlexKupreev committed Jun 7, 2014
1 parent d7cdffb commit b073ac7b0e377a8cbe95978c5fe5305725349eab
Showing with 78 additions and 23 deletions.
  1. +70 −16 app/entity/Task.php
  2. +1 −1 app/interactor/Task/Creation.php
  3. +5 −5 app/mock/repository/Task.php
  4. +2 −1 app/repository/TaskInterface.php
View
@@ -4,23 +4,52 @@
class Task
{
public $id;
public $userId;
public $title;
public $description;
public $notes;
public $children = [];
public function __construct(array $data)
/**
*
* @var int $id
*/
protected $id;
/**
*
* @var int $userId
*/
protected $userId;
/**
*
* @var string $title
*/
protected $title;
/**
*
* @var string $description
*/
protected $description;
/**
*
* @var string $notes
*/
protected $notes;
/**
*
* @var array $children
*/
protected $children = [];
public function __construct($id, $userId, $title, $description, $notes, $children = [])
{
$this->id = $data['id'];
$this->userId = $data['userId'];
$this->title = $data['title'];
$this->description = ! empty($data['description']) ? $data['description'] : '';
$this->notes = ! empty($data['notes']) ? $data['notes'] : '';
if (! empty($data['children']) and is_array($data['children'])) {
foreach ($data['children'] as $child) {
$this->id = $id;
$this->userId = $userId;
$this->title = $title;
$this->description = $description;
$this->notes = $notes;
if (! empty($children) and is_array($children)) {
foreach ($children as $child) {
if ($child instanceof Task) {
$this->children[] = $child;
}
@@ -32,4 +61,29 @@ public function addChild(Task $task)
{
$this->children[] = $task;
}
public function getId()
{
return $this->id;
}
public function getUserId()
{
return $this->userId;
}
public function getTitle()
{
return $this->title;
}
public function getDescription()
{
return $this->description;
}
public function getNotes()
{
return $this->notes;
}
}
@@ -43,7 +43,7 @@ public function __construct(
public function execute(Request\Task\Creation $request)
{
$userId = $this->session->getLoggedInUserId();
$this->taskRepo->create($userId, $request);
$this->taskRepo->create(null, $userId, $request);
return true;
}
@@ -26,13 +26,13 @@ class Task implements Repo\TaskInterface
* @param Request\Task\Creation $request
* @return Entity\Task
*/
public function create($userId, Request\Task\Creation $request)
public function create($id, $userId, Request\Task\Creation $request)
{
if (empty($data['id']) or ! $this->isFreeId($data['id'])) {
$data['id'] = $this->getUniqId();
if (empty($id) or ! $this->isFreeId($id)) {
$id = $this->getUniqId();
}
$task = new Entity\Task($data);
$this->taskIds[] = $task->id;
$task = new Entity\Task($id, $userId, $request->getTitle(), $request->getDescription(), $request->getNotes());
$this->taskIds[] = $task->getId();
return $task;
}
@@ -8,8 +8,9 @@
{
/**
* Creates a task from a data array
* @param int $id
* @param int $userId
* @param Request\Task\Creation $request
*/
public function create($userId, Request\Task\Creation $request);
public function create($id, $userId, Request\Task\Creation $request);
}

0 comments on commit b073ac7

Please sign in to comment.