1 | <?php |
||
6 | trait UserPresenter |
||
7 | { |
||
8 | /** |
||
9 | * The default avatar used when there is no avatar for the user. |
||
10 | * |
||
11 | * @var string |
||
12 | */ |
||
13 | protected $defaultAvatar = '/images/avatar.png'; |
||
14 | |||
15 | /** |
||
16 | * The default primary color used when there is no primary color defined. |
||
17 | * |
||
18 | * @var string |
||
19 | */ |
||
20 | protected $defaultAvatarPrimaryColor = '#B4AEA4'; |
||
21 | |||
22 | /** |
||
23 | * Get the account first name. |
||
24 | * |
||
25 | * @return string |
||
26 | */ |
||
27 | public function getFirstNameAttribute(): string |
||
31 | |||
32 | /** |
||
33 | * Get the account last name. |
||
34 | * |
||
35 | * @return string |
||
36 | */ |
||
37 | public function getLastNameAttribute(): string |
||
41 | |||
42 | /** |
||
43 | * Get whatever the user has rubies or not. |
||
44 | * |
||
45 | * @return boolean |
||
46 | */ |
||
47 | public function getHasRubiesAttribute(): bool |
||
51 | |||
52 | /** |
||
53 | * Get the account full name. Return the username if the user |
||
54 | * has not set his first name and last name. |
||
55 | * |
||
56 | * @return string |
||
57 | */ |
||
58 | public function getFullNameAttribute(): string |
||
68 | |||
69 | /** |
||
70 | * Get the experiences total formated. |
||
71 | * |
||
72 | * @return integer |
||
73 | */ |
||
74 | public function getExperiencesTotalAttribute($experiencesTotal): int |
||
78 | |||
79 | /** |
||
80 | * Get the account facebook. |
||
81 | * |
||
82 | * @return string |
||
83 | */ |
||
84 | public function getFacebookAttribute(): string |
||
88 | |||
89 | /** |
||
90 | * Get the account twitter. |
||
91 | * |
||
92 | * @return string |
||
93 | */ |
||
94 | public function getTwitterAttribute(): string |
||
98 | |||
99 | /** |
||
100 | * Get the account biography. |
||
101 | * |
||
102 | * @return string |
||
103 | */ |
||
104 | public function getBiographyAttribute(): string |
||
108 | |||
109 | /** |
||
110 | * Get the account signature. |
||
111 | * |
||
112 | * @return string |
||
113 | */ |
||
114 | public function getSignatureAttribute(): string |
||
118 | |||
119 | /** |
||
120 | * Get the small avatar. |
||
121 | * |
||
122 | * @return string |
||
123 | */ |
||
124 | public function getAvatarSmallAttribute(): string |
||
128 | |||
129 | /** |
||
130 | * Get the medium avatar. |
||
131 | * |
||
132 | * @return string |
||
133 | */ |
||
134 | public function getAvatarMediumAttribute(): string |
||
138 | |||
139 | /** |
||
140 | * Get the big avatar. |
||
141 | * |
||
142 | * @return string |
||
143 | */ |
||
144 | public function getAvatarBigAttribute(): string |
||
148 | |||
149 | /** |
||
150 | * Get the profile background. |
||
151 | * |
||
152 | * @return string |
||
153 | */ |
||
154 | public function getProfileBackgroundAttribute(): string |
||
158 | |||
159 | /** |
||
160 | * Get the profile url. |
||
161 | * |
||
162 | * @return string |
||
163 | */ |
||
164 | public function getProfileUrlAttribute(): string |
||
172 | |||
173 | /** |
||
174 | * Get the primary color detected in the avatar. |
||
175 | * |
||
176 | * @return string |
||
177 | */ |
||
178 | public function getAvatarPrimaryColorAttribute(): string |
||
186 | |||
187 | /** |
||
188 | * We must decrement the post count due to the first post being counted. |
||
189 | * |
||
190 | * @param int $count The actual post count cache. |
||
191 | * |
||
192 | * @return int |
||
193 | */ |
||
194 | public function getDiscussPostCountAttribute($count): int |
||
198 | |||
199 | /** |
||
200 | * Parse a mdedia and return it if isset or return the default avatar. |
||
201 | * |
||
202 | * @param string $type The type of the media to get. |
||
203 | * |
||
204 | * @return string |
||
205 | */ |
||
206 | protected function parseMedia(string $type): string |
||
214 | |||
215 | /** |
||
216 | * Parse an attribute and return its value or empty if null. |
||
217 | * |
||
218 | * @param Object|null $relation The relation or the user object. |
||
219 | * Can be `$this` or `$this->account` for exemple |
||
220 | * @param string|null $attribute The attribute to parse. |
||
221 | * |
||
222 | * @return string |
||
223 | */ |
||
224 | protected function parse($relation, $attribute): string |
||
232 | } |
||
233 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: