partkeepr

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

commit 3560935cb480e0b0d40aba3d3fac393a6aeeeb38
parent e1faebe24a3f56f454955af8d009502d4813cb29
Author: Felicitus <felicitus@felicitus.org>
Date:   Mon, 16 Dec 2013 23:19:58 +0100

Moved SiPrefix to its own bundle

Diffstat:
Mapp/AppKernel.php | 2++
Asrc/PartKeepr/SiPrefixBundle/Model/SiPrefix.php | 127+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/PartKeepr/SiPrefixBundle/PartKeeprSiPrefixBundle.php | 9+++++++++
Rsetup-data/siprefixes.yaml -> src/PartKeepr/SiPrefixBundle/Resources/data/siprefixes.yaml | 0
Asrc/PartKeepr/SiPrefixBundle/Resources/translations/validators.en.yml | 3+++
Asrc/PartKeepr/SiPrefixBundle/Tests/Model/SiPrefixTest.php | 34++++++++++++++++++++++++++++++++++
Msrc/backend/PartKeepr/Part/PartManager.php | 2+-
Msrc/backend/PartKeepr/PartKeepr.php | 2+-
Msrc/backend/PartKeepr/PartParameter/PartParameter.php | 4++--
Msrc/backend/PartKeepr/Setup/SiPrefixSetup.php | 4++--
Msrc/backend/PartKeepr/Setup/UnitSetup.php | 2+-
Dsrc/backend/PartKeepr/SiPrefix/SiPrefix.php | 93-------------------------------------------------------------------------------
Msrc/backend/PartKeepr/SiPrefix/SiPrefixManager.php | 4++--
Msrc/backend/PartKeepr/SiPrefix/SiPrefixService.php | 2+-
Msrc/backend/PartKeepr/Unit/Unit.php | 4++--
Msrc/backend/PartKeepr/Unit/UnitService.php | 2+-
16 files changed, 188 insertions(+), 106 deletions(-)

