partkeepr

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

commit 65c9341c6d2a5ac1990c71a644a5c01758ca6c26
parent f2dbcad896516534dec2b27018c2b9d4308f3010
Author: Felicitus <felicitus@felicitus.org>
Date:   Fri, 26 Jun 2015 11:58:28 +0200

Added 1:n relations, implemented manufacturers

Diffstat:
Mapp/AppKernel.php | 2++
Mapp/config/config.yml | 57++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
Mcomposer.json | 3++-
Mcomposer.lock | 134++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
Msrc/PartKeepr/DoctrineReflectionBundle/Resources/views/model.js.twig | 25+++++++++++++++++++++++++
Msrc/PartKeepr/DoctrineReflectionBundle/Services/ReflectionService.php | 29++++++++++++++++++++++++++++-
Msrc/PartKeepr/FrontendBundle/Resources/public/js/Components/Manufacturer/ManufacturerEditor.js | 4++--
Msrc/PartKeepr/FrontendBundle/Resources/public/js/Components/Manufacturer/ManufacturerEditorComponent.js | 3+--
Asrc/PartKeepr/ManufacturerBundle/Entity/Manufacturer.php | 246+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/PartKeepr/ManufacturerBundle/Entity/ManufacturerICLogo.php | 52++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/PartKeepr/ManufacturerBundle/PartKeeprManufacturerBundle.php | 8++++++++
Dsrc/backend/PartKeepr/Manufacturer/Manufacturer.php | 252-------------------------------------------------------------------------------
Dsrc/backend/PartKeepr/Manufacturer/ManufacturerICLogo.php | 65-----------------------------------------------------------------
Dsrc/backend/PartKeepr/Manufacturer/ManufacturerManager.php | 105-------------------------------------------------------------------------------
Dsrc/backend/PartKeepr/Manufacturer/ManufacturerService.php | 83-------------------------------------------------------------------------------
Dsrc/backend/PartKeepr/ManufacturerICLogo/ManufacturerICLogoManager.php | 66------------------------------------------------------------------
Dsrc/backend/PartKeepr/ManufacturerICLogo/ManufacturerICLogoService.php | 102-------------------------------------------------------------------------------
Msrc/backend/PartKeepr/Part/PartManager.php | 2+-
Msrc/backend/PartKeepr/Part/PartManufacturer.php | 4++--
Msrc/backend/PartKeepr/PartDistributor/PartDistributorManager.php | 2+-
Msrc/backend/PartKeepr/PartDistributor/PartDistributorService.php | 4++--
Msrc/backend/PartKeepr/PartKeepr.php | 4++--
Msrc/backend/PartKeepr/Setup/ManufacturerSetup.php | 4++--
Msrc/backend/PartKeepr/UploadedFile/UploadedFile.php | 29+++++++++++++++++++++--------
24 files changed, 586 insertions(+), 699 deletions(-)

