/** * Sets up the manufacturers using the YAML file. * @param $yaml string The path to the manufacturers YAML file */ public function setupManufacturers() { $count = 0; $skipped = 0; $data = Setup::loadYAML(self::MANUFACTURER_FILE); foreach ($data as $mfgname => $logos) { try { ManufacturerManager::getInstance()->getManufacturerByName($mfgname); $skipped++; } catch (\Exception $e) { $manufacturer = new Manufacturer(); $manufacturer->setName($mfgname); $this->entityManager->persist($manufacturer); foreach ($logos as $logo) { $mfglogo = new ManufacturerICLogo(); $mfglogo->setManufacturer($manufacturer); $mfglogo->replace(self::MANUFACTURER_PATH . "images/" . $logo); $mfglogo->setOriginalFilename($logo); $this->entityManager->persist($mfglogo); } $count++; } } $this->entityManager->flush(); $this->logMessage(sprintf("Imported %d Manufacturers, skipped %d because they already exist", $count, $skipped)); }
/** * (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()); }
/** * 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()); }
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()); PartKeepr::getEM()->persist($image); PartKeepr::getEM()->flush(); return $image->serialize(); }
/** * Deserializes the part manufacturer * @param array $parameters The array with the parameters to set */ public function deserialize(array $parameters) { foreach ($parameters as $key => $value) { switch ($key) { case "manufacturer_id": $manufacturer = Manufacturer::loadById($value); $this->setManufacturer($manufacturer); break; case "partNumber": $this->setPartNumber($value); break; } } }
/** * 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(); }
<?php namespace PartKeepr\Frontend; use PartKeepr\PartKeepr; use PartKeepr\Image\Image; use PartKeepr\Manufacturer\ManufacturerICLogo; use PartKeepr\Manufacturer\Manufacturer; include "../src/backend/PartKeepr/PartKeepr.php"; PartKeepr::initialize(""); $keys = array_keys($_FILES); $file = $_FILES[$keys[0]]["tmp_name"]; $filename = $_FILES[$keys[0]]["name"]; switch ($_REQUEST["uploadMode"]) { case "image": switch ($_REQUEST["uploadType"]) { case Image::IMAGE_ICLOGO: $manufacturer = Manufacturer::loadById($_REQUEST["manufacturer"]); $image = new ManufacturerICLogo(); $image->setManufacturer($manufacturer); $image->replace($file); $image->setOriginalFilename(basename($filename)); PartKeepr::getEM()->persist($image); PartKeepr::getEM()->flush(); } break; } echo json_encode("OK");
private function processManufacturerChanges(Part $part, array $data) { if (array_key_exists("updates", $data)) { foreach ($data["updates"] as $record) { foreach ($part->getManufacturers() as $partManufacturer) { if ($partManufacturer->getId() == $record["id"]) { $partManufacturer->setPartNumber($record["partNumber"]); $partManufacturer->setManufacturer(Manufacturer::loadById($record["manufacturer_id"])); break; } } } } if (array_key_exists("removals", $data)) { foreach ($data["removals"] as $record) { foreach ($part->getManufacturers() as $partManufacturer) { if ($partManufacturer->getId() == $record["id"]) { PartKeepr::getEM()->remove($partManufacturer); $part->getManufacturers()->removeElement($partManufacturer); break; } } } } if (array_key_exists("inserts", $data)) { foreach ($data["inserts"] as $record) { $manufacturer = new PartManufacturer($part, Manufacturer::loadById($record["manufacturer_id"])); $manufacturer->setPartNumber($record["partNumber"]); $part->getManufacturers()->add($manufacturer); } } }