PartKeepr\FootprintBundle\Entity\Footprint::setImage PHP Method

setImage() public method

Sets the footprint image.
public setImage ( FootprintImage $image ) : void
$image FootprintImage The footprint image
return void
    public function setImage($image)
    {
        if ($image instanceof FootprintImage) {
            $image->setFootprint($this);
            $this->image = $image;
        } else {
            // Because this is a 1:1 relationship. only allow the temporary image to be set when no image exists.
            // If an image exists, the frontend needs to deliver the old file ID with the replacement property set.
            if ($this->getImage() === null) {
                $this->image = $image;
            }
        }
    }

Usage Example

 protected function createFootprint($footprintName, $footprintData)
 {
     $fileService = $this->get("partkeepr_uploadedfile_service");
     $footprintCategoryService = $this->get("partkeepr.footprint.category_service");
     $footprintCategoryRootNode = $footprintCategoryService->getRootNode();
     $footprint = new Footprint();
     $footprint->setName($footprintName);
     if (array_key_exists("description", $footprintData)) {
         $footprint->setDescription($footprintData["description"]);
     }
     if (array_key_exists("category", $footprintData)) {
         $footprintCategory = $this->addFootprintCategoryPath(explode("/", $footprintData["category"]), $footprintCategoryRootNode);
         $footprint->setCategory($footprintCategory);
     }
     if (array_key_exists("image", $footprintData)) {
         $footprintImage = new FootprintImage();
         $file = $this->get("kernel")->locateResource(self::FOOTPRINT_PATH . $footprintData["image"]);
         $fileService->replaceFromFilesystem($footprintImage, new File($file));
         $footprint->setImage($footprintImage);
     }
     $this->get("doctrine.orm.default_entity_manager")->persist($footprint);
 }
All Usage Examples Of PartKeepr\FootprintBundle\Entity\Footprint::setImage