/** * (non-PHPdoc) * @see PartKeepr\Service.RestfulService::create() */ 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()); $image->setOriginalFilename($tmpImage->getOriginalFilename()); PartKeepr::getEM()->persist($image); PartKeepr::getEM()->flush(); return $image->serialize(); }
$image = new PartImage(); $image->replace($attachment->getFilename()); break; default: $image = null; // Add default image? } } catch (\Exception $e) { $image = null; // Something bad happened } } if ($image == null) { // Could not find the image, but maybe we want a temporary image? if (array_key_exists("tmpId", $_REQUEST)) { $image = TempImage::loadById($_REQUEST["tmpId"]); } if ($image === null) { /* The image is still null - output an "image not found" image. */ ImageRenderer::outputRenderNotFoundImage($_REQUEST["w"], $_REQUEST["h"]); exit; } } $mode = "fit"; if (array_key_exists("m", $_REQUEST)) { $mode = $_REQUEST["m"]; } if (array_key_exists("cache", $_REQUEST)) { if ($_REQUEST["cache"] == "false") { CachedImage::invalidate($image); }
/** * Replaces the file with a given temporary file. * @param string $id The temporary id (prefixed with TMP:) */ public function replaceFromTemporaryFile($id) { if (substr($id, 0, 4) === "TMP:") { $tmpFileId = str_replace("TMP:", "", $id); $tmpFile = TempImage::loadById($tmpFileId); $this->replace($tmpFile->getFilename()); $this->setOriginalFilename($tmpFile->getOriginalFilename()); } }