partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

commit 1dbad8824f88fb3ee6b12aae9e1faf66ec1fca8e
parent c366a262ba7475fd46904cb45d349c59cdb4e8a9
Author: Felicitus <felicitus@felicitus.org>
Date:   Wed, 24 Jun 2015 20:21:56 +0200

Refactored Distributors to their own bundle

Diffstat:
Mapp/AppKernel.php | 1+
Mapp/config/config.yml | 13+++++++++++++
Asrc/PartKeepr/DistributorBundle/Entity/Distributor.php | 304+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/PartKeepr/DistributorBundle/PartKeeprDistributorBundle.php | 8++++++++
Msrc/PartKeepr/FrontendBundle/Resources/public/js/Components/Distributor/DistributorEditorComponent.js | 3+--
Dsrc/backend/PartKeepr/Distributor/Distributor.php | 260-------------------------------------------------------------------------------
Dsrc/backend/PartKeepr/Distributor/DistributorManager.php | 107-------------------------------------------------------------------------------
Dsrc/backend/PartKeepr/Distributor/DistributorService.php | 83-------------------------------------------------------------------------------
Msrc/backend/PartKeepr/Part/PartDistributor.php | 7++++---
Msrc/backend/PartKeepr/Part/PartManager.php | 2+-
Msrc/backend/PartKeepr/PartKeepr.php | 2+-
Msrc/backend/PartKeepr/Setup/Migration/PartDB/DistributorMigration.php | 2+-
12 files changed, 334 insertions(+), 458 deletions(-)

