src/Entity/Livre.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\ORM\Mapping as ORM;
  5. /**
  6. * Livre
  7. *
  8. * @ORM\Table(name="livre")
  9. * @ORM\Entity(repositoryClass="App\Repository\LivreRepository")
  10. */
  11. class Livre
  12. {
  13. /**
  14. * @var int
  15. *
  16. * @ORM\Column(name="id", type="integer")
  17. * @ORM\Id
  18. * @ORM\GeneratedValue(strategy="AUTO")
  19. */
  20. private $id;
  21. /**
  22. * @var string
  23. *
  24. * @ORM\Column(name="titre", type="string", length=255)
  25. */
  26. private $titre;
  27. /**
  28. * @ORM\ManyToOne(targetEntity="App\Entity\Category")
  29. * @ORM\JoinColumn(name="category_id", referencedColumnName="id", nullable=true)
  30. */
  31. private $category;
  32. /**
  33. * @ORM\ManyToOne(targetEntity="App\Entity\Collection")
  34. * @ORM\JoinColumn(name="collection_id", referencedColumnName="id", nullable=true)
  35. */
  36. private $collection;
  37. /**
  38. * @var string
  39. *
  40. * @ORM\Column(name="isbn", type="string", length=255, nullable=true)
  41. */
  42. private $isbn;
  43. /**
  44. * @var int
  45. *
  46. * @ORM\Column(name="numero", type="integer", nullable=true)
  47. */
  48. private $numero;
  49. /**
  50. * @var string
  51. *
  52. * @ORM\Column(name="annee", type="integer", nullable=true)
  53. */
  54. private $annee;
  55. /**
  56. * @ORM\ManyToOne(targetEntity="App\Entity\Edition")
  57. * @ORM\JoinColumn(name="edition_id", referencedColumnName="id", nullable=true)
  58. */
  59. private $edition;
  60. /**
  61. * @var string
  62. *
  63. * @ORM\Column(name="cycle", type="string", length=255, nullable=true)
  64. */
  65. private $cycle;
  66. /**
  67. * @var int
  68. *
  69. * @ORM\Column(name="tome", type="integer", nullable=true)
  70. */
  71. private $tome;
  72. /**
  73. * @var int
  74. *
  75. * @ORM\Column(name="pages", type="integer", nullable=true)
  76. */
  77. private $pages;
  78. /**
  79. * @var float
  80. *
  81. * @ORM\Column(name="prixBase", type="float", nullable=true)
  82. */
  83. private $prixBase;
  84. /**
  85. * @ORM\ManyToOne(targetEntity="App\Entity\Monnaie")
  86. * @ORM\JoinColumn(name="monnaie_id", referencedColumnName="id", nullable=true)
  87. */
  88. private $monnaie;
  89. /**
  90. * @var int
  91. *
  92. * @ORM\Column(name="cote", type="integer", nullable=true)
  93. */
  94. private $cote;
  95. /**
  96. * @var string
  97. *
  98. * @ORM\Column(name="amazon", type="text", nullable=true)
  99. */
  100. private $amazon;
  101. /**
  102. * @var float
  103. *
  104. * @ORM\Column(name="poids", type="float", nullable=true)
  105. */
  106. private $poids;
  107. /**
  108. * @var string
  109. *
  110. * @ORM\Column(name="resume", type="text", nullable=true)
  111. */
  112. private $resume;
  113. /**
  114. * @ORM\OneToMany(targetEntity="App\Entity\LienAuteurLivre", mappedBy="livre", cascade={"persist", "remove"})
  115. */
  116. protected $listeAuteur;
  117. /**
  118. * @ORM\OneToMany(targetEntity="App\Entity\LienUserLivre", mappedBy="livre", cascade={"persist", "remove"})
  119. */
  120. protected $listeUser;
  121. /**
  122. * @var string
  123. *
  124. * @ORM\Column(name="image", type="blob", nullable=true)
  125. */
  126. private $image;
  127. /**
  128. * @var string|null
  129. *
  130. * @ORM\Column(name="image_2", type="string", length=255, nullable=true)
  131. */
  132. private $image2;
  133. /**
  134. * Constructor
  135. */
  136. public function __construct()
  137. {
  138. $this->listeAuteur = new ArrayCollection();
  139. $this->listeUser = new ArrayCollection();
  140. }
  141. /**
  142. * Get id
  143. *
  144. * @return int
  145. */
  146. public function getId()
  147. {
  148. return $this->id;
  149. }
  150. /**
  151. * Set titre
  152. *
  153. * @param string $titre
  154. *
  155. * @return Livre
  156. */
  157. public function setTitre($titre)
  158. {
  159. $this->titre = $titre;
  160. return $this;
  161. }
  162. /**
  163. * Get titre
  164. *
  165. * @return string
  166. */
  167. public function getTitre()
  168. {
  169. return $this->titre;
  170. }
  171. /**
  172. * Set category
  173. *
  174. * @param Category $category
  175. *
  176. * @return Livre
  177. */
  178. public function setCategory($category)
  179. {
  180. $this->category = $category;
  181. return $this;
  182. }
  183. /**
  184. * Get category
  185. *
  186. * @return Category
  187. */
  188. public function getCategory()
  189. {
  190. return $this->category;
  191. }
  192. /**
  193. * Set collection
  194. *
  195. * @param Collection $collection
  196. *
  197. * @return Livre
  198. */
  199. public function setCollection($collection)
  200. {
  201. $this->collection = $collection;
  202. return $this;
  203. }
  204. /**
  205. * Get collection
  206. *
  207. * @return Collection
  208. */
  209. public function getCollection()
  210. {
  211. return $this->collection;
  212. }
  213. /**
  214. * Set isbn
  215. *
  216. * @param string $isbn
  217. *
  218. * @return Livre
  219. */
  220. public function setIsbn($isbn)
  221. {
  222. $this->isbn= $isbn;
  223. return $this;
  224. }
  225. /**
  226. * Get isbn
  227. *
  228. * @return string
  229. */
  230. public function getIsbn()
  231. {
  232. return $this->isbn;
  233. }
  234. /**
  235. * Set numero
  236. *
  237. * @param integer $numero
  238. *
  239. * @return Livre
  240. */
  241. public function setNumero($numero)
  242. {
  243. $this->numero = $numero;
  244. return $this;
  245. }
  246. /**
  247. * Get numero
  248. *
  249. * @return int
  250. */
  251. public function getNumero()
  252. {
  253. return $this->numero;
  254. }
  255. /**
  256. * Set annee
  257. *
  258. * @param string $annee
  259. *
  260. * @return Livre
  261. */
  262. public function setAnnee($annee)
  263. {
  264. $this->annee = $annee;
  265. return $this;
  266. }
  267. /**
  268. * Get annee
  269. *
  270. * @return string
  271. */
  272. public function getAnnee()
  273. {
  274. return $this->annee;
  275. }
  276. /**
  277. * Set edition
  278. *
  279. * @param Edition $edition
  280. *
  281. * @return Livre
  282. */
  283. public function setEdition($edition)
  284. {
  285. $this->edition = $edition;
  286. return $this;
  287. }
  288. /**
  289. * Get edition
  290. *
  291. * @return Edition
  292. */
  293. public function getEdition()
  294. {
  295. return $this->edition;
  296. }
  297. /**
  298. * Set cycle
  299. *
  300. * @param string $cycle
  301. *
  302. * @return Livre
  303. */
  304. public function setCycle($cycle)
  305. {
  306. $this->cycle = $cycle;
  307. return $this;
  308. }
  309. /**
  310. * Get cycle
  311. *
  312. * @return string
  313. */
  314. public function getCycle()
  315. {
  316. return $this->cycle;
  317. }
  318. /**
  319. * Set tome
  320. *
  321. * @param integer $tome
  322. *
  323. * @return Livre
  324. */
  325. public function setTome($tome)
  326. {
  327. $this->tome = $tome;
  328. return $this;
  329. }
  330. /**
  331. * Get tome
  332. *
  333. * @return int
  334. */
  335. public function getTome()
  336. {
  337. return $this->tome;
  338. }
  339. /**
  340. * Set pages
  341. *
  342. * @param integer $pages
  343. *
  344. * @return Livre
  345. */
  346. public function setPages($pages)
  347. {
  348. $this->pages = $pages;
  349. return $this;
  350. }
  351. /**
  352. * Get pages
  353. *
  354. * @return int
  355. */
  356. public function getPages()
  357. {
  358. return $this->pages;
  359. }
  360. /**
  361. * Set prixBase
  362. *
  363. * @param float $prixBase
  364. *
  365. * @return Livre
  366. */
  367. public function setPrixBase($prixBase)
  368. {
  369. $this->prixBase = $prixBase;
  370. return $this;
  371. }
  372. /**
  373. * Get prixBase
  374. *
  375. * @return float
  376. */
  377. public function getPrixBase()
  378. {
  379. return $this->prixBase;
  380. }
  381. /**
  382. * Set monnaie
  383. *
  384. * @param Monnaie $monnaie
  385. *
  386. * @return Livre
  387. */
  388. public function setMonnaie($monnaie)
  389. {
  390. $this->monnaie = $monnaie;
  391. return $this;
  392. }
  393. /**
  394. * Get monnaie
  395. *
  396. * @return Monnaie
  397. */
  398. public function getMonnaie()
  399. {
  400. return $this->monnaie;
  401. }
  402. /**
  403. * Set cote
  404. *
  405. * @param integer $cote
  406. *
  407. * @return Livre
  408. */
  409. public function setCote($cote)
  410. {
  411. $this->cote = $cote;
  412. return $this;
  413. }
  414. /**
  415. * Get cote
  416. *
  417. * @return int
  418. */
  419. public function getCote()
  420. {
  421. return $this->cote;
  422. }
  423. /**
  424. * Set amazon
  425. *
  426. * @param string $amazon
  427. *
  428. * @return Livre
  429. */
  430. public function setAmazon($amazon)
  431. {
  432. $this->amazon = $amazon;
  433. return $this;
  434. }
  435. /**
  436. * Get amazon
  437. *
  438. * @return string
  439. */
  440. public function getAmazon()
  441. {
  442. return $this->amazon;
  443. }
  444. /**
  445. * Set poids
  446. *
  447. * @param float $poids
  448. *
  449. * @return Livre
  450. */
  451. public function setPoids($poids)
  452. {
  453. $this->poids = $poids;
  454. return $this;
  455. }
  456. /**
  457. * Get poids
  458. *
  459. * @return float
  460. */
  461. public function getPoids()
  462. {
  463. return $this->poids;
  464. }
  465. /**
  466. * Set resume
  467. *
  468. * @param string $resume
  469. *
  470. * @return Livre
  471. */
  472. public function setResume($resume)
  473. {
  474. $this->resume = $resume;
  475. return $this;
  476. }
  477. /**
  478. * Get resume
  479. *
  480. * @return string
  481. */
  482. public function getResume()
  483. {
  484. return $this->resume;
  485. }
  486. /**
  487. * Set image
  488. *
  489. * @param string $image
  490. *
  491. * @return Livre
  492. */
  493. public function setImage($image)
  494. {
  495. $this->image = $image;
  496. return $this;
  497. }
  498. /**
  499. * Get image
  500. *
  501. * @return string
  502. */
  503. public function getImage()
  504. {
  505. return $this->image;
  506. }
  507. public function getImage64(){
  508. return base64_encode(stream_get_contents($this->image));
  509. }
  510. /**
  511. * Get best image URL or base64 encoded blob
  512. * Priority: image2 (downloaded file) > image (blob)
  513. *
  514. * @return string|null Returns URL if available, otherwise base64 encoded blob
  515. */
  516. public function getBestImage(): ?string
  517. {
  518. if (!empty($this->image2)) {
  519. return '/uploads/covers/' . $this->image2;
  520. }
  521. if (!empty($this->image)) {
  522. return 'data:image/jpeg;base64,' . base64_encode(stream_get_contents($this->image));
  523. }
  524. return null;
  525. }
  526. /**
  527. * Add Auteur
  528. *
  529. * @param \App\Entity\LienAuteurLivre $auteur
  530. *
  531. * @return Livre
  532. */
  533. public function addAuteur(LienAuteurLivre $auteur)
  534. {
  535. $this->listeAuteur[] = $auteur;
  536. return $this;
  537. }
  538. /**
  539. * Remove Auteur
  540. *
  541. * @param \App\Entity\LienAuteurLivre $auteur
  542. */
  543. public function removeAuteur(LienAuteurLivre $auteur)
  544. {
  545. $this->listeAuteur->removeElement($auteur);
  546. }
  547. /**
  548. * Get listeAuteur
  549. *
  550. * @return \Doctrine\Common\Collections\Collection
  551. */
  552. public function getListeAuteur()
  553. {
  554. return $this->listeAuteur;
  555. }
  556. /**
  557. * Set listeAuteur
  558. *
  559. * @param \Doctrine\Common\Collections\Collection $listeAuteur
  560. *
  561. * @return Livre
  562. */
  563. public function setListeAuteur($listeAuteur)
  564. {
  565. foreach ($this->getListeAuteur() as $c)
  566. $this->removeAuteur($c);
  567. foreach ($listeAuteur as $c)
  568. $this->addAuteur($c);
  569. return $this;
  570. }
  571. /**
  572. * Add User
  573. *
  574. * @param \App\Entity\LienUserLivre $user
  575. *
  576. * @return Livre
  577. */
  578. public function addUser(LienUserLivre $user)
  579. {
  580. $this->listeUser[] = $user;
  581. return $this;
  582. }
  583. /**
  584. * Remove User
  585. *
  586. * @param \App\Entity\LienUserLivre $user
  587. */
  588. public function removeUser(LienAuteurLivre $user)
  589. {
  590. $this->listeUser->removeElement($user);
  591. }
  592. /**
  593. * Get listeUser
  594. *
  595. * @return \Doctrine\Common\Collections\Collection
  596. */
  597. public function getListeUser()
  598. {
  599. return $this->listeUser;
  600. }
  601. /**
  602. * Set listeUser
  603. *
  604. * @param \Doctrine\Common\Collections\Collection $listeUser
  605. *
  606. * @return Livre
  607. */
  608. public function setListeUser($listeUser)
  609. {
  610. foreach ($this->getListeUser() as $c)
  611. $this->removeUser($c);
  612. foreach ($listeUser as $c)
  613. $this->addUser($c);
  614. return $this;
  615. }
  616. /**
  617. * Get image2
  618. *
  619. * @return string|null
  620. */
  621. public function getImage2(): ?string
  622. {
  623. return $this->image2;
  624. }
  625. /**
  626. * Set image2
  627. *
  628. * @param string|null $image2
  629. *
  630. * @return Livre
  631. */
  632. public function setImage2(?string $image2): self
  633. {
  634. $this->image2 = $image2;
  635. return $this;
  636. }
  637. }