Passed
Push — master ( 78e10e...44b866 )
by Julito
10:54
created

UserRelUser   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 139
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 44
dl 0
loc 139
rs 10
c 1
b 0
f 0
wmc 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A setUser() 0 5 1
A getId() 0 3 1
A getLastEdit() 0 3 1
A setRelationType() 0 5 1
A getRelationType() 0 3 1
A __construct() 0 3 1
A getUser() 0 3 1
A setLastEdit() 0 5 1
A setFriend() 0 5 1
A getFriend() 0 3 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 ApiPlatform\Core\Annotation\ApiResource;
10
use Chamilo\CoreBundle\Traits\UserTrait;
11
use DateTime;
12
use Doctrine\ORM\Mapping as ORM;
13
14
/**
15
 * Associations between users.
16
 *
17
 * @ORM\Table(name="user_rel_user", indexes={
18
 *     @ORM\Index(name="idx_user_rel_user__user", columns={"user_id"}),
19
 *     @ORM\Index(name="idx_user_rel_user__friend_user", columns={"friend_user_id"}),
20
 *     @ORM\Index(name="idx_user_rel_user__user_friend_user", columns={"user_id", "friend_user_id"})
21
 * })
22
 * @ORM\Entity
23
 */
24
#[ApiResource(
25
    collectionOperations: [
26
        'get' => [
27
            //'security' => "is_granted('ROLE_ADMIN')",
28
        ],
29
        'post' => [
30
            //'security' => "is_granted('ROLE_ADMIN') or object.user == user",
31
        ],
32
    ],
33
    itemOperations: [
34
        'get' => [
35
            //'security' => "is_granted('ROLE_ADMIN')",
36
        ],
37
        'put' => [
38
            //'security' => "is_granted('ROLE_ADMIN') or object.user == user",
39
        ],
40
        'delete' => [
41
            //'security' => "is_granted('ROLE_ADMIN') or object.user == user",
42
        ],
43
    ],
44
    attributes: [
45
        'security' => 'is_granted("ROLE_USER") and object.user == user',
46
    ],
47
    denormalizationContext: [
48
        'groups' => ['message_tag:write'],
49
    ],
50
    normalizationContext: [
51
        'groups' => ['message_tag:read'],
52
    ],
53
)]
54
class UserRelUser
55
{
56
    use UserTrait;
57
58
    public const USER_RELATION_TYPE_UNKNOWN = 1;
59
    public const USER_RELATION_TYPE_PARENT = 2;
60
    public const USER_RELATION_TYPE_FRIEND = 3;
61
    public const USER_RELATION_TYPE_GOODFRIEND = 4; // should be deprecated is useless
62
    public const USER_RELATION_TYPE_ENEMY = 5; // should be deprecated is useless
63
    public const USER_RELATION_TYPE_DELETED = 6;
64
    public const USER_RELATION_TYPE_RRHH = 7;
65
    public const USER_RELATION_TYPE_BOSS = 8;
66
    public const USER_RELATION_TYPE_HRM_REQUEST = 9;
67
68
    /**
69
     * @ORM\Column(name="id", type="bigint")
70
     * @ORM\Id
71
     * @ORM\GeneratedValue
72
     */
73
    protected int $id;
74
75
    /**
76
     * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\User", inversedBy="friends")
77
     * @ORM\JoinColumn(name="user_id", referencedColumnName="id", onDelete="CASCADE", nullable=false)
78
     */
79
    protected User $user;
80
81
    /**
82
     * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\User", inversedBy="friendsWithMe")
83
     * @ORM\JoinColumn(name="friend_user_id", referencedColumnName="id", onDelete="CASCADE", nullable=false)
84
     */
85
    protected User $friend;
86
87
    /**
88
     * @ORM\Column(name="relation_type", type="integer", nullable=false)
89
     */
90
    protected int $relationType;
91
92
    /**
93
     * @ORM\Column(name="last_edit", type="datetime", nullable=true)
94
     */
95
    protected ?DateTime $lastEdit = null;
96
97
    public function __construct()
98
    {
99
        $this->relationType = self::USER_RELATION_TYPE_FRIEND;
100
    }
101
102
    public function getUser(): User
103
    {
104
        return $this->user;
105
    }
106
107
    public function setUser(User $user): self
108
    {
109
        $this->user = $user;
110
111
        return $this;
112
    }
113
114
    public function getFriend(): User
115
    {
116
        return $this->friend;
117
    }
118
119
    public function setFriend(User $friend): self
120
    {
121
        $this->friend = $friend;
122
123
        return $this;
124
    }
125
126
    public function setRelationType(int $relationType): self
127
    {
128
        $this->relationType = $relationType;
129
130
        return $this;
131
    }
132
133
    public function getRelationType(): ?int
134
    {
135
        return $this->relationType;
136
    }
137
138
    public function setLastEdit(DateTime $lastEdit): self
139
    {
140
        $this->lastEdit = $lastEdit;
141
142
        return $this;
143
    }
144
145
    /**
146
     * Get lastEdit.
147
     *
148
     * @return DateTime
149
     */
150
    public function getLastEdit()
151
    {
152
        return $this->lastEdit;
153
    }
154
155
    /**
156
     * Get id.
157
     *
158
     * @return int
159
     */
160
    public function getId()
161
    {
162
        return $this->id;
163
    }
164
}
165