|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Entity; |
|
4
|
|
|
|
|
5
|
|
|
use App\Repository\BookRepository; |
|
6
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
7
|
|
|
|
|
8
|
|
|
#[ORM\Entity(repositoryClass: BookRepository::class)] |
|
9
|
|
|
class Book |
|
10
|
|
|
{ |
|
11
|
|
|
#[ORM\Id] |
|
12
|
|
|
#[ORM\GeneratedValue] |
|
13
|
|
|
#[ORM\Column] |
|
14
|
|
|
// @phpstan-ignore-next-line |
|
15
|
|
|
private ?int $id = null; |
|
16
|
|
|
|
|
17
|
|
|
#[ORM\Column(length: 255)] |
|
18
|
|
|
private ?string $title = null; |
|
19
|
|
|
|
|
20
|
|
|
#[ORM\Column(length: 13, nullable: true)] |
|
21
|
|
|
private ?string $isbn = null; |
|
22
|
|
|
|
|
23
|
|
|
#[ORM\Column(length: 255, nullable: true)] |
|
24
|
|
|
private ?string $author = null; |
|
25
|
|
|
|
|
26
|
|
|
#[ORM\Column(length: 255, nullable: true)] |
|
27
|
|
|
private ?string $img; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* getId. |
|
31
|
|
|
*/ |
|
32
|
11 |
|
public function getId(): ?int |
|
33
|
|
|
{ |
|
34
|
11 |
|
return $this->id; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* getTitle. |
|
39
|
|
|
*/ |
|
40
|
11 |
|
public function getTitle(): ?string |
|
41
|
|
|
{ |
|
42
|
11 |
|
return $this->title; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* setTitle. |
|
47
|
|
|
*/ |
|
48
|
3 |
|
public function setTitle(string $title): static |
|
49
|
|
|
{ |
|
50
|
|
|
// If string to long cut it |
|
51
|
3 |
|
(strlen($title) < 255) ? $this->title = $title : $this->title = substr($title, 0, 255); |
|
52
|
|
|
|
|
53
|
3 |
|
return $this; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* getISBN. |
|
58
|
|
|
*/ |
|
59
|
11 |
|
public function getISBN(): ?string |
|
60
|
|
|
{ |
|
61
|
11 |
|
return $this->isbn; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* setISBN. |
|
66
|
|
|
* |
|
67
|
|
|
* Set isbn of book if the param is 13 digits long |
|
68
|
|
|
*/ |
|
69
|
3 |
|
public function setISBN(?string $isbn): static |
|
70
|
|
|
{ |
|
71
|
3 |
|
if (null === $isbn) { |
|
72
|
1 |
|
$this->isbn = null; |
|
73
|
|
|
|
|
74
|
1 |
|
return $this; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
// isbn is 13 digits or else null |
|
78
|
3 |
|
(13 == strlen($isbn)) ? $this->isbn = $isbn : $this->isbn = null; |
|
79
|
|
|
|
|
80
|
3 |
|
return $this; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* getAuthor. |
|
85
|
|
|
*/ |
|
86
|
11 |
|
public function getAuthor(): ?string |
|
87
|
|
|
{ |
|
88
|
11 |
|
return $this->author; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* setAuthor. |
|
93
|
|
|
*/ |
|
94
|
3 |
|
public function setAuthor(?string $author): static |
|
95
|
|
|
{ |
|
96
|
3 |
|
if (null === $author) { |
|
97
|
1 |
|
$this->author = null; |
|
98
|
|
|
|
|
99
|
1 |
|
return $this; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
// If string to long cut it |
|
103
|
3 |
|
(strlen($author) < 255) ? $this->author = $author : $this->author = substr($author, 0, 255); |
|
104
|
|
|
|
|
105
|
3 |
|
return $this; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* getImg. |
|
110
|
|
|
* |
|
111
|
|
|
* @return string|null |
|
112
|
|
|
*/ |
|
113
|
11 |
|
public function getImg() |
|
114
|
|
|
{ |
|
115
|
11 |
|
return $this->img; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* setImg. |
|
120
|
|
|
* |
|
121
|
|
|
* @param string|null $img |
|
122
|
|
|
*/ |
|
123
|
3 |
|
public function setImg($img): static |
|
124
|
|
|
{ |
|
125
|
3 |
|
if (null === $img) { |
|
126
|
2 |
|
$this->img = null; |
|
127
|
|
|
|
|
128
|
2 |
|
return $this; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
// If string to long null it |
|
132
|
2 |
|
(strlen($img) < 255) ? $this->img = $img : $this->img = null; |
|
133
|
2 |
|
$this->img = $img; |
|
134
|
|
|
|
|
135
|
2 |
|
return $this; |
|
136
|
|
|
} |
|
137
|
|
|
} |
|
138
|
|
|
|