1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* Exposes API endpoints for Opportunity entities |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
elgg_ws_expose_function( |
7
|
|
|
"get.opportunity", |
8
|
|
|
"get_opportunity", |
9
|
|
|
array( |
10
|
|
|
"user" => array('type' => 'string', 'required' => true), |
11
|
|
|
"guid" => array('type' => 'int', 'required' => true), |
12
|
|
|
"lang" => array('type' => 'string', 'required' => false, 'default' => "en") |
13
|
|
|
), |
14
|
|
|
'Retrieves a opportunity based on user id and opportunity id', |
15
|
|
|
'POST', |
16
|
|
|
true, |
17
|
|
|
false |
18
|
|
|
); |
19
|
|
|
|
20
|
|
|
elgg_ws_expose_function( |
21
|
|
|
"get.opportunities", |
22
|
|
|
"get_opportunities", |
23
|
|
|
array( |
24
|
|
|
"user" => array('type' => 'string', 'required' => true), |
25
|
|
|
"limit" => array('type' => 'int', 'required' => false, 'default' => 10), |
26
|
|
|
"offset" => array('type' => 'int', 'required' => false, 'default' => 0), |
27
|
|
|
"filters" => array('type' => 'string', 'required' => false, 'default' => ""), |
28
|
|
|
"lang" => array('type' => 'string', 'required' => false, 'default' => "en") |
29
|
|
|
), |
30
|
|
|
'Retrieves opportunities based on user id', |
31
|
|
|
'POST', |
32
|
|
|
true, |
33
|
|
|
false |
34
|
|
|
); |
35
|
|
|
|
36
|
|
|
elgg_ws_expose_function( |
37
|
|
|
"apply.post", |
38
|
|
|
"apply_post", |
39
|
|
|
array( |
40
|
|
|
"user" => array('type' => 'string', 'required' => true), |
41
|
|
|
"message" => array('type' => 'string', 'required' => true, 'default' => ""), |
42
|
|
|
"guid" => array('type' => 'int', 'required' => true), |
43
|
|
|
"lang" => array('type' => 'string', 'required' => false, 'default' => "en") |
44
|
|
|
), |
45
|
|
|
'Retrieves a opportunity based on user id and opportunity id', |
46
|
|
|
'POST', |
47
|
|
|
true, |
48
|
|
|
false |
49
|
|
|
); |
50
|
|
|
|
51
|
|
|
elgg_ws_expose_function( |
52
|
|
|
"withdraw.post", |
53
|
|
|
"withdraw_post", |
54
|
|
|
array( |
55
|
|
|
"user" => array('type' => 'string', 'required' => true), |
56
|
|
|
"message" => array('type' => 'string', 'required' => true, 'default' => ""), |
57
|
|
|
"guid" => array('type' => 'int', 'required' => true), |
58
|
|
|
"lang" => array('type' => 'string', 'required' => false, 'default' => "en") |
59
|
|
|
), |
60
|
|
|
'Retrieves a opportunity based on user id and opportunity id', |
61
|
|
|
'POST', |
62
|
|
|
true, |
63
|
|
|
false |
64
|
|
|
); |
65
|
|
|
|
66
|
|
|
elgg_ws_expose_function( |
67
|
|
|
"accept.post", |
68
|
|
|
"accept_post", |
69
|
|
|
array( |
70
|
|
|
"user" => array('type' => 'string', 'required' => true), |
71
|
|
|
"guid" => array('type' => 'int', 'required' => true), |
72
|
|
|
"lang" => array('type' => 'string', 'required' => false, 'default' => "en") |
73
|
|
|
), |
74
|
|
|
'Retrieves a opportunity based on user id and opportunity id', |
75
|
|
|
'POST', |
76
|
|
|
true, |
77
|
|
|
false |
78
|
|
|
); |
79
|
|
|
|
80
|
|
|
elgg_ws_expose_function( |
81
|
|
|
"accept.post", |
82
|
|
|
"accept_post", |
83
|
|
|
array( |
84
|
|
|
"user" => array('type' => 'string', 'required' => true), |
85
|
|
|
"guid" => array('type' => 'int', 'required' => true), |
86
|
|
|
"lang" => array('type' => 'string', 'required' => false, 'default' => "en") |
87
|
|
|
), |
88
|
|
|
'Retrieves a opportunity based on user id and opportunity id', |
89
|
|
|
'POST', |
90
|
|
|
true, |
91
|
|
|
false |
92
|
|
|
); |
93
|
|
|
|
94
|
|
|
elgg_ws_expose_function( |
95
|
|
|
"create.opportinities1", |
96
|
|
|
"create_opportinities1", |
97
|
|
|
array( |
98
|
|
|
"user" => array('type' => 'string', 'required' => true), |
99
|
|
|
"formData" => array('type' => 'array', 'required' => true), |
100
|
|
|
"lang" => array('type' => 'string', 'required' => false, 'default' => "en") |
101
|
|
|
), |
102
|
|
|
'Retrieves a opportunity based on user id and opportunity id', |
103
|
|
|
'POST', |
104
|
|
|
true, |
105
|
|
|
false |
106
|
|
|
); |
107
|
|
|
|
108
|
|
|
elgg_ws_expose_function( |
109
|
|
|
"create.opportinities2", |
110
|
|
|
"create_opportinities2", |
111
|
|
|
array( |
112
|
|
|
"user" => array('type' => 'string', 'required' => true), |
113
|
|
|
"formData" => array('type' => 'array', 'required' => true), |
114
|
|
|
"lang" => array('type' => 'string', 'required' => false, 'default' => "en") |
115
|
|
|
), |
116
|
|
|
'Retrieves a opportunity based on user id and opportunity id', |
117
|
|
|
'POST', |
118
|
|
|
true, |
119
|
|
|
false |
120
|
|
|
); |
121
|
|
|
|
122
|
|
|
elgg_ws_expose_function( |
123
|
|
|
"create.opportinities3", |
124
|
|
|
"create_opportinities3", |
125
|
|
|
array( |
126
|
|
|
"user" => array('type' => 'string', 'required' => true), |
127
|
|
|
"formData" => array('type' => 'array', 'required' => true), |
128
|
|
|
"lang" => array('type' => 'string', 'required' => false, 'default' => "en") |
129
|
|
|
), |
130
|
|
|
'Retrieves a opportunity based on user id and opportunity id', |
131
|
|
|
'POST', |
132
|
|
|
true, |
133
|
|
|
false |
134
|
|
|
); |
135
|
|
|
function get_opportunity($user, $guid, $lang) |
136
|
|
|
{ |
137
|
|
|
$user_entity = is_numeric($user) ? get_user($user) : (strpos($user, '@') !== false ? get_user_by_email($user)[0] : get_user_by_username($user)); |
138
|
|
|
if (!$user_entity) { |
139
|
|
|
return "User was not found. Please try a different GUID, username, or email address"; |
140
|
|
|
} |
141
|
|
|
if (!$user_entity instanceof ElggUser) { |
142
|
|
|
return "Invalid user. Please try a different GUID, username, or email address"; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
if (!elgg_is_logged_in()) { |
146
|
|
|
login($user_entity); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
$entity = get_entity($guid); |
150
|
|
|
if (!$entity) { |
151
|
|
|
return "Opportunity was not found. Please try a different GUID"; |
152
|
|
|
} |
153
|
|
|
if (!elgg_instanceof($entity, 'object', 'mission')) { |
154
|
|
|
return "Invalid opportunity. Please try a different GUID"; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
|
158
|
|
|
|
159
|
|
|
$opportunities = elgg_list_entities(array( |
160
|
|
|
'type' => 'object', |
161
|
|
|
'subtype' => 'mission', |
162
|
|
|
'guid' => $guid |
163
|
|
|
)); |
164
|
|
|
$opportunity = json_decode($opportunities)[0]; |
165
|
|
|
|
166
|
|
|
$opportunity->title = gc_explode_translation($opportunity->title, $lang); |
167
|
|
|
|
168
|
|
|
$likes = elgg_get_annotations(array( |
169
|
|
|
'guid' => $opportunity->guid, |
170
|
|
|
'annotation_name' => 'likes' |
171
|
|
|
)); |
172
|
|
|
$opportunity->likes = count($likes); |
173
|
|
|
|
174
|
|
|
$liked = elgg_get_annotations(array( |
175
|
|
|
'guid' => $opportunity->guid, |
176
|
|
|
'annotation_owner_guid' => $user_entity->guid, |
177
|
|
|
'annotation_name' => 'likes' |
178
|
|
|
)); |
179
|
|
|
$opportunity->liked = count($liked) > 0; |
180
|
|
|
|
181
|
|
|
$opportunity->comments = get_entity_comments($opportunity->guid); |
182
|
|
|
|
183
|
|
|
$opportunity->userDetails = get_user_block($opportunity->owner_guid, $lang); |
184
|
|
|
$opportunity->description = gc_explode_translation($opportunity->description, $lang); |
185
|
|
|
|
186
|
|
|
$opportunityObj = get_entity($opportunity->guid); |
187
|
|
|
$opportunity->jobtype = elgg_echo($opportunityObj->job_type); |
188
|
|
|
$opportunity->roletype = elgg_echo($opportunityObj->role_type); |
189
|
|
|
//$opportunity->programArea = elgg_echo('missions:program_area') . ": " . elgg_echo($opportunityObj->program_area); //This should work and translate to user lang but doesnt |
190
|
|
|
$opportunity->programArea = elgg_echo($opportunityObj->program_area); |
191
|
|
|
$opportunity->numOpportunities = $opportunityObj->number; |
192
|
|
|
$opportunity->idealStart = $opportunityObj->start_date; |
193
|
|
|
$opportunity->idealComplete = $opportunityObj->complete_date; |
194
|
|
|
$opportunity->deadline = $opportunityObj->deadline; |
195
|
|
|
$opportunity->oppVirtual = $opportunityObj->remotely; |
196
|
|
|
$opportunity->oppOnlyIn = $opportunityObj->openess; |
197
|
|
|
$opportunity->location = elgg_echo($opportunityObj->location); |
198
|
|
|
$opportunity->security = elgg_echo($opportunityObj->security); |
199
|
|
|
$opportunity->skills = $opportunityObj->key_skills; |
200
|
|
|
//$opportunity->participants = $opportunityObj->; |
201
|
|
|
//$opportunity->applicants = $opportunityObj->; |
202
|
|
|
$opportunity->timezone = elgg_echo($opportunityObj->timezone); |
203
|
|
|
$opportunity->timecommitment = $opportunityObj->time_commitment; |
204
|
|
|
$opportunity->department = $opportunityObj->department; |
205
|
|
|
$opportunity->state = $opportunityObj->state; |
206
|
|
|
|
207
|
|
|
//Language metadata |
208
|
|
|
$unpacked_array = mm_unpack_mission($opportunityObj); |
209
|
|
|
$unpacked_language = ''; |
210
|
|
View Code Duplication |
if (! empty($unpacked_array['lwc_english']) || ! empty($unpacked_array['lwc_french'])) { |
211
|
|
|
$unpacked_language .= '<b>' . elgg_echo('missions:written_comprehension') . ': </b>'; |
212
|
|
|
if (! empty($unpacked_array['lwc_english'])) { |
213
|
|
|
$unpacked_language .= '<span name="mission-lwc-english">' . elgg_echo('missions:formatted:english', array($unpacked_array['lwc_english'])) . '</span> '; |
214
|
|
|
} |
215
|
|
|
if (! empty($unpacked_array['lwc_french'])) { |
216
|
|
|
$unpacked_language .= '<span name="mission-lwc-french">' . elgg_echo('missions:formatted:french', array($unpacked_array['lwc_french'])) . '</span>'; |
217
|
|
|
} |
218
|
|
|
$unpacked_language .= '<br>'; |
219
|
|
|
} |
220
|
|
View Code Duplication |
if (! empty($unpacked_array['lwe_english']) || ! empty($unpacked_array['lwe_french'])) { |
221
|
|
|
$unpacked_language .= '<b>' . elgg_echo('missions:written_expression') . ': </b>'; |
222
|
|
|
if (! empty($unpacked_array['lwe_english'])) { |
223
|
|
|
$unpacked_language .= '<span name="mission-lwe-english">' . elgg_echo('missions:formatted:english', array($unpacked_array['lwe_english'])) . '</span> '; |
224
|
|
|
} |
225
|
|
|
if (! empty($unpacked_array['lwe_french'])) { |
226
|
|
|
$unpacked_language .= '<span name="mission-lwe-french">' . elgg_echo('missions:formatted:french', array($unpacked_array['lwe_french'])) . '</span>'; |
227
|
|
|
} |
228
|
|
|
$unpacked_language .= '<br>'; |
229
|
|
|
} |
230
|
|
View Code Duplication |
if (! empty($unpacked_array['lop_english']) || ! empty($unpacked_array['lop_french'])) { |
231
|
|
|
$unpacked_language .= '<b>' . elgg_echo('missions:oral_proficiency') . ': </b>'; |
232
|
|
|
if (! empty($unpacked_array['lop_english'])) { |
233
|
|
|
$unpacked_language .= '<span name="mission-lop-english">' . elgg_echo('missions:formatted:english', array($unpacked_array['lop_english'])) . '</span> '; |
234
|
|
|
} |
235
|
|
|
if (! empty($unpacked_array['lop_french'])) { |
236
|
|
|
$unpacked_language .= '<span name="mission-lop-french">' . elgg_echo('missions:formatted:french', array($unpacked_array['lop_french'])) . '</span>'; |
237
|
|
|
} |
238
|
|
|
$unpacked_language .= '<br>'; |
239
|
|
|
} |
240
|
|
|
if (empty($unpacked_language)) { |
241
|
|
|
$unpacked_language = '<span name="no-languages">' . elgg_echo('missions:none_required') . '</span>'; |
242
|
|
|
} |
243
|
|
|
$opportunity->languageRequirements = $unpacked_language; |
244
|
|
|
|
245
|
|
|
//scheduling metadata |
246
|
|
|
$unpacked_time = ''; |
247
|
|
|
if ($opportunityObj->mon_start) { |
248
|
|
|
$unpacked_time .= '<b>' . elgg_echo('missions:mon') . ': </b>'; |
249
|
|
|
$unpacked_time .= $opportunityObj->mon_start . elgg_echo('missions:to') . $opportunityObj->mon_duration . '<br>'; |
250
|
|
|
} |
251
|
|
|
if ($opportunityObj->tue_start) { |
252
|
|
|
$unpacked_time .= '<b>' . elgg_echo('missions:tue') . ': </b>'; |
253
|
|
|
$unpacked_time .= '<span name="mission-tue-start">' . $opportunityObj->tue_start . '</span>' . elgg_echo('missions:to') . '<span name="mission-tue-duration">' . $opportunityObj->tue_duration . '</span><br>'; |
254
|
|
|
} |
255
|
|
|
if ($opportunityObj->wed_start) { |
256
|
|
|
$unpacked_time .= '<b>' . elgg_echo('missions:wed') . ': </b>'; |
257
|
|
|
$unpacked_time .= $opportunityObj->wed_start . elgg_echo('missions:to') . $opportunityObj->wed_duration . '<br>'; |
258
|
|
|
} |
259
|
|
|
if ($opportunityObj->thu_start) { |
260
|
|
|
$unpacked_time .= '<b>' . elgg_echo('missions:thu') . ': </b>'; |
261
|
|
|
$unpacked_time .= '<span name="mission-thu-start">' . $opportunityObj->thu_start . '</span>' . elgg_echo('missions:to') . '<span name="mission-thu-duration">' . $opportunityObj->thu_duration . '</span><br>'; |
262
|
|
|
} |
263
|
|
|
if ($opportunityObj->fri_start) { |
264
|
|
|
$unpacked_time .= '<b>' . elgg_echo('missions:fri') . ': </b>'; |
265
|
|
|
$unpacked_time .= '<span name="mission-fri-start">' . $opportunityObj->fri_start . '</span>' . elgg_echo('missions:to') . '<span name="mission-fri-duration">' . $opportunityObj->fri_duration . '</span><br>'; |
266
|
|
|
} |
267
|
|
|
if ($opportunityObj->sat_start) { |
268
|
|
|
$unpacked_time .= '<b>' . elgg_echo('missions:sat') . ': </b>'; |
269
|
|
|
$unpacked_time .= '<span name="mission-sat-start">' . $opportunityObj->sat_start . '</span>' . elgg_echo('missions:to') . '<span name="mission-sat-duration">' . $opportunityObj->sat_duration . '</span><br>'; |
270
|
|
|
} |
271
|
|
|
if ($opportunityObj->sun_start) { |
272
|
|
|
$unpacked_time .= '<b>' . elgg_echo('missions:sun') . ': </b>'; |
273
|
|
|
$unpacked_time .= '<span name="mission-sun-start">' . $opportunityObj->sun_start . '</span>' . elgg_echo('missions:to') . '<span name="mission-sun-duration">' . $opportunityObj->sun_duration . '</span><br>'; |
274
|
|
|
} |
275
|
|
|
if (empty($unpacked_time)) { |
276
|
|
|
$unpacked_time = '<span name="no-times">' . elgg_echo('missions:none_required') . '</span>'; |
277
|
|
|
} |
278
|
|
|
$opportunity->schedulingRequirements = $unpacked_time; |
279
|
|
|
|
280
|
|
|
|
281
|
|
|
return $opportunity; |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
function get_opportunities($user, $limit, $offset, $filters, $lang) |
285
|
|
|
{ |
286
|
|
|
$user_entity = is_numeric($user) ? get_user($user) : (strpos($user, '@') !== false ? get_user_by_email($user)[0] : get_user_by_username($user)); |
287
|
|
|
if (!$user_entity) { |
288
|
|
|
return "User was not found. Please try a different GUID, username, or email address"; |
289
|
|
|
} |
290
|
|
|
if (!$user_entity instanceof ElggUser) { |
291
|
|
|
return "Invalid user. Please try a different GUID, username, or email address"; |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
if (!elgg_is_logged_in()) { |
295
|
|
|
login($user_entity); |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
$filter_data = json_decode($filters); |
299
|
|
|
if (!empty($filter_data)) { |
300
|
|
|
$params = array( |
301
|
|
|
'type' => 'object', |
302
|
|
|
'subtype' => 'mission', |
303
|
|
|
'limit' => $limit, |
304
|
|
|
'offset' => $offset |
305
|
|
|
); |
306
|
|
|
|
307
|
|
|
if ($filter_data->type) { |
308
|
|
|
$params['metadata_name'] = 'job_type'; |
309
|
|
|
$params['metadata_value'] = $filter_data->type; |
310
|
|
|
} |
311
|
|
|
|
312
|
|
View Code Duplication |
if ($filter_data->name) { |
313
|
|
|
$db_prefix = elgg_get_config('dbprefix'); |
314
|
|
|
$params['joins'] = array("JOIN {$db_prefix}objects_entity oe ON e.guid = oe.guid"); |
315
|
|
|
$params['wheres'] = array("(oe.title LIKE '%" . $filter_data->name . "%' OR oe.description LIKE '%" . $filter_data->name . "%')"); |
316
|
|
|
} |
317
|
|
|
|
318
|
|
|
if ($filter_data->mine) { |
319
|
|
|
$all_opportunities = elgg_list_entities_from_relationship($params); |
320
|
|
|
} else { |
321
|
|
|
$all_opportunities = elgg_list_entities_from_metadata($params); |
322
|
|
|
} |
323
|
|
|
} else { |
324
|
|
|
$all_opportunities = elgg_list_entities(array( |
325
|
|
|
'type' => 'object', |
326
|
|
|
'subtype' => 'mission', |
327
|
|
|
'limit' => $limit, |
328
|
|
|
'offset' => $offset |
329
|
|
|
)); |
330
|
|
|
} |
331
|
|
|
|
332
|
|
|
$opportunities = json_decode($all_opportunities); |
333
|
|
|
|
334
|
|
|
foreach ($opportunities as $opportunity) { |
335
|
|
|
$opportunityObj = get_entity($opportunity->guid); |
336
|
|
|
$opportunity->title = gc_explode_translation($opportunity->title, $lang); |
337
|
|
|
|
338
|
|
|
$likes = elgg_get_annotations(array( |
339
|
|
|
'guid' => $opportunity->guid, |
340
|
|
|
'annotation_name' => 'likes' |
341
|
|
|
)); |
342
|
|
|
$opportunity->likes = count($likes); |
343
|
|
|
|
344
|
|
|
$liked = elgg_get_annotations(array( |
345
|
|
|
'guid' => $opportunity->guid, |
346
|
|
|
'annotation_owner_guid' => $user_entity->guid, |
347
|
|
|
'annotation_name' => 'likes' |
348
|
|
|
)); |
349
|
|
|
if($opportunity->owner_guid != $user_entity->guid){ |
350
|
|
|
|
351
|
|
|
if($opportunityObj->state != 'completed' && $opportunityObj->state != 'cancelled'){ |
352
|
|
|
$relationship_count = elgg_get_entities_from_relationship(array( |
353
|
|
|
'relationship' => 'mission_accepted', |
354
|
|
|
'relationship_guid' => $opportunity->guid, |
355
|
|
|
'count' => true |
356
|
|
|
)); |
357
|
|
|
if($relationship_count < $opportunityObj->number) { |
358
|
|
|
|
359
|
|
|
$opportunity->apply = 'mission_apply'; // user can apply |
360
|
|
|
} |
361
|
|
|
|
362
|
|
|
if(check_entity_relationship($opportunity->guid, 'mission_tentative', $user_entity->guid)) { |
363
|
|
|
//console.log($opportunity->title); |
364
|
|
|
$opportunity->apply = 'tentative'; // user can accecpt offer |
365
|
|
|
} |
366
|
|
|
if(check_entity_relationship($opportunity->guid, 'mission_offered', $user_entity->guid)) { |
367
|
|
|
$opportunity->apply = 'offered'; // user can accecpt offer |
368
|
|
|
|
369
|
|
|
} |
370
|
|
|
if(check_entity_relationship($opportunity->guid, 'mission_accepted', $user_entity->guid) || |
371
|
|
|
check_entity_relationship($opportunity->guid, 'mission_applied', $user_entity->guid)) { |
372
|
|
|
$opportunity->apply = 'withdraw'; // user can accecpt offer |
373
|
|
|
|
374
|
|
|
} |
375
|
|
|
}else{ |
376
|
|
|
$opportunity->apply = 'close'; |
377
|
|
|
} |
378
|
|
|
} |
379
|
|
|
|
380
|
|
|
$opportunity->liked = count($liked) > 0; |
381
|
|
|
$opportunity->jobtype = elgg_echo($opportunityObj->job_type); |
382
|
|
|
$opportunity->roletype = elgg_echo($opportunityObj->role_type); |
383
|
|
|
$opportunity->deadline = $opportunityObj->deadline; |
384
|
|
|
$opportunity->programArea = elgg_echo($opportunityObj->program_area); |
385
|
|
|
$opportunity->owner = ($opportunityObj->getOwnerEntity() == $user_entity); |
386
|
|
|
$opportunity->iconURL = $opportunityObj->getIconURL(); |
387
|
|
|
$opportunity->userDetails = get_user_block($opportunity->owner_guid, $lang); |
388
|
|
|
$opportunity->description = clean_text(gc_explode_translation($opportunity->description, $lang)); |
389
|
|
|
$opportunity->state = $opportunityObj->state; |
390
|
|
|
|
391
|
|
|
} |
392
|
|
|
|
393
|
|
|
return $opportunities; |
394
|
|
|
} |
395
|
|
|
|
396
|
|
|
|
397
|
|
|
|
398
|
|
|
function apply_post($user,$message,$guid, $lang) |
399
|
|
|
{ |
400
|
|
|
$user_entity = is_numeric($user) ? get_user($user) : (strpos($user, '@') !== false ? get_user_by_email($user)[0] : get_user_by_username($user)); |
401
|
|
|
if (!$user_entity) { |
402
|
|
|
return "User was not found. Please try a different GUID, username, or email address"; |
403
|
|
|
} |
404
|
|
|
if (!$user_entity instanceof ElggUser) { |
405
|
|
|
return "Invalid user. Please try a different GUID, username, or email address"; |
406
|
|
|
} |
407
|
|
|
|
408
|
|
|
if (!elgg_is_logged_in()) { |
409
|
|
|
login($user_entity); |
410
|
|
|
} |
411
|
|
|
|
412
|
|
|
$entity = get_entity($guid); |
413
|
|
|
if (!$entity) { |
414
|
|
|
return "Opportunity was not found. Please try a different GUID"; |
415
|
|
|
} |
416
|
|
|
if (!elgg_instanceof($entity, 'object', 'mission')) { |
417
|
|
|
return "Invalid opportunity. Please try a different GUID"; |
418
|
|
|
} |
419
|
|
|
|
420
|
|
|
// Creates an applied relationship between user and mission if there is no relationship there already. |
421
|
|
|
if(!check_entity_relationship($entity->guid, 'mission_accepted', $user_entity->guid) && !check_entity_relationship($entity->guid, 'mission_tentative', $user_entity->guid)) { |
422
|
|
|
add_entity_relationship($entity->guid, 'mission_applied', $user_entity->guid); |
423
|
|
|
$message_info = elgg_echo('missions:you_have_applied_to_mission', array($entity->job_title, $entity->name)); |
424
|
|
|
|
425
|
|
|
$title_applicant_en = elgg_echo('missions:application_notice_sentence_title', array($user_entity->name, $entity->job_title),'en') ; |
426
|
|
|
$title_applicant_fr = elgg_echo('missions:application_notice_sentence_title', array($user_entity->name, $entity->job_title),'fr') ; |
427
|
|
|
|
428
|
|
|
$content_applicant_en = elgg_echo('missions:application_notice_sentence', 'en') . '<br>'; |
|
|
|
|
429
|
|
|
$content_applicant_fr = elgg_echo('missions:application_notice_sentence', 'fr') . '<br>'; |
|
|
|
|
430
|
|
|
$content_applicant_en .= '<br>'.elgg_echo('missions:see_full_profile','en') . ': '; |
|
|
|
|
431
|
|
|
$content_applicant_fr .= '<br>'.elgg_echo('missions:see_full_profile','fr') . ': '; |
|
|
|
|
432
|
|
|
|
433
|
|
|
$content_applicant_en .= '<a href="'.$user_entity->getURL().'">'.$user_entity->username.'<a/><br>'; |
434
|
|
|
$content_applicant_fr .= '<a href="'.$user_entity->getURL().'">'.$user_entity->username.'<a/><br>'; |
435
|
|
|
|
436
|
|
|
$content_applicant_en .= elgg_echo('missions:see_full_mission','en') . ': '; |
|
|
|
|
437
|
|
|
$content_applicant_fr .= elgg_echo('missions:see_full_mission','fr') . ': '; |
|
|
|
|
438
|
|
|
|
439
|
|
|
$content_applicant_en .= '<a href="'.$entity->getURL().'">'.$entity->job_title.'<a/><br>'; |
440
|
|
|
$content_applicant_fr .= '<a href="'.$entity->getURL().'">'.$entity->job_title.'<a/><br>'; |
441
|
|
|
|
442
|
|
|
$content_applicant_en .= '<br>'.elgg_echo('missions:from_message',array($user_entity->username),'en').'<br><span style="font-style: italic;">'.$message . '</span><br>'; |
443
|
|
|
$content_applicant_fr .= '<br>'.elgg_echo('missions:from_message',array($user_entity->username),'fr').'<br><span style="font-style: italic;">'.$message . '</span><br>'; |
444
|
|
|
|
445
|
|
|
// Lists all educations of the applicant. |
446
|
|
|
$education_list = $user_entity->education; |
447
|
|
|
if(!is_array($education_list)) { |
448
|
|
|
$education_list = array_filter(array($education_list)); |
449
|
|
|
} |
450
|
|
View Code Duplication |
if(!empty($education_list)) { |
451
|
|
|
foreach ($education_list as $education) { |
452
|
|
|
$education = get_entity($education); |
453
|
|
|
$education_ending_en = date("F", mktime(null, null, null, $education->enddate)) . ', ' . $education->endyear; |
454
|
|
|
$education_ending_fr = $cal_month[$education->enddate] . ', ' . $education->endyear; |
|
|
|
|
455
|
|
|
|
456
|
|
|
if ($education->ongoing == 'true') { |
457
|
|
|
$education_ending_en = 'Present'; |
458
|
|
|
$education_ending_fr = 'Présent'; |
459
|
|
|
} |
460
|
|
|
|
461
|
|
|
$education_beginning_en = date("F", mktime(null, null, null, $education->startdate)) . ', ' . $education->startyear; |
462
|
|
|
$education_beginning_fr = $cal_month[$education->startdate] . ', ' . $education->startyear; |
463
|
|
|
|
464
|
|
|
// TODO: This section should be in the language files eventually. |
465
|
|
|
$content_applicant_en .= '<br><b><font size="4">' . $education->school . ':</font></b>' . "<br>"; |
466
|
|
|
$content_applicant_en .= $education_beginning_en . ' - ' . $education_ending_en . "<br>"; |
467
|
|
|
$content_applicant_en .= '<b>' . $education->degree . ':</b> ' . $education->field . "<br>"; |
468
|
|
|
|
469
|
|
|
$content_applicant_fr .= '<br><b><font size="4">' . $education->school . ':</font></b>' . "<br>"; |
470
|
|
|
$content_applicant_fr .= $education_beginning_fr . ' - ' . $education_ending_fr . "<br>"; |
471
|
|
|
$content_applicant_fr .= '<b>' . $education->degree . ':</b> ' . $education->field . "<br>"; |
472
|
|
|
} |
473
|
|
|
} |
474
|
|
|
|
475
|
|
|
//Lists all work experiences of the applicant. |
476
|
|
|
$experience_list = $user_entity->work; |
477
|
|
|
if(!is_array($experience_list)) { |
478
|
|
|
$experience_list = array_filter(array($experience_list)); |
479
|
|
|
} |
480
|
|
View Code Duplication |
if(!empty($experience_list)) { |
481
|
|
|
foreach ($experience_list as $experience) { |
482
|
|
|
$experience = get_entity($experience); |
483
|
|
|
$experience_ending_en = date("F", mktime(null, null, null, $experience->enddate)) . ', ' . $experience->endyear; |
484
|
|
|
$experience_ending_fr = $cal_month[$experience->enddate] . ', ' . $experience->endyear; |
485
|
|
|
if ($experience->ongoing == 'true') { |
486
|
|
|
$experience_ending_en = 'Present'; |
487
|
|
|
$experience_ending_fr = 'Présent'; |
488
|
|
|
} |
489
|
|
|
$experience_beginning_en = date("F", mktime(null, null, null, $experience->startdate)) . ', ' . $experience->startyear; |
490
|
|
|
$experience_beginning_fr = $cal_month[$experience->startdate] . ', ' . $experience->startyear; |
491
|
|
|
|
492
|
|
|
// TODO: This section should be in the language files eventually. |
493
|
|
|
$content_applicant_en .= '<br><b><font size="4">' . $experience->organization . ':</font></b>' . "<br>"; |
494
|
|
|
$content_applicant_en .= $experience_beginning_en . ' - ' . $experience_ending_en . "<br>"; |
495
|
|
|
$content_applicant_en .= '<b>' . $experience->title . '</b>' . "<br>"; |
496
|
|
|
$content_applicant_en .= $experience->responsibilities . "<br><br>"; |
497
|
|
|
|
498
|
|
|
$content_applicant_fr .= '<br><b><font size="4">' . $experience->organization . ':</font></b>' . "<br>"; |
499
|
|
|
$content_applicant_fr .= $experience_beginning_fr . ' - ' . $experience_ending_fr . "<br>"; |
500
|
|
|
$content_applicant_fr .= '<b>' . $experience->title . '</b>' . "<br>"; |
501
|
|
|
$content_applicant_fr .= $experience->responsibilities . "<br><br>"; |
502
|
|
|
} |
503
|
|
|
} |
504
|
|
|
|
505
|
|
|
// Lists all skills of the applicant. |
506
|
|
|
$skill_list = $user_entity->gc_skills; |
507
|
|
|
if(!is_array($skill_list)) { |
508
|
|
|
$skill_list = array_filter(array($skill_list)); |
509
|
|
|
} |
510
|
|
View Code Duplication |
if(!empty($skill_list)) { |
511
|
|
|
foreach ($skill_list as $skill) { |
512
|
|
|
$skill = get_entity($skill); |
513
|
|
|
$content_applicant_en .= '<b>' . $skill->title . '</b>' . "<br>"; |
514
|
|
|
$content_applicant_fr .= '<b>' . $skill->title . '</b>' . "<br>"; |
515
|
|
|
} |
516
|
|
|
} |
517
|
|
|
|
518
|
|
|
// Sends the application via email and notification. |
519
|
|
|
$content_applicant_en .= elgg_view('output/url', array( |
520
|
|
|
'href' => elgg_get_site_url() . 'missions/mission-offer/' . $entity->guid . '/' . $user_entity->guid, |
521
|
|
|
'text' => '<br>'.elgg_echo('missions:offer','en') |
|
|
|
|
522
|
|
|
)); |
523
|
|
|
|
524
|
|
|
$content_applicant_fr .= elgg_view('output/url', array( |
525
|
|
|
'href' => elgg_get_site_url() . 'missions/mission-offer/' . $entity->guid . '/' . $user_entity->guid, |
526
|
|
|
'text' => '<br>'.elgg_echo('missions:offer','fr') |
|
|
|
|
527
|
|
|
)); |
528
|
|
|
|
529
|
|
|
$subject = elgg_echo('missions:application_to','en') . $entity->job_title.' | '.elgg_echo('missions:application_to','fr') . $entity->job_title; |
|
|
|
|
530
|
|
|
|
531
|
|
|
mm_notify_user($entity->guid, $user_entity->guid, $subject,$title_applicant_en,$title_applicant_fr, $content_applicant_en, $content_applicant_fr); |
532
|
|
|
|
533
|
|
|
} |
534
|
|
|
|
535
|
|
|
// Opt in applicant if they are not opted in yet. |
536
|
|
|
if(!check_if_opted_in($user_entity)) { |
537
|
|
|
$user_entity->opt_in_missions = 'gcconnex_profile:opt:yes'; |
538
|
|
|
$user_entity->save(); |
539
|
|
|
} |
540
|
|
|
return $message_info; |
|
|
|
|
541
|
|
|
|
542
|
|
|
} |
543
|
|
|
|
544
|
|
|
function withdraw_post($user,$message, $guid, $lang) |
545
|
|
|
{ |
546
|
|
|
$user_entity = is_numeric($user) ? get_user($user) : (strpos($user, '@') !== false ? get_user_by_email($user)[0] : get_user_by_username($user)); |
547
|
|
|
if (!$user_entity) { |
548
|
|
|
return "User was not found. Please try a different GUID, username, or email address"; |
549
|
|
|
} |
550
|
|
|
if (!$user_entity instanceof ElggUser) { |
551
|
|
|
return "Invalid user. Please try a different GUID, username, or email address"; |
552
|
|
|
} |
553
|
|
|
|
554
|
|
|
if (!elgg_is_logged_in()) { |
555
|
|
|
login($user_entity); |
556
|
|
|
} |
557
|
|
|
|
558
|
|
|
$entity = get_entity($guid); |
559
|
|
|
if (!$entity) { |
560
|
|
|
return "Opportunity was not found. Please try a different GUID"; |
561
|
|
|
} |
562
|
|
|
if (!elgg_instanceof($entity, 'object', 'mission')) { |
563
|
|
|
return "Invalid opportunity. Please try a different GUID"; |
564
|
|
|
} |
565
|
|
|
|
566
|
|
|
// Deletes the tentative relationship between mission and applicant. |
567
|
|
View Code Duplication |
if(check_entity_relationship($entity->guid, 'mission_tentative', $user_entity->guid)) { |
568
|
|
|
$message_return = 'missions:declination_has_been_sent'; |
569
|
|
|
remove_entity_relationship($entity->guid, 'mission_tentative', $user_entity->guid); |
570
|
|
|
} |
571
|
|
|
if(check_entity_relationship($entity->guid, 'mission_applied', $user_entity->guid)) { |
572
|
|
|
$message_return = 'missions:withdrawal_has_been_sent'; |
573
|
|
|
remove_entity_relationship($entity->guid, 'mission_applied', $user_entity->guid); |
574
|
|
|
} |
575
|
|
View Code Duplication |
if(check_entity_relationship($entity->guid, 'mission_offered', $user_entity->guid)) { |
576
|
|
|
$message_return = 'missions:declination_has_been_sent'; |
577
|
|
|
remove_entity_relationship($entity->guid, 'mission_offered', $user_entity->guid); |
578
|
|
|
} |
579
|
|
View Code Duplication |
if(check_entity_relationship($entity->guid, 'mission_accepted', $user_entity->guid)) { |
580
|
|
|
$message_return = 'missions:withdrawal_has_been_sent'; |
581
|
|
|
remove_entity_relationship($entity->guid, 'mission_accepted', $user_entity->guid); |
582
|
|
|
mm_complete_mission_inprogress_reports($entity, true); |
583
|
|
|
} |
584
|
|
|
|
585
|
|
|
$reason = array('workload', 'interest', 'engagement', 'approval'); |
586
|
|
|
if (in_array($message,$reason)){ |
587
|
|
|
$reasonEn = elgg_echo('missions:decline:'.$message,'en'); |
|
|
|
|
588
|
|
|
$reasonFr = elgg_echo('missions:decline:'.$message,'fr'); |
|
|
|
|
589
|
|
|
}else{ |
590
|
|
|
$reasonEn = $message; |
591
|
|
|
$reasonFr = $message; |
592
|
|
|
} |
593
|
|
|
|
594
|
|
|
$mission_link = '<a href="'.$entity->getURL().'" >'.elgg_get_excerpt($entity->job_title, elgg_get_plugin_setting('mission_job_title_card_cutoff', 'missions')).' </a>'; |
595
|
|
|
$subject = elgg_echo('missions:applicant_leaves', array($user_entity->name),'en')." | ". elgg_echo('missions:applicant_leaves', array($user_entity->name),'fr'); |
596
|
|
|
|
597
|
|
|
$withdrawnEn .= elgg_echo('missions:applicant_leaves_more', array($user_entity->name),'en') . $mission_link . '.' . "\n"; |
|
|
|
|
598
|
|
|
$withdrawnReasonEn .= elgg_echo('missions:reason_given', array($reasonEn),'en'); |
|
|
|
|
599
|
|
|
|
600
|
|
|
$withdrawnFr .= elgg_echo('missions:applicant_leaves_more', array($user_entity->name),'fr') . $mission_link . '.' . "\n"; |
|
|
|
|
601
|
|
|
$withdrawnReasonFr .= elgg_echo('missions:reason_given', array($reasonFr),'fr'); |
|
|
|
|
602
|
|
|
|
603
|
|
|
mm_notify_user($entity->guid, $user_entity->guid, $subject, $withdrawnEn, $withdrawnFr,$withdrawnReasonEn ,$withdrawnReasonFr ); |
604
|
|
|
|
605
|
|
|
|
606
|
|
|
return elgg_echo($message_return, array($entity->job_title)); |
|
|
|
|
607
|
|
|
|
608
|
|
|
|
609
|
|
|
} |
610
|
|
|
|
611
|
|
|
function accept_post($user, $guid, $lang) |
612
|
|
|
{ |
613
|
|
|
$user_entity = is_numeric($user) ? get_user($user) : (strpos($user, '@') !== false ? get_user_by_email($user)[0] : get_user_by_username($user)); |
614
|
|
|
if (!$user_entity) { |
615
|
|
|
return "User was not found. Please try a different GUID, username, or email address"; |
616
|
|
|
} |
617
|
|
|
if (!$user_entity instanceof ElggUser) { |
618
|
|
|
return "Invalid user. Please try a different GUID, username, or email address"; |
619
|
|
|
} |
620
|
|
|
|
621
|
|
|
if (!elgg_is_logged_in()) { |
622
|
|
|
login($user_entity); |
623
|
|
|
} |
624
|
|
|
|
625
|
|
|
$entity = get_entity($guid); |
626
|
|
|
if (!$entity) { |
627
|
|
|
return "Opportunity was not found. Please try a different GUID"; |
628
|
|
|
} |
629
|
|
|
if (!elgg_instanceof($entity, 'object', 'mission')) { |
630
|
|
|
return "Invalid opportunity. Please try a different GUID"; |
631
|
|
|
} |
632
|
|
|
|
633
|
|
View Code Duplication |
if(check_entity_relationship($entity->guid, 'mission_offered', $user_entity->guid)) { |
634
|
|
|
|
635
|
|
|
remove_entity_relationship($entity->guid, 'mission_offered', $user_entity->guid); |
636
|
|
|
add_entity_relationship($entity->guid, 'mission_accepted', $user_entity->guid); |
637
|
|
|
} |
638
|
|
|
$mission_link = '<a href="'.$entity->getURL().'">'.$entity->title.'</a>'; |
639
|
|
|
|
640
|
|
|
// notify participant |
641
|
|
|
$subject = elgg_echo('missions:participating_in', array(elgg_get_excerpt($entity->job_title, elgg_get_plugin_setting('mission_job_title_card_cutoff', 'missions'))),'en').' | '.elgg_echo('missions:participating_in', array(elgg_get_excerpt($entity->job_title, elgg_get_plugin_setting('mission_job_title_card_cutoff', 'missions'))),'fr'); |
642
|
|
|
$message_en = elgg_echo('missions:participating_in_more', array($user_entity->name),'en') . $mission_link . '.'; |
643
|
|
|
$message_fr = elgg_echo('missions:participating_in_more', array($user_entity->name),'fr') . $mission_link . '.'; |
644
|
|
|
|
645
|
|
|
mm_notify_user($user_entity->guid, $entity->guid, $subject, '','',$message_en,$message_fr); |
646
|
|
|
|
647
|
|
|
// notify owner |
648
|
|
|
$subject = elgg_echo( 'missions:participating_in2', array($user_entity->name),'en').' | '.elgg_echo( 'missions:participating_in2', array($user_entity->name),'fr'); |
649
|
|
|
$message_en = elgg_echo('missions:participating_in2_more', array($user_entity->name),'en') . $mission_link . '.'; |
650
|
|
|
$message_fr = elgg_echo('missions:participating_in2_more', array($user_entity->name),'fr') . $mission_link . '.'; |
651
|
|
|
|
652
|
|
|
mm_notify_user($entity->guid, $user_entity->guid, $subject, '','',$message_en,$message_fr); |
653
|
|
|
|
654
|
|
|
return elgg_echo('missions:now_participating_in_mission', array($entity->job_title)); |
655
|
|
|
} |
656
|
|
|
|
657
|
|
|
function create_opportinities1($user, $formData, $lang) |
|
|
|
|
658
|
|
|
{ |
659
|
|
|
$user_entity = is_numeric($user) ? get_user($user) : (strpos($user, '@') !== false ? get_user_by_email($user)[0] : get_user_by_username($user)); |
660
|
|
|
if (!$user_entity) { |
661
|
|
|
return "User was not found. Please try a different GUID, username, or email address"; |
662
|
|
|
} |
663
|
|
|
if (!$user_entity instanceof ElggUser) { |
664
|
|
|
return "Invalid user. Please try a different GUID, username, or email address"; |
665
|
|
|
} |
666
|
|
|
|
667
|
|
|
if (!elgg_is_logged_in()) { |
668
|
|
|
login($user_entity); |
669
|
|
|
} |
670
|
|
|
|
671
|
|
|
|
672
|
|
|
|
673
|
|
|
elgg_make_sticky_form('firstfill'); |
674
|
|
|
$_SESSION['mission_duplicating_override_first'] = true; |
675
|
|
|
unset($_SESSION['mission_uncheck_post_mission_disclaimer']); |
676
|
|
|
|
677
|
|
|
$err = ''; |
678
|
|
|
|
679
|
|
|
$first_form = elgg_get_sticky_values('firstfill'); |
680
|
|
|
|
681
|
|
|
$first_form['name'] = $formData["name"]; |
682
|
|
|
$first_form['department'] = $formData["departement"]; |
683
|
|
|
$first_form['email'] = $formData["email"]; |
684
|
|
|
$first_form['phone'] = $formData["phone"]; |
685
|
|
|
$first_form['disclaimer'] = $formData["agree"]; |
686
|
|
|
|
687
|
|
|
// Error checking function. |
688
|
|
|
$err .= mm_first_post_error_check($first_form); |
689
|
|
View Code Duplication |
if ($err == '') { |
690
|
|
|
$_SESSION['missions_pass_department_to_second_form'] = mo_get_last_input_node($first_form); |
691
|
|
|
forward(elgg_get_site_url() . 'missions/mission-post/step-two'); |
692
|
|
|
} else { |
693
|
|
|
error_log('error in first form: '.$err); |
694
|
|
|
} |
695
|
|
|
|
696
|
|
|
|
697
|
|
|
return $formData["name"]; |
698
|
|
|
} |
699
|
|
|
|
700
|
|
|
|
701
|
|
|
function create_opportinities2($user, $formData, $lang) |
|
|
|
|
702
|
|
|
{ |
703
|
|
|
$user_entity = is_numeric($user) ? get_user($user) : (strpos($user, '@') !== false ? get_user_by_email($user)[0] : get_user_by_username($user)); |
704
|
|
|
if (!$user_entity) { |
705
|
|
|
return "User was not found. Please try a different GUID, username, or email address"; |
706
|
|
|
} |
707
|
|
|
if (!$user_entity instanceof ElggUser) { |
708
|
|
|
return "Invalid user. Please try a different GUID, username, or email address"; |
709
|
|
|
} |
710
|
|
|
|
711
|
|
|
if (!elgg_is_logged_in()) { |
712
|
|
|
login($user_entity); |
713
|
|
|
} |
714
|
|
|
|
715
|
|
|
elgg_make_sticky_form('secondfill'); |
716
|
|
|
$_SESSION['mission_duplicating_override_second'] = true; |
717
|
|
|
|
718
|
|
|
$err = ''; |
719
|
|
|
$first_form = elgg_get_sticky_values('firstfill'); |
720
|
|
|
$second_form = elgg_get_sticky_values('secondfill'); |
721
|
|
|
|
722
|
|
|
$second_form['job_title'] = $formData["name"]; |
723
|
|
|
$second_form['role_type'] = $formData["offert"]; |
724
|
|
|
$second_form['job_type'] = $formData["type"]; |
725
|
|
|
$second_form['job_area'] = $formData["program"]; |
726
|
|
|
$second_form['number'] = $formData["num_opt"]; |
727
|
|
|
$second_form['start_date'] = $formData["start_date"]; |
728
|
|
|
$second_form['completion_date'] = $formData["completion_date"]; |
729
|
|
|
$second_form['deadline'] = $formData["deadline"]; |
730
|
|
|
$second_form['description'] = $formData["description"]; |
731
|
|
|
|
732
|
|
|
// Error checking function. |
733
|
|
|
$err .= mm_first_post_error_check($first_form); |
734
|
|
|
$err .= mm_second_post_error_check($second_form); |
735
|
|
|
|
736
|
|
|
if ($err == '') { |
737
|
|
|
forward(elgg_get_site_url() . 'missions/mission-post/step-three'); |
738
|
|
|
} else { |
739
|
|
|
error_log('error in first form: '.$err); |
740
|
|
|
} |
741
|
|
|
|
742
|
|
|
|
743
|
|
|
|
744
|
|
|
error_log('first :'.print_r($first_form,true)); |
745
|
|
|
error_log('second :'.print_r($second_form,true)); |
746
|
|
|
return $formData["title"]; |
747
|
|
|
} |
748
|
|
|
|
749
|
|
|
function create_opportinities3($user, $formData,$lang) |
|
|
|
|
750
|
|
|
{ |
751
|
|
|
$user_entity = is_numeric($user) ? get_user($user) : (strpos($user, '@') !== false ? get_user_by_email($user)[0] : get_user_by_username($user)); |
752
|
|
|
if (!$user_entity) { |
753
|
|
|
return "User was not found. Please try a different GUID, username, or email address"; |
754
|
|
|
} |
755
|
|
|
if (!$user_entity instanceof ElggUser) { |
756
|
|
|
return "Invalid user. Please try a different GUID, username, or email address"; |
757
|
|
|
} |
758
|
|
|
|
759
|
|
|
if (!elgg_is_logged_in()) { |
760
|
|
|
login($user_entity); |
761
|
|
|
} |
762
|
|
|
|
763
|
|
|
elgg_make_sticky_form('thirdfill'); |
764
|
|
|
elgg_make_sticky_form('ldropfill'); |
765
|
|
|
elgg_make_sticky_form('tdropfill'); |
766
|
|
|
$_SESSION['mission_duplicating_override_third'] = true; |
767
|
|
|
|
768
|
|
|
$first_form = elgg_get_sticky_values('firstfill'); |
769
|
|
|
$second_form = elgg_get_sticky_values('secondfill'); |
770
|
|
|
$third_form = elgg_get_sticky_values('thirdfill'); |
771
|
|
|
|
772
|
|
|
|
773
|
|
|
|
774
|
|
|
|
775
|
|
|
|
776
|
|
|
|
777
|
|
|
|
778
|
|
|
$err = ''; |
779
|
|
|
|
780
|
|
|
// Error checking function. |
781
|
|
|
$first_form['name'] = $first_form['formData']["name"]; |
782
|
|
|
$first_form['department'] = $first_form['formData']["departement"]; |
783
|
|
|
$first_form['email'] = $first_form['formData']["email"]; |
784
|
|
|
$first_form['phone'] = $first_form['formData']["phone"]; |
785
|
|
|
$first_form['disclaimer'] = $first_form['formData']["agree"]; |
786
|
|
|
|
787
|
|
|
$err .= mm_first_post_error_check($first_form); |
788
|
|
|
$second_form['job_title'] = $second_form['formData']["title"]; |
789
|
|
|
$second_form['role_type'] = $second_form['formData']["offert"]; |
790
|
|
|
$second_form['job_type'] = $second_form['formData']["type"]; |
791
|
|
|
$second_form['job_area'] = $second_form['formData']["program"]; |
792
|
|
|
$second_form['number'] = $second_form['formData']["num_opt"]; |
793
|
|
|
$second_form['start_date'] = $second_form['formData']["start_date"]; |
794
|
|
|
$second_form['completion_date'] = $second_form['formData']["completion_date"]; |
795
|
|
|
$second_form['deadline'] = $second_form['formData']["deadline"]; |
796
|
|
|
$second_form['description'] = $second_form['formData']["description"]; |
797
|
|
|
error_log(print_r($second_form,true)); |
798
|
|
|
|
799
|
|
|
$err .= mm_second_post_error_check($second_form); |
800
|
|
|
|
801
|
|
|
$third_form['key_skills'] = $third_form['formData']["skills"]; |
802
|
|
|
$third_form['time_commitment'] = $third_form['formData']["hours"]; |
803
|
|
|
$third_form['time_interval'] = $third_form['formData']["repetition"]; |
804
|
|
|
$third_form['timezone'] = $third_form['formData']["timezone"]; |
805
|
|
|
$third_form['mon_start'] = $third_form['formData']["mon_start"]; |
806
|
|
|
$third_form['mon_duration'] = $third_form['formData']["mon_duration"]; |
807
|
|
|
$third_form['tue_start'] = $third_form['formData']["tue_start"]; |
808
|
|
|
$third_form['tue_duration'] = $third_form['formData']["tue_duration"]; |
809
|
|
|
$third_form['wed_start'] = $third_form['formData']["wed_start"]; |
810
|
|
|
$third_form['wed_duration'] = $third_form['formData']["wed_duration"]; |
811
|
|
|
$third_form['thu_start'] = $third_form['formData']["thu_start"]; |
812
|
|
|
$third_form['thu_duration'] = $third_form['formData']["thu_duration"]; |
813
|
|
|
$third_form['fri_start'] = $third_form['formData']["fri_start"]; |
814
|
|
|
$third_form['fri_duration'] = $third_form['formData']["fri_duration"]; |
815
|
|
|
$third_form['sat_start'] = $third_form['formData']["sat_start"]; |
816
|
|
|
$third_form['sat_duration'] = $third_form['formData']["sat_duration"]; |
817
|
|
|
$third_form['sun_start'] = $third_form['formData']["sun_start"]; |
818
|
|
|
$third_form['sun_duration'] = $third_form['formData']["sun_duration"]; |
819
|
|
|
$third_form['remotely'] = $third_form['formData']["remotly"]; |
820
|
|
|
$third_form['location'] = $third_form['formData']["location"]; |
821
|
|
|
$third_form['security'] = $third_form['formData']["security"]; |
822
|
|
|
|
823
|
|
|
$err .= mm_third_post_error_check($third_form); |
824
|
|
|
|
825
|
|
|
// A specialized function for checking for errors in the time fields |
826
|
|
|
$err .= mm_validate_time_all($third_form); |
827
|
|
|
|
828
|
|
|
if($err == '') { |
829
|
|
|
$err .= mm_third_post_special_error_check($third_form); |
830
|
|
|
} |
831
|
|
|
if ($err != '') { |
832
|
|
|
error_log('error in first form: '.$err); |
833
|
|
|
return $err; |
834
|
|
|
|
835
|
|
|
}else { |
836
|
|
|
|
837
|
|
|
// Creation of an ELGGObject of subtype Mission |
838
|
|
|
$mission = new ElggObject(); |
839
|
|
|
$mission->subtype = 'mission'; |
840
|
|
|
$mission->title = $second_form['job_title']; |
841
|
|
|
$mission->description = $second_form['description']; |
842
|
|
|
$mission->access_id = ACCESS_LOGGED_IN; |
843
|
|
|
$mission->owner_guid = elgg_get_logged_in_user_guid(); |
844
|
|
|
|
845
|
|
|
// Attaches the form data as metadata to the object |
846
|
|
|
$mission->name = $first_form['name']; |
847
|
|
|
|
848
|
|
|
// If the organization tree is loaded, then the custom dropdown values will be processed and stored. |
849
|
|
View Code Duplication |
if(mo_get_tree_root()) { |
850
|
|
|
$department_string = mo_get_last_input_node($first_form); |
851
|
|
|
$department_paths = mo_string_all_ancestors($department_string); |
852
|
|
|
$mission->department = $department_string; |
853
|
|
|
$mission->department_path_english = $department_paths['english_path']; |
854
|
|
|
$mission->department_path_french = $department_paths['french_path']; |
855
|
|
|
} |
856
|
|
|
// If the organization tree is not loaded, then the basic free text entry will be stored. |
857
|
|
|
else { |
858
|
|
|
$mission->department = $first_form['department']; |
859
|
|
|
$mission->department_path_english = $first_form['department']; |
860
|
|
|
$mission->department_path_french = $first_form['department']; |
861
|
|
|
} |
862
|
|
|
|
863
|
|
|
$mission->email = $first_form['email']; |
864
|
|
|
$mission->phone = $first_form['phone']; |
865
|
|
|
|
866
|
|
|
$accounts = get_user_by_email($first_form['email']); |
867
|
|
|
//Compare email and username for user with more than one account |
868
|
|
|
foreach ($accounts as $key) { |
869
|
|
|
if($key->name == $first_form['name']){ |
870
|
|
|
$guid_account[] = $key; |
|
|
|
|
871
|
|
|
} |
872
|
|
|
} |
873
|
|
|
|
874
|
|
View Code Duplication |
if($guid_account){ |
|
|
|
|
875
|
|
|
$mission->account = array_pop($guid_account)->guid; |
876
|
|
|
}else{ |
877
|
|
|
$mission->account = array_pop($accounts)->guid; |
878
|
|
|
} |
879
|
|
|
|
880
|
|
|
|
881
|
|
|
$mission->job_title = $second_form['job_title']; |
882
|
|
|
$mission->role_type = $second_form['role_type']; |
883
|
|
|
$mission->job_type = $second_form['job_type']; |
884
|
|
|
// Stores the value of program area selected unless it is other. |
885
|
|
View Code Duplication |
if($second_form['job_area'] != 'missions:other') { |
886
|
|
|
$mission->program_area = $second_form['job_area']; |
887
|
|
|
} |
888
|
|
|
// When other is selected, the free text entry is stored instead. |
889
|
|
|
else { |
890
|
|
|
$mission->program_area = $second_form['other_text']; |
891
|
|
|
} |
892
|
|
|
$mission->number = $second_form['number']; |
893
|
|
|
$mission->start_date = $second_form['start_date']; |
894
|
|
|
$mission->completion_date = $second_form['completion_date']; |
895
|
|
|
$mission->deadline = $second_form['deadline']; |
896
|
|
|
$mission->descriptor = $second_form['description']; |
897
|
|
|
$mission->openess = $second_form['openess']; |
898
|
|
|
|
899
|
|
|
//Nick - Adding group and level to the mission meta data |
900
|
|
|
if($second_form['group']){ |
901
|
|
|
$mission->gl_group = $second_form['group']; |
902
|
|
|
$mission->gl_level = $second_form['level']; |
903
|
|
|
} |
904
|
|
|
|
905
|
|
|
$mission->remotely = $third_form['remotely']; |
906
|
|
|
$mission->security = $third_form['security']; |
907
|
|
|
$mission->location = $third_form['location']; |
908
|
|
|
$mission->time_commitment = $third_form['time_commitment']; |
909
|
|
|
$mission->time_interval = $third_form['time_interval']; |
910
|
|
|
$mission->timezone = $third_form['timezone']; |
911
|
|
|
|
912
|
|
|
// Stores the multiple skill fields in a comma separated string. |
913
|
|
|
$count = 0; |
914
|
|
|
$key_skills = ''; |
915
|
|
|
$skill_array = array(); |
916
|
|
View Code Duplication |
foreach($third_form as $key => $value) { |
917
|
|
|
if(!(strpos($key, 'skill') === false) && $value) { |
918
|
|
|
$skill_array[$count] = $value; |
919
|
|
|
if($count == 0) { |
920
|
|
|
$key_skills .= $value; |
921
|
|
|
} |
922
|
|
|
else { |
923
|
|
|
$key_skills .= ', ' . $value; |
924
|
|
|
} |
925
|
|
|
$count++; |
926
|
|
|
} |
927
|
|
|
} |
928
|
|
|
$mission->key_skills = $key_skills; |
929
|
|
|
|
930
|
|
|
$mission->english = mm_pack_language($third_form['lwc_english'], $third_form['lwe_english'], $third_form['lop_english'], 'english'); |
931
|
|
|
$mission->french = mm_pack_language($third_form['lwc_french'], $third_form['lwe_french'], $third_form['lop_french'], 'french'); |
932
|
|
|
$mission->mon_start = $third_form['mon_start']; |
933
|
|
|
$mission->mon_duration = $third_form['mon_duration']; |
934
|
|
|
$mission->tue_start = $third_form['tue_start']; |
935
|
|
|
$mission->tue_duration = $third_form['tue_duration']; |
936
|
|
|
$mission->wed_start = $third_form['wed_start']; |
937
|
|
|
$mission->wed_duration = $third_form['wed_duration']; |
938
|
|
|
$mission->thu_start = $third_form['thu_start']; |
939
|
|
|
$mission->thu_duration = $third_form['thu_duration']; |
940
|
|
|
$mission->fri_start = $third_form['fri_start']; |
941
|
|
|
$mission->fri_duration = $third_form['fri_duration']; |
942
|
|
|
$mission->sat_start = $third_form['sat_start']; |
943
|
|
|
$mission->sat_duration = $third_form['sat_duration']; |
944
|
|
|
$mission->sun_start = $third_form['sun_start']; |
945
|
|
|
$mission->sun_duration = $third_form['sun_duration']; |
946
|
|
|
|
947
|
|
|
$mission->state = 'posted'; |
948
|
|
|
$mission->version = elgg_get_plugin_setting('mission_version', 'missions'); |
949
|
|
|
|
950
|
|
|
$mission->time_to_post = time() - $_SESSION['mission_creation_begin_timestamp']; |
951
|
|
|
|
952
|
|
|
// Sends the object and all its metadata to the database |
953
|
|
|
$mission->save(); |
954
|
|
|
|
955
|
|
|
$mission->meta_guid = $mission->guid; |
956
|
|
|
|
957
|
|
|
$mission->save(); |
958
|
|
|
|
959
|
|
|
// Generate an analytics record to track "posted". |
960
|
|
|
$analytics_record = new ElggObject(); |
961
|
|
|
$analytics_record->subtype = 'mission-posted'; |
962
|
|
|
$analytics_record->title = 'Mission Posted Report'; |
963
|
|
|
$analytics_record->mission_guid = $mission->guid; |
964
|
|
|
$analytics_record->access_id = ACCESS_LOGGED_IN; |
965
|
|
|
$analytics_record->save(); |
966
|
|
|
|
967
|
|
|
// Creates a relationships between the user (manager) and the mission. |
968
|
|
|
add_entity_relationship($mission->account, 'mission_posted', $mission->guid); |
969
|
|
|
|
970
|
|
|
// Add to the river so it can be seen on the main page. |
971
|
|
|
elgg_create_river_item(array( |
972
|
|
|
'view' => 'river/object/mission/create', |
973
|
|
|
'action_type' => 'create', |
974
|
|
|
'subject_guid' => $mission->owner_guid, |
975
|
|
|
'object_guid' => $mission->getGUID() |
976
|
|
|
)); |
977
|
|
|
|
978
|
|
|
$_SESSION['mission_skill_match_array'] = $skill_array; |
979
|
|
|
unset($_SESSION['mission_duplicating_override_first']); |
980
|
|
|
unset($_SESSION['mission_duplicating_override_second']); |
981
|
|
|
unset($_SESSION['mission_duplicating_override_third']); |
982
|
|
|
|
983
|
|
|
if(count($skill_array) == 0) { |
984
|
|
|
elgg_clear_sticky_form('firstfill'); |
985
|
|
|
elgg_clear_sticky_form('secondfill'); |
986
|
|
|
elgg_clear_sticky_form('thirdfill'); |
987
|
|
|
elgg_clear_sticky_form('ldropfill'); |
988
|
|
|
elgg_clear_sticky_form('tdropfill'); |
989
|
|
|
return elgg_echo('missions:succesfully_posted', array($mission->job_title)); |
990
|
|
|
} |
991
|
|
View Code Duplication |
else { |
992
|
|
|
if($third_form['hidden_java_state'] == 'noscript') { |
993
|
|
|
// Required action security tokens. |
994
|
|
|
$ts = time(); |
995
|
|
|
$token = generate_action_token($ts); |
996
|
|
|
set_input('__elgg_ts', $ts); |
997
|
|
|
set_input('__elgg_token', $token); |
|
|
|
|
998
|
|
|
|
999
|
|
|
action('missions/post-mission-skill-match'); |
1000
|
|
|
} |
1001
|
|
|
else { |
1002
|
|
|
$_SESSION['mission_skill_match_is_interlude'] = true; |
1003
|
|
|
system_message(elgg_echo('missions:saved_beginning_skill_match', array($key_skills))); |
1004
|
|
|
forward(REFERER); |
1005
|
|
|
} |
1006
|
|
|
} |
1007
|
|
|
|
1008
|
|
|
return 'Post with success '; |
1009
|
|
|
} |
1010
|
|
|
|
1011
|
|
|
|
1012
|
|
|
} |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: