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? } } catch (\Exception $e) { $image = null;
/** * Deserializes the footprint * @param array $parameters The array with the parameters to set */ public function deserialize(array $parameters) { foreach ($parameters as $key => $value) { switch ($key) { case "name": $this->setName($value); break; case "description": $this->setDescription($value); break; case "image_id": if ($value == "") { echo "/** Breaking because of empty value */"; break; } try { $image = FootprintImage::loadById($value); $this->setImage($image); } catch (\Exception $e) { if ($this->getImage()) { // Image was not found, maybe a temporary image? $this->getImage()->replaceFromTemporaryFile($value); } else { $image = FootprintImage::createFromTemporaryFile($value); $this->setImage($image); } } break; case "category": try { $category = FootprintCategory::loadById($value); $this->setCategory($category); } catch (\Exception $e) { // Category was not found, do not change category. } break; case "attachments": $this->deserializeChildren($value, $this->getAttachments(), "PartKeepr\\Footprint\\FootprintAttachment"); foreach ($this->getAttachments() as $attachment) { $attachment->setFootprint($this); } break; } } }