src/Entity/PictureCategory.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. /**
  5. * @ORM\Table(name="pictures_categories")
  6. * @ORM\Entity
  7. */
  8. class PictureCategory extends Picture
  9. {
  10. const PATH = 'public/assets/products';
  11. /**
  12. * @ORM\ManyToOne(targetEntity="Category", inversedBy="pictures")
  13. * @ORM\JoinColumn(name="categories_id", referencedColumnName="categories_id")
  14. */
  15. private $category;
  16. public function getCategory() {
  17. return $this->category;
  18. }
  19. public function setCategory($category) {
  20. $this->category = $category;
  21. }
  22. public function getUploadDir() {
  23. return 'assets/categories/';
  24. }
  25. public function generateThumbmailName($ext='jpg') {
  26. $title = $this->getTitle();
  27. if (empty($title)) {
  28. $title = $this->getGenericProduct()->getName();
  29. }
  30. $tmp = $this->getUploadDir() . \App\Helpers\CustomEncoder::formatUrl($title);
  31. $cpt = 0;
  32. $f_name = $tmp . '.' . $ext;
  33. while (file_exists($this->getWebRootDir() . $f_name)) {
  34. $cpt++;
  35. $f_name = $tmp . ($cpt ? ('-' . $cpt) : '') . '.' . $ext;
  36. }
  37. return $f_name;
  38. }
  39. public function getWebPath() {
  40. return 'assets/categories/'.$this->getUrl();
  41. }
  42. }