@@ -98,9 +98,7 @@ class User extends Authenticatable
98
98
*
99
99
* @var array
100
100
*/
101
- // protected $fillable = [
102
- // 'firstname', 'lastname', 'username', 'avatar_path', 'email', 'password', 'bio', 'twitter', 'website', 'country_iso', 'privacy', 'email_display', 'receive_emails', 'magic_key','current_country','provider'
103
- // ];
101
+
104
102
105
103
protected $ guarded = [];
106
104
@@ -110,19 +108,27 @@ class User extends Authenticatable
110
108
* @var array
111
109
*/
112
110
protected $ hidden = [
113
- 'password ' , 'remember_token ' , 'magic_key '
111
+ 'password ' ,
112
+ 'remember_token ' ,
113
+ 'magic_key '
114
114
];
115
115
116
116
protected $ appends = ['fullName ' ];
117
117
118
- protected $ dates = ['deleted_at ' ];
118
+ protected $ dates = ['consent_given_at ' , ' future_consent_given_at ' ];
119
119
120
120
121
121
public function getName ()
122
122
{
123
- if (!empty ($ this ->username )) return $ this ->username ;
124
- if (!empty ($ this ->firstname ) && !empty ($ this ->lastname )) return $ this ->firstname . " " . $ this ->lastname ;
125
- if (!empty ($ this ->firstname ) && empty ($ this ->lastname )) return $ this ->firstname ;
123
+ if (!empty ($ this ->username )) {
124
+ return $ this ->username ;
125
+ }
126
+ if (!empty ($ this ->firstname ) && !empty ($ this ->lastname )) {
127
+ return $ this ->firstname . " " . $ this ->lastname ;
128
+ }
129
+ if (!empty ($ this ->firstname ) && empty ($ this ->lastname )) {
130
+ return $ this ->firstname ;
131
+ }
126
132
return $ this ->email ;
127
133
}
128
134
@@ -139,8 +145,6 @@ public function setAmbassadorAttribute($value)
139
145
} else {
140
146
$ this ->removeRole ('ambassador ' );
141
147
}
142
-
143
-
144
148
}
145
149
146
150
public function achievements ()
@@ -155,19 +159,15 @@ public function getLeadingTeacherAttribute()
155
159
156
160
public function setLeadingTeacherAttribute ($ value )
157
161
{
158
-
159
162
if ($ value ) {
160
163
$ this ->assignRole ('leading teacher ' );
161
164
} else {
162
165
$ this ->removeRole ('leading teacher ' );
163
166
}
164
-
165
-
166
167
}
167
168
168
169
public function isAdmin ()
169
170
{
170
-
171
171
return $ this ->hasRole ("super admin " );
172
172
}
173
173
@@ -218,7 +218,8 @@ public function participations()
218
218
219
219
public function expertises ()
220
220
{
221
- return $ this ->belongsToMany (LeadingTeacherExpertise::class, 'leading_teacher_expertise_user ' , 'user_id ' , 'lte_id ' );
221
+ return $ this ->belongsToMany (LeadingTeacherExpertise::class, 'leading_teacher_expertise_user ' , 'user_id ' ,
222
+ 'lte_id ' );
222
223
}
223
224
224
225
public function levels ()
@@ -259,25 +260,27 @@ public function actions()
259
260
260
261
public function resetExperience ($ year = null )
261
262
{
262
- if (is_null ($ year )) $ year = Carbon::now ()->year ;
263
+ if (is_null ($ year )) {
264
+ $ year = Carbon::now ()->year ;
265
+ }
263
266
$ this ->getExperience ($ year )->update (
264
267
["points " => 0 ]
265
268
);
266
-
267
-
268
269
}
269
270
270
271
public function getPoints ($ year = null )
271
272
{
272
- if (is_null ($ year )) $ year = Carbon::now ()->year ;
273
+ if (is_null ($ year )) {
274
+ $ year = Carbon::now ()->year ;
275
+ }
273
276
return $ this ->getExperience ($ year )->points ;
274
-
275
-
276
277
}
277
278
278
279
public function getExperience ($ year = null )
279
280
{
280
- if (is_null ($ year )) $ year = Carbon::now ()->year ;
281
+ if (is_null ($ year )) {
282
+ $ year = Carbon::now ()->year ;
283
+ }
281
284
282
285
$ experience = Experience::firstOrCreate (
283
286
[
@@ -294,17 +297,18 @@ public function getExperience($year = null)
294
297
295
298
public function awardExperience ($ points , $ year = null )
296
299
{
297
-
298
- if (is_null ($ year )) $ year = Carbon::now ()->year ;
300
+ if (is_null ($ year )) {
301
+ $ year = Carbon::now ()->year ;
302
+ }
299
303
$ this ->getExperience ($ year )->awardExperience ($ points );
300
-
301
304
}
302
305
303
306
public function stripExperience ($ points , $ year = null )
304
307
{
305
- if (is_null ($ year )) $ year = Carbon::now ()->year ;
308
+ if (is_null ($ year )) {
309
+ $ year = Carbon::now ()->year ;
310
+ }
306
311
$ this ->getExperience ($ year )->stripExperience ($ points );
307
-
308
312
}
309
313
310
314
@@ -316,9 +320,10 @@ public function stripExperience($points, $year = null)
316
320
*/
317
321
public function getAvatarPathAttribute ($ avatar )
318
322
{
319
- if (is_null ($ avatar )) $ avatar = 'avatars/default_avatar.png ' ;
323
+ if (is_null ($ avatar )) {
324
+ $ avatar = 'avatars/default_avatar.png ' ;
325
+ }
320
326
return Storage::disk ('s3 ' )->url ($ avatar );
321
-
322
327
}
323
328
324
329
/**
@@ -329,14 +334,11 @@ public function getAvatarPathAttribute($avatar)
329
334
*/
330
335
public function getAvatarAttribute ()
331
336
{
332
-
333
337
$ arr = explode ("/ " , $ this ->avatar_path );
334
338
$ filename = array_pop ($ arr );
335
339
array_push ($ arr , $ filename );
336
340
$ glued = implode ("/ " , $ arr );
337
341
return $ glued ;
338
-
339
-
340
342
}
341
343
342
344
@@ -365,7 +367,6 @@ public static function getGeoIPData()
365
367
366
368
public function activities ($ edition )
367
369
{
368
-
369
370
return DB ::table ('events ' )
370
371
->where ('creator_id ' , '= ' , $ this ->id )
371
372
->where ('status ' , "= " , "APPROVED " )
@@ -376,7 +377,6 @@ public function activities($edition)
376
377
377
378
public function reported ($ edition = null )
378
379
{
379
-
380
380
$ query = DB ::table ('events ' )
381
381
->where ('creator_id ' , '= ' , $ this ->id )
382
382
->where ('status ' , "= " , "APPROVED " )
@@ -393,9 +393,10 @@ public function reported($edition = null)
393
393
394
394
public function influence ($ edition = null )
395
395
{
396
-
397
396
Log::info ("Influence for $ this ->email for edition $ edition " );
398
- if (is_null ($ this ->tag )) return 0 ;
397
+ if (is_null ($ this ->tag )) {
398
+ return 0 ;
399
+ }
399
400
400
401
// $nameInTag = TagsHelper::getNameInTag($this->tag);
401
402
@@ -440,7 +441,6 @@ public function unsubscribe()
440
441
441
442
public function getEventsToReviewCount ()
442
443
{
443
-
444
444
if (auth ()->user ()->isAmbassador ()) {
445
445
return EventHelper::getPendingEventsCount ($ this ->country_iso );
446
446
}
@@ -457,7 +457,6 @@ public function getEventsToReviewCount()
457
457
458
458
public function getNextPendingEvent (Event $ event )
459
459
{
460
-
461
460
if (auth ()->user ()->isAmbassador ()) {
462
461
return EventHelper::getNextPendingEvent ($ event , $ this ->country_iso );
463
462
}
@@ -483,4 +482,31 @@ public function taggedActivities()
483
482
}
484
483
485
484
485
+ public function hasGivenConsent ()
486
+ {
487
+ return $ this ->consent_given_at !== null ;
488
+ }
489
+
490
+ public function hasGivenFutureConsent ()
491
+ {
492
+ return $ this ->future_consent_given_at !== null ;
493
+ }
494
+
495
+ public function giveConsent ()
496
+ {
497
+ if (!$ this ->hasGivenConsent ()) {
498
+ $ this ->consent_given_at = now ();
499
+ $ this ->save ();
500
+ }
501
+ }
502
+
503
+ public function giveFutureConsent ()
504
+ {
505
+ if (!$ this ->hasGivenFutureConsent ()) {
506
+ $ this ->future_consent_given_at = now ();
507
+ $ this ->save ();
508
+ }
509
+ }
510
+
511
+
486
512
}
0 commit comments