/**
  * Deserializes the storage location
  * @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 "image_id":
                 if ($value == "") {
                     echo "/** Breaking because of empty value */";
                     break;
                 }
                 try {
                     $image = StorageLocationImage::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 = StorageLocationImage::createFromTemporaryFile($value);
                         $this->setImage($image);
                         echo "/**";
                         echo $image->getId();
                         echo "*/";
                         echo "/** FOO */";
                     }
                 }
                 break;
         }
     }
 }
Example #2
0
$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;
        // Something bad happened
    }
}