public function get () { $qb = PartKeepr::getEM()->createQueryBuilder(); $qb->select("se")->from("de\RaumZeitLabor\PartKeepr\Stock\StockEntry","se") ->where("se.part = :part") ->orderBy("se.dateTime", "DESC") ->setParameter("part", $this->getParameter("item")); $results = $qb->getQuery()->getResult(); $aData = array(); foreach ($results as $result) { $aData[] = array( "username" => is_object($result->getUser()) ? $result->getUser()->getUsername() : PartKeepr::i18n("Unknown User"), "amount" => abs($result->getStockLevel()), "datetime" => $result->getDateTime()->format("Y-m-d H:i:s"), "id" => $result->getId(), "direction" => ($result->getStockLevel() < 0) ? "out" : "in", "price" => $result->getPrice() ); } return array("data" => $aData); }
/** * Loads the entity from the database. * @param integer $id The entity's id */ public static function loadById ($id) { $entity = PartKeepr::getEM()->find(get_called_class(), $id); if (!is_object($entity)) { throw new EntityNotFoundException(get_called_class(), $id); } return $entity; }
public function destroy () { $this->requireParameter("id"); $logo = ManufacturerICLogo::loadById($this->getParameter("id")); PartKeepr::getEM()->remove($logo); PartKeepr::getEM()->flush(); return array("data" => null); }
/** * (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); PartKeepr::getEM()->flush(); return array("data" => $distributor->serialize()); }
/** * (non-PHPdoc) * @see de\RaumZeitLabor\PartKeepr\Service.RestfulService::update() */ public function update () { $this->requireParameter("id"); $this->requireParameter("name"); $manufacturer = ManufacturerManager::getInstance()->getManufacturer($this->getParameter("id")); $this->setManufacturerData($manufacturer); PartKeepr::getEM()->flush(); return array("data" => $manufacturer->serialize()); }
/** * Sets the packaging unit for a specific distributor. * * For example, some distributors only sell resistors in packs of 100, so you can't order just one. We use the * packagingUnit to calculate how many pieces will be delivered once ordered. So if your stock level falls below * the minimum (example: you would need to order 10 resistors), we suggest that you only order one resistor pack * instead of 10. * * @param int $packagingUnit The amount of items in one package * @throws \de\RaumZeitLabor\PartKeepr\Part\OutOfRangeException When the packaging unit is less than 1 */ public function setPackagingUnit ($packagingUnit) { $packagingUnit = intval($packagingUnit); if ($packagingUnit < 1) { $exception = new OutOfRangeException(PartKeepr::i18n("Packaging Unit is out of range")); $exception->setDetail(PartKeepr::i18n("The packaging unit must be 1 or higher")); throw $exception; } $this->packagingUnit = $packagingUnit; }
public function update () { $this->requireParameter("id"); $this->requireParameter("name"); $unit = UnitManager::getInstance()->getUnit($this->getParameter("id")); $this->setUnitData($unit); PartKeepr::getEM()->flush(); return array("data" => $unit->serialize()); }
/** * (non-PHPdoc) * @see de\RaumZeitLabor\PartKeepr\Service.RestfulService::update() */ public function update () { $this->requireParameter("id"); $this->requireParameter("footprint"); $footprint = FootprintManager::getInstance()->getFootprint($this->getParameter("id")); $footprint->setName($this->getParameter("footprint")); $footprint->setDescription($this->getParameter("description")); PartKeepr::getEM()->flush(); return array("data" => $footprint->serialize()); }
/** * Updates the given category. */ public function update () { $this->requireParameter("id"); $this->requireParameter("name"); $category = CategoryManager::getInstance()->getCategory($this->getParameter("id")); $category->getNode()->setName($this->getParameter("name")); $category->getNode()->setDescription($this->getParameter("description", "")); PartKeepr::getEM()->persist($category->getNode()); return array("data" => $this->serializeCategory($category)); }
public function getOrCreateStorageLocation ($storageLocation) { if (is_int($storageLocation)) { try { return $this->getStorageLocation($storageLocation); } catch (StorageLocationNotFoundException $e) {} } $sl = new StorageLocation(); $sl->setName($storageLocation); PartKeepr::getEM()->persist($sl); return $sl; }
public function resumeSession ($session) { $query = PartKeepr::getEM()->createQuery("SELECT s FROM de\\RaumZeitLabor\\PartKeepr\\Session\\Session s WHERE s.sessionid = :session"); $query->setParameter("session", $session); $query->execute(); try { self::$currentSession = $query->getSingleResult(); return self::$currentSession; } catch (\Doctrine\ORM\NonUniqueResultException $e) { throw new \Exception("Fatal error: Multiple sessions with id $session found."); } catch (\Doctrine\ORM\NoResultException $e) { throw new SessionNotFoundException($session); } }
public function testLogin () { $user = new User; $user->setUsername("test"); $user->setPassword("test"); $this->userManager->createUser($user); PartKeepr::getEM()->flush(); $user2 = new User; $user2->setRawUsername("2test"); $user2->setPassword("test"); /* User shouldn't be able to login, even if we cut numbers and special chars from usernames */ $this->setExpectedException("de\RaumZeitLabor\PartKeepr\Auth\Exceptions\InvalidLoginDataException"); $this->userManager->authenticate($user2); }
public function createSnapshot () { $snapshot = new StatisticSnapshot(); $snapshot->setParts(PartManager::getInstance()->getPartCount()); $snapshot->setCategories(CategoryManager::getInstance()->getCategoryCount()); $result = PartUnitManager::getInstance()->getUnitCounts(); foreach ($result as $row) { $snapshotUnit = new StatisticSnapshotUnit(); $snapshotUnit->setPartUnit($row[0]); $snapshotUnit->setStatisticSnapshot($snapshot); $snapshotUnit->setStockLevel($row["stockLevel"]); $snapshot->getUnits()->add($snapshotUnit); } PartKeepr::getEM()->persist($snapshot); PartKeepr::getEM()->flush(); }
public function upload () { $tmpFile = new TempUploadedFile(); if (array_key_exists("userfile", $_FILES) && file_exists($_FILES["userfile"]["tmp_name"])) { $file = $_FILES['userfile']['tmp_name']; $filename = $_FILES['userfile']['name']; $tmpFile->replace($file); $tmpFile->setOriginalFilename(basename($filename)); } elseif (array_key_exists("url", $_REQUEST)) { $tmpFile->replaceFromURL($_REQUEST["url"]); } else { throw new \Exception("Error: No valid file given"); } PartKeepr::getEM()->persist($tmpFile); PartKeepr::getEM()->flush(); return array("id" => $tmpFile->getId(), "extension" => $tmpFile->getExtension(), "size" => $tmpFile->getSize(), "originalFilename" => $tmpFile->getOriginalFilename()); }
/** * 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("de\RaumZeitLabor\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("de\RaumZeitLabor\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()); }
/** * Constructs a new file object. * */ public function __construct () { $this->filename = PartKeepr::createGUIDv4(); }
/** * (non-PHPdoc) * @see de\RaumZeitLabor\PartKeepr\Service.RestfulService::destroy() */ public function destroy () { $this->requireParameter("id"); $file = FootprintAttachment::loadById($this->getParameter("id")); PartKeepr::getEM()->remove($file); PartKeepr::getEM()->flush(); return array("data" => null); }
/** * Updates the average price for a part */ public function updatePrice () { $query = PartKeepr::getEM()->createQuery("SELECT SUM(se.price*se.stockLevel) / SUM(se.stockLevel) FROM de\RaumZeitLabor\PartKeepr\Stock\StockEntry se WHERE se.part = :part AND se.stockLevel > 0"); $query->setParameter("part", $this->part); $val = $query->getSingleScalarResult(); $query = PartKeepr::getEM()->createQuery('UPDATE de\RaumZeitLabor\PartKeepr\Part\Part p SET p.averagePrice = :val WHERE p = :part'); $query->setParameter("val", $val); $query->setParameter("part", $this->part); $query->execute(); }
<?php namespace de\RaumZeitLabor\PartKeepr\Frontend; declare(encoding = 'UTF-8'); use de\RaumZeitLabor\PartKeepr\PartKeepr, de\RaumZeitLabor\PartKeepr\Service\ServiceManager; include("../src/de/RaumZeitLabor/PartKeepr/PartKeepr.php"); PartKeepr::initialize(""); /** * This script dispatches the request to the ServiceManager. * * You have a few options how to define which service and call you wish to request: * * * DIRECT SPECIFICATION * ==================== * * You have a few options to specify the call directly: * * - You can specify the call via a HTTP header. Set the header named "call" to the call you wish to execute. * - You can specify the call via a HTTP POST or GET variable. Set the variable named "call" to the call you wish * to execute. * - You can specify the call as second parameter in the URL, e.g. if your service is "Part" and your call is * "getParts", you would invoke rest.php/Part/getParts * * If you specify the call, the ServiceManager ignores the HTTP verb. * * SERVICE * =======
$oPartParameter->setValue($val); $oPartParameter->setSiPrefix($prefix); PartKeepr::getEM()->persist($oPartParameter); } $fc++; if ($fc>100) { PartKeepr::getEM()->flush(); $fc=0; } } PartKeepr::getEM()->flush(); echo "All done.\n"; apc_clear_cache(); apc_clear_cache("user"); function convertText ($string) { $string = stripslashes($string); $string = html_entity_decode($string, ENT_QUOTES, 'UTF-8');
/** * 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(); }
/** * Scales the image to fit within the given size. * * @param int $w The width * @param int $h The height * @param boolean $padding If true, pad the output image to the given size (transparent background). * @return string The path to the scaled file */ public function fitWithin ($w, $h, $padding = false) { $this->ensureCachedirExists(); if ($padding) { $pd = "p"; } else { $pd = ""; } $outputFile = Configuration::getOption("partkeepr.images.cache").md5($this->getFilename().$w."x".$h."fw".$pd).".png"; if (file_exists($outputFile)) { return $outputFile; } $image = new \Imagick(); $image->readImage($this->getFilename()); $sourceAspectRatio = $image->getImageWidth() / $image->getImageHeight(); $targetAspectRatio = $w / $h; $filter = \Imagick::FILTER_UNDEFINED; $blur = 1; $targetHeight = $h; $targetWidth = $w; if ($sourceAspectRatio < $targetAspectRatio) { $targetWidth = $h * $sourceAspectRatio; $image->resizeImage($h * $sourceAspectRatio, $h, $filter, $blur); } else { $targetHeight = $w / $sourceAspectRatio; $image->resizeImage($w, $w / $sourceAspectRatio, $filter, $blur); } if ($padding) { $posX = intval(($w - $targetWidth) / 2); $posY = intval(($h - $targetHeight) / 2); $image->extentImage($w, $h,-$posX, -$posY); } $image->writeImage($outputFile); $cachedImage = new CachedImage($this, $outputFile); PartKeepr::getEM()->persist($cachedImage); return $outputFile; }
<?php namespace de\RaumZeitLabor\PartKeepr\Tests; declare(encoding = 'UTF-8'); use de\raumzeitlabor\PartKeepr\PartKeepr; include(dirname(__DIR__). "/src/de/RaumZeitLabor/PartKeepr/PartKeepr.php"); PartKeepr::initialize("test"); $tool = new \Doctrine\ORM\Tools\SchemaTool(PartKeepr::getEM()); $classes = PartKeepr::getClassMetaData(); $tool->dropSchema($classes); $tool->createSchema($classes); ?>
public function __construct () { parent::__construct(PartKeepr::i18n("Username or Password wrong.")); }
public function get () { $query = PartKeepr::getEM()->createQuery("SELECT si.id, si.prefix, si.symbol, si.power FROM de\RaumZeitLabor\PartKeepr\SiPrefix\SiPrefix si"); return array("data" => $query->getArrayResult()); }
<?php use de\RaumZeitLabor\PartKeepr\Service\ServiceManager; use de\RaumZeitLabor\PartKeepr\PartKeepr; use Doctrine\Common\ClassLoader; include("src/de/RaumZeitLabor/PartKeepr/PartKeepr.php"); PartKeepr::initialize(""); $em = PartKeepr::getEM(); $classes = PartKeepr::getEntityClasses(); $helperSet = new \Symfony\Component\Console\Helper\HelperSet(array( 'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()), 'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em) ));
public function deletePartDistributor ($id) { $manufacturer = $this->getManufacturer($id); PartKeepr::getEM()->remove($manufacturer); PartKeepr::getEM()->flush(); }
public function __construct ($class, $id) { parent::__construct( sprintf( PartKeepr::i18n("The entity %s with the id %d could not be found"), $class, $id)); }
public function saveStorageLocation () { $this->requireParameter("id"); $this->requireParameter("name"); $storageLocation = StorageLocationManager::getInstance()->getStorageLocation($this->getParameter("id")); $storageLocation->setName($this->getParameter("name")); PartKeepr::getEM()->flush(); return $storageLocation->serialize(); }
/** * Removes all caches for a specific image. This is usually called * when a new version of an image is uploaded. * * Automatically calls "flush" on the entity manager. * * @param Image $image The image to invalidate */ public static function invalidate (Image $image) { $qb = PartKeepr::getEM()->createQueryBuilder(); $qb->select(array("c")) ->from('de\RaumZeitLabor\PartKeepr\Image\CachedImage', 'c') ->where("c.originalId = :id") ->andWhere("c.originalType = :type") ->setParameter("id", $image->getId()) ->setParameter("type", $image->getType()); $query = $qb->getQuery(); $bImagesRemoved = false; foreach ($query->getResult() as $file) { unlink($file->getCacheFile()); PartKeepr::getEM()->remove($file); $bImagesRemoved = true; } if ($bImagesRemoved) { PartKeepr::getEM()->flush(); } }