| @@ 22-110 (lines=89) @@ | ||
| 19 | * |
|
| 20 | * @author Beñat Espiña <[email protected]> |
|
| 21 | */ |
|
| 22 | class Privilege implements PrivilegeInterface |
|
| 23 | { |
|
| 24 | /** |
|
| 25 | * Description. |
|
| 26 | * |
|
| 27 | * @var string |
|
| 28 | */ |
|
| 29 | protected $description; |
|
| 30 | ||
| 31 | /** |
|
| 32 | * Reputation. |
|
| 33 | * |
|
| 34 | * @var int |
|
| 35 | */ |
|
| 36 | protected $reputation; |
|
| 37 | ||
| 38 | /** |
|
| 39 | * Short description. |
|
| 40 | * |
|
| 41 | * @var string |
|
| 42 | */ |
|
| 43 | protected $shortDescription; |
|
| 44 | ||
| 45 | /** |
|
| 46 | * Constructor. |
|
| 47 | * |
|
| 48 | * @param null|mixed[] $json The json string being decoded |
|
| 49 | */ |
|
| 50 | public function __construct($json = null) |
|
| 51 | { |
|
| 52 | $this->description = Util::setIfStringExists($json, 'description'); |
|
| 53 | $this->reputation = Util::setIfIntegerExists($json, 'reputation'); |
|
| 54 | $this->shortDescription = Util::setIfStringExists($json, 'short_description'); |
|
| 55 | } |
|
| 56 | ||
| 57 | /** |
|
| 58 | * {@inheritdoc} |
|
| 59 | */ |
|
| 60 | public function setDescription($description) |
|
| 61 | { |
|
| 62 | $this->description = $description; |
|
| 63 | ||
| 64 | return $this; |
|
| 65 | } |
|
| 66 | ||
| 67 | /** |
|
| 68 | * {@inheritdoc} |
|
| 69 | */ |
|
| 70 | public function getDescription() |
|
| 71 | { |
|
| 72 | return $this->description; |
|
| 73 | } |
|
| 74 | ||
| 75 | /** |
|
| 76 | * {@inheritdoc} |
|
| 77 | */ |
|
| 78 | public function setReputation($reputation) |
|
| 79 | { |
|
| 80 | $this->reputation = $reputation; |
|
| 81 | ||
| 82 | return $this; |
|
| 83 | } |
|
| 84 | ||
| 85 | /** |
|
| 86 | * {@inheritdoc} |
|
| 87 | */ |
|
| 88 | public function getReputation() |
|
| 89 | { |
|
| 90 | return $this->reputation; |
|
| 91 | } |
|
| 92 | ||
| 93 | /** |
|
| 94 | * {@inheritdoc} |
|
| 95 | */ |
|
| 96 | public function setShortDescription($shortDescription) |
|
| 97 | { |
|
| 98 | $this->shortDescription = $shortDescription; |
|
| 99 | ||
| 100 | return $this; |
|
| 101 | } |
|
| 102 | ||
| 103 | /** |
|
| 104 | * {@inheritdoc} |
|
| 105 | */ |
|
| 106 | public function getShortDescription() |
|
| 107 | { |
|
| 108 | return $this->shortDescription; |
|
| 109 | } |
|
| 110 | } |
|
| 111 | ||
| @@ 21-127 (lines=107) @@ | ||
| 18 | * |
|
| 19 | * @author Beñat Espiña <[email protected]> |
|
| 20 | */ |
|
| 21 | trait GenericIdTrait |
|
| 22 | { |
|
| 23 | /** |
|
| 24 | * The answer id. |
|
| 25 | * |
|
| 26 | * @var int|null |
|
| 27 | */ |
|
| 28 | protected $answerId; |
|
| 29 | ||
| 30 | /** |
|
| 31 | * The body. |
|
| 32 | * |
|
| 33 | * @var string|null |
|
| 34 | */ |
|
| 35 | protected $body; |
|
| 36 | ||
| 37 | /** |
|
| 38 | * The question id. |
|
| 39 | * |
|
| 40 | * @var int|null |
|
| 41 | */ |
|
| 42 | protected $questionId; |
|
| 43 | ||
| 44 | /** |
|
| 45 | * Sets the answer id. |
|
| 46 | * |
|
| 47 | * @param int $answerId The answer id |
|
| 48 | * |
|
| 49 | * @return $this self Object |
|
| 50 | */ |
|
| 51 | public function setAnswerId($answerId) |
|
| 52 | { |
|
| 53 | $this->answerId = $answerId; |
|
| 54 | ||
| 55 | return $this; |
|
| 56 | } |
|
| 57 | ||
| 58 | /** |
|
| 59 | * Gets the answer id. |
|
| 60 | * |
|
| 61 | * @return int |
|
| 62 | */ |
|
| 63 | public function getAnswerId() |
|
| 64 | { |
|
| 65 | return $this->answerId; |
|
| 66 | } |
|
| 67 | ||
| 68 | /** |
|
| 69 | * Sets body. |
|
| 70 | * |
|
| 71 | * @param string|null $body The body |
|
| 72 | * |
|
| 73 | * @return $this self Object |
|
| 74 | */ |
|
| 75 | public function setBody($body) |
|
| 76 | { |
|
| 77 | $this->body = $body; |
|
| 78 | ||
| 79 | return $this; |
|
| 80 | } |
|
| 81 | ||
| 82 | /** |
|
| 83 | * Gets body. |
|
| 84 | * |
|
| 85 | * @return string|null |
|
| 86 | */ |
|
| 87 | public function getBody() |
|
| 88 | { |
|
| 89 | return $this->body; |
|
| 90 | } |
|
| 91 | ||
| 92 | /** |
|
| 93 | * Sets the question id. |
|
| 94 | * |
|
| 95 | * @param int|null $questionId The question id |
|
| 96 | * |
|
| 97 | * @return $this self Object |
|
| 98 | */ |
|
| 99 | public function setQuestionId($questionId) |
|
| 100 | { |
|
| 101 | $this->questionId = $questionId; |
|
| 102 | ||
| 103 | return $this; |
|
| 104 | } |
|
| 105 | ||
| 106 | /** |
|
| 107 | * Gets the question id. |
|
| 108 | * |
|
| 109 | * @return int|null |
|
| 110 | */ |
|
| 111 | public function getQuestionId() |
|
| 112 | { |
|
| 113 | return $this->questionId; |
|
| 114 | } |
|
| 115 | ||
| 116 | /** |
|
| 117 | * Loads the variables if the data exist into resource. It works like a constructor. |
|
| 118 | * |
|
| 119 | * @param null|mixed[] $resource The resource |
|
| 120 | */ |
|
| 121 | protected function loadGenericId($resource) |
|
| 122 | { |
|
| 123 | $this->answerId = Util::setIfIntegerExists($resource, 'answer_id'); |
|
| 124 | $this->body = Util::setIfStringExists($resource, 'body'); |
|
| 125 | $this->questionId = Util::setIfIntegerExists($resource, 'question_id'); |
|
| 126 | } |
|
| 127 | } |
|
| 128 | ||