diff --git a/app/AppKernel.php b/app/AppKernel.php @@ -61,6 +61,7 @@ class AppKernel extends Kernel new PartKeepr\ApiDocBundle\PartKeeprApiDocBundle(), new Dunglas\ApiBundle\DunglasApiBundle(), new Brainbits\FugueIconsBundle\BrainbitsFugueIconsBundle(), + new Liip\ImagineBundle\LiipImagineBundle(), ); // Developer bundles @@ -79,6 +80,7 @@ class AppKernel extends Kernel $bundles[] = new PartKeepr\UnitBundle\PartKeeprUnitBundle(); $bundles[] = new PartKeepr\PartBundle\PartKeeprPartBundle(); $bundles[] = new PartKeepr\DistributorBundle\PartKeeprDistributorBundle(); + $bundles[] = new PartKeepr\ManufacturerBundle\PartKeeprManufacturerBundle(); return $bundles; } diff --git a/app/config/config.yml b/app/config/config.yml @@ -119,6 +119,61 @@ services: arguments: - { groups: [ "default" ] } + resource.manufacturer: + parent: "api.resource" + arguments: [ "PartKeepr\\ManufacturerBundle\Entity\Manufacturer" ] + tags: [ { name: "api.resource" } ] + calls: + - method: "initFilters" + arguments: [ [ "@resource.order_filter" ] ] + - method: "initNormalizationContext" + arguments: [ { groups: [ "default" ] } ] + - method: "initDenormalizationContext" + arguments: + - { groups: [ "default" ] } + + resource.manufacturer_ic_logo.item_operation.custom_put: + class: "Dunglas\ApiBundle\Api\Operation\Operation" + public: false + factory: [ "@api.operation_factory", "createItemOperation" ] + arguments: + - "@resource.manufacturer_ic_logo" # Resource + - [ "GET" ] # Methods + - "/manufacturter_i_c_logo/{id}/getImage" # Path + - "PartKeeprManufacturerBundle:ManufacturerIcLogo:getImage" # Controller + - "ManufacturerIcLogoGetImage" # Route name + - # Context (will be present in Hydra documentation) + "@type": "hydra:Operation" + "hydra:title": "A custom operation" + "returns": "xmls:string" + + resource.manufacturer_ic_logo.item_operation.get: + class: "Dunglas\ApiBundle\Api\Operation\Operation" + public: false + factory: [ "@api.operation_factory", "createItemOperation" ] + arguments: [ "@resource.manufacturer_ic_logo", "GET" ] + + resource.manufacturer_ic_logo.item_operation.put: + class: "Dunglas\ApiBundle\Api\Operation\Operation" + public: false + factory: [ "@api.operation_factory", "createItemOperation" ] + arguments: [ "@resource.manufacturer_ic_logo", "PUT" ] + + resource.manufacturer_ic_logo: + parent: "api.resource" + arguments: [ "PartKeepr\\ManufacturerBundle\Entity\ManufacturerICLogo" ] + tags: [ { name: "api.resource" } ] + calls: + - method: "initItemOperations" + arguments: [ [ "@resource.manufacturer_ic_logo.item_operation.custom_put", "@resource.manufacturer_ic_logo.item_operation.get", "@resource.manufacturer_ic_logo.item_operation.put" ] ] + - 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 @@ -128,7 +183,7 @@ services: - [ "PUT" ] # Methods - "/part_measurement_units/{id}/setDefault" # Path - "PartKeeprPartBundle:PartMeasurementUnit:setDefault" # Controller - - "my_custom_route" # Route name + - "PartMeasurementUnitSetDefault" # Route name - # Context (will be present in Hydra documentation) "@type": "hydra:Operation" "hydra:title": "A custom operation" diff --git a/composer.json b/composer.json @@ -47,7 +47,8 @@ "knplabs/knp-paginator-bundle": "2.4.1", "dunglas/api-bundle": "1.0.*@dev", "symfony/serializer": "2.7.1", - "brainbits/fugue-icons-bundle": "^3.5" + "brainbits/fugue-icons-bundle": "^3.5", + "liip/imagine-bundle": "^1.3" }, "autoload": { "psr-0": { "": "src/", diff --git a/composer.lock b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "c391c64cc6451d5d25a24f1a4911f621", + "hash": "8136ef51db822c160f3d5a93b057ccab", "packages": [ { "name": "brainbits/fugue-icons-bundle", @@ -1329,6 +1329,63 @@ "time": "2015-01-27 09:39:58" }, { + "name": "imagine/imagine", + "version": "0.6.2", + "source": { + "type": "git", + "url": "https://github.com/avalanche123/Imagine.git", + "reference": "83ca8babede0e54f935ec09d55a726bf4b0a3f7c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/avalanche123/Imagine/zipball/83ca8babede0e54f935ec09d55a726bf4b0a3f7c", + "reference": "83ca8babede0e54f935ec09d55a726bf4b0a3f7c", + "shasum": "" + }, + "require": { + "php": ">=5.3.2" + }, + "require-dev": { + "sami/sami": "dev-master" + }, + "suggest": { + "ext-gd": "to use the GD implementation", + "ext-gmagick": "to use the Gmagick implementation", + "ext-imagick": "to use the Imagick implementation" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-develop": "0.7-dev" + } + }, + "autoload": { + "psr-0": { + "Imagine": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Bulat Shakirzyanov", + "email": "mallluhuct@gmail.com", + "homepage": "http://avalanche123.com" + } + ], + "description": "Image processing for PHP 5.3", + "homepage": "http://imagine.readthedocs.org/", + "keywords": [ + "drawing", + "graphics", + "image manipulation", + "image processing" + ], + "time": "2014-11-11 11:36:02" + }, + { "name": "incenteev/composer-parameter-handler", "version": "v2.1.1", "source": { @@ -1631,6 +1688,81 @@ "time": "2014-12-12 05:04:05" }, { + "name": "liip/imagine-bundle", + "version": "1.3.0", + "target-dir": "Liip/ImagineBundle", + "source": { + "type": "git", + "url": "https://github.com/liip/LiipImagineBundle.git", + "reference": "24c977ccf1a15854dc5fb3efc5de86011f8f0ef3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/liip/LiipImagineBundle/zipball/24c977ccf1a15854dc5fb3efc5de86011f8f0ef3", + "reference": "24c977ccf1a15854dc5fb3efc5de86011f8f0ef3", + "shasum": "" + }, + "require": { + "imagine/imagine": "~0.5,<0.7", + "php": ">=5.3.2", + "symfony/filesystem": "~2.3 || ~3.0", + "symfony/finder": "~2.3 || ~3.0", + "symfony/framework-bundle": "~2.3 || ~3.0", + "symfony/options-resolver": "~2.3 || ~3.0" + }, + "require-dev": { + "amazonwebservices/aws-sdk-for-php": "~1.0", + "aws/aws-sdk-php": "~2.4", + "doctrine/cache": "~1.1", + "doctrine/mongodb-odm": "1.0.*", + "doctrine/orm": "~2.3", + "ext-gd": "*", + "phpunit/phpunit": "~4.3", + "psr/log": "~1.0", + "symfony/browser-kit": "~2.3 || ~3.0", + "symfony/console": "~2.3 || ~3.0", + "symfony/form": "~2.3 || ~3.0", + "symfony/phpunit-bridge": "~2.3 || ~3.0", + "symfony/yaml": "~2.3 || ~3.0", + "twig/twig": "~1.0" + }, + "suggest": { + "amazonwebservices/aws-sdk-for-php": "Add it if you'd like to use aws v1 resolver", + "aws/aws-sdk-php": "Add it if you'd like to use aws v2 or v3 resolver", + "monolog/monolog": "If you'd want to write logs", + "twig/twig": "If you'd want to use some handy twig filters" + }, + "type": "symfony-bundle", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev", + "dev-0.x": "0.x-dev" + } + }, + "autoload": { + "psr-0": { + "Liip\\ImagineBundle": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Liip and other contributors", + "homepage": "https://github.com/liip/LiipImagineBundle/contributors" + } + ], + "description": "This Bundle assists in imagine manipulation using the imagine library", + "homepage": "http://liip.ch", + "keywords": [ + "image", + "imagine" + ], + "time": "2015-06-04 11:44:07" + }, + { "name": "michelf/php-markdown", "version": "1.5.0", "source": { diff --git a/src/PartKeepr/DoctrineReflectionBundle/Resources/views/model.js.twig b/src/PartKeepr/DoctrineReflectionBundle/Resources/views/model.js.twig @@ -8,7 +8,32 @@ Ext.define('{{ className }}', { { name: '{{ field.name|raw }}'{% if field.type%}, type: '{{ field.type }}'{% endif %}}{% if not loop.last %},{% endif %} {% endfor %} + {% if associations.MANY_TO_ONE|length > 0 %} + , + {% for association in associations.MANY_TO_ONE %} + { name: '{{ association.name }}Id', + reference: '{{ association.target }}' + }{% if not loop.last %},{% endif %} + + {% endfor %} + {% endif %} + ], + + {% if associations.ONE_TO_MANY|length > 0 %} + hasMany: [ + {% for association in associations.ONE_TO_MANY %} + { + name: '{{ association.name }}', + associationKey: '{{ association.name }}', + model: '{{ association.target }}' + }{% if not loop.last %},{% endif %} + + {% endfor %} + ], + {% endif %} + + {% if associations.MANY_TO_MANY|length > 0 %} manyToMany: { {% for association in associations.MANY_TO_MANY %} diff --git a/src/PartKeepr/DoctrineReflectionBundle/Services/ReflectionService.php b/src/PartKeepr/DoctrineReflectionBundle/Services/ReflectionService.php @@ -70,25 +70,52 @@ class ReflectionService { $associationMappings = array(); foreach ($associations as $association) { + $getterPlural = false; $associationType = $association["type"]; + switch ($association["type"]) { case ClassMetadataInfo::MANY_TO_MANY: $associationType = "MANY_TO_MANY"; + $getterPlural = true; break; + case ClassMetadataInfo::MANY_TO_ONE: + $associationType = "MANY_TO_ONE"; + $getterPlural = false; + break; + case ClassMetadataInfo::ONE_TO_MANY: + $associationType = "ONE_TO_MANY"; + $getterPlural = true; + break; //default: // die("Unknown association ".$association["type"]); } + $getter = "get".ucfirst($association["fieldName"]); + $getterField = lcfirst($cm->getReflectionClass()->getShortName()).str_replace( + ".", + "", + $this->convertPHPToExtJSClassName($association["targetEntity"]) + ); + if ($getterPlural) { + //$getter .= "s"; + $getterField .= "s"; + } + + + + $associationMappings[$associationType][] = array( "name" => $association["fieldName"], "target" => $this->convertPHPToExtJSClassName($association["targetEntity"]), + "getter" => $getter, + "getterField" => $getterField ); } $renderParams = array( "fields" => $fieldMappings, "associations" => $associationMappings, - "className" => $this->convertPHPToExtJSClassName($entity), + "className" => $this->convertPHPToExtJSClassName($entity) ); $targetService = $this->reader->getClassAnnotation( diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Manufacturer/ManufacturerEditor.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Manufacturer/ManufacturerEditor.js @@ -101,7 +101,7 @@ Ext.define('PartKeepr.ManufacturerEditor', { }, _onItemSaved: function (record) { - this.iclogoGrid.bindStore(record.iclogos()); + this.iclogoGrid.bindStore(record.icLogos()); }, onFileUploaded: function (response) { this.iclogoGrid.getStore().add({ @@ -118,7 +118,7 @@ Ext.define('PartKeepr.ManufacturerEditor', { this.iclogoGrid.store.remove(this.iclogoGrid.getSelectionModel().getLastSelected()); }, onEditStart: function () { - var store = this.record.iclogos(); + var store = this.record.icLogos(); this.iclogoGrid.bindStore(store); } }); \ No newline at end of file diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Manufacturer/ManufacturerEditorComponent.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Manufacturer/ManufacturerEditorComponent.js @@ -4,11 +4,10 @@ Ext.define('PartKeepr.ManufacturerEditorComponent', { navigationClass: 'PartKeepr.ManufacturerGrid', editorClass: 'PartKeepr.ManufacturerEditor', newItemText: i18n("New Manufacturer"), - model: 'PartKeepr.Manufacturer', + model: 'PartKeepr.ManufacturerBundle.Entity.Manufacturer', initComponent: function () { this.createStore({ sorters: [{ - proxy: PartKeepr.getRESTProxy("Manufacurer"), property: 'name', direction:'ASC' }] diff --git a/src/PartKeepr/ManufacturerBundle/Entity/Manufacturer.php b/src/PartKeepr/ManufacturerBundle/Entity/Manufacturer.php @@ -0,0 +1,245 @@ +<?php +namespace PartKeepr\ManufacturerBundle\Entity; + +use Doctrine\ORM\Mapping as ORM; +use PartKeepr\DoctrineReflectionBundle\Annotation\TargetService; +use PartKeepr\Manufacturer\ArrayCollection; +use PartKeepr\Util\BaseEntity; +use Symfony\Component\Serializer\Annotation\Groups; + +/** + * Represents a manufacturer + * + * @ORM\Entity + * @TargetService(uri="/api/manufacturers") + **/ +class Manufacturer extends BaseEntity +{ + /** + * The name of the manufacturer + * @ORM\Column(type="string",unique=true) + * @Groups({"default"}) + * + * @var string + */ + private $name; + + /** + * The address of the manufacturer + * @ORM\Column(type="text",nullable=true) + * @Groups({"default"}) + * + * @var string + */ + private $address; + + /** + * The URL + * @ORM\Column(type="string",nullable=true) + * @Groups({"default"}) + * + * @var string + */ + private $url; + + /** + * The email + * @ORM\Column(type="string",nullable=true) + * @Groups({"default"}) + * + * @var string + */ + private $email; + + /** + * The comment + * @ORM\Column(type="text",nullable=true) + * @Groups({"default"}) + * + * @var string + */ + private $comment; + + /** + * The phone number + * @ORM\Column(type="string",nullable=true) + * @Groups({"default"}) + * + * @var string + */ + private $phone; + + /** + * The fax number + * @ORM\Column(type="string",nullable=true) + * @Groups({"default"}) + * + * @var string + */ + private $fax; + + /** + * All ic logos of this manufacturer + * @ORM\OneToMany(targetEntity="PartKeepr\ManufacturerBundle\Entity\ManufacturerICLogo",mappedBy="manufacturer",cascade={"persist", "remove"}) + * @Groups({"default"}) + */ + private $icLogos; + + /** + * Creates a new manufacturer instance + */ + public function __construct() + { + $this->icLogos = new ArrayCollection(); + } + + /** + * Sets the name + * + * @param string $name The name + */ + public function setName($name) + { + $this->name = $name; + } + + /** + * Returns the name + * + * @return string The name + */ + public function getName() + { + return $this->name; + } + + /** + * Sets the phone number + * + * @param string $phone The phone number + */ + public function setPhone($phone) + { + $this->phone = $phone; + } + + /** + * Returns the phone number + * + * @return string The phone number + */ + public function getPhone() + { + return $this->phone; + } + + /** + * Sets the fax number + * + * @param string $fax The fax number + */ + public function setFax($fax) + { + $this->fax = $fax; + } + + /** + * Returns the fax number + * + * @return string The fax number + */ + public function getFax() + { + return $this->fax; + } + + /** + * Sets the address + * + * @param string $address The address + */ + public function setAddress($address) + { + $this->address = $address; + } + + /** + * Returns the address + * + * @return string The address + */ + public function getAddress() + { + return $this->address; + } + + /** + * Sets the comment + * + * @param string $comment The comment + */ + public function setComment($comment) + { + $this->comment = $comment; + } + + /** + * Returns the comment + * + * @return string The comment + */ + public function getComment() + { + return $this->comment; + } + + /** + * Sets the email + * + * @param string $email The email + */ + public function setEmail($email) + { + $this->email = $email; + } + + /** + * Returns the email + * + * @return string The email + */ + public function getEmail() + { + return $this->email; + } + + /** + * Sets the URL + * + * @param string $url The URL + */ + public function setURL($url) + { + $this->url = $url; + } + + /** + * Returns the URL + * + * @return string The url + */ + public function getURL() + { + return $this->url; + } + + /** + * Returns the ic logos + * + * @return ArrayCollection The array with all ic logos + */ + public function getICLogos() + { + return $this->icLogos; + } +}+ \ No newline at end of file diff --git a/src/PartKeepr/ManufacturerBundle/Entity/ManufacturerICLogo.php b/src/PartKeepr/ManufacturerBundle/Entity/ManufacturerICLogo.php @@ -0,0 +1,51 @@ +<?php +namespace PartKeepr\ManufacturerBundle\Entity; + +use Doctrine\ORM\Mapping as ORM; +use PartKeepr\Image\Image; +use PartKeepr\Util\Deserializable; +use PartKeepr\Util\Serializable; + +/** + * Holds a manufacturer IC logo + * + * @ORM\Entity + **/ +class ManufacturerICLogo extends Image +{ + /** + * The manufacturer object + * @ORM\ManyToOne(targetEntity="PartKeepr\ManufacturerBundle\Entity\Manufacturer", inversedBy="icLogos") + * + * @var Manufacturer + */ + private $manufacturer = null; + + /** + * Creates a new IC logo instance + */ + public function __construct() + { + parent::__construct(Image::IMAGE_ICLOGO); + } + + /** + * Sets the manufacturer + * + * @param Manufacturer $manufacturer The manufacturer to set + */ + public function setManufacturer(Manufacturer $manufacturer) + { + $this->manufacturer = $manufacturer; + } + + /** + * Returns the manufacturer + * + * @return Manufacturer the manufacturer + */ + public function getManufacturer() + { + return $this->manufacturer; + } +}+ \ No newline at end of file diff --git a/src/PartKeepr/ManufacturerBundle/PartKeeprManufacturerBundle.php b/src/PartKeepr/ManufacturerBundle/PartKeeprManufacturerBundle.php @@ -0,0 +1,8 @@ +<?php +namespace PartKeepr\ManufacturerBundle; + +use Symfony\Component\HttpKernel\Bundle\Bundle; + +class PartKeeprManufacturerBundle extends Bundle +{ +} diff --git a/src/backend/PartKeepr/Manufacturer/Manufacturer.php b/src/backend/PartKeepr/Manufacturer/Manufacturer.php @@ -1,251 +0,0 @@ -<?php -namespace PartKeepr\Manufacturer; - -use PartKeepr\Util\Deserializable, - PartKeepr\Util\Serializable, - PartKeepr\Util\BaseEntity, - PartKeepr\PartKeepr, - Doctrine\ORM\Mapping as ORM; - -/** - * Represents a manufacturer - * @ORM\Entity **/ -class Manufacturer extends BaseEntity implements Serializable, Deserializable { - /** - * The name of the manufacturer - * @ORM\Column(type="string",unique=true) - * @var string - */ - private $name; - - /** - * The address of the manufacturer - * @ORM\Column(type="text",nullable=true) - * @var string - */ - private $address; - - /** - * The URL - * @ORM\Column(type="string",nullable=true) - * @var string - */ - private $url; - - /** - * The email - * @ORM\Column(type="string",nullable=true) - * @var string - */ - private $email; - - /** - * The comment - * @ORM\Column(type="text",nullable=true) - * @var string - */ - private $comment; - - /** - * The phone number - * @ORM\Column(type="string",nullable=true) - * @var string - */ - private $phone; - - /** - * The fax number - * @ORM\Column(type="string",nullable=true) - * @var string - */ - private $fax; - - /** - * All ic logos of this manufacturer - * @ORM\OneToMany(targetEntity="PartKeepr\Manufacturer\ManufacturerICLogo",mappedBy="manufacturer",cascade={"persist", "remove"}) - */ - private $icLogos; - - /** - * Creates a new manufacturer instance - */ - public function __construct () { - $this->icLogos = new \Doctrine\Common\Collections\ArrayCollection(); - } - - /** - * Sets the name - * @param string $name The name - */ - public function setName ($name) { - $this->name = $name; - } - - /** - * Returns the name - * @return string The name - */ - public function getName () { - return $this->name; - } - - /** - * Sets the phone number - * @param string $phone The phone number - */ - public function setPhone ($phone) { - $this->phone = $phone; - } - - /** - * Returns the phone number - * @return string The phone number - */ - public function getPhone () { - return $this->phone; - } - - /** - * Sets the fax number - * @param string $fax The fax number - */ - public function setFax ($fax) { - $this->fax = $fax; - } - - /** - * Returns the fax number - * @return string The fax number - */ - public function getFax () { - return $this->fax; - } - - /** - * Sets the address - * @param string $address The address - */ - public function setAddress ($address) { - $this->address = $address; - } - - /** - * Returns the address - * @return string The address - */ - public function getAddress () { - return $this->address; - } - - /** - * Sets the comment - * @param string $comment The comment - */ - public function setComment ($comment) { - $this->comment = $comment; - } - - /** - * Returns the comment - * @return string The comment - */ - public function getComment () { - return $this->comment; - } - - /** - * Sets the email - * @param string $email The email - */ - public function setEmail ($email) { - $this->email = $email; - } - - /** - * Returns the email - * @return string The email - */ - public function getEmail () { - return $this->email; - } - - /** - * Sets the URL - * @param string $url The URL - */ - public function setURL ($url) { - $this->url = $url; - } - - /** - * Returns the URL - * @return string The url - */ - public function getURL () { - return $this->url; - } - - /** - * Returns the ic logos - * @return ArrayCollection The array with all ic logos - */ - public function getICLogos () { - return $this->icLogos; - } - - /** - * Returns this manufacturer in serialized form - * @return array The serialized manufacturer - */ - 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(), - "iclogos" => $this->serializeChildren($this->getICLogos()) - ); - } - - /** - * 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 "url": - $this->setURL($value); - break; - case "comment": - $this->setComment($value); - break; - case "email": - $this->setEmail($value); - break; - case "fax": - $this->setFax($value); - break; - case "phone": - $this->setPhone($value); - break; - case "address": - $this->setAddress($value); - break; - case "iclogos": - $this->deserializeChildren($value, $this->getICLogos(), "PartKeepr\Manufacturer\ManufacturerICLogo"); - foreach ($this->getICLogos() as $iclogo) { - $iclogo->setManufacturer($this); - } - break; - } - } - } -}- \ No newline at end of file diff --git a/src/backend/PartKeepr/Manufacturer/ManufacturerICLogo.php b/src/backend/PartKeepr/Manufacturer/ManufacturerICLogo.php @@ -1,64 +0,0 @@ -<?php -namespace PartKeepr\Manufacturer; - -use PartKeepr\Util\Deserializable, - PartKeepr\Util\Serializable, - PartKeepr\Image\Image, - Doctrine\ORM\Mapping as ORM; - -/** - * Holds a manufacturer IC logo - * @ORM\Entity - **/ -class ManufacturerICLogo extends Image implements Serializable, Deserializable { - /** - * The manufacturer object - * @ORM\ManyToOne(targetEntity="PartKeepr\Manufacturer\Manufacturer", inversedBy="icLogos") - * @var Manufacturer - */ - private $manufacturer = null; - - /** - * Creates a new IC logo instance - */ - public function __construct () { - parent::__construct(Image::IMAGE_ICLOGO); - } - - /** - * Sets the manufacturer - * @param Manufacturer $manufacturer The manufacturer to set - */ - public function setManufacturer (Manufacturer $manufacturer) { - $this->manufacturer = $manufacturer; - } - - /** - * Returns the manufacturer - * @return Manufacturer the manufacturer - */ - public function getManufacturer () { - return $this->manufacturer; - } - - /** - * - * Serializes this ic logo - * @return array The serialized ic logo - */ - public function serialize () { - return array("id" => $this->getId(), "manufacturer_id" => $this->getManufacturer()->getId()); - } - - /** - * Deserializes the iclogo - * @param array $parameters The array with the parameters to set - */ - public function deserialize (array $parameters) { - if (array_key_exists("id", $parameters)) { - if (substr($parameters["id"], 0, 4) === "TMP:") { - $this->replaceFromTemporaryFile($parameters["id"]); - } - } - } -}- \ No newline at end of file diff --git a/src/backend/PartKeepr/Manufacturer/ManufacturerManager.php b/src/backend/PartKeepr/Manufacturer/ManufacturerManager.php @@ -1,104 +0,0 @@ -<?php -namespace PartKeepr\Manufacturer; - -use PartKeepr\Util\Singleton, - PartKeepr\Manufacturer\Manufacturer, - PartKeepr\PartKeepr, - PartKeepr\Category\CategoryManager, - PartKeepr\Manufacturer\Exceptions\ManufacturerNotFoundException; - -class ManufacturerManager extends Singleton { - /** - * Returns a list of manufacturers. - * - * @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 manufacturer's name by, default empty - */ - public function getManufacturers ($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")->from("PartKeepr\Manufacturer\Manufacturer","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\Manufacturer\Manufacturer","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()); - } - - /** - * Adds a new manufacturer by name - * - * @param string $name The manufacturer name - */ - public function addManufacturer ($name) { - $manufacturer = new Manufacturer(); - $manufacturer->setName($name); - - PartKeepr::getEM()->persist($manufacturer); - PartKeepr::getEM()->flush(); - - return $manufacturer; - } - - /** - * Loads a manufacturer by id - * - * @param int $id The manufacturer id - */ - public function getManufacturer ($id) { - return Manufacturer::loadById($id); - } - - /** - * Deletes the manufacturer by id - * @param int $id The manufacturer's id - */ - public function deleteManufacturer ($id) { - $manufacturer = Manufacturer::loadById($id); - - PartKeepr::getEM()->remove($manufacturer); - PartKeepr::getEM()->flush(); - } - - /** - * Retrieves a manufacturer by its name. - * - * @param string $name The name of the manufacturer to retrieve - * @throws Doctrine\ORM\NoResultException If the manufacturer was not found - */ - public function getManufacturerByName ($name) { - $dql = "SELECT m FROM PartKeepr\Manufacturer\Manufacturer m WHERE m.name = :name"; - $query = PartKeepr::getEM()->createQuery($dql); - $query->setParameter("name", $name); - - return $query->getSingleResult(); - } -}- \ No newline at end of file diff --git a/src/backend/PartKeepr/Manufacturer/ManufacturerService.php b/src/backend/PartKeepr/Manufacturer/ManufacturerService.php @@ -1,82 +0,0 @@ -<?php -namespace PartKeepr\Manufacturer; - -use PartKeepr\Service\RestfulService; - -use PartKeepr\Service\Service, - PartKeepr\Part\PartManager, - PartKeepr\Stock\StockEntry, - PartKeepr\PartKeepr, - PartKeepr\Session\SessionManager; - -class ManufacturerService extends Service implements RestfulService { - /** - * (non-PHPdoc) - * @see PartKeepr\Service.RestfulService::get() - */ - public function get () { - if ($this->hasParameter("id")) { - return array("data" => ManufacturerManager::getInstance()->getManufacturer($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 ManufacturerManager::getInstance()->getManufacturers( - $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"); - - $manufacturer = new Manufacturer; - $manufacturer->deserialize($this->getParameters()); - - PartKeepr::getEM()->persist($manufacturer); - PartKeepr::getEM()->flush(); - - return array("data" => $manufacturer->serialize()); - } - - /** - * (non-PHPdoc) - * @see PartKeepr\Service.RestfulService::update() - */ - public function update () { - $this->requireParameter("id"); - $this->requireParameter("name"); - $manufacturer = ManufacturerManager::getInstance()->getManufacturer($this->getParameter("id")); - $manufacturer->deserialize($this->getParameters()); - - PartKeepr::getEM()->flush(); - - return array("data" => $manufacturer->serialize()); - - } - - /** - * (non-PHPdoc) - * @see PartKeepr\Service.RestfulService::destroy() - */ - public function destroy () { - $this->requireParameter("id"); - - ManufacturerManager::getInstance()->deleteManufacturer($this->getParameter("id")); - - return array("data" => null); - } -}- \ No newline at end of file diff --git a/src/backend/PartKeepr/ManufacturerICLogo/ManufacturerICLogoManager.php b/src/backend/PartKeepr/ManufacturerICLogo/ManufacturerICLogoManager.php @@ -1,65 +0,0 @@ -<?php -namespace PartKeepr\ManufacturerICLogo; - -use PartKeepr\Util\Singleton, - PartKeepr\Manufacturer\Manufacturer, - PartKeepr\PartKeepr, - PartKeepr\Manufacturer\Exceptions\ManufacturerNotFoundException; - -class ManufacturerICLogoManager extends Singleton { - /** - * Returns a list of manufacturer ic logos. - * - * @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 The manufacturer id - */ - public function getManufacturerICLogos ($start = 0, $limit = 10, $sort = "name", $dir = "asc", $filter = "") { - - $qb = PartKeepr::getEM()->createQueryBuilder(); - $qb->select("st.id, maf.id AS manufacturer_id")->from("PartKeepr\Manufacturer\ManufacturerICLogo","st") - ->leftJoin('st.manufacturer', "maf"); - - if ($filter != "") { - $manufacturer = Manufacturer::loadById($filter); - $qb = $qb->where("st.manufacturer = :manufacturer"); - $qb->setParameter("manufacturer", $manufacturer); - } - - 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\Manufacturer\ManufacturerICLogo","st"); - - - - if ($filter != "") { - $totalQueryBuilder = $totalQueryBuilder->where("st.manufacturer = :manufacturer"); - $totalQueryBuilder->setParameter("manufacturer", $manufacturer); - } - - $totalQuery = $totalQueryBuilder->getQuery(); - - return array("data" => $result, "totalCount" => $totalQuery->getSingleScalarResult()); - } - - /** - * Returns a manufacturer ic logo by id - * @param int $id The manufacturer ic logo id - */ - public function getManufacturerICLogo ($id) { - return ManufacturerICLogo::loadById($id); - } - -}- \ No newline at end of file diff --git a/src/backend/PartKeepr/ManufacturerICLogo/ManufacturerICLogoService.php b/src/backend/PartKeepr/ManufacturerICLogo/ManufacturerICLogoService.php @@ -1,101 +0,0 @@ -<?php -namespace PartKeepr\ManufacturerICLogo; - -use PartKeepr\Manufacturer\ManufacturerICLogo, - PartKeepr\TempImage\TempImage, - PartKeepr\Service\RestfulService, - PartKeepr\Service\Service, - PartKeepr\PartKeepr, - PartKeepr\Manufacturer\Manufacturer, - PartKeepr\Session\SessionManager; - -class ManufacturerICLogoService extends Service implements RestfulService { - /** - * (non-PHPdoc) - * @see PartKeepr\Service.RestfulService::get() - */ - public function get () { - if ($this->hasParameter("id")) { - return ManufacturerICLogoManager::getInstance()->getManufacturerICLogo($this->getParameter("id"))->serialize(); - } else { - if ($this->hasParameter("sort")) { - $tmp = json_decode($this->getParameter("sort"), true); - - $aSortParams = $tmp[0]; - } else { - $aSortParams = array( - "property" => "id", - "direction" => "ASC"); - } - - $filter = ""; - - if ($this->hasParameter("filter")) { - $tmp = json_decode($this->getParameter("filter"), true); - - foreach ($tmp as $item) { - if (array_key_exists("property", $item)) { - if ($item["property"] == "manufacturer_id") { - if (array_key_exists("value", $item)) { - $filter = $item["value"]; - } - } - } - } - } - return ManufacturerICLogoManager::getInstance()->getManufacturerICLogos( - $this->getParameter("start", $this->getParameter("start", 0)), - $this->getParameter("limit", $this->getParameter("limit", 25)), - $this->getParameter("sortby", $aSortParams["property"]), - $this->getParameter("dir", $aSortParams["direction"]), - $filter); - } - } - - /** - * (non-PHPdoc) - * @see PartKeepr\Service.RestfulService::create() - */ - public function create () { - $this->requireParameter("tmp_id"); - $this->requireParameter("manufacturer_id"); - - $tmpImage = TempImage::loadById($this->getParameter("tmp_id")); - - $image = new ManufacturerICLogo(); - - $manufacturer = Manufacturer::loadById($this->getParameter("manufacturer_id")); - - $image->setManufacturer($manufacturer); - $image->replace($tmpImage->getFilename()); - $image->setOriginalFilename($tmpImage->getOriginalFilename()); - PartKeepr::getEM()->persist($image); - PartKeepr::getEM()->flush(); - - return $image->serialize(); - } - - /** - * (non-PHPdoc) - * @see PartKeepr\Service.RestfulService::update() - */ - public function update () { - - } - - /** - * (non-PHPdoc) - * @see PartKeepr\Service.RestfulService::destroy() - */ - public function destroy () { - $this->requireParameter("id"); - - $logo = ManufacturerICLogo::loadById($this->getParameter("id")); - - PartKeepr::getEM()->remove($logo); - PartKeepr::getEM()->flush(); - - return array("data" => null); - } - -}- \ No newline at end of file diff --git a/src/backend/PartKeepr/Part/PartManager.php b/src/backend/PartKeepr/Part/PartManager.php @@ -18,7 +18,7 @@ use PartKeepr\UploadedFile\TempUploadedFile, Doctrine\ORM\Query, PartKeepr\PartUnit\PartUnitManager, PartKeepr\DistributorBundle\Entity\Distributor, - PartKeepr\Manufacturer\Manufacturer, + PartKeepr\ManufacturerBundle\Entity\Manufacturer, \PartKeepr\FootprintBundle\Entity\FootprintManager, PartKeepr\Session\SessionManager, PartKeepr\Stock\StockEntry, diff --git a/src/backend/PartKeepr/Part/PartManufacturer.php b/src/backend/PartKeepr/Part/PartManufacturer.php @@ -5,7 +5,7 @@ use PartKeepr\Util\Deserializable, PartKeepr\Util\Serializable, PartKeepr\Util\BaseEntity, PartKeepr\PartKeepr, - PartKeepr\Manufacturer\Manufacturer, + PartKeepr\ManufacturerBundle\Entity\Manufacturer, Doctrine\ORM\Mapping as ORM; /** @ORM\Entity **/ @@ -16,7 +16,7 @@ class PartManufacturer extends BaseEntity implements Serializable, Deserializabl private $part; /** - * @ORM\ManyToOne(targetEntity="PartKeepr\Manufacturer\Manufacturer") + * @ORM\ManyToOne(targetEntity="PartKeepr\ManufacturerBundle\Entity\Manufacturer") */ private $manufacturer; diff --git a/src/backend/PartKeepr/PartDistributor/PartDistributorManager.php b/src/backend/PartKeepr/PartDistributor/PartDistributorManager.php @@ -2,7 +2,7 @@ namespace PartKeepr\PartDistributor; use PartKeepr\Util\Singleton, - PartKeepr\Manufacturer\Manufacturer, + PartKeepr\ManufacturerBundle\Entity\Manufacturer, PartKeepr\PartKeepr, PartKeepr\Manufacturer\Exceptions\ManufacturerNotFoundException; diff --git a/src/backend/PartKeepr/PartDistributor/PartDistributorService.php b/src/backend/PartKeepr/PartDistributor/PartDistributorService.php @@ -1,11 +1,11 @@ <?php namespace PartKeepr\ManufacturerICLogo; -use PartKeepr\Manufacturer\ManufacturerICLogo, +use PartKeepr\ManufacturerBundle\Entity\ManufacturerICLogo, PartKeepr\Service\RestfulService, PartKeepr\Service\Service, PartKeepr\PartKeepr, - PartKeepr\Manufacturer\Manufacturer, + PartKeepr\ManufacturerBundle\Entity\Manufacturer, PartKeepr\Session\SessionManager; class PartDistributorService extends Service implements RestfulService { diff --git a/src/backend/PartKeepr/PartKeepr.php b/src/backend/PartKeepr/PartKeepr.php @@ -180,8 +180,8 @@ class PartKeepr { 'PartKeepr\Stock\StockEntry', - 'PartKeepr\Manufacturer\Manufacturer', - 'PartKeepr\Manufacturer\ManufacturerICLogo', + 'PartKeepr\ManufacturerBundle\Entity\Manufacturer', + 'PartKeepr\ManufacturerBundle\Entity\ManufacturerICLogo', 'PartKeepr\DistributorBundle\Entity\Distributor', diff --git a/src/backend/PartKeepr/Setup/ManufacturerSetup.php b/src/backend/PartKeepr/Setup/ManufacturerSetup.php @@ -2,9 +2,9 @@ namespace PartKeepr\Setup; use PartKeepr\PartKeepr, - PartKeepr\Manufacturer\Manufacturer, + PartKeepr\ManufacturerBundle\Entity\Manufacturer, PartKeepr\Manufacturer\ManufacturerManager, - PartKeepr\Manufacturer\ManufacturerICLogo, + PartKeepr\ManufacturerBundle\Entity\ManufacturerICLogo, PartKeepr\Setup\SiPrefixSetup; /** diff --git a/src/backend/PartKeepr/UploadedFile/UploadedFile.php b/src/backend/PartKeepr/UploadedFile/UploadedFile.php @@ -8,6 +8,7 @@ use PartKeepr\Util\SerializableException, PartKeepr\UploadedFile\TempUploadedFile, PartKeepr\Util\Configuration, Doctrine\ORM\Mapping as ORM; +use Symfony\Component\Serializer\Annotation\Groups; /** * @ORM\MappedSuperclass @@ -16,36 +17,48 @@ abstract class UploadedFile extends BaseEntity implements Serializable { /** * Specifies the type of the file. * - * @var string * @ORM\Column(type="string") + * @Groups({"default"}) + * + * @var string **/ private $type; /** * The unique filename of the file * - * @var string * @ORM\Column(type="string") + * @Groups({"default"}) + * + * @var string */ private $filename; /** * The original name of the file - * @ORM\Column(type="string",nullable=true) + * + * @ORM\Column(type="string",nullable=true,name="originalname") + * @Groups({"default"}) + * * @var string */ - private $originalname; + private $originalFilename; /** - * The mimetype for the file - * @var string + * The MimeType for the file + * * @ORM\Column(type="string") + * @Groups({"default"}) + * + * @var string */ private $mimetype; /** * The size of the uploaded file * @ORM\Column(type="integer") + * @Groups({"default"}) + * * @var integer */ private $size; @@ -71,7 +84,7 @@ abstract class UploadedFile extends BaseEntity implements Serializable { * @return string The original filename */ public function getOriginalFilename () { - return $this->originalname; + return $this->originalFilename; } /** @@ -79,7 +92,7 @@ abstract class UploadedFile extends BaseEntity implements Serializable { * @param string $filename The original filename */ public function setOriginalFilename ($filename) { - $this->originalname = $filename; + $this->originalFilename = $filename; } /**