diff --git a/app/AppKernel.php b/app/AppKernel.php @@ -78,6 +78,7 @@ class AppKernel extends Kernel $bundles[] = new PartKeepr\FootprintBundle\PartKeeprFootprintBundle(); $bundles[] = new PartKeepr\UnitBundle\PartKeeprUnitBundle(); $bundles[] = new PartKeepr\PartBundle\PartKeeprPartBundle(); + $bundles[] = new PartKeepr\DistributorBundle\PartKeeprDistributorBundle(); return $bundles; } diff --git a/app/config/config.yml b/app/config/config.yml @@ -106,6 +106,19 @@ services: parent: "api.doctrine.orm.order_filter" arguments: [ ~ ] # This line can also be omitted + resource.distributor: + parent: "api.resource" + arguments: [ "PartKeepr\\DistributorBundle\Entity\Distributor" ] + tags: [ { name: "api.resource" } ] + calls: + - method: "initFilters" + arguments: [ [ "@resource.order_filter" ] ] + - method: "initNormalizationContext" + arguments: [ { groups: [ "default" ] } ] + - method: "initDenormalizationContext" + arguments: + - { groups: [ "default" ] } + resource.partmeasurementunit.item_operation.custom_put: class: "Dunglas\ApiBundle\Api\Operation\Operation" public: false diff --git a/src/PartKeepr/DistributorBundle/Entity/Distributor.php b/src/PartKeepr/DistributorBundle/Entity/Distributor.php @@ -0,0 +1,304 @@ +<?php +namespace PartKeepr\DistributorBundle\Entity; + +use Doctrine\ORM\Mapping as ORM; +use PartKeepr\DoctrineReflectionBundle\Annotation\TargetService; +use PartKeepr\Util\BaseEntity; +use Symfony\Component\Serializer\Annotation\Groups; + +/** + * Represents a distributor + * + * @ORM\Entity + * @TargetService(uri="/api/distributors") + **/ +class Distributor extends BaseEntity +{ + /** + * Holds the name of the distributor + * @ORM\Column(type="string",unique=true) + * @Groups({"default"}) + * + * @var string + */ + private $name; + + /** + * Holds the address of the distributor + * @ORM\Column(type="text",nullable=true) + * @Groups({"default"}) + * + * @var string + */ + private $address; + + /** + * Holds the URL of the distributor + * @ORM\Column(type="string",nullable=true) + * @Groups({"default"}) + * + * @var string + */ + private $url; + + /** + * Holds the phone number of the distributor + * @ORM\Column(type="string",nullable=true) + * @Groups({"default"}) + * + * @var string + */ + private $phone; + + /** + * Holds the fax number of the distributor + * @ORM\Column(type="string",nullable=true) + * @Groups({"default"}) + * + * @var string + */ + private $fax; + + /** + * Holds the email of the distributor + * @ORM\Column(type="string",nullable=true) + * @Groups({"default"}) + * + * @var string + */ + private $email; + + /** + * Holds a comment for the distributor + * @ORM\Column(type="text",nullable=true) + * @Groups({"default"}) + * + * @var string + */ + private $comment; + + /** + * Holds the SKU lookup URL of the distributor + * @ORM\Column(type="string",nullable=true) + * + * @var string + */ + private $skuurl; + + /** + * Sets the name for the distributor + * + * @param string $name The distributor's name + */ + public function setName($name) + { + $this->name = $name; + } + + /** + * Returns the name of the distributor + * + * @return string The distributor's name + */ + public function getName() + { + return $this->name; + } + + /** + * Sets the address of this distributor + * + * @param string $address The address of the distributor + */ + public function setAddress($address) + { + $this->address = $address; + } + + /** + * Returns the address of this distributor + * + * @return string The address of this distributor + */ + public function getAddress() + { + return $this->address; + } + + /** + * Sets the phone number for this distributor + * + * @param string $phone The phone number of this distributor + */ + public function setPhone($phone) + { + $this->phone = $phone; + } + + /** + * Returns the phone number of this distributor + * + * @return string The phone number + */ + public function getPhone() + { + return $this->phone; + } + + /** + * Sets the fax number for this distributor + * + * @param string $fax The fax number + */ + public function setFax($fax) + { + $this->fax = $fax; + } + + /** + * Returns the fax number for this distributor + * + * @return string $fax The fax number + */ + public function getFax() + { + return $this->fax; + } + + /** + * Sets the comment for this distributor + * + * @param string $comment The comment for this distributor + */ + public function setComment($comment) + { + $this->comment = $comment; + } + + /** + * Returns the comment for this distributor + * + * @return string The comment + */ + public function getComment() + { + return $this->comment; + } + + /** + * Sets the email for this distributor + * + * @param string $email The email for this distributor + */ + public function setEmail($email) + { + $this->email = $email; + } + + /** + * Returns the email for this distributor + * + * @return string The email + */ + public function getEmail() + { + return $this->email; + } + + /** + * Sets the URL for this distributor + * + * @param string $url The URL for this distributor + */ + public function setURL($url) + { + $this->url = $url; + } + + /** + * Returns the URL for this distributor + * + * @return string The URL + */ + public function getURL() + { + return $this->url; + } + + /** + * Sets the SKU lookup URL for this distributor + * + * @param string $skuurl The SKU lookup URL for this distributor + */ + public function setSKUURL($skuurl) + { + $this->skuurl = $skuurl; + } + + /** + * Returns the SKU lookup URL for this distributor + * + * @return string The SKU lookup URL + */ + public function getSKUURL() + { + return $this->skuurl; + } + + /** + * Returns the distributor in serialized form. + * + * @return array The serialized distributor + */ + public function serialize() + { + return array( + "id" => $this->getId(), + "name" => $this->getName(), + "url" => $this->getURL(), + "address" => $this->getAddress(), + "email" => $this->getEmail(), + "comment" => $this->getComment(), + "phone" => $this->getPhone(), + "fax" => $this->getFax(), + "skuurl" => $this->getSKUURL(), + ); + } + + /** + * 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; + case "skuurl": + $this->setSKUURL($value); + break; + } + } + } +} diff --git a/src/PartKeepr/DistributorBundle/PartKeeprDistributorBundle.php b/src/PartKeepr/DistributorBundle/PartKeeprDistributorBundle.php @@ -0,0 +1,8 @@ +<?php +namespace PartKeepr\DistributorBundle; + +use Symfony\Component\HttpKernel\Bundle\Bundle; + +class PartKeeprDistributorBundle extends Bundle +{ +} diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Distributor/DistributorEditorComponent.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Distributor/DistributorEditorComponent.js @@ -4,10 +4,9 @@ Ext.define('PartKeepr.DistributorEditorComponent', { navigationClass: 'PartKeepr.DistributorGrid', editorClass: 'PartKeepr.DistributorEditor', newItemText: i18n("New Distributor"), - model: 'PartKeepr.Distributor', + model: 'PartKeepr.DistributorBundle.Entity.Distributor', initComponent: function () { this.createStore({ - proxy: PartKeepr.getRESTProxy("Distributor"), sorters: [{ property: 'name', direction:'ASC' diff --git a/src/backend/PartKeepr/Distributor/Distributor.php b/src/backend/PartKeepr/Distributor/Distributor.php @@ -1,260 +0,0 @@ -<?php -namespace PartKeepr\Distributor; - -use PartKeepr\Util\Deserializable, - PartKeepr\Util\Serializable, - PartKeepr\Util\BaseEntity, - PartKeepr\PartKeepr, - Doctrine\ORM\Mapping as ORM; - -/** - * Represents a distributor - * @ORM\Entity **/ -class Distributor extends BaseEntity implements Serializable, Deserializable { - /** - * Holds the name of the distributor - * @ORM\Column(type="string",unique=true) - * @var string - */ - private $name; - - /** - * Holds the address of the distributor - * @ORM\Column(type="text",nullable=true) - * @var string - */ - private $address; - - /** - * Holds the URL of the distributor - * @ORM\Column(type="string",nullable=true) - * @var string - */ - private $url; - - /** - * Holds the phone number of the distributor - * @ORM\Column(type="string",nullable=true) - * @var string - */ - private $phone; - - /** - * Holds the fax number of the distributor - * @ORM\Column(type="string",nullable=true) - * @var string - */ - private $fax; - - /** - * Holds the email of the distributor - * @ORM\Column(type="string",nullable=true) - * @var string - */ - private $email; - - /** - * Holds a comment for the distributor - * @ORM\Column(type="text",nullable=true) - * @var string - */ - private $comment; - - /** - * Holds the SKU lookup URL of the distributor - * @ORM\Column(type="string",nullable=true) - * @var string - */ - private $skuurl; - - /** - * Sets the name for the distributor - * - * @param string $name The distributor's name - */ - public function setName ($name) { - $this->name = $name; - } - - /** - * Returns the name of the distributor - * @return string The distributor's name - */ - public function getName () { - return $this->name; - } - - /** - * Sets the address of this distributor - * - * @param string $address The address of the distributor - */ - public function setAddress ($address) { - $this->address = $address; - } - - /** - * Returns the address of this distributor - * @return string The address of this distributor - */ - public function getAddress () { - return $this->address; - } - - /** - * Sets the phone number for this distributor - * - * @param string $phone The phone number of this distributor - */ - public function setPhone ($phone) { - $this->phone = $phone; - } - - /** - * Returns the phone number of this distributor - * @return string The phone number - */ - public function getPhone () { - return $this->phone; - } - - /** - * Sets the fax number for this distributor - * - * @param string $fax The fax number - */ - public function setFax ($fax) { - $this->fax = $fax; - } - - /** - * Returns the fax number for this distributor - * - * @return string $fax The fax number - */ - public function getFax () { - return $this->fax; - } - - /** - * Sets the comment for this distributor - * - * @param string $comment The comment for this distributor - */ - public function setComment ($comment) { - $this->comment = $comment; - } - - /** - * Returns the comment for this distributor - * - * @return string The comment - */ - public function getComment () { - return $this->comment; - } - - /** - * Sets the email for this distributor - * - * @param string $email The email for this distributor - */ - public function setEmail ($email) { - $this->email = $email; - } - - /** - * Returns the email for this distributor - * @return string The email - */ - public function getEmail () { - return $this->email; - } - - /** - * Sets the URL for this distributor - * - * @param string $url The URL for this distributor - */ - public function setURL ($url) { - $this->url = $url; - } - - /** - * Returns the URL for this distributor - * @return string The URL - */ - public function getURL () { - return $this->url; - } - - /** - * Sets the SKU lookup URL for this distributor - * - * @param string $skuurl The SKU lookup URL for this distributor - */ - public function setSKUURL ($skuurl) { - $this->skuurl = $skuurl; - } - - /** - * Returns the SKU lookup URL for this distributor - * @return string The SKU lookup URL - */ - public function getSKUURL () { - return $this->skuurl; - } - - /** - * Returns the distributor in serialized form. - * @return array The serialized distributor - */ - public function serialize () { - return array( - "id" => $this->getId(), - "name" => $this->getName(), - "url" => $this->getURL(), - "address" => $this->getAddress(), - "email" => $this->getEmail(), - "comment" => $this->getComment(), - "phone" => $this->getPhone(), - "fax" => $this->getFax(), - "skuurl" => $this->getSKUURL() - ); - } - - /** - * 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; - case "skuurl": - $this->setSKUURL($value); - break; - } - } - } -} diff --git a/src/backend/PartKeepr/Distributor/DistributorManager.php b/src/backend/PartKeepr/Distributor/DistributorManager.php @@ -1,107 +0,0 @@ -<?php -namespace PartKeepr\Distributor; - -use PartKeepr\Util\Singleton, - PartKeepr\Distributor\Distributor, - PartKeepr\PartKeepr, - PartKeepr\Category\CategoryManager, - PartKeepr\Distributor\Exceptions\DistributorNotFoundException; - -class DistributorManager extends Singleton { - /** - * Returns a list of distributors. - * - * @param int $start Start of the list, default 0 - * @param int $limit Number of users to list, default 10 - * @param string $sort The field to sort by, default "name" - * @param string $dir The direction to sort (ASC or DESC), default ASC - * @param string $filter A string to filter the distributor's name by, default empty - */ - public function getDistributors ($start = 0, $limit = 10, $sort = "name", $dir = "asc", $filter = "") { - - $qb = PartKeepr::getEM()->createQueryBuilder(); - $qb->select("st.id, st.name, st.url, st.email, st.comment, st.address, st.skuurl")->from("PartKeepr\Distributor\Distributor","st"); - - if ($filter != "") { - $qb = $qb->where("LOWER(st.name) LIKE :filter"); - $qb->setParameter("filter", "%".strtolower($filter)."%"); - } - - if ($limit > -1) { - $qb->setMaxResults($limit); - $qb->setFirstResult($start); - } - - $qb->orderBy("st.".$sort, $dir); - - $query = $qb->getQuery(); - - $result = $query->getResult(); - - $totalQueryBuilder = PartKeepr::getEM()->createQueryBuilder(); - $totalQueryBuilder->select("COUNT(st.id)")->from("PartKeepr\Distributor\Distributor","st"); - - - - if ($filter != "") { - $totalQueryBuilder = $totalQueryBuilder->where("LOWER(st.name) LIKE :filter"); - $totalQueryBuilder->setParameter("filter", "%".strtolower($filter)."%"); - } - - $totalQuery = $totalQueryBuilder->getQuery(); - - return array("data" => $result, "totalCount" => $totalQuery->getSingleScalarResult()); - } - - /** - * Returns a distributor by ID. - * - * @param int $id The distributor id - * @return Distributor The distributor - * @throws EntityNotFoundException If no distributor with the ID was found - */ - public function getDistributor ($id) { - return Distributor::loadById($id); - } - - /** - * Creates a new distributor with the given name. - * @param string $name The name of the distributor - * @return Distributor The new distributor object - */ - public function addDistributor ($name) { - $distributor = new Distributor(); - $distributor->setName($name); - - PartKeepr::getEM()->persist($distributor); - PartKeepr::getEM()->flush(); - - return $distributor; - } - - /** - * Deletes a distributor by id - * - * @param int $id The ID of the distributor to delete - */ - public function deleteDistributor ($id) { - $distributor = $this->getDistributor($id); - - PartKeepr::getEM()->remove($distributor); - PartKeepr::getEM()->flush(); - } - - /** - * Retrieves a distributor by its name. - * - * @param string $name The name of the distributor to retrieve - * @throws Doctrine\ORM\NoResultException If the distributor was not found - */ - public function getDistributorByName ($name) { - $dql = "SELECT d FROM PartKeepr\Distributor\Distributor d WHERE d.name = :name"; - $query = PartKeepr::getEM()->createQuery($dql); - $query->setParameter("name", $name); - - return $query->getSingleResult(); - } -} diff --git a/src/backend/PartKeepr/Distributor/DistributorService.php b/src/backend/PartKeepr/Distributor/DistributorService.php @@ -1,82 +0,0 @@ -<?php -namespace PartKeepr\Distributor; -use PartKeepr\Service\RestfulService; - -use PartKeepr\Service\Service, - PartKeepr\Part\PartManager, - PartKeepr\Stock\StockEntry, - PartKeepr\PartKeepr, - PartKeepr\Session\SessionManager; - -class DistributorService extends Service implements RestfulService { - /** - * (non-PHPdoc) - * @see PartKeepr\Service.RestfulService::get() - */ - public function get () { - if ($this->hasParameter("id")) { - return array("data" => DistributorManager::getInstance()->getDistributor($this->getParameter("id"))->serialize()); - } else { - if ($this->hasParameter("sort")) { - $tmp = json_decode($this->getParameter("sort"), true); - - $aSortParams = $tmp[0]; - } else { - $aSortParams = array( - "property" => "name", - "direction" => "ASC"); - } - return DistributorManager::getInstance()->getDistributors( - $this->getParameter("start", $this->getParameter("start", 0)), - $this->getParameter("limit", $this->getParameter("limit", 25)), - $this->getParameter("sortby", $aSortParams["property"]), - $this->getParameter("dir", $aSortParams["direction"]), - $this->getParameter("query", "")); - } - } - - /** - * (non-PHPdoc) - * @see PartKeepr\Service.RestfulService::create() - */ - public function create () { - $this->requireParameter("name"); - - $distributor = new Distributor; - $distributor->deserialize($this->getParameters()); - - PartKeepr::getEM()->persist($distributor); - PartKeepr::getEM()->flush(); - - return array("data" => $distributor->serialize()); - } - - /** - * (non-PHPdoc) - * @see PartKeepr\Service.RestfulService::update() - */ - public function update () { - $this->requireParameter("id"); - $this->requireParameter("name"); - - $distributor = Distributor::loadById($this->getParameter("id")); - $distributor->deserialize($this->getParameters()); - - PartKeepr::getEM()->flush(); - - return array("data" => $distributor->serialize()); - - } - - /** - * (non-PHPdoc) - * @see PartKeepr\Service.RestfulService::destroy() - */ - public function destroy () { - $this->requireParameter("id"); - - DistributorManager::getInstance()->deleteDistributor($this->getParameter("id")); - - return array("data" => null); - } -}- \ No newline at end of file diff --git a/src/backend/PartKeepr/Part/PartDistributor.php b/src/backend/PartKeepr/Part/PartDistributor.php @@ -5,7 +5,7 @@ use PartKeepr\Util\Deserializable, PartKeepr\Util\Serializable, PartKeepr\Util\BaseEntity, PartKeepr\PartKeepr, - PartKeepr\Distributor\Distributor, + PartKeepr\DistributorBundle\Entity\Distributor, Doctrine\ORM\Mapping as ORM; /** @@ -18,7 +18,7 @@ class PartDistributor extends BaseEntity implements Serializable, Deserializable private $part; /** - * @ORM\ManyToOne(targetEntity="PartKeepr\Distributor\Distributor") + * @ORM\ManyToOne(targetEntity="PartKeepr\DistributorBundle\Entity\Distributor") */ private $distributor; @@ -113,7 +113,8 @@ class PartDistributor extends BaseEntity implements Serializable, Deserializable /** * Sets the distributor - * @param Distributor $distributor The distributor + * +*@param \PartKeepr\DistributorBundle\Entity\Distributor $distributor The distributor */ public function setDistributor (Distributor $distributor) { $this->distributor = $distributor; diff --git a/src/backend/PartKeepr/Part/PartManager.php b/src/backend/PartKeepr/Part/PartManager.php @@ -17,7 +17,7 @@ use PartKeepr\UploadedFile\TempUploadedFile, PartKeepr\Part\Part, Doctrine\ORM\Query, PartKeepr\PartUnit\PartUnitManager, - PartKeepr\Distributor\Distributor, + PartKeepr\DistributorBundle\Entity\Distributor, PartKeepr\Manufacturer\Manufacturer, \PartKeepr\FootprintBundle\Entity\FootprintManager, PartKeepr\Session\SessionManager, diff --git a/src/backend/PartKeepr/PartKeepr.php b/src/backend/PartKeepr/PartKeepr.php @@ -183,7 +183,7 @@ class PartKeepr { 'PartKeepr\Manufacturer\Manufacturer', 'PartKeepr\Manufacturer\ManufacturerICLogo', - 'PartKeepr\Distributor\Distributor', + 'PartKeepr\DistributorBundle\Entity\Distributor', 'PartKeepr\Image\Image', 'PartKeepr\Image\CachedImage', diff --git a/src/backend/PartKeepr/Setup/Migration/PartDB/DistributorMigration.php b/src/backend/PartKeepr/Setup/Migration/PartDB/DistributorMigration.php @@ -2,7 +2,7 @@ namespace PartKeepr\Setup\Migration\PartDB; use PartKeepr\PartKeepr, - PartKeepr\Distributor\Distributor, + PartKeepr\DistributorBundle\Entity\Distributor, PartKeepr\Distributor\DistributorManager, PartKeepr\Setup\AbstractSetup;