modules/CDev/FileAttachments/src/Model/Product/Attachment/Storage.php line 18

Open in your IDE?
  1. <?php
  2. /**
  3.  * Copyright (c) 2011-present Qualiteam software Ltd. All rights reserved.
  4.  * See https://www.x-cart.com/license-agreement.html for license details.
  5.  */
  6. namespace CDev\FileAttachments\Model\Product\Attachment;
  7. use Doctrine\ORM\Mapping as ORM;
  8. /**
  9.  * Product attchament's storage
  10.  *
  11.  * @ORM\Entity
  12.  * @ORM\Table  (name="product_attachment_storages")
  13.  */
  14. class Storage extends \XLite\Model\Base\Storage
  15. {
  16.     // {{{ Associations
  17.     /**
  18.      * Relation to a attachment
  19.      *
  20.      * @var \CDev\FileAttachments\Model\Product\Attachment
  21.      *
  22.      * @ORM\OneToOne  (targetEntity="CDev\FileAttachments\Model\Product\Attachment", inversedBy="storage")
  23.      * @ORM\JoinColumn (name="attachment_id", referencedColumnName="id", onDelete="CASCADE")
  24.      */
  25.     protected $attachment;
  26.     // }}}
  27.     // {{{ Service operations
  28.     /**
  29.      * Assemble path for save into DB
  30.      *
  31.      * @param string $path Path
  32.      *
  33.      * @return string
  34.      */
  35.     protected function assembleSavePath($path)
  36.     {
  37.         return $this->getAttachment()->getProduct()->getProductId() . LC_DS parent::assembleSavePath($path);
  38.     }
  39.     /**
  40.      * Get valid file system storage root
  41.      *
  42.      * @return string
  43.      */
  44.     protected function getStoreFileSystemRoot()
  45.     {
  46.         $path parent::getStoreFileSystemRoot() . $this->getAttachment()->getProduct()->getProductId() . LC_DS;
  47.         \Includes\Utils\FileManager::mkdirRecursive($path);
  48.         return $path;
  49.     }
  50.     /**
  51.      * Clone for attachment
  52.      *
  53.      * @param \CDev\FileAttachments\Model\Product\Attachment $attachment Attachment
  54.      *
  55.      * @return \XLite\Model\AEntity
  56.      */
  57.     public function cloneEntityForAttachment(\CDev\FileAttachments\Model\Product\Attachment $attachment)
  58.     {
  59.         $newStorage parent::cloneEntity();
  60.         $attachment->setStorage($newStorage);
  61.         $newStorage->setAttachment($attachment);
  62.         if ($this->getStorageType() !== static::STORAGE_URL) {
  63.             // Clone local image (will be created new file with unique name)
  64.             $newStorage->loadFromLocalFile($this->getStoragePath(), nullfalse);
  65.         }
  66.         return $newStorage;
  67.     }
  68.     /**
  69.      * Get list of administrator permissions to download files of the storage
  70.      *
  71.      * @return array
  72.      */
  73.     public function getAdminPermissions()
  74.     {
  75.         return ['ROLE_MANAGE_CATALOG'];
  76.     }
  77.     /**
  78.      * Set mime
  79.      *
  80.      * @param string $mime
  81.      * @return Storage
  82.      */
  83.     public function setMime($mime)
  84.     {
  85.         $this->mime $mime;
  86.         return $this;
  87.     }
  88.     /**
  89.      * Get mime
  90.      *
  91.      * @return string
  92.      */
  93.     public function getMime()
  94.     {
  95.         return $this->mime;
  96.     }
  97.     /**
  98.      * Set storageType
  99.      *
  100.      * @param string $storageType
  101.      * @return Storage
  102.      */
  103.     public function setStorageType($storageType)
  104.     {
  105.         $this->storageType $storageType;
  106.         return $this;
  107.     }
  108.     /**
  109.      * Set attachment
  110.      *
  111.      * @param \CDev\FileAttachments\Model\Product\Attachment $attachment
  112.      * @return Storage
  113.      */
  114.     public function setAttachment(\CDev\FileAttachments\Model\Product\Attachment $attachment null)
  115.     {
  116.         $this->attachment $attachment;
  117.         return $this;
  118.     }
  119.     /**
  120.      * Get attachment
  121.      *
  122.      * @return \CDev\FileAttachments\Model\Product\Attachment
  123.      */
  124.     public function getAttachment()
  125.     {
  126.         return $this->attachment;
  127.     }
  128. }