/**
  * 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));
 }
 public function destroy()
 {
     $this->requireParameter("id");
     $logo = ManufacturerICLogo::loadById($this->getParameter("id"));
     PartKeepr::getEM()->remove($logo);
     PartKeepr::getEM()->flush();
     return array("data" => null);
 }
Exemple #3
0
use PartKeepr\Part\PartAttachment;
use PartKeepr\Image\ImageRenderer;
use PartKeepr\Part\PartImage, PartKeepr\StorageLocation\StorageLocationImage, PartKeepr\Footprint\FootprintImage, PartKeepr\TempImage\TempImage, PartKeepr\PartKeepr, PartKeepr\Image\Image, PartKeepr\Image\CachedImage, PartKeepr\Manufacturer\ManufacturerICLogo;
include "../src/backend/PartKeepr/PartKeepr.php";
PartKeepr::initialize("");
$type = $_REQUEST["type"];
$id = $_REQUEST["id"];
if (substr($id, 0, 4) === "TMP:") {
    $tmpImageId = str_replace("TMP:", "", $id);
    $image = TempImage::loadById($tmpImageId);
} else {
    try {
        switch ($type) {
            case Image::IMAGE_ICLOGO:
                $image = ManufacturerICLogo::loadById($id);
                break;
            case Image::IMAGE_FOOTPRINT:
                $image = FootprintImage::loadById($id);
                break;
            case Image::IMAGE_STORAGELOCATION:
                $image = StorageLocationImage::loadById($id);
                break;
            case "partattachment":
                $attachment = PartAttachment::loadById($id);
                $image = new PartImage();
                $image->replace($attachment->getFilename());
                break;
            default:
                $image = null;
                // Add default image?
Exemple #4
0
<?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");