1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Stack Exchange Api Client library. |
5
|
|
|
* |
6
|
|
|
* Copyright (c) 2015 Beñat Espiña <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace BenatEspina\StackExchangeApiClient\Model\Traits; |
13
|
|
|
|
14
|
|
|
use BenatEspina\StackExchangeApiClient\Util\Util; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Trait FavoriteTrait. |
18
|
|
|
* |
19
|
|
|
* @author Beñat Espiña <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
trait FavoriteTrait |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* Number of favorite votes. |
25
|
|
|
* |
26
|
|
|
* @var int |
27
|
|
|
*/ |
28
|
|
|
protected $favoriteCount; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Boolean that shows it it is favorited or not. |
32
|
|
|
* |
33
|
|
|
* @var boolean. |
34
|
|
|
*/ |
35
|
|
|
protected $favorited; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Sets number of favorites. |
39
|
|
|
* |
40
|
|
|
* @param int $favoriteCount The number of favorites |
41
|
|
|
* |
42
|
|
|
* @return $this self Object |
43
|
|
|
*/ |
44
|
|
|
public function setFavoriteCount($favoriteCount) |
45
|
|
|
{ |
46
|
|
|
$this->favoriteCount = $favoriteCount; |
47
|
|
|
|
48
|
|
|
return $this; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Gets number of favorites. |
53
|
|
|
* |
54
|
|
|
* @return int |
55
|
|
|
*/ |
56
|
|
|
public function getFavoriteCount() |
57
|
|
|
{ |
58
|
|
|
return $this->favoriteCount; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Sets is favorited. |
63
|
|
|
* |
64
|
|
|
* @param bool $favorited The favorited boolean |
65
|
|
|
* |
66
|
|
|
* @return $this self Object |
67
|
|
|
*/ |
68
|
|
|
public function setFavorited($favorited) |
69
|
|
|
{ |
70
|
|
|
$this->favorited = $favorited; |
71
|
|
|
|
72
|
|
|
return $this; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Gets is favorited. |
77
|
|
|
* |
78
|
|
|
* @return bool |
79
|
|
|
*/ |
80
|
|
|
public function isFavorited() |
81
|
|
|
{ |
82
|
|
|
return $this->favorited; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Loads the variables if the data exist into resource. It works like a constructor. |
87
|
|
|
* |
88
|
|
|
* @param null|mixed[] $resource The resource |
89
|
|
|
*/ |
90
|
|
|
protected function loadFavorite($resource) |
91
|
|
|
{ |
92
|
|
|
$this->favoriteCount = Util::setIfIntegerExists($resource, 'favorite_count'); |
93
|
|
|
$this->favorited = Util::setIfBoolExists($resource, 'favorited'); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|