forked from DallasMuseumArt/OctoberFriends
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUsermeta.php
171 lines (148 loc) · 3.86 KB
/
Usermeta.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<?php namespace DMA\Friends\Models;
use Model;
use RainLab\User\Models\User;
use RainLab\User\Models\State;
/**
* Usermeta Model
*/
class Usermeta extends Model
{
const NON_MEMBER = 0;
const IS_MEMBER = 1;
const IS_STAFF = 2;
/**
* @var array $genderOptions
* Provide a list of gender options for the user profile
*/
public static $genderOptions = [
'Male',
'Female',
'Non Binary/Other',
];
/**
* @var array $raceOptions
* Provide a list of race options for the user profile
*/
public static $raceOptions = [
'White',
'Hispanic',
'Black or African American',
'American Indian or Alaska Native',
'Asian',
'Native Hawaiian or Other Pacific Islander',
'Two or more races',
'Other',
];
/**
* @var array $householdIncomeOptions
* Provide a list of income options for the user profile
*/
public static $householdIncomeOptions = [
'Less then $25,000',
'$25,000 - $50,000',
'$50,000 - $75,000',
'$75,000 - $150,000',
'$150,000 - $500,000',
'$500,000 or more',
];
/**
* @var array $educationOptions
* Provide a list of education options for the user profile
*/
public static $educationOptions = [
'K-12',
'High School/GED',
'Some College',
'Vocational or Trade School',
'Bachelors Degree',
'Masters Degree',
'PhD',
];
/**
* @var string The database table used by the model.
*/
public $table = 'dma_friends_usermetas';
/**
* @var boolean $timestamps
* Do not use timestamps on the usermeta object
*/
public $timestamps = false;
public $primaryKey = 'user_id';
/**
* @var string $key
*/
protected $key = 'user_id';
/**
* @var array Guarded fields
*/
protected $guarded = ['user_id'];
/**
* @var array Fillable fields
*/
protected $fillable = [
'first_name',
'last_name',
'birth_date',
'email_optin',
'gender',
'race',
'household_income',
'household_size',
'education',
'current_member',
'current_member_number',
];
/**
* @var array Relations
*/
public $belongsTo = [
'user' => ['RainLab\User\Models\User',
'key' => 'user_id',
],
];
/**
* Automatically creates a metadata entry for a user if not one already.
* @param RainLab\User\Models\User $user
* @return DMA\Friends\Models\Usermeta
*/
public static function getFromUser($user = null)
{
if (!$user)
return null;
if (!$user->metadata) {
$meta = new static;
User::find($user->getKey())->metadata()->save($meta);
$user = User::find($user->getKey());
}
return $user->metadata;
}
/**
* Return users that are not staff and order them by points descending
*/
public function scopeByPoints($query)
{
return $query->excludeStaff()->orderBy('points', 'desc');
}
/**
* Exclude staff members from results
*/
public function scopeExcludeStaff($query)
{
return $query->where('current_member', '!=', self::IS_STAFF);
}
/**
* @return array
* Return all demographic options
*/
public static function getOptions()
{
$states = State::where('country_id', '=', 1)->get();
return [
'gender' => self::$genderOptions,
'states' => $states,
'race' => self::$raceOptions,
'household_income' => self::$householdIncomeOptions,
'education' => self::$educationOptions,
];
}
}