src/ProductBundle/Entity/Category.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\ProductBundle\Entity;
  3. use App\ContentBundle\Entity\Post;
  4. use App\MediaBundle\Entity\Image;
  5. use App\ProductBundle\Entity\Translation\CategoryTranslation;
  6. use App\SeoBundle\Entity\Seo;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\Common\Collections\Criteria;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use PN\LocaleBundle\Model\LocaleTrait;
  12. use PN\LocaleBundle\Model\Translatable;
  13. use PN\ServiceBundle\Interfaces\DateTimeInterface;
  14. use PN\ServiceBundle\Model\DateTimeTrait;
  15. use PN\ServiceBundle\Model\VirtualDeleteTrait;
  16. /**
  17. * @ORM\HasLifecycleCallbacks
  18. * @ORM\Table(name="category")
  19. * @ORM\Entity(repositoryClass="App\ProductBundle\Repository\CategoryRepository")
  20. */
  21. class Category implements Translatable, DateTimeInterface
  22. {
  23. use VirtualDeleteTrait,
  24. DateTimeTrait,
  25. LocaleTrait;
  26. /**
  27. * @ORM\Column(name="id", type="integer")
  28. * @ORM\Id
  29. * @ORM\GeneratedValue(strategy="AUTO")
  30. */
  31. private ?int $id = null;
  32. /**
  33. * @ORM\OneToOne(targetEntity="App\MediaBundle\Entity\Image", cascade={"persist", "remove" })
  34. */
  35. private ?Image $image = null;
  36. /**
  37. * @ORM\OneToOne(targetEntity="App\ContentBundle\Entity\Post", cascade={"persist", "remove" })
  38. */
  39. private ?Post $post = null;
  40. /**
  41. * @ORM\OneToOne(targetEntity="\App\SeoBundle\Entity\Seo", cascade={"persist", "remove" })
  42. */
  43. private ?Seo $seo = null;
  44. /**
  45. * @ORM\ManyToOne(targetEntity="Category", inversedBy="children")
  46. */
  47. private ?Category $parent = null;
  48. /**
  49. * @ORM\ManyToOne(targetEntity="Category")
  50. */
  51. private ?Category $levelOne = null;
  52. /**
  53. * @ORM\Column(name="title", type="string", length=100)
  54. */
  55. private ?string $title = null;
  56. /**
  57. * @ORM\Column(name="concatIds", type="text", nullable=true)
  58. */
  59. private ?string $concatIds = null;
  60. /**
  61. * @ORM\Column(name="tarteb", type="smallint", nullable=true)
  62. */
  63. private ?int $tarteb = null;
  64. /**
  65. * @ORM\Column(type="integer")
  66. */
  67. private ?int $depth;
  68. /**
  69. * @ORM\Column(name="no_of_images", type="smallint", nullable=true, options={"default" : 0})
  70. */
  71. private int $noOfImages = 0;
  72. /**
  73. * @ORM\Column(name="no_of_products", type="smallint", nullable=true, options={"default" : 0})
  74. */
  75. private int $noOfProducts = 0;
  76. /**
  77. * @ORM\Column(name="no_of_publish_products", type="smallint", nullable=true, options={"default" : 0})
  78. */
  79. private int $noOfPublishProducts = 0;
  80. /**
  81. * @ORM\Column(name="parentConcatIds", type="text", nullable=true)
  82. */
  83. private ?string $parentConcatIds = null;
  84. /**
  85. * @ORM\Column(name="publish", type="boolean")
  86. */
  87. private bool $publish = true;
  88. /**
  89. * @ORM\Column(name="featured", type="boolean")
  90. */
  91. private bool $featured = false;
  92. /**
  93. * @ORM\OneToMany(targetEntity="App\ProductBundle\Entity\Translation\CategoryTranslation", mappedBy="translatable", cascade={"ALL"}, orphanRemoval=true, fetch="EAGER")
  94. */
  95. private Collection $translations;
  96. /**
  97. * @ORM\OneToMany(targetEntity="Category", mappedBy="parent")
  98. * @ORM\OrderBy({"tarteb" = "ASC"})
  99. */
  100. private Collection $children;
  101. /**
  102. * @ORM\OneToMany(targetEntity="Attribute", mappedBy="category")
  103. */
  104. private Collection $attributes;
  105. public function __construct()
  106. {
  107. $this->children = new ArrayCollection();
  108. $this->translations = new ArrayCollection();
  109. $this->attributes = new ArrayCollection();
  110. }
  111. public function __toString()
  112. {
  113. return $this->getTitle();
  114. }
  115. public function hasChildren(): bool
  116. {
  117. $children = $this->getChildren();
  118. if (count($children) > 0) {
  119. return true;
  120. }
  121. return false;
  122. }
  123. public function getChildren($deleted = null)
  124. {
  125. $criteria = Criteria::create();
  126. if ($deleted == null) {
  127. $criteria->where(Criteria::expr()->eq('deleted', null));
  128. }
  129. return $this->children->matching($criteria);
  130. }
  131. public function getId(): ?int
  132. {
  133. return $this->id;
  134. }
  135. public function getTitle(): ?string
  136. {
  137. return !$this->currentTranslation ? $this->title : $this->currentTranslation->getTitle();
  138. }
  139. public function setTitle(string $title): self
  140. {
  141. $this->title = $title;
  142. return $this;
  143. }
  144. public function getConcatIds(): ?string
  145. {
  146. return $this->concatIds;
  147. }
  148. public function setConcatIds(?string $concatIds): self
  149. {
  150. $this->concatIds = $concatIds;
  151. return $this;
  152. }
  153. public function getTarteb(): ?int
  154. {
  155. return $this->tarteb;
  156. }
  157. public function setTarteb(?int $tarteb): self
  158. {
  159. $this->tarteb = $tarteb;
  160. return $this;
  161. }
  162. public function getNoOfImages(): ?int
  163. {
  164. return $this->noOfImages;
  165. }
  166. public function setNoOfImages(?int $noOfImages): self
  167. {
  168. $this->noOfImages = $noOfImages;
  169. return $this;
  170. }
  171. public function getNoOfProducts(): ?int
  172. {
  173. return $this->noOfProducts;
  174. }
  175. public function setNoOfProducts(?int $noOfProducts): self
  176. {
  177. $this->noOfProducts = $noOfProducts;
  178. return $this;
  179. }
  180. public function getNoOfPublishProducts(): ?int
  181. {
  182. return $this->noOfPublishProducts;
  183. }
  184. public function setNoOfPublishProducts(?int $noOfPublishProducts): self
  185. {
  186. $this->noOfPublishProducts = $noOfPublishProducts;
  187. return $this;
  188. }
  189. public function getParentConcatIds(): ?string
  190. {
  191. return $this->parentConcatIds;
  192. }
  193. public function setParentConcatIds(?string $parentConcatIds): self
  194. {
  195. $this->parentConcatIds = $parentConcatIds;
  196. return $this;
  197. }
  198. public function getSeo(): ?Seo
  199. {
  200. return $this->seo;
  201. }
  202. public function setSeo(?Seo $seo): self
  203. {
  204. $this->seo = $seo;
  205. return $this;
  206. }
  207. public function getParent(): ?self
  208. {
  209. return $this->parent;
  210. }
  211. public function setParent(?self $parent): self
  212. {
  213. $this->parent = $parent;
  214. return $this;
  215. }
  216. public function getLevelOne(): ?self
  217. {
  218. return $this->levelOne;
  219. }
  220. public function setLevelOne(?self $levelOne): self
  221. {
  222. $this->levelOne = $levelOne;
  223. return $this;
  224. }
  225. public function addChild(Category $child): self
  226. {
  227. if (!$this->children->contains($child)) {
  228. $this->children[] = $child;
  229. $child->setParent($this);
  230. }
  231. return $this;
  232. }
  233. public function removeChild(Category $child): self
  234. {
  235. if ($this->children->removeElement($child)) {
  236. // set the owning side to null (unless already changed)
  237. if ($child->getParent() === $this) {
  238. $child->setParent(null);
  239. }
  240. }
  241. return $this;
  242. }
  243. /**
  244. * @return Collection|CategoryTranslation[]
  245. */
  246. public function getTranslations(): Collection
  247. {
  248. return $this->translations;
  249. }
  250. public function addTranslation(CategoryTranslation $translation): self
  251. {
  252. if (!$this->translations->contains($translation)) {
  253. $this->translations[] = $translation;
  254. $translation->setTranslatable($this);
  255. }
  256. return $this;
  257. }
  258. public function removeTranslation(CategoryTranslation $translation): self
  259. {
  260. if ($this->translations->removeElement($translation)) {
  261. // set the owning side to null (unless already changed)
  262. if ($translation->getTranslatable() === $this) {
  263. $translation->setTranslatable(null);
  264. }
  265. }
  266. return $this;
  267. }
  268. public function getDepth(): ?int
  269. {
  270. return $this->depth;
  271. }
  272. public function setDepth(int $depth): self
  273. {
  274. $this->depth = $depth;
  275. return $this;
  276. }
  277. public function getImage(): ?Image
  278. {
  279. return $this->image;
  280. }
  281. public function setImage(?Image $image): self
  282. {
  283. $this->image = $image;
  284. return $this;
  285. }
  286. /**
  287. * @return Collection|Attribute[]
  288. */
  289. public function getAttributes(): Collection
  290. {
  291. return $this->attributes;
  292. }
  293. public function addAttribute(Attribute $attribute): self
  294. {
  295. if (!$this->attributes->contains($attribute)) {
  296. $this->attributes[] = $attribute;
  297. $attribute->setCategory($this);
  298. }
  299. return $this;
  300. }
  301. public function removeAttribute(Attribute $attribute): self
  302. {
  303. if ($this->attributes->removeElement($attribute)) {
  304. // set the owning side to null (unless already changed)
  305. if ($attribute->getCategory() === $this) {
  306. $attribute->setCategory(null);
  307. }
  308. }
  309. return $this;
  310. }
  311. public function getPost(): ?Post
  312. {
  313. return $this->post;
  314. }
  315. public function setPost(?Post $post): self
  316. {
  317. $this->post = $post;
  318. return $this;
  319. }
  320. public function isPublish(): ?bool
  321. {
  322. return $this->publish;
  323. }
  324. public function setPublish(bool $publish): self
  325. {
  326. $this->publish = $publish;
  327. return $this;
  328. }
  329. public function isFeatured(): ?bool
  330. {
  331. return $this->featured;
  332. }
  333. public function setFeatured(bool $featured): self
  334. {
  335. $this->featured = $featured;
  336. return $this;
  337. }
  338. }