<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Table(name="pictures_categories")
* @ORM\Entity
*/
class PictureCategory extends Picture
{
const PATH = 'public/assets/products';
/**
* @ORM\ManyToOne(targetEntity="Category", inversedBy="pictures")
* @ORM\JoinColumn(name="categories_id", referencedColumnName="categories_id")
*/
private $category;
public function getCategory() {
return $this->category;
}
public function setCategory($category) {
$this->category = $category;
}
public function getUploadDir() {
return 'assets/categories/';
}
public function generateThumbmailName($ext='jpg') {
$title = $this->getTitle();
if (empty($title)) {
$title = $this->getGenericProduct()->getName();
}
$tmp = $this->getUploadDir() . \App\Helpers\CustomEncoder::formatUrl($title);
$cpt = 0;
$f_name = $tmp . '.' . $ext;
while (file_exists($this->getWebRootDir() . $f_name)) {
$cpt++;
$f_name = $tmp . ($cpt ? ('-' . $cpt) : '') . '.' . $ext;
}
return $f_name;
}
public function getWebPath() {
return 'assets/categories/'.$this->getUrl();
}
}