commit 768595a24a253b214394a3376e82862a20b1b225
parent 463604882c8cee5dcbddb610b42f4bac68480ec5
Author: Felicitus <felicitus@felicitus.org>
Date: Tue, 21 Jun 2011 14:39:03 +0200
Reworked part unit to new deserialize model
Diffstat:
2 files changed, 25 insertions(+), 26 deletions(-)
diff --git a/src/de/RaumZeitLabor/PartKeepr/Part/PartUnit.php b/src/de/RaumZeitLabor/PartKeepr/Part/PartUnit.php
@@ -1,5 +1,10 @@
<?php
namespace de\RaumZeitLabor\PartKeepr\Part;
+use de\RaumZeitLabor\PartKeepr\Util\Deserializable;
+use de\RaumZeitLabor\PartKeepr\Util\Serializable;
+
+use de\RaumZeitLabor\PartKeepr\Util\BaseEntity;
+
declare(encoding = 'UTF-8');
use de\RaumZeitLabor\PartKeepr\PartKeepr,
@@ -7,14 +12,7 @@ use de\RaumZeitLabor\PartKeepr\PartKeepr,
/** @Entity **/
-class PartUnit {
- /**
- * @Id @Column(type="integer")
- * @GeneratedValue(strategy="AUTO")
- * @var int
- */
- private $id;
-
+class PartUnit extends BaseEntity implements Serializable, Deserializable {
/**
* Defines the name of the unit
* @Column
@@ -91,15 +89,6 @@ class PartUnit {
}
/**
- * Returns the ID for this object.
- * @param none
- * @return int The ID for this object
- */
- public function getId () {
- return $this->id;
- }
-
- /**
* Defines if the unit is default or not.
* @param boolean $default True if the unit is default, false otherwise
*/
@@ -130,5 +119,22 @@ class PartUnit {
"default" => $this->getDefault()
);
}
+
+ /**
+ * Deserializes the manufacturer
+ * @param array $parameters The array with the parameters to set
+ */
+ public function deserialize (array $parameters) {
+ foreach ($parameters as $key => $value) {
+ switch ($key) {
+ case "name":
+ $this->setName($value);
+ break;
+ case "shortName":
+ $this->setShortName($value);
+ break;
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/src/de/RaumZeitLabor/PartKeepr/PartUnit/PartUnitService.php b/src/de/RaumZeitLabor/PartKeepr/PartUnit/PartUnitService.php
@@ -36,8 +36,7 @@ class PartUnitService extends Service implements RestfulService {
$this->requireParameter("name");
$partUnit = new PartUnit;
-
- $this->setPartUnitData($partUnit);
+ $partUnit->deserialize($this->getParameters());
PartKeepr::getEM()->persist($partUnit);
PartKeepr::getEM()->flush();
@@ -45,18 +44,12 @@ class PartUnitService extends Service implements RestfulService {
return array("data" => $partUnit->serialize());
}
- private function setPartUnitData (PartUnit $partUnit) {
- $partUnit->setName($this->getParameter("name"));
- $partUnit->setShortName($this->getParameter("shortName",""));
- }
-
public function update () {
$this->requireParameter("id");
$this->requireParameter("name");
$partUnit = PartUnitManager::getInstance()->getPartUnit($this->getParameter("id"));
-
- $this->setPartUnitData($partUnit);
+ $partUnit->deserialize($this->getParameters());
PartKeepr::getEM()->flush();
return array("data" => $partUnit->serialize());