Passed
Pull Request — master (#6922)
by
unknown
08:21
created

GradebookCertificate   A

Complexity

Total Complexity 21

Size/Duplication

Total Lines 145
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 54
dl 0
loc 145
rs 10
c 0
b 0
f 0
wmc 21

19 Methods

Rating   Name   Duplication   Size   Complexity  
A setPathCertificate() 0 5 1
A getId() 0 3 1
A getResourceIdentifier() 0 3 1
A setDownloadedAt() 0 5 1
A getUser() 0 3 1
A setResourceName() 0 3 1
A setUser() 0 5 1
A getPathCertificate() 0 3 1
A getCategory() 0 3 1
A getDownloadedAt() 0 3 1
A setScoreCertificate() 0 5 1
A setCreatedAt() 0 5 1
A getScoreCertificate() 0 3 1
A setCategory() 0 5 1
A getCreatedAt() 0 3 1
A getResourceName() 0 3 1
A __toString() 0 5 3
A getPublish() 0 3 1
A setPublish() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
/* For licensing terms, see /license.txt */
6
7
namespace Chamilo\CoreBundle\Entity;
8
9
use Chamilo\CoreBundle\Repository\GradebookCertificateRepository;
10
use Chamilo\CoreBundle\Traits\UserTrait;
11
use DateTime;
12
use Doctrine\ORM\Mapping as ORM;
13
use Gedmo\Mapping\Annotation as Gedmo;
14
use Stringable;
15
16
#[ORM\Table(name: 'gradebook_certificate')]
17
#[ORM\Index(columns: ['user_id'], name: 'idx_gradebook_certificate_user_id')]
18
#[ORM\Entity(repositoryClass: GradebookCertificateRepository::class)]
19
class GradebookCertificate extends AbstractResource implements ResourceInterface, Stringable
20
{
21
    use UserTrait;
22
23
    #[ORM\Column(name: 'id', type: 'integer')]
24
    #[ORM\Id]
25
    #[ORM\GeneratedValue]
26
    protected ?int $id = null;
27
28
    #[ORM\ManyToOne(targetEntity: GradebookCategory::class)]
29
    #[ORM\JoinColumn(name: 'cat_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
30
    protected ?GradebookCategory $category = null;
31
32
    #[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'gradeBookCertificates')]
33
    #[ORM\JoinColumn(name: 'user_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
34
    protected User $user;
35
36
    #[ORM\Column(name: 'score_certificate', type: 'float', precision: 10, scale: 0, nullable: false)]
37
    protected float $scoreCertificate;
38
39
    #[Gedmo\Timestampable(on: 'create')]
40
    #[ORM\Column(name: 'created_at', type: 'datetime', nullable: false)]
41
    protected DateTime $createdAt;
42
43
    #[ORM\Column(name: 'path_certificate', type: 'text', nullable: true)]
44
    protected ?string $pathCertificate = null;
45
46
    #[ORM\Column(name: 'downloaded_at', type: 'datetime', nullable: true)]
47
    protected ?DateTime $downloadedAt = null;
48
49
    #[ORM\Column(name: 'publish', type: 'boolean', options: ['default' => false])]
50
    protected bool $publish = false;
51
52
    public function __toString(): string
53
    {
54
        $user = isset($this->user) ? $this->user->getUsername() : 'user';
55
        $when = isset($this->createdAt) ? $this->createdAt->format('Y-m-d H:i') : 'pending';
56
        return "Certificate for {$user} ({$when})";
57
    }
58
59
    public function getResourceIdentifier(): int
60
    {
61
        return $this->getId();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getId() 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...
62
    }
63
64
    public function getResourceName(): string
65
    {
66
        return (string) $this;
67
    }
68
69
    public function setResourceName(string $name)
70
    {
71
        return $this;
72
    }
73
74
    public function getId(): ?int
75
    {
76
        return $this->id;
77
    }
78
79
    public function setCategory(?GradebookCategory $category): self
80
    {
81
        $this->category = $category;
82
83
        return $this;
84
    }
85
86
    public function getCategory(): ?GradebookCategory
87
    {
88
        return $this->category;
89
    }
90
91
    public function setUser(User $user): self
92
    {
93
        $this->user = $user;
94
95
        return $this;
96
    }
97
98
    public function getUser(): User
99
    {
100
        return $this->user;
101
    }
102
103
    public function setScoreCertificate(float $scoreCertificate): self
104
    {
105
        $this->scoreCertificate = $scoreCertificate;
106
107
        return $this;
108
    }
109
110
    public function getScoreCertificate(): float
111
    {
112
        return $this->scoreCertificate;
113
    }
114
115
    public function setCreatedAt(DateTime $createdAt): self
116
    {
117
        $this->createdAt = $createdAt;
118
119
        return $this;
120
    }
121
122
    public function getCreatedAt(): DateTime
123
    {
124
        return $this->createdAt;
125
    }
126
127
    public function setPathCertificate(?string $pathCertificate): self
128
    {
129
        $this->pathCertificate = $pathCertificate;
130
131
        return $this;
132
    }
133
134
    public function getPathCertificate(): ?string
135
    {
136
        return $this->pathCertificate;
137
    }
138
139
    public function getDownloadedAt(): ?DateTime
140
    {
141
        return $this->downloadedAt;
142
    }
143
144
    public function setDownloadedAt(?DateTime $downloadedAt): self
145
    {
146
        $this->downloadedAt = $downloadedAt;
147
148
        return $this;
149
    }
150
151
    public function setPublish(bool $publish): self
152
    {
153
        $this->publish = $publish;
154
155
        return $this;
156
    }
157
158
    public function getPublish(): bool
159
    {
160
        return $this->publish;
161
    }
162
}
163