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

Commit

Permalink
Add fieldMap to config. Update entities so they use fieldMap. Remove …
Browse files Browse the repository at this point in the history
…boilerplate serialize and unserialize code.
  • Loading branch information
jeremiahsmall committed Mar 20, 2013
1 parent 4d60bff commit 0950e1a
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 78 deletions.
16 changes: 8 additions & 8 deletions module/Application/Module.php
Expand Up @@ -52,18 +52,18 @@ public function getServiceConfig()
return $dbAdapter;
},
'alternate_gateway_project' => function ($sm) {
$entity = new \Application\Entity\Project();
$config = $sm->get('config');
$fieldMap = $config['sfm_field_map'];
$entity = new \Application\Entity\Project($fieldMap);
$simpleFMAdapter = $sm->get('alternate_simple_fm');
$layoutnamePointer = 'ProjectPointer';
$layoutname = 'Project';
return new \Application\Gateway\Project($sm, $entity, $simpleFMAdapter, $layoutnamePointer, $layoutname);
return new \Application\Gateway\Project($fieldMap, $entity, $simpleFMAdapter);
},
'alternate_gateway_task' => function ($sm) {
$entity = new \Application\Entity\Task();
$config = $sm->get('config');
$fieldMap = $config['sfm_field_map'];
$entity = new \Application\Entity\Task($fieldMap);
$simpleFMAdapter = $sm->get('alternate_simple_fm');
$layoutnamePointer = 'TaskPointer';
$layoutname = 'Task';
return new \Application\Gateway\Task($sm, $entity, $simpleFMAdapter, $layoutnamePointer, $layoutname);
return new \Application\Gateway\Task($fieldMap, $entity, $simpleFMAdapter);
},
),
);
Expand Down
53 changes: 49 additions & 4 deletions module/Application/config/module.config.php
Expand Up @@ -5,6 +5,47 @@
*/

return array(
'sfm_field_map' => array(
'Application\Entity\Project' => array(
'writeable' => array(
'projectName' => 'Project Name',
'description' => 'Description',
'tag' => 'Tag',
),
'readonly' => array(
'id' => 'PROJECT ID MATCH FIELD',
'startDate' => 'Start Date',
'dueDate' => 'Due Date',
'daysRemaining' => 'Days Remaining',
'daysElapsed' => 'Days Elapsed',
'statusOnScreen' => 'Status on Screen',
'createdBy' => 'Created By',
),
),
'Application\Entity\Task' => array(
'writeable' => array(
'taskName' => 'Task Name',
'description' => 'Description',
'tag' => 'Tag',
),
'readonly' => array(
'id' => 'TASK ID MATCH FIELD',
'startDate' => 'Start Date',
'dueDate' => 'Due Date',
'daysRemaining' => 'Days Remaining',
'daysElapsed' => 'Days Elapsed',
'status' => 'Status',
'statusOnScreen' => 'Status on Screen',
'priority' => 'Priority Number List',
'priorityOnScreen' => 'Priority on Screen',
'taskCompletionPercentage' => 'Task Completion Percentage',
'createdBy' => 'Created By',
'personnelName' => 'PERSONNEL NAME MATCH FIELD',
'personnelEmail' => 'Personnel::Email',
'personnelPhone' => 'Personnel::Phone',
),
),
),
'router' => array(
'routes' => array(
'home' => array(
Expand Down Expand Up @@ -92,14 +133,18 @@
*/
'simple_fm' => 'Soliant\SimpleFM\ZF2\AdapterServiceFactory',
'gateway_project' => function ($sm) {
$entity = new \Application\Entity\Project();
$config = $sm->get('config');
$fieldMap = $config['sfm_field_map'];
$entity = new \Application\Entity\Project($fieldMap);
$simpleFMAdapter = $sm->get('simple_fm');
return new \Application\Gateway\Project($sm, $entity, $simpleFMAdapter);
return new \Application\Gateway\Project($fieldMap, $entity, $simpleFMAdapter);
},
'gateway_task' => function ($sm) {
$entity = new \Application\Entity\Task();
$config = $sm->get('config');
$fieldMap = $config['sfm_field_map'];
$entity = new \Application\Entity\Task($fieldMap);
$simpleFMAdapter = $sm->get('simple_fm');
return new \Application\Gateway\Task($sm, $entity, $simpleFMAdapter);
return new \Application\Gateway\Task($fieldMap, $entity, $simpleFMAdapter);
},


Expand Down
33 changes: 3 additions & 30 deletions module/Application/src/Application/Entity/Project.php
Expand Up @@ -36,10 +36,10 @@ class Project extends AbstractEntity
*/
protected $tasks;

public function __construct($simpleFMAdapterRow = array())
public function __construct($fieldMap, $simpleFMAdapterRow = array())
{
$this->tasks = new ArrayCollection();
parent::__construct($simpleFMAdapterRow);
parent::__construct($fieldMap, $simpleFMAdapterRow);
}

/**
Expand All @@ -49,42 +49,15 @@ public function __construct($simpleFMAdapterRow = array())
public function unserialize()
{
parent::unserialize();

$this->unserializeField('projectName', 'Project Name', TRUE);
$this->unserializeField('description', 'Description', TRUE);
$this->unserializeField('tag', 'Tag', TRUE);

$this->unserializeField('id', 'PROJECT ID MATCH FIELD');
$this->unserializeField('startDate', 'Start Date');
$this->unserializeField('dueDate', 'Due Date');
$this->unserializeField('daysRemaining', 'Days Remaining');
$this->unserializeField('daysElapsed', 'Days Elapsed');
$this->unserializeField('statusOnScreen', 'Status on Screen');
$this->unserializeField('createdBy', 'Created By');

if (!empty($this->simpleFMAdapterRow["Tasks"]["rows"])){
foreach ($this->simpleFMAdapterRow["Tasks"]["rows"] as $row){
$this->tasks->add(new Task($row));
$this->tasks->add(new Task($this->fieldMap, $row));
}
}

return $this;
}

/**
* @see \Soliant\SimpleFM\ZF2\Entity\AbstractEntity::serialize()
* @return the $simpleFMAdapterRow
*/
public function serialize()
{
parent::serialize();

$this->serializeField('Project Name', 'getProjectName');
$this->serializeField('Description', 'getDescription');
$this->serializeField('Tag', 'getTag');

return $this->simpleFMAdapterRow;
}

public function getName(){
return $this->getProjectName();
Expand Down
39 changes: 3 additions & 36 deletions module/Application/src/Application/Entity/Task.php
Expand Up @@ -46,9 +46,9 @@ class Task extends AbstractEntity
/**
* @param array $simpleFMAdapterRow
*/
public function __construct($simpleFMAdapterRow = array())
public function __construct($fieldMap, $simpleFMAdapterRow = array())
{
parent::__construct($simpleFMAdapterRow);
parent::__construct($fieldMap, $simpleFMAdapterRow);
}

/**
Expand All @@ -58,46 +58,13 @@ public function __construct($simpleFMAdapterRow = array())
public function unserialize()
{
parent::unserialize();

$this->unserializeField('taskName', 'Task Name', TRUE);
$this->unserializeField('description', 'Description', TRUE);
$this->unserializeField('tag', 'Tag', TRUE);

$this->unserializeField('id', 'TASK ID MATCH FIELD');
$this->unserializeField('startDate', 'Start Date');
$this->unserializeField('dueDate', 'Due Date');
$this->unserializeField('daysRemaining', 'Days Remaining');
$this->unserializeField('daysElapsed', 'Days Elapsed');
$this->unserializeField('status', 'Status');
$this->unserializeField('statusOnScreen', 'Status on Screen');
$this->unserializeField('priority', 'Priority Number List');
$this->unserializeField('priorityOnScreen', 'Priority on Screen');
$this->unserializeField('taskCompletionPercentage', 'Task Completion Percentage');
$this->unserializeField('createdBy', 'Created By');
$this->unserializeField('personnelName', 'PERSONNEL NAME MATCH FIELD');
$this->unserializeField('personnelEmail', 'Personnel::Email');
$this->unserializeField('personnelPhone', 'Personnel::Phone');

if (!empty($this->simpleFMAdapterRow["Projects"]["rows"])){
$this->project = new Project($this->simpleFMAdapterRow["Projects"]["rows"][0]);
$this->project = new Project($this->fieldMap, $this->simpleFMAdapterRow["Projects"]["rows"][0]);
}

return $this;
}

/**
* @see \Soliant\SimpleFM\ZF2\Entity\AbstractEntity::serialize()
*/
public function serialize()
{
parent::serialize();

$this->serializeField('Task Name', 'getTaskName');
$this->serializeField('Description', 'getDescription');
$this->serializeField('Tag', 'getTag');

return $this->simpleFMAdapterRow;
}

/**
* @see \Soliant\SimpleFM\ZF2\Entity\AbstractEntity::getName()
Expand Down

0 comments on commit 0950e1a

Please sign in to comment.