Passed
Pull Request — master (#5720)
by
unknown
07:05
created

CBlog::getIid()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/* For licensing terms, see /license.txt */
6
7
namespace Chamilo\CourseBundle\Entity;
8
9
use Chamilo\CoreBundle\Entity\AbstractResource;
10
use Chamilo\CoreBundle\Entity\ResourceInterface;
11
use Doctrine\Common\Collections\ArrayCollection;
12
use Doctrine\Common\Collections\Collection;
13
use Doctrine\ORM\Mapping as ORM;
14
use Stringable;
15
use Symfony\Component\Validator\Constraints as Assert;
16
17
#[ORM\Table(name: 'c_blog')]
18
#[ORM\Entity]
19
class CBlog extends AbstractResource implements ResourceInterface, Stringable
20
{
21
    #[ORM\Column(name: 'iid', type: 'integer')]
22
    #[ORM\Id]
23
    #[ORM\GeneratedValue]
24
    protected ?int $iid = null;
25
26
    #[Assert\NotBlank]
27
    #[ORM\Column(name: 'title', type: 'text', nullable: false)]
28
    protected string $title;
29
30
    #[ORM\Column(name: 'blog_subtitle', type: 'string', length: 250, nullable: true)]
31
    protected ?string $blogSubtitle = null;
32
33
    #[ORM\Column(name: 'date_creation', type: 'datetime', nullable: false)]
34
    protected \DateTime $dateCreation;
35
36
    #[ORM\OneToMany(mappedBy: 'blog', targetEntity: CBlogAttachment::class, cascade: ['persist', 'remove'])]
37
    private Collection $attachments;
38
39
    public function __construct()
40
    {
41
        $this->attachments = new ArrayCollection();
42
    }
43
44
    public function getIid(): ?int
45
    {
46
        return $this->iid;
47
    }
48
49
    public function getTitle(): string
50
    {
51
        return $this->title;
52
    }
53
54
    public function setTitle(string $title): self
55
    {
56
        $this->title = $title;
57
        return $this;
58
    }
59
60
    public function getBlogSubtitle(): ?string
61
    {
62
        return $this->blogSubtitle;
63
    }
64
65
    public function setBlogSubtitle(?string $blogSubtitle): self
66
    {
67
        $this->blogSubtitle = $blogSubtitle;
68
        return $this;
69
    }
70
71
    public function getDateCreation(): \DateTime
72
    {
73
        return $this->dateCreation;
74
    }
75
76
    public function setDateCreation(\DateTime $dateCreation): self
77
    {
78
        $this->dateCreation = $dateCreation;
79
        return $this;
80
    }
81
82
    /**
83
     * @return Collection<int, CBlogAttachment>
84
     */
85
    public function getAttachments(): Collection
86
    {
87
        return $this->attachments;
88
    }
89
90
    public function addAttachment(CBlogAttachment $attachment): self
91
    {
92
        if (!$this->attachments->contains($attachment)) {
93
            $this->attachments->add($attachment);
94
            $attachment->setBlog($this);
95
        }
96
97
        return $this;
98
    }
99
100
    public function removeAttachment(CBlogAttachment $attachment): self
101
    {
102
        if ($this->attachments->removeElement($attachment)) {
103
            if ($attachment->getBlog() === $this) {
104
                $attachment->setBlog(null);
105
            }
106
        }
107
108
        return $this;
109
    }
110
111
    public function getResourceIdentifier(): int
112
    {
113
        return $this->getIid();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getIid() could return the type null which is incompatible with the type-hinted return integer. Consider adding an additional type-check to rule them out.
Loading history...
114
    }
115
116
    public function getResourceName(): string
117
    {
118
        return $this->getTitle();
119
    }
120
121
    public function setResourceName(string $name): self
122
    {
123
        return $this->setTitle($name);
124
    }
125
126
    public function __toString(): string
127
    {
128
        return $this->getTitle();
129
    }
130
}
131