Passed
Push — master ( ab8dec...906584 )
by Julito
09:36
created

Tool::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
namespace Chamilo\CoreBundle\Entity;
6
7
use Doctrine\Common\Collections\ArrayCollection;
8
use Doctrine\Common\Collections\Criteria;
9
use Doctrine\ORM\Mapping as ORM;
10
11
/**
12
 * Tool.
13
 *
14
 * @ORM\Table(name="tool")
15
 * @ORM\Entity
16
 */
17
class Tool
18
{
19
    /**
20
     * @var int
21
     *
22
     * @ORM\Column(name="id", type="integer")
23
     * @ORM\Id
24
     * @ORM\GeneratedValue
25
     */
26
    protected $id;
27
28
    /**
29
     * @ORM\Column(name="name", type="string", nullable=false, unique=true)
30
     */
31
    protected string $name;
32
33
    /**
34
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\ResourceType", mappedBy="tool", cascade={"persist", "remove"})
35
     */
36
    protected $resourceTypes;
37
38
    public function __construct()
39
    {
40
        $this->resourceTypes = new ArrayCollection();
41
    }
42
43
    public function __toString(): string
44
    {
45
        return $this->getName();
46
    }
47
48
    /**
49
     * @return ArrayCollection
50
     */
51
    /*public function getToolResourceRight()
52
    {
53
        return $this->toolResourceRight;
54
    }*/
55
56
    /*public function setToolResourceRight($toolResourceRight)
57
    {
58
        $this->toolResourceRight = new ArrayCollection();
59
60
        foreach ($toolResourceRight as $item) {
61
            $this->addToolResourceRight($item);
62
        }
63
    }*/
64
65
    /**
66
     * @return $this
67
     */
68
    /*public function addToolResourceRight(ToolResourceRight $toolResourceRight)
69
    {
70
        $toolResourceRight->setTool($this);
71
        $this->toolResourceRight[] = $toolResourceRight;
72
73
        return $this;
74
    }*/
75
76
    /*public function getResourceNodes()
77
    {
78
        return $this->resourceNodes;
79
    }*/
80
81
    /**
82
     * @return $this
83
     */
84
    /*public function setResourceNodes($resourceNodes)
85
    {
86
        $this->resourceNodes = $resourceNodes;
87
88
        return $this;
89
    }*/
90
91
    /**
92
     * Get id.
93
     */
94
    public function getId(): int
95
    {
96
        return $this->id;
97
    }
98
99
    /**
100
     * Set name.
101
     */
102
    public function setName(string $name): self
103
    {
104
        $this->name = $name;
105
106
        return $this;
107
    }
108
109
    /**
110
     * Get name.
111
     */
112
    public function getName(): string
113
    {
114
        return $this->name;
115
    }
116
117
    /**
118
     * @return ArrayCollection
119
     */
120
    public function getResourceTypes()
121
    {
122
        return $this->resourceTypes;
123
    }
124
125
    public function hasResourceType(ResourceType $resourceType): bool
126
    {
127
        if ($this->resourceTypes->count()) {
128
            $criteria = Criteria::create()->where(
129
                Criteria::expr()->eq('name', $resourceType->getName())
130
            );
131
            $relation = $this->resourceTypes->matching($criteria);
132
133
            return $relation->count() > 0;
134
        }
135
136
        return false;
137
    }
138
139
    public function setResourceTypes($resourceTypes): self
140
    {
141
        $this->resourceTypes = $resourceTypes;
142
143
        return $this;
144
    }
145
146
    /**
147
     * @param $name
148
     *
149
     * @return ResourceType
150
     */
151
    public function getResourceTypeByName($name)
152
    {
153
        $criteria = Criteria::create()->where(Criteria::expr()->eq('name', $name));
154
155
        return $this->getResourceTypes()->matching($criteria)->first();
156
    }
157
}
158