partkeepr

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

commit aeebf552009032f532a5eb22dc25d9933ff03fa9
parent a27660c6eab709e115cca0c687cccd238ac52909
Author: Felicitus <felicitus@felicitus.org>
Date:   Mon, 13 Jul 2015 23:48:22 +0200

Removed obsolete manager/service code

Diffstat:
Dsrc/PartKeepr/FootprintBundle/Entity/FootprintCategoryManager.php | 43-------------------------------------------
Dsrc/PartKeepr/FootprintBundle/Entity/FootprintCategoryService.php | 10----------
Dsrc/PartKeepr/FootprintBundle/Entity/FootprintManager.php | 158-------------------------------------------------------------------------------
Dsrc/PartKeepr/FootprintBundle/Entity/FootprintService.php | 96-------------------------------------------------------------------------------
Dsrc/PartKeepr/PartBundle/Entity/PartCategoryManager.php | 43-------------------------------------------
Dsrc/PartKeepr/PartBundle/Entity/PartCategoryService.php | 10----------
6 files changed, 0 insertions(+), 360 deletions(-)

diff --git a/src/PartKeepr/FootprintBundle/Entity/FootprintCategoryManager.php b/src/PartKeepr/FootprintBundle/Entity/FootprintCategoryManager.php @@ -1,42 +0,0 @@ -<?php -namespace PartKeepr\FootprintBundle\Entity; - -use PartKeepr\Category\AbstractCategoryManager; -use DoctrineExtensions\NestedSet\NodeWrapper; -use PartKeepr\Util\SerializableException; -use PartKeepr\PartKeepr; - -class FootprintCategoryManager extends AbstractCategoryManager { - protected $categoryClass = "PartKeepr\FootprintBundle\Entity\FootprintCategory"; - - /** - * Deletes the given category ID. - * @param $id int The category id to delete - * @throws CategoryNotFoundException If the category wasn't found - */ - public function deleteCategory ($id) { - $category = $this->getCategory($id); - - try { - - if ($category->hasChildren()) { - $exception = new SerializableException(sprintf(PartKeepr::i18n("Category '%s' contains other categories."), $category->getNode()->getName())); - $exception->setDetail(sprintf(PartKeepr::i18n("You tried to delete the category '%s', but it still contains other categories. Please move the categories or delete them first."), $category->getNode()->getName())); - - throw $exception; - } - - parent::deleteCategory($id); - } catch (\PDOException $e) { - if ($e->getCode() == "23000") { - $exception = new SerializableException(sprintf(PartKeepr::i18n("Category '%s' contains footprints."), $category->getNode()->getName())); - $exception->setDetail(sprintf(PartKeepr::i18n("You tried to delete the category '%s', but it still contains footprints. Please move the footprints to another category."), $category->getNode()->getName())); - - throw $exception; - } else { - throw $e; - } - } - } - -}- \ No newline at end of file diff --git a/src/PartKeepr/FootprintBundle/Entity/FootprintCategoryService.php b/src/PartKeepr/FootprintBundle/Entity/FootprintCategoryService.php @@ -1,9 +0,0 @@ -<?php -namespace PartKeepr\FootprintBundle\Entity; - -use PartKeepr\Category\AbstractCategoryService; - -class FootprintCategoryService extends AbstractCategoryService { - protected $categoryManagerClass = "PartKeepr\FootprintBundle\Entity\FootprintCategoryManager"; - protected $categoryClass = "PartKeepr\FootprintBundle\Entity\FootprintCategory"; -}- \ No newline at end of file diff --git a/src/PartKeepr/FootprintBundle/Entity/FootprintManager.php b/src/PartKeepr/FootprintBundle/Entity/FootprintManager.php @@ -1,158 +0,0 @@ -<?php -namespace PartKeepr\FootprintBundle\Entity; - -use PartKeepr\Util\Singleton, - PartKeepr\Util\SerializableException, - \PartKeepr\FootprintBundle\Entity\Footprint, - PartKeepr\PartKeepr, - PartKeepr\Util\Exceptions\EntityNotFoundException; - -class FootprintManager extends Singleton { - /** - * Returns a list of footprints. - * - * @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 footprint's name by, default empty - */ - public function getFootprints ($start = 0, $limit = 10, $sort = "name", $dir = "asc", $filter = "") { - - $qb = PartKeepr::getEM()->createQueryBuilder(); - $qb->select("f.id, f.name, f.description, im.id AS image_id, ca.id AS category")->from("PartKeepr\Footprint\Footprint","f") - ->leftJoin("f.image", "im") - ->leftJoin("f.category", "ca"); - - if ($filter != "") { - $qb = $qb->where("LOWER(f.name) LIKE :filter"); - $qb->setParameter("filter", "%".strtolower($filter)."%"); - } - - if ($limit > -1) { - $qb->setMaxResults($limit); - $qb->setFirstResult($start); - } - - $qb->orderBy("f.".$sort, $dir); - - $query = $qb->getQuery(); - - $result = $query->getResult(); - - $totalQueryBuilder = PartKeepr::getEM()->createQueryBuilder(); - $totalQueryBuilder->select("COUNT(f.id)")->from("PartKeepr\Footprint\Footprint","f")->leftJoin("f.image", "im"); - - - - if ($filter != "") { - $totalQueryBuilder = $totalQueryBuilder->where("LOWER(f.name) LIKE :filter"); - $totalQueryBuilder->setParameter("filter", "%".strtolower($filter)."%"); - } - - $totalQuery = $totalQueryBuilder->getQuery(); - - return array("data" => $result, "totalCount" => $totalQuery->getSingleScalarResult()); - } - - /** - * Creates a new footprint - * - * @param string $footprint The footprint's name - * @throws \PartKeepr\Util\SerializableException - * @throws PDOException - */ - public function addFootprint ($name) { - $fp = new Footprint(); - $fp->setName($name); - - // @todo Port the UniqueEntityValidator from Symfony2 to here. - try { - PartKeepr::getEM()->persist($fp); - PartKeepr::getEM()->flush(); - } catch (\PDOException $e) { - if ($e->getCode() == "23000") { - $exception = new SerializableException(sprintf(PartKeepr::i18n("Footprint %s already exists!"), $name)); - $exception->setDetail(sprintf(PartKeepr::i18n("You tried to add the footprint %s, but a footprint with the same name already exists."), $name)); - - throw $exception; - } else { - throw $e; - } - } - - return $fp; - } - - /** - * Deletes the footprint with the given id. - * - * @param int $id The footprint id to delete - * @throws \PartKeepr\Util\SerializableException - */ - public function deleteFootprint ($id) { - $footprint = Footprint::loadById($id); - - try { - PartKeepr::getEM()->remove($footprint); - PartKeepr::getEM()->flush(); - } catch (\PDOException $e) { - if ($e->getCode() == "23000") { - $exception = new SerializableException(sprintf(PartKeepr::i18n("Footprint %s is in use by some parts!"), $footprint->getName())); - $exception->setDetail(sprintf(PartKeepr::i18n("You tried to delete the footprint %s, but there are parts which use this footprint."), $footprint->getName())); - - throw $exception; - } - } - } - - /** - * Loads a footprint by id - * @param int $id The footprint id - */ - public function getFootprint ($id) { - return Footprint::loadById($id); - } - - /** - * Finds or creates a footprint by name. - * - * @param mixed $footprint Either the ID or the footprint's name to find - */ - public function getOrCreateFootprint ($footprint) { - try { - $footprint = Footprint::loadById($footprint); - return $footprint; - } catch (EntityNotFoundException $e) {} - - $dql = "SELECT f FROM PartKeepr\Footprint\Footprint f WHERE f.name = :name"; - $query = PartKeepr::getEM()->createQuery($dql); - $query->setParameter("name", $footprint); - - try { - $footprint = $query->getSingleResult(); - return $footprint; - } catch (\Exception $e) {} - - $fp = new Footprint(); - $fp->setName($footprint); - - PartKeepr::getEM()->persist($fp); - - return $fp; - } - - /** - * 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 getFootprintByName ($name) { - $dql = "SELECT fp FROM PartKeepr\Footprint\Footprint fp WHERE fp.name = :name"; - $query = PartKeepr::getEM()->createQuery($dql); - $query->setParameter("name", $name); - - return $query->getSingleResult(); - } -} diff --git a/src/PartKeepr/FootprintBundle/Entity/FootprintService.php b/src/PartKeepr/FootprintBundle/Entity/FootprintService.php @@ -1,96 +0,0 @@ -<?php -namespace PartKeepr\FootprintBundle\Entity; - -use PartKeepr\ImageBundle\Entity\TempImage, - \PartKeepr\FootprintBundle\Entity\FootprintCategory, - PartKeepr\Service\Service, - PartKeepr\Service\RestfulService, - PartKeepr\PartKeepr, - \PartKeepr\FootprintBundle\Entity\FootprintManager; - -class FootprintService extends Service implements RestfulService { - /** - * (non-PHPdoc) - * @see PartKeepr\Service.RestfulService::get() - */ - public function get () { - if ($this->hasParameter("id")) { - return array("data" => FootprintManager::getInstance()->getFootprint($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 FootprintManager::getInstance()->getFootprints( - $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"); - - $footprint = new Footprint(); - $footprint->deserialize($this->getParameters()); - - PartKeepr::getEM()->persist($footprint); - - PartKeepr::getEM()->flush(); - - return array("data" => $footprint->serialize()); - } - - /** - * (non-PHPdoc) - * @see PartKeepr\Service.RestfulService::update() - */ - public function update () { - $this->requireParameter("id"); - $this->requireParameter("name"); - $footprint = Footprint::loadById($this->getParameter("id")); - - $footprint->deserialize($this->getParameters()); - - PartKeepr::getEM()->flush(); - - return array("data" => $footprint->serialize()); - - } - - /** - * (non-PHPdoc) - * @see PartKeepr\Service.RestfulService::destroy() - */ - public function destroy () { - $this->requireParameter("id"); - - FootprintManager::getInstance()->deleteFootprint($this->getParameter("id")); - - return array("data" => null); - } - - public function moveFootprint () { - $this->requireParameter("targetCategory"); - $this->requireParameter("id"); - - $footprint = Footprint::loadById($this->getParameter("id")); - $category = FootprintCategory::loadById($this->getParameter("targetCategory")); - - $footprint->setCategory($category); - - PartKeepr::getEM()->flush(); - } - -} diff --git a/src/PartKeepr/PartBundle/Entity/PartCategoryManager.php b/src/PartKeepr/PartBundle/Entity/PartCategoryManager.php @@ -1,42 +0,0 @@ -<?php -namespace PartKeepr\PartBundle\Entity; - -use PartKeepr\Category\AbstractCategoryManager; -use DoctrineExtensions\NestedSet\NodeWrapper; -use PartKeepr\Util\SerializableException; -use PartKeepr\PartKeepr; - -class PartCategoryManager extends AbstractCategoryManager { - protected $categoryClass = "PartKeepr\PartBundle\Entity\PartCategory"; - - /** - * Deletes the given category ID. - * @param $id int The category id to delete - * @throws CategoryNotFoundException If the category wasn't found - */ - public function deleteCategory ($id) { - $category = $this->getCategory($id); - - try { - - if ($category->hasChildren()) { - $exception = new SerializableException(sprintf(PartKeepr::i18n("Category '%s' contains other categories."), $category->getNode()->getName())); - $exception->setDetail(sprintf(PartKeepr::i18n("You tried to delete the category '%s', but it still contains other categories. Please move the categories or delete them first."), $category->getNode()->getName())); - - throw $exception; - } - - parent::deleteCategory($id); - } catch (\PDOException $e) { - if ($e->getCode() == "23000") { - $exception = new SerializableException(sprintf(PartKeepr::i18n("Category '%s' contains parts."), $category->getNode()->getName())); - $exception->setDetail(sprintf(PartKeepr::i18n("You tried to delete the category '%s', but it still contains parts. Please move the parts to another category."), $category->getNode()->getName())); - - throw $exception; - } else { - throw $e; - } - } - } - -}- \ No newline at end of file diff --git a/src/PartKeepr/PartBundle/Entity/PartCategoryService.php b/src/PartKeepr/PartBundle/Entity/PartCategoryService.php @@ -1,9 +0,0 @@ -<?php -namespace PartKeepr\PartBundle\Entity; - -use PartKeepr\Category\AbstractCategoryService; - -class PartCategoryService extends AbstractCategoryService { - protected $categoryManagerClass = "PartKeepr\PartBundle\Entity\PartCategoryManager"; - protected $categoryClass = "PartKeepr\PartBundle\Entity\PartCategory"; -}- \ No newline at end of file