diff --git a/app/AppKernel.php b/app/AppKernel.php @@ -56,6 +56,8 @@ class AppKernel extends Kernel new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(), new PartKeepr\FrontendBundle\PartKeeprFrontendBundle(), + + new PartKeepr\SiPrefixBundle\PartKeeprSiPrefixBundle() ); if (in_array($this->getEnvironment(), array('dev', 'test'))) { diff --git a/src/PartKeepr/SiPrefixBundle/Model/SiPrefix.php b/src/PartKeepr/SiPrefixBundle/Model/SiPrefix.php @@ -0,0 +1,126 @@ +<?php +namespace PartKeepr\SiPrefixBundle\Model; + +use PartKeepr\Util\BaseEntity, + Doctrine\ORM\Mapping as ORM, + Symfony\Component\Validator\Constraints as Assert; + +/** + * Represents an SI Prefix + * + * @link http://en.wikipedia.org/wiki/Metric_prefix + * + * @ORM\Entity + */ +class SiPrefix extends BaseEntity +{ + /** + * The prefix of the Si-Prefix (e.g. yotta, deca, deci, centi) + * + * @ORM\Column(type="string") + * + * @Assert\Type(type="string") + * @Assert\NotBlank(message="siprefix.prefix.not_blank") + * + * @var string + */ + private $prefix; + + /** + * The symbol of the Si-Prefix (e.g. m, M, G) + * + * @ORM\Column(type="string",length=2) + * + * @Assert\Type(type="string") + * @Assert\NotBlank(message="siprefix.symbol.not_blank") + * + * @var string + */ + private $symbol; + + /** + * The power of the Si-Prefix (e.g. milli = 10^-3) + * + * @ORM\Column(type="integer") + * @Assert\Type(type="integer") + * + * @var int + */ + private $power; + + /** + * Sets the prefix name. + * + * @param string $prefix + */ + public function setPrefix($prefix) + { + $this->prefix = $prefix; + } + + /** + * Returns the prefix name + * + * + * @return string The prefix name + */ + public function getPrefix() + { + return $this->prefix; + } + + /** + * Sets the symbol for the prefix + * + * @param string $symbol The symbol + */ + public function setSymbol($symbol) + { + $this->symbol = $symbol; + } + + /** + * Returns the symbol for the prefix + * + * @return string The symbol + */ + public function getSymbol() + { + return $this->symbol; + } + + /** + * Sets the power in a 10^n power (n=power) + * + * @param int $power The 10^power + */ + public function setPower($power) + { + $this->power = $power; + } + + /** + * Returns the power (10^n) + * + * @return int The power + */ + public function getPower() + { + return $this->power; + } + + /** + * Serializes the object into an array format. + * + * @return array the object in serialized format. + */ + public function serialize() + { + return array( + "id" => $this->getId(), + "symbol" => $this->getSymbol(), + "prefix" => $this->getPrefix(), + "power" => $this->getPower() + ); + } +}+ \ No newline at end of file diff --git a/src/PartKeepr/SiPrefixBundle/PartKeeprSiPrefixBundle.php b/src/PartKeepr/SiPrefixBundle/PartKeeprSiPrefixBundle.php @@ -0,0 +1,8 @@ +<?php +namespace PartKeepr\SiPrefixBundle; + +use Symfony\Component\HttpKernel\Bundle\Bundle; + +class PartKeeprSiPrefixBundle extends Bundle +{ +}+ \ No newline at end of file diff --git a/setup-data/siprefixes.yaml b/src/PartKeepr/SiPrefixBundle/Resources/data/siprefixes.yaml diff --git a/src/PartKeepr/SiPrefixBundle/Resources/translations/validators.en.yml b/src/PartKeepr/SiPrefixBundle/Resources/translations/validators.en.yml @@ -0,0 +1,2 @@ +siprefix.prefix.not_blank: The SI prefix may not be empty. +siprefix.symbol.not_blank: The SI prefix symbol may not be empty.+ \ No newline at end of file diff --git a/src/PartKeepr/SiPrefixBundle/Tests/Model/SiPrefixTest.php b/src/PartKeepr/SiPrefixBundle/Tests/Model/SiPrefixTest.php @@ -0,0 +1,33 @@ +<?php +namespace PartKeepr\SiPrefixBundle\Tests\Model; + +use PartKeepr\SiPrefixBundle\Model\SiPrefix; + +class SiPrefixTest extends \PHPUnit_Framework_TestCase { + + public function testPrefix () { + $siPrefix = $this->getSiPrefix(); + + $siPrefix->setPrefix("yotta"); + $this->assertEquals("yotta", $siPrefix->getPrefix()); + } + + public function testSymbol () { + $siPrefix = $this->getSiPrefix(); + + $siPrefix->setSymbol("µ"); + + $this->assertEquals("µ", $siPrefix->getSymbol()); + } + + public function testPower () { + $siPrefix = $this->getSiPrefix(); + + $siPrefix->setPower(10); + $this->assertEquals(10, $siPrefix->getPower()); + } + + private function getSiPrefix () { + return new SiPrefix(); + } +}+ \ No newline at end of file diff --git a/src/backend/PartKeepr/Part/PartManager.php b/src/backend/PartKeepr/Part/PartManager.php @@ -9,7 +9,7 @@ use PartKeepr\UploadedFile\TempUploadedFile, PartKeepr\PartParameter\PartParameter, PartKeepr\Manager\AbstractManager, PartKeepr\Unit\Unit, - PartKeepr\SiPrefix\SiPrefix, + PartKeepr\SiPrefixBundle\Model\SiPrefix, PartKeepr\Part\PartDistributor, PartKeepr\Part\PartManufacturer, PartKeepr\StorageLocation\StorageLocation, diff --git a/src/backend/PartKeepr/PartKeepr.php b/src/backend/PartKeepr/PartKeepr.php @@ -194,7 +194,7 @@ class PartKeepr { 'PartKeepr\Statistic\StatisticSnapshot', 'PartKeepr\Statistic\StatisticSnapshotUnit', - 'PartKeepr\SiPrefix\SiPrefix', + 'PartKeepr\SiPrefixBundle\Model\SiPrefix', 'PartKeepr\Unit\Unit', 'PartKeepr\PartParameter\PartParameter', diff --git a/src/backend/PartKeepr/PartParameter/PartParameter.php b/src/backend/PartKeepr/PartParameter/PartParameter.php @@ -5,7 +5,7 @@ use PartKeepr\PartKeepr, PartKeepr\Util\Exceptions\OutOfRangeException, PartKeepr\Unit\Unit, PartKeepr\Part\Part, -PartKeepr\SiPrefix\SiPrefix, +PartKeepr\SiPrefixBundle\Model\SiPrefix, Doctrine\ORM\Mapping as ORM; @@ -64,7 +64,7 @@ class PartParameter { /** * The SiPrefix of the unit - * @ORM\ManyToOne(targetEntity="PartKeepr\SiPrefix\SiPrefix") + * @ORM\ManyToOne(targetEntity="PartKeepr\SiPrefixBundle\Model\SiPrefix") * @var object */ private $siPrefix; diff --git a/src/backend/PartKeepr/Setup/SiPrefixSetup.php b/src/backend/PartKeepr/Setup/SiPrefixSetup.php @@ -2,8 +2,8 @@ namespace PartKeepr\Setup; use PartKeepr\PartKeepr, - PartKeepr\SiPrefix\SiPrefix, - PartKeepr\SiPrefix\SiPrefixManager; + PartKeepr\SiPrefixBundle\Model\SiPrefix, + PartKeepr\SiPrefixBundle\Model\SiPrefixManager; class SiPrefixSetup extends AbstractSetup { diff --git a/src/backend/PartKeepr/Setup/UnitSetup.php b/src/backend/PartKeepr/Setup/UnitSetup.php @@ -3,7 +3,7 @@ namespace PartKeepr\Setup; use PartKeepr\PartKeepr, PartKeepr\Unit\Unit, - PartKeepr\SiPrefix\SiPrefixManager, + PartKeepr\SiPrefixBundle\Model\SiPrefixManager, PartKeepr\Unit\UnitManager, PartKeepr\Setup\SiPrefixSetup; diff --git a/src/backend/PartKeepr/SiPrefix/SiPrefix.php b/src/backend/PartKeepr/SiPrefix/SiPrefix.php @@ -1,92 +0,0 @@ -<?php -namespace PartKeepr\SiPrefix; - -use PartKeepr\Util\BaseEntity, - PartKeepr\PartKeepr, - PartKeepr\Util\Exceptions\OutOfRangeException, - Doctrine\ORM\Mapping as ORM; - - -/** @ORM\Entity **/ -class SiPrefix extends BaseEntity { - /** - * The prefix of the Si-Prefix (e.g. yotta, deca, deci, centi) - * @ORM\Column(type="string") - * @var string - */ - private $prefix; - - /** - * The symbol of the Si-Prefix (e.g. m, M, G) - * @ORM\Column(type="string",length=2) - * @var string - */ - private $symbol; - - /** - * The power of the Si-Prefix (e.g. milli = 10^-3) - * @ORM\Column(type="integer") - * @var int - */ - private $power; - - /** - * Sets the prefix name. - * @param string $prefix - */ - public function setPrefix ($prefix) { - $this->prefix = $prefix; - } - - /** - * Returns the prefix name - * @return string The prefix name - */ - public function getPrefix () { - return $this->prefix; - } - - /** - * Sets the symbol for the prefix - * @param string $symbol The symbol - */ - public function setSymbol ($symbol) { - $this->symbol = $symbol; - } - - /** - * Returns the symbol for the prefix - * @return string The symbol - */ - public function getSymbol () { - return $this->symbol; - } - - /** - * Sets the power in a 10^n power (n=power) - * @param int $power The 10^power - */ - public function setPower ($power) { - $this->power = $power; - } - - /** - * Returns the power (10^n) - * @return int The power - */ - public function getPower () { - return $this->power; - } - - /** - * Serializes the object into an array format. - * @return array the object in serialized format. - */ - public function serialize () { - return array( - "id" => $this->getId(), - "symbol" => $this->getSymbol(), - "prefix" => $this->getPrefix(), - "power" => $this->getPower()); - } -}- \ No newline at end of file diff --git a/src/backend/PartKeepr/SiPrefix/SiPrefixManager.php b/src/backend/PartKeepr/SiPrefix/SiPrefixManager.php @@ -22,14 +22,14 @@ class SiPrefixManager extends Singleton { } private function createSiPrefixSymbolCache () { - $dql = "SELECT sip FROM PartKeepr\SiPrefix\SiPrefix sip"; + $dql = "SELECT sip FROM PartKeepr\SiPrefixBundle\Model\SiPrefix sip"; $query = PartKeepr::getEM()->createQuery($dql); $this->siPrefixSymbolCache = $query->getResult(); } public function siPrefixExists ($prefix) { - $dql = "SELECT COUNT(sip) FROM PartKeepr\SiPrefix\SiPrefix sip WHERE sip.prefix = :prefix"; + $dql = "SELECT COUNT(sip) FROM PartKeepr\SiPrefixBundle\Model\SiPrefix sip WHERE sip.prefix = :prefix"; $query = PartKeepr::getEM()->createQuery($dql); $query->setParameter("prefix", $prefix); diff --git a/src/backend/PartKeepr/SiPrefix/SiPrefixService.php b/src/backend/PartKeepr/SiPrefix/SiPrefixService.php @@ -8,7 +8,7 @@ use PartKeepr\Service\RestfulService, class SiPrefixService extends Service implements RestfulService { public function get () { - $query = PartKeepr::getEM()->createQuery("SELECT si.id, si.prefix, si.symbol, si.power FROM PartKeepr\SiPrefix\SiPrefix si"); + $query = PartKeepr::getEM()->createQuery("SELECT si.id, si.prefix, si.symbol, si.power FROM PartKeepr\SiPrefixBundle\Model\SiPrefix si"); return array("data" => $query->getArrayResult()); } diff --git a/src/backend/PartKeepr/Unit/Unit.php b/src/backend/PartKeepr/Unit/Unit.php @@ -6,7 +6,7 @@ use PartKeepr\Util\Deserializable, PartKeepr\Util\BaseEntity, PartKeepr\PartKeepr, PartKeepr\Util\Exceptions\OutOfRangeException, - PartKeepr\SiPrefix\SiPrefix, + PartKeepr\SiPrefixBundle\Model\SiPrefix, Doctrine\ORM\Mapping as ORM; @@ -32,7 +32,7 @@ class Unit extends BaseEntity implements Serializable, Deserializable { /** * Defines the allowed SiPrefixes for this parameter unit - * @ORM\ManyToMany(targetEntity="PartKeepr\SiPrefix\SiPrefix") + * @ORM\ManyToMany(targetEntity="PartKeepr\SiPrefixBundle\Model\SiPrefix") * @ORM\JoinTable(name="UnitSiPrefixes", * joinColumns={@ORM\JoinColumn(name="unit_id", referencedColumnName="id")}, * inverseJoinColumns={@ORM\JoinColumn(name="siprefix_id", referencedColumnName="id")} diff --git a/src/backend/PartKeepr/Unit/UnitService.php b/src/backend/PartKeepr/Unit/UnitService.php @@ -5,7 +5,7 @@ use PartKeepr\Service\RestfulService, PartKeepr\Service\Service, PartKeepr\PartKeepr, PartKeepr\Part\PartUnit, - PartKeepr\SiPrefix\SiPrefix, + PartKeepr\SiPrefixBundle\Model\SiPrefix, PartKeepr\Session\SessionManager; class UnitService extends Service implements RestfulService {