commit 3994a53e78f8e59ac10beb6be08f85856ab1d102
parent b6a70d4b278d394b36a5f5b85300cf899b5e23c3
Author: Felicitus <felicitus@felicitus.org>
Date: Tue, 21 Jun 2011 14:21:56 +0200
Reworked distributors+manufacturers to the new method of deserializing data
Diffstat:
10 files changed, 114 insertions(+), 38 deletions(-)
diff --git a/frontend/js/Components/Distributor/DistributorEditor.js b/frontend/js/Components/Distributor/DistributorEditor.js
@@ -18,6 +18,14 @@ Ext.define('PartKeepr.DistributorEditor', {
name: 'email',
fieldLabel: i18n("Email")
},{
+ xtype: 'textfield',
+ name: 'phone',
+ fieldLabel: i18n("Phone")
+ },{
+ xtype: 'textfield',
+ name: 'fax',
+ fieldLabel: i18n("Fax")
+ },{
xtype: 'textarea',
name: 'comment',
fieldLabel: i18n("Comment")
diff --git a/frontend/js/Components/Manufacturer/ManufacturerEditor.js b/frontend/js/Components/Manufacturer/ManufacturerEditor.js
@@ -74,6 +74,14 @@ Ext.define('PartKeepr.ManufacturerEditor', {
name: 'email',
fieldLabel: i18n("Email")
},{
+ xtype: 'textfield',
+ name: 'phone',
+ fieldLabel: i18n("Phone")
+ },{
+ xtype: 'textfield',
+ name: 'fax',
+ fieldLabel: i18n("Fax")
+ },{
xtype: 'textarea',
name: 'comment',
fieldLabel: i18n("Comment")
diff --git a/frontend/js/Models/Distributor.js b/frontend/js/Models/Distributor.js
@@ -6,6 +6,8 @@ Ext.define("PartKeepr.Distributor", {
{ name: 'url', type: 'string'},
{ name: 'comment', type: 'string'},
{ name: 'address', type: 'string'},
+ { name: 'phone', type: 'string'},
+ { name: 'fax', type: 'string'},
{ name: 'email', type: 'string'}
],
proxy: PartKeepr.getRESTProxy("Distributor"),
diff --git a/frontend/js/Models/Manufacturer.js b/frontend/js/Models/Manufacturer.js
@@ -6,6 +6,8 @@ Ext.define("PartKeepr.Manufacturer", {
{ name: 'url', type: 'string'},
{ name: 'comment', type: 'string'},
{ name: 'address', type: 'string'},
+ { name: 'phone', type: 'string'},
+ { name: 'fax', type: 'string'},
{ name: 'email', type: 'string'}
],
hasMany: {model: 'PartKeepr.ManufacturerICLogo', name: 'iclogos'},
diff --git a/src/de/RaumZeitLabor/PartKeepr/Distributor/Distributor.php b/src/de/RaumZeitLabor/PartKeepr/Distributor/Distributor.php
@@ -1,5 +1,7 @@
<?php
namespace de\RaumZeitLabor\PartKeepr\Distributor;
+use de\RaumZeitLabor\PartKeepr\Util\Deserializable;
+
use de\RaumZeitLabor\PartKeepr\Util\Serializable;
use de\RaumZeitLabor\PartKeepr\Util\BaseEntity;
@@ -11,7 +13,7 @@ use de\RaumZeitLabor\PartKeepr\PartKeepr;
/**
* Represents a distributor
* @Entity **/
-class Distributor extends BaseEntity implements Serializable {
+class Distributor extends BaseEntity implements Serializable, Deserializable {
/**
* Holds the name of the distributor
* @Column(type="string",unique=true)
@@ -193,7 +195,41 @@ class Distributor extends BaseEntity implements Serializable {
"url" => $this->getURL(),
"address" => $this->getAddress(),
"email" => $this->getEmail(),
- "comment" => $this->getComment()
+ "comment" => $this->getComment(),
+ "phone" => $this->getPhone(),
+ "fax" => $this->getFax()
);
}
+
+ /**
+ * Deserializes the distributor
+ * @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 "url":
+ $this->setURL($value);
+ break;
+ case "comment":
+ $this->setComment($value);
+ break;
+ case "fax":
+ $this->setFax($value);
+ break;
+ case "phone":
+ $this->setPhone($value);
+ break;
+ case "email":
+ $this->setEmail($value);
+ break;
+ case "address":
+ $this->setAddress($value);
+ break;
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/src/de/RaumZeitLabor/PartKeepr/Distributor/DistributorService.php b/src/de/RaumZeitLabor/PartKeepr/Distributor/DistributorService.php
@@ -45,8 +45,7 @@ class DistributorService extends Service implements RestfulService {
$this->requireParameter("name");
$distributor = new Distributor;
-
- $this->setDistributorData($distributor);
+ $distributor->deserialize($this->getParameters());
PartKeepr::getEM()->persist($distributor);
PartKeepr::getEM()->flush();
@@ -55,27 +54,16 @@ class DistributorService extends Service implements RestfulService {
}
/**
- * Sets the data for the distributor.
- * @param Distributor $distributor The distributor to process
- */
- private function setDistributorData (Distributor $distributor) {
- $distributor->setName($this->getParameter("name"));
- $distributor->setComment($this->getParameter("comment", ""));
- $distributor->setAddress($this->getParameter("address", ""));
- $distributor->setURL($this->getParameter("url", ""));
- $distributor->setEmail($this->getParameter("email", ""));
- }
-
- /**
* (non-PHPdoc)
* @see de\RaumZeitLabor\PartKeepr\Service.RestfulService::update()
*/
public function update () {
$this->requireParameter("id");
$this->requireParameter("name");
- $distributor = DistributorManager::getInstance()->getDistributor($this->getParameter("id"));
-
- $this->setDistributorData($distributor);
+
+ $distributor = Distributor::loadById($this->getParameter("id"));
+ $distributor->deserialize($this->getParameters());
+
PartKeepr::getEM()->flush();
return array("data" => $distributor->serialize());
diff --git a/src/de/RaumZeitLabor/PartKeepr/Manufacturer/Manufacturer.php b/src/de/RaumZeitLabor/PartKeepr/Manufacturer/Manufacturer.php
@@ -208,12 +208,14 @@ class Manufacturer extends BaseEntity implements Serializable, Deserializable {
"address" => $this->getAddress(),
"email" => $this->getEmail(),
"comment" => $this->getComment(),
+ "phone" => $this->getPhone(),
+ "fax" => $this->getFax(),
"iclogos" => $this->serializeChildren($this->getICLogos())
);
}
/**
- * Deserializes the footprint
+ * Deserializes the manufacturer
* @param array $parameters The array with the parameters to set
*/
public function deserialize (array $parameters) {
@@ -231,6 +233,12 @@ class Manufacturer extends BaseEntity implements Serializable, Deserializable {
case "email":
$this->setEmail($value);
break;
+ case "fax":
+ $this->setFax($value);
+ break;
+ case "phone":
+ $this->setPhone($value);
+ break;
case "address":
$this->setAddress($value);
break;
diff --git a/src/de/RaumZeitLabor/PartKeepr/StorageLocation/StorageLocation.php b/src/de/RaumZeitLabor/PartKeepr/StorageLocation/StorageLocation.php
@@ -1,34 +1,56 @@
<?php
namespace de\RaumZeitLabor\PartKeepr\StorageLocation;
+
+use de\RaumZeitLabor\PartKeepr\Util\Deserializable,
+ de\RaumZeitLabor\PartKeepr\Util\Serializable,
+ de\RaumZeitLabor\PartKeepr\Util\BaseEntity;
+
declare(encoding = 'UTF-8');
/** @Entity **/
-class StorageLocation {
-
- /**
- * @Id @Column(type="integer")
- * @GeneratedValue(strategy="AUTO")
- * @var unknown_type
- */
- private $id;
-
+class StorageLocation extends BaseEntity implements Serializable, Deserializable {
/**
+ * Holds the name for our storage location
* @Column(type="string",unique=true)
+ * @var string
*/
private $name;
-
+
+ /**
+ * Sets the name for the storage location
+ * @param string $name the name to set
+ */
public function setName ($name) {
$this->name = $name;
}
+ /**
+ * Returns the name of the storage location
+ * @return string The name
+ */
public function getName () {
return $this->name;
}
- public function getId () {
- return $this->id;
- }
+ /**
+ * Returns this storage location in serialized form
+ * @return array The serialized storage location
+ */
public function serialize () {
- return array("id" => $this->id, "name" => $this->name);
+ return array("id" => $this->getId(), "name" => $this->getName());
+ }
+
+ /**
+ * Deserializes the storage location
+ * @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;
+ }
+ }
}
}
\ No newline at end of file
diff --git a/src/de/RaumZeitLabor/PartKeepr/StorageLocation/StorageLocationService.php b/src/de/RaumZeitLabor/PartKeepr/StorageLocation/StorageLocationService.php
@@ -37,16 +37,17 @@ class StorageLocationService extends Service implements RestfulService {
public function create () {
$this->requireParameter("name");
- $sl = StorageLocationManager::getInstance()->addStorageLocation($this->getParameter("name"));
+ $storageLocation = new StorageLocation();
+ $storageLocation->deserialize($this->getParameters());
- return array("data" => $sl->serialize());
+ return array("data" => $storageLocation->serialize());
}
public function update () {
$this->requireParameter("id");
$this->requireParameter("name");
$storageLocation = StorageLocationManager::getInstance()->getStorageLocation($this->getParameter("id"));
- $storageLocation->setName($this->getParameter("name"));
+ $storageLocation->deserialize($this->getParameters());
PartKeepr::getEM()->flush();
diff --git a/src/de/RaumZeitLabor/PartKeepr/UploadedFile/UploadedFile.php b/src/de/RaumZeitLabor/PartKeepr/UploadedFile/UploadedFile.php
@@ -135,12 +135,13 @@ abstract class UploadedFile extends BaseEntity {
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
$data = curl_exec($curl);
- curl_close($curl);
if ($data === false) {
throw new \Exception("replaceFromURL error: ".curl_error($curl));
}
+ curl_close($curl);
+
$tempName = tempnam("/tmp", "PARTKEEPR");
file_put_contents($tempName, $data);