Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add fieldMap to config. Update entities so they use fieldMap. Remove …

…boilerplate serialize and unserialize code.
  • Loading branch information...
commit 0950e1a136ce852a6d0b17c16adc52a120213873 1 parent 4d60bff
@jeremiahsmall jeremiahsmall authored
View
16 module/Application/Module.php
@@ -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);
},
),
);
View
53 module/Application/config/module.config.php
@@ -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(
@@ -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);
},
View
33 module/Application/src/Application/Entity/Project.php
@@ -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);
}
/**
@@ -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();
View
39 module/Application/src/Application/Entity/Task.php
@@ -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);
}
/**
@@ -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()
Please sign in to comment.
Something went wrong with that request. Please try again.