Completed
Pull Request — dev (#24)
by
unknown
03:54
created

SurveyQuestion::setSurveys()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 9
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 9
loc 9
rs 9.6666
c 0
b 0
f 0
ccs 0
cts 5
cp 0
cc 2
eloc 5
nc 2
nop 1
crap 6
1
<?php
2
3
namespace AppBundle\Entity;
4
5
use Doctrine\ORM\Mapping as ORM;
6
use Knp\DoctrineBehaviors\Model as ORMBehaviors;
7
use Doctrine\Common\Collections\ArrayCollection;
8
use Symfony\Component\Validator\Constraints as Assert;
9
use Symfony\Component\Serializer\Annotation\Groups;
10
11
/**
12
 * SurveyQuestion.
13
 *
14
 * @ORM\Entity(repositoryClass="AppBundle\Repository\SurveyQuestionRepository")
15
 */
16
class SurveyQuestion
17
{
18
    use ORMBehaviors\Timestampable\Timestampable;
19
20
    /**
21
     * @var int
22
     *
23
     * @ORM\Column(type="integer")
24
     * @ORM\Id
25
     * @ORM\GeneratedValue(strategy="AUTO")
26
     * @Groups({"group2", "group3"})
27
     */
28
    private $id;
29
30
    /**
31
     * @var string
32
     * @Assert\NotBlank()
33
     * @Assert\Type("string")
34
     * @Assert\Length(
35
     *      max = 500
36
     * )
37
     * @ORM\Column(type="string")
38
     * @Groups({"group2", "group3"})
39
     */
40
    private $title;
41
42
    /**
43
     * @var SurveyType
44
     * @Assert\Type("object")
45
     * @Assert\Valid
46
     * @ORM\ManyToOne(targetEntity="SurveyType", inversedBy="questions")
47
     */
48
    private $surveyType;
49
50
    /**
51
     * @var ArrayCollection[Survey]
52
     * @ORM\ManyToMany(targetEntity="Survey", inversedBy="questions")
53
     */
54
    private $surveys;
55
56
    /**
57
     * @var ArrayCollection[SurveyAnswer]
58
     * @ORM\OneToMany(targetEntity="SurveyAnswer", mappedBy="question")
59
     */
60
    private $answers;
61
62
    public function __construct()
63
    {
64
        $this->surveys = new ArrayCollection();
65
        $this->answers = new ArrayCollection();
66
    }
67
68
    /**
69
     * Get id.
70
     *
71
     * @return int
72
     */
73 1
    public function getId()
74
    {
75 1
        return $this->id;
76
    }
77
78
    /**
79
     * Set title.
80
     *
81
     * @param string $title
82
     *
83
     * @return SurveyQuestion
84
     */
85
    public function setTitle($title)
86
    {
87
        $this->title = $title;
88
89
        return $this;
90
    }
91
92
    /**
93
     * Get title.
94
     *
95
     * @return string
96
     */
97 3
    public function getTitle()
98
    {
99 3
        return $this->title;
100
    }
101
102
    /**
103
     * Set type.
104
     *
105
     * @param SurveyType $type
106
     *
107
     * @return SurveyQuestion
108
     */
109
    public function setSurveyType(SurveyType $type)
110
    {
111
        $this->surveyType = $type;
112
113
        return $this;
114
    }
115
116
    /**
117
     * Get type.
118
     *
119
     * @return SurveyType
120
     */
121
    public function getSurveyType()
122
    {
123
        return $this->surveyType;
124
    }
125
126
    /**
127
     * @param Survey $survey
128
     *
129
     * @return SurveyQuestion
130
     */
131 1
    public function addSurvey(Survey $survey)
132
    {
133 1
        if (!$this->surveys->contains($survey)) {
134 1
            $this->surveys->add($survey);
135 1
            $survey->addQuestion($this);
136
        }
137
138 1
        return $this;
139
    }
140
141
    /**
142
     * Get Surveys.
143
     *
144
     * @return ArrayCollection
145
     */
146
    public function getSurveys()
147
    {
148
        return $this->surveys;
149
    }
150
151
    /**
152
     * Get Answers.
153
     *
154
     * @return ArrayCollection
155
     */
156
    public function getAnswers()
157
    {
158
        return $this->answers;
159
    }
160
}
161