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
|
|
|
function get_opportunity($user, $guid, $lang) |
81
|
|
|
{ |
82
|
|
|
$user_entity = is_numeric($user) ? get_user($user) : (strpos($user, '@') !== false ? get_user_by_email($user)[0] : get_user_by_username($user)); |
83
|
|
|
if (!$user_entity) { |
84
|
|
|
return "User was not found. Please try a different GUID, username, or email address"; |
85
|
|
|
} |
86
|
|
|
if (!$user_entity instanceof ElggUser) { |
87
|
|
|
return "Invalid user. Please try a different GUID, username, or email address"; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
if (!elgg_is_logged_in()) { |
91
|
|
|
login($user_entity); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
$entity = get_entity($guid); |
95
|
|
|
if (!$entity) { |
96
|
|
|
return "Opportunity was not found. Please try a different GUID"; |
97
|
|
|
} |
98
|
|
|
if (!elgg_instanceof($entity, 'object', 'mission')) { |
99
|
|
|
return "Invalid opportunity. Please try a different GUID"; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
|
103
|
|
|
|
104
|
|
|
$opportunities = elgg_list_entities(array( |
105
|
|
|
'type' => 'object', |
106
|
|
|
'subtype' => 'mission', |
107
|
|
|
'guid' => $guid |
108
|
|
|
)); |
109
|
|
|
$opportunity = json_decode($opportunities)[0]; |
110
|
|
|
|
111
|
|
|
$opportunity->title = gc_explode_translation($opportunity->title, $lang); |
112
|
|
|
|
113
|
|
|
$likes = elgg_get_annotations(array( |
114
|
|
|
'guid' => $opportunity->guid, |
115
|
|
|
'annotation_name' => 'likes' |
116
|
|
|
)); |
117
|
|
|
$opportunity->likes = count($likes); |
118
|
|
|
|
119
|
|
|
$liked = elgg_get_annotations(array( |
120
|
|
|
'guid' => $opportunity->guid, |
121
|
|
|
'annotation_owner_guid' => $user_entity->guid, |
122
|
|
|
'annotation_name' => 'likes' |
123
|
|
|
)); |
124
|
|
|
$opportunity->liked = count($liked) > 0; |
125
|
|
|
|
126
|
|
|
$opportunity->comments = get_entity_comments($opportunity->guid); |
127
|
|
|
|
128
|
|
|
$opportunity->userDetails = get_user_block($opportunity->owner_guid, $lang); |
129
|
|
|
$opportunity->description = gc_explode_translation($opportunity->description, $lang); |
130
|
|
|
|
131
|
|
|
$opportunityObj = get_entity($opportunity->guid); |
132
|
|
|
$opportunity->jobtype = elgg_echo($opportunityObj->job_type); |
133
|
|
|
$opportunity->roletype = elgg_echo($opportunityObj->role_type); |
134
|
|
|
//$opportunity->programArea = elgg_echo('missions:program_area') . ": " . elgg_echo($opportunityObj->program_area); //This should work and translate to user lang but doesnt |
135
|
|
|
$opportunity->programArea = elgg_echo($opportunityObj->program_area); |
136
|
|
|
$opportunity->numOpportunities = $opportunityObj->number; |
137
|
|
|
$opportunity->idealStart = $opportunityObj->start_date; |
138
|
|
|
$opportunity->idealComplete = $opportunityObj->complete_date; |
139
|
|
|
$opportunity->deadline = $opportunityObj->deadline; |
140
|
|
|
$opportunity->oppVirtual = $opportunityObj->remotely; |
141
|
|
|
$opportunity->oppOnlyIn = $opportunityObj->openess; |
142
|
|
|
$opportunity->location = elgg_echo($opportunityObj->location); |
143
|
|
|
$opportunity->security = elgg_echo($opportunityObj->security); |
144
|
|
|
$opportunity->skills = $opportunityObj->key_skills; |
145
|
|
|
//$opportunity->participants = $opportunityObj->; |
146
|
|
|
//$opportunity->applicants = $opportunityObj->; |
147
|
|
|
$opportunity->timezone = elgg_echo($opportunityObj->timezone); |
148
|
|
|
$opportunity->timecommitment = $opportunityObj->time_commitment; |
149
|
|
|
$opportunity->department = $opportunityObj->department; |
150
|
|
|
$opportunity->state = $opportunityObj->state; |
151
|
|
|
|
152
|
|
|
//Language metadata |
153
|
|
|
$unpacked_array = mm_unpack_mission($opportunityObj); |
154
|
|
|
$unpacked_language = ''; |
155
|
|
View Code Duplication |
if (! empty($unpacked_array['lwc_english']) || ! empty($unpacked_array['lwc_french'])) { |
156
|
|
|
$unpacked_language .= '<b>' . elgg_echo('missions:written_comprehension') . ': </b>'; |
157
|
|
|
if (! empty($unpacked_array['lwc_english'])) { |
158
|
|
|
$unpacked_language .= '<span name="mission-lwc-english">' . elgg_echo('missions:formatted:english', array($unpacked_array['lwc_english'])) . '</span> '; |
159
|
|
|
} |
160
|
|
|
if (! empty($unpacked_array['lwc_french'])) { |
161
|
|
|
$unpacked_language .= '<span name="mission-lwc-french">' . elgg_echo('missions:formatted:french', array($unpacked_array['lwc_french'])) . '</span>'; |
162
|
|
|
} |
163
|
|
|
$unpacked_language .= '<br>'; |
164
|
|
|
} |
165
|
|
View Code Duplication |
if (! empty($unpacked_array['lwe_english']) || ! empty($unpacked_array['lwe_french'])) { |
166
|
|
|
$unpacked_language .= '<b>' . elgg_echo('missions:written_expression') . ': </b>'; |
167
|
|
|
if (! empty($unpacked_array['lwe_english'])) { |
168
|
|
|
$unpacked_language .= '<span name="mission-lwe-english">' . elgg_echo('missions:formatted:english', array($unpacked_array['lwe_english'])) . '</span> '; |
169
|
|
|
} |
170
|
|
|
if (! empty($unpacked_array['lwe_french'])) { |
171
|
|
|
$unpacked_language .= '<span name="mission-lwe-french">' . elgg_echo('missions:formatted:french', array($unpacked_array['lwe_french'])) . '</span>'; |
172
|
|
|
} |
173
|
|
|
$unpacked_language .= '<br>'; |
174
|
|
|
} |
175
|
|
View Code Duplication |
if (! empty($unpacked_array['lop_english']) || ! empty($unpacked_array['lop_french'])) { |
176
|
|
|
$unpacked_language .= '<b>' . elgg_echo('missions:oral_proficiency') . ': </b>'; |
177
|
|
|
if (! empty($unpacked_array['lop_english'])) { |
178
|
|
|
$unpacked_language .= '<span name="mission-lop-english">' . elgg_echo('missions:formatted:english', array($unpacked_array['lop_english'])) . '</span> '; |
179
|
|
|
} |
180
|
|
|
if (! empty($unpacked_array['lop_french'])) { |
181
|
|
|
$unpacked_language .= '<span name="mission-lop-french">' . elgg_echo('missions:formatted:french', array($unpacked_array['lop_french'])) . '</span>'; |
182
|
|
|
} |
183
|
|
|
$unpacked_language .= '<br>'; |
184
|
|
|
} |
185
|
|
|
if (empty($unpacked_language)) { |
186
|
|
|
$unpacked_language = '<span name="no-languages">' . elgg_echo('missions:none_required') . '</span>'; |
187
|
|
|
} |
188
|
|
|
$opportunity->languageRequirements = $unpacked_language; |
189
|
|
|
|
190
|
|
|
//scheduling metadata |
191
|
|
|
$unpacked_time = ''; |
192
|
|
|
if ($opportunityObj->mon_start) { |
193
|
|
|
$unpacked_time .= '<b>' . elgg_echo('missions:mon') . ': </b>'; |
194
|
|
|
$unpacked_time .= $opportunityObj->mon_start . elgg_echo('missions:to') . $opportunityObj->mon_duration . '<br>'; |
195
|
|
|
} |
196
|
|
|
if ($opportunityObj->tue_start) { |
197
|
|
|
$unpacked_time .= '<b>' . elgg_echo('missions:tue') . ': </b>'; |
198
|
|
|
$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>'; |
199
|
|
|
} |
200
|
|
|
if ($opportunityObj->wed_start) { |
201
|
|
|
$unpacked_time .= '<b>' . elgg_echo('missions:wed') . ': </b>'; |
202
|
|
|
$unpacked_time .= $opportunityObj->wed_start . elgg_echo('missions:to') . $opportunityObj->wed_duration . '<br>'; |
203
|
|
|
} |
204
|
|
|
if ($opportunityObj->thu_start) { |
205
|
|
|
$unpacked_time .= '<b>' . elgg_echo('missions:thu') . ': </b>'; |
206
|
|
|
$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>'; |
207
|
|
|
} |
208
|
|
|
if ($opportunityObj->fri_start) { |
209
|
|
|
$unpacked_time .= '<b>' . elgg_echo('missions:fri') . ': </b>'; |
210
|
|
|
$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>'; |
211
|
|
|
} |
212
|
|
|
if ($opportunityObj->sat_start) { |
213
|
|
|
$unpacked_time .= '<b>' . elgg_echo('missions:sat') . ': </b>'; |
214
|
|
|
$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>'; |
215
|
|
|
} |
216
|
|
|
if ($opportunityObj->sun_start) { |
217
|
|
|
$unpacked_time .= '<b>' . elgg_echo('missions:sun') . ': </b>'; |
218
|
|
|
$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>'; |
219
|
|
|
} |
220
|
|
|
if (empty($unpacked_time)) { |
221
|
|
|
$unpacked_time = '<span name="no-times">' . elgg_echo('missions:none_required') . '</span>'; |
222
|
|
|
} |
223
|
|
|
$opportunity->schedulingRequirements = $unpacked_time; |
224
|
|
|
|
225
|
|
|
|
226
|
|
|
return $opportunity; |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
function get_opportunities($user, $limit, $offset, $filters, $lang) |
230
|
|
|
{ |
231
|
|
|
$user_entity = is_numeric($user) ? get_user($user) : (strpos($user, '@') !== false ? get_user_by_email($user)[0] : get_user_by_username($user)); |
232
|
|
|
if (!$user_entity) { |
233
|
|
|
return "User was not found. Please try a different GUID, username, or email address"; |
234
|
|
|
} |
235
|
|
|
if (!$user_entity instanceof ElggUser) { |
236
|
|
|
return "Invalid user. Please try a different GUID, username, or email address"; |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
if (!elgg_is_logged_in()) { |
240
|
|
|
login($user_entity); |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
$filter_data = json_decode($filters); |
244
|
|
|
if (!empty($filter_data)) { |
245
|
|
|
$params = array( |
246
|
|
|
'type' => 'object', |
247
|
|
|
'subtype' => 'mission', |
248
|
|
|
'limit' => $limit, |
249
|
|
|
'offset' => $offset |
250
|
|
|
); |
251
|
|
|
|
252
|
|
|
if ($filter_data->type) { |
253
|
|
|
$params['metadata_name'] = 'job_type'; |
254
|
|
|
$params['metadata_value'] = $filter_data->type; |
255
|
|
|
} |
256
|
|
|
|
257
|
|
View Code Duplication |
if ($filter_data->name) { |
258
|
|
|
$db_prefix = elgg_get_config('dbprefix'); |
259
|
|
|
$params['joins'] = array("JOIN {$db_prefix}objects_entity oe ON e.guid = oe.guid"); |
260
|
|
|
$params['wheres'] = array("(oe.title LIKE '%" . $filter_data->name . "%' OR oe.description LIKE '%" . $filter_data->name . "%')"); |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
if ($filter_data->mine) { |
264
|
|
|
$all_opportunities = elgg_list_entities_from_relationship($params); |
265
|
|
|
} else { |
266
|
|
|
$all_opportunities = elgg_list_entities_from_metadata($params); |
267
|
|
|
} |
268
|
|
|
} else { |
269
|
|
|
$all_opportunities = elgg_list_entities(array( |
270
|
|
|
'type' => 'object', |
271
|
|
|
'subtype' => 'mission', |
272
|
|
|
'limit' => $limit, |
273
|
|
|
'offset' => $offset |
274
|
|
|
)); |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
$opportunities = json_decode($all_opportunities); |
278
|
|
|
|
279
|
|
|
foreach ($opportunities as $opportunity) { |
280
|
|
|
$opportunityObj = get_entity($opportunity->guid); |
281
|
|
|
$opportunity->title = gc_explode_translation($opportunity->title, $lang); |
282
|
|
|
|
283
|
|
|
$likes = elgg_get_annotations(array( |
284
|
|
|
'guid' => $opportunity->guid, |
285
|
|
|
'annotation_name' => 'likes' |
286
|
|
|
)); |
287
|
|
|
$opportunity->likes = count($likes); |
288
|
|
|
|
289
|
|
|
$liked = elgg_get_annotations(array( |
290
|
|
|
'guid' => $opportunity->guid, |
291
|
|
|
'annotation_owner_guid' => $user_entity->guid, |
292
|
|
|
'annotation_name' => 'likes' |
293
|
|
|
)); |
294
|
|
|
if($opportunity->owner_guid != $user_entity->guid){ |
295
|
|
|
|
296
|
|
|
if($opportunityObj->state != 'completed' && $opportunityObj->state != 'cancelled'){ |
297
|
|
|
$relationship_count = elgg_get_entities_from_relationship(array( |
298
|
|
|
'relationship' => 'mission_accepted', |
299
|
|
|
'relationship_guid' => $opportunity->guid, |
300
|
|
|
'count' => true |
301
|
|
|
)); |
302
|
|
|
if($relationship_count < $opportunityObj->number) { |
303
|
|
|
|
304
|
|
|
$opportunity->apply = 'mission_apply'; // user can apply |
305
|
|
|
} |
306
|
|
|
|
307
|
|
|
if(check_entity_relationship($opportunity->guid, 'mission_tentative', $user_entity->guid)) { |
308
|
|
|
//console.log($opportunity->title); |
309
|
|
|
$opportunity->apply = 'tentative'; // user can accecpt offer |
310
|
|
|
} |
311
|
|
|
if(check_entity_relationship($opportunity->guid, 'mission_offered', $user_entity->guid)) { |
312
|
|
|
$opportunity->apply = 'offered'; // user can accecpt offer |
313
|
|
|
|
314
|
|
|
} |
315
|
|
|
if(check_entity_relationship($opportunity->guid, 'mission_accepted', $user_entity->guid) || |
316
|
|
|
check_entity_relationship($opportunity->guid, 'mission_applied', $user_entity->guid)) { |
317
|
|
|
$opportunity->apply = 'withdraw'; // user can accecpt offer |
318
|
|
|
|
319
|
|
|
} |
320
|
|
|
}else{ |
321
|
|
|
$opportunity->apply = 'close'; |
322
|
|
|
} |
323
|
|
|
} |
324
|
|
|
|
325
|
|
|
$opportunity->liked = count($liked) > 0; |
326
|
|
|
$opportunity->jobtype = elgg_echo($opportunityObj->job_type); |
327
|
|
|
$opportunity->roletype = elgg_echo($opportunityObj->role_type); |
328
|
|
|
$opportunity->deadline = $opportunityObj->deadline; |
329
|
|
|
$opportunity->programArea = elgg_echo($opportunityObj->program_area); |
330
|
|
|
$opportunity->owner = ($opportunityObj->getOwnerEntity() == $user_entity); |
331
|
|
|
$opportunity->iconURL = $opportunityObj->getIconURL(); |
332
|
|
|
$opportunity->userDetails = get_user_block($opportunity->owner_guid, $lang); |
333
|
|
|
$opportunity->description = clean_text(gc_explode_translation($opportunity->description, $lang)); |
334
|
|
|
$opportunity->state = $opportunityObj->state; |
335
|
|
|
|
336
|
|
|
} |
337
|
|
|
|
338
|
|
|
return $opportunities; |
339
|
|
|
} |
340
|
|
|
|
341
|
|
|
|
342
|
|
|
|
343
|
|
|
function apply_post($user,$message,$guid, $lang) |
344
|
|
|
{ |
345
|
|
|
$user_entity = is_numeric($user) ? get_user($user) : (strpos($user, '@') !== false ? get_user_by_email($user)[0] : get_user_by_username($user)); |
346
|
|
|
if (!$user_entity) { |
347
|
|
|
return "User was not found. Please try a different GUID, username, or email address"; |
348
|
|
|
} |
349
|
|
|
if (!$user_entity instanceof ElggUser) { |
350
|
|
|
return "Invalid user. Please try a different GUID, username, or email address"; |
351
|
|
|
} |
352
|
|
|
|
353
|
|
|
if (!elgg_is_logged_in()) { |
354
|
|
|
login($user_entity); |
355
|
|
|
} |
356
|
|
|
|
357
|
|
|
$entity = get_entity($guid); |
358
|
|
|
if (!$entity) { |
359
|
|
|
return "Opportunity was not found. Please try a different GUID"; |
360
|
|
|
} |
361
|
|
|
if (!elgg_instanceof($entity, 'object', 'mission')) { |
362
|
|
|
return "Invalid opportunity. Please try a different GUID"; |
363
|
|
|
} |
364
|
|
|
|
365
|
|
|
// Creates an applied relationship between user and mission if there is no relationship there already. |
366
|
|
|
if(!check_entity_relationship($entity->guid, 'mission_accepted', $user_entity->guid) && !check_entity_relationship($entity->guid, 'mission_tentative', $user_entity->guid)) { |
367
|
|
|
add_entity_relationship($entity->guid, 'mission_applied', $user_entity->guid); |
368
|
|
|
$message_info = elgg_echo('missions:you_have_applied_to_mission', array($entity->job_title, $entity->name)); |
369
|
|
|
|
370
|
|
|
$title_applicant_en = elgg_echo('missions:application_notice_sentence_title', array($user_entity->name, $entity->job_title),'en') ; |
371
|
|
|
$title_applicant_fr = elgg_echo('missions:application_notice_sentence_title', array($user_entity->name, $entity->job_title),'fr') ; |
372
|
|
|
|
373
|
|
|
$content_applicant_en = elgg_echo('missions:application_notice_sentence', 'en') . '<br>'; |
|
|
|
|
374
|
|
|
$content_applicant_fr = elgg_echo('missions:application_notice_sentence', 'fr') . '<br>'; |
|
|
|
|
375
|
|
|
$content_applicant_en .= '<br>'.elgg_echo('missions:see_full_profile','en') . ': '; |
|
|
|
|
376
|
|
|
$content_applicant_fr .= '<br>'.elgg_echo('missions:see_full_profile','fr') . ': '; |
|
|
|
|
377
|
|
|
|
378
|
|
|
$content_applicant_en .= '<a href="'.$user_entity->getURL().'">'.$user_entity->username.'<a/><br>'; |
379
|
|
|
$content_applicant_fr .= '<a href="'.$user_entity->getURL().'">'.$user_entity->username.'<a/><br>'; |
380
|
|
|
|
381
|
|
|
$content_applicant_en .= elgg_echo('missions:see_full_mission','en') . ': '; |
|
|
|
|
382
|
|
|
$content_applicant_fr .= elgg_echo('missions:see_full_mission','fr') . ': '; |
|
|
|
|
383
|
|
|
|
384
|
|
|
$content_applicant_en .= '<a href="'.$entity->getURL().'">'.$entity->job_title.'<a/><br>'; |
385
|
|
|
$content_applicant_fr .= '<a href="'.$entity->getURL().'">'.$entity->job_title.'<a/><br>'; |
386
|
|
|
|
387
|
|
|
$content_applicant_en .= '<br>'.elgg_echo('missions:from_message',array($user_entity->username),'en').'<br><span style="font-style: italic;">'.$message . '</span><br>'; |
388
|
|
|
$content_applicant_fr .= '<br>'.elgg_echo('missions:from_message',array($user_entity->username),'fr').'<br><span style="font-style: italic;">'.$message . '</span><br>'; |
389
|
|
|
|
390
|
|
|
// Lists all educations of the applicant. |
391
|
|
|
$education_list = $user_entity->education; |
392
|
|
|
if(!is_array($education_list)) { |
393
|
|
|
$education_list = array_filter(array($education_list)); |
394
|
|
|
} |
395
|
|
View Code Duplication |
if(!empty($education_list)) { |
396
|
|
|
foreach ($education_list as $education) { |
397
|
|
|
$education = get_entity($education); |
398
|
|
|
$education_ending_en = date("F", mktime(null, null, null, $education->enddate)) . ', ' . $education->endyear; |
399
|
|
|
$education_ending_fr = $cal_month[$education->enddate] . ', ' . $education->endyear; |
|
|
|
|
400
|
|
|
|
401
|
|
|
if ($education->ongoing == 'true') { |
402
|
|
|
$education_ending_en = 'Present'; |
403
|
|
|
$education_ending_fr = 'Présent'; |
404
|
|
|
} |
405
|
|
|
|
406
|
|
|
$education_beginning_en = date("F", mktime(null, null, null, $education->startdate)) . ', ' . $education->startyear; |
407
|
|
|
$education_beginning_fr = $cal_month[$education->startdate] . ', ' . $education->startyear; |
408
|
|
|
|
409
|
|
|
// TODO: This section should be in the language files eventually. |
410
|
|
|
$content_applicant_en .= '<br><b><font size="4">' . $education->school . ':</font></b>' . "<br>"; |
411
|
|
|
$content_applicant_en .= $education_beginning_en . ' - ' . $education_ending_en . "<br>"; |
412
|
|
|
$content_applicant_en .= '<b>' . $education->degree . ':</b> ' . $education->field . "<br>"; |
413
|
|
|
|
414
|
|
|
$content_applicant_fr .= '<br><b><font size="4">' . $education->school . ':</font></b>' . "<br>"; |
415
|
|
|
$content_applicant_fr .= $education_beginning_fr . ' - ' . $education_ending_fr . "<br>"; |
416
|
|
|
$content_applicant_fr .= '<b>' . $education->degree . ':</b> ' . $education->field . "<br>"; |
417
|
|
|
} |
418
|
|
|
} |
419
|
|
|
|
420
|
|
|
//Lists all work experiences of the applicant. |
421
|
|
|
$experience_list = $user_entity->work; |
422
|
|
|
if(!is_array($experience_list)) { |
423
|
|
|
$experience_list = array_filter(array($experience_list)); |
424
|
|
|
} |
425
|
|
View Code Duplication |
if(!empty($experience_list)) { |
426
|
|
|
foreach ($experience_list as $experience) { |
427
|
|
|
$experience = get_entity($experience); |
428
|
|
|
$experience_ending_en = date("F", mktime(null, null, null, $experience->enddate)) . ', ' . $experience->endyear; |
429
|
|
|
$experience_ending_fr = $cal_month[$experience->enddate] . ', ' . $experience->endyear; |
430
|
|
|
if ($experience->ongoing == 'true') { |
431
|
|
|
$experience_ending_en = 'Present'; |
432
|
|
|
$experience_ending_fr = 'Présent'; |
433
|
|
|
} |
434
|
|
|
$experience_beginning_en = date("F", mktime(null, null, null, $experience->startdate)) . ', ' . $experience->startyear; |
435
|
|
|
$experience_beginning_fr = $cal_month[$experience->startdate] . ', ' . $experience->startyear; |
436
|
|
|
|
437
|
|
|
// TODO: This section should be in the language files eventually. |
438
|
|
|
$content_applicant_en .= '<br><b><font size="4">' . $experience->organization . ':</font></b>' . "<br>"; |
439
|
|
|
$content_applicant_en .= $experience_beginning_en . ' - ' . $experience_ending_en . "<br>"; |
440
|
|
|
$content_applicant_en .= '<b>' . $experience->title . '</b>' . "<br>"; |
441
|
|
|
$content_applicant_en .= $experience->responsibilities . "<br><br>"; |
442
|
|
|
|
443
|
|
|
$content_applicant_fr .= '<br><b><font size="4">' . $experience->organization . ':</font></b>' . "<br>"; |
444
|
|
|
$content_applicant_fr .= $experience_beginning_fr . ' - ' . $experience_ending_fr . "<br>"; |
445
|
|
|
$content_applicant_fr .= '<b>' . $experience->title . '</b>' . "<br>"; |
446
|
|
|
$content_applicant_fr .= $experience->responsibilities . "<br><br>"; |
447
|
|
|
} |
448
|
|
|
} |
449
|
|
|
|
450
|
|
|
// Lists all skills of the applicant. |
451
|
|
|
$skill_list = $user_entity->gc_skills; |
452
|
|
|
if(!is_array($skill_list)) { |
453
|
|
|
$skill_list = array_filter(array($skill_list)); |
454
|
|
|
} |
455
|
|
View Code Duplication |
if(!empty($skill_list)) { |
456
|
|
|
foreach ($skill_list as $skill) { |
457
|
|
|
$skill = get_entity($skill); |
458
|
|
|
$content_applicant_en .= '<b>' . $skill->title . '</b>' . "<br>"; |
459
|
|
|
$content_applicant_fr .= '<b>' . $skill->title . '</b>' . "<br>"; |
460
|
|
|
} |
461
|
|
|
} |
462
|
|
|
|
463
|
|
|
// Sends the application via email and notification. |
464
|
|
|
$content_applicant_en .= elgg_view('output/url', array( |
465
|
|
|
'href' => elgg_get_site_url() . 'missions/mission-offer/' . $entity->guid . '/' . $user_entity->guid, |
466
|
|
|
'text' => '<br>'.elgg_echo('missions:offer','en') |
|
|
|
|
467
|
|
|
)); |
468
|
|
|
|
469
|
|
|
$content_applicant_fr .= elgg_view('output/url', array( |
470
|
|
|
'href' => elgg_get_site_url() . 'missions/mission-offer/' . $entity->guid . '/' . $user_entity->guid, |
471
|
|
|
'text' => '<br>'.elgg_echo('missions:offer','fr') |
|
|
|
|
472
|
|
|
)); |
473
|
|
|
|
474
|
|
|
$subject = elgg_echo('missions:application_to','en') . $entity->job_title.' | '.elgg_echo('missions:application_to','fr') . $entity->job_title; |
|
|
|
|
475
|
|
|
|
476
|
|
|
mm_notify_user($entity->guid, $user_entity->guid, $subject,$title_applicant_en,$title_applicant_fr, $content_applicant_en, $content_applicant_fr); |
477
|
|
|
|
478
|
|
|
} |
479
|
|
|
|
480
|
|
|
// Opt in applicant if they are not opted in yet. |
481
|
|
|
if(!check_if_opted_in($user_entity)) { |
482
|
|
|
$user_entity->opt_in_missions = 'gcconnex_profile:opt:yes'; |
483
|
|
|
$user_entity->save(); |
484
|
|
|
} |
485
|
|
|
return $message_info; |
|
|
|
|
486
|
|
|
|
487
|
|
|
} |
488
|
|
|
|
489
|
|
|
function withdraw_post($user,$message, $guid, $lang) |
490
|
|
|
{ |
491
|
|
|
$user_entity = is_numeric($user) ? get_user($user) : (strpos($user, '@') !== false ? get_user_by_email($user)[0] : get_user_by_username($user)); |
492
|
|
|
if (!$user_entity) { |
493
|
|
|
return "User was not found. Please try a different GUID, username, or email address"; |
494
|
|
|
} |
495
|
|
|
if (!$user_entity instanceof ElggUser) { |
496
|
|
|
return "Invalid user. Please try a different GUID, username, or email address"; |
497
|
|
|
} |
498
|
|
|
|
499
|
|
|
if (!elgg_is_logged_in()) { |
500
|
|
|
login($user_entity); |
501
|
|
|
} |
502
|
|
|
|
503
|
|
|
$entity = get_entity($guid); |
504
|
|
|
if (!$entity) { |
505
|
|
|
return "Opportunity was not found. Please try a different GUID"; |
506
|
|
|
} |
507
|
|
|
if (!elgg_instanceof($entity, 'object', 'mission')) { |
508
|
|
|
return "Invalid opportunity. Please try a different GUID"; |
509
|
|
|
} |
510
|
|
|
|
511
|
|
|
// Deletes the tentative relationship between mission and applicant. |
512
|
|
View Code Duplication |
if(check_entity_relationship($entity->guid, 'mission_tentative', $user_entity->guid)) { |
513
|
|
|
$message_return = 'missions:declination_has_been_sent'; |
514
|
|
|
remove_entity_relationship($entity->guid, 'mission_tentative', $user_entity->guid); |
515
|
|
|
} |
516
|
|
|
if(check_entity_relationship($entity->guid, 'mission_applied', $user_entity->guid)) { |
517
|
|
|
$message_return = 'missions:withdrawal_has_been_sent'; |
518
|
|
|
remove_entity_relationship($entity->guid, 'mission_applied', $user_entity->guid); |
519
|
|
|
} |
520
|
|
View Code Duplication |
if(check_entity_relationship($entity->guid, 'mission_offered', $user_entity->guid)) { |
521
|
|
|
$message_return = 'missions:declination_has_been_sent'; |
522
|
|
|
remove_entity_relationship($entity->guid, 'mission_offered', $user_entity->guid); |
523
|
|
|
} |
524
|
|
View Code Duplication |
if(check_entity_relationship($entity->guid, 'mission_accepted', $user_entity->guid)) { |
525
|
|
|
$message_return = 'missions:withdrawal_has_been_sent'; |
526
|
|
|
remove_entity_relationship($entity->guid, 'mission_accepted', $user_entity->guid); |
527
|
|
|
mm_complete_mission_inprogress_reports($entity, true); |
528
|
|
|
} |
529
|
|
|
|
530
|
|
|
$reasonEn = elgg_echo('missions:decline:'.$message,'en'); |
|
|
|
|
531
|
|
|
$reasonFr = elgg_echo('missions:decline:'.$message,'fr'); |
|
|
|
|
532
|
|
|
$mission_link = '<a href="'.$entity->getURL().'" >'.elgg_get_excerpt($entity->job_title, elgg_get_plugin_setting('mission_job_title_card_cutoff', 'missions')).' </a>'; |
533
|
|
|
$subject = elgg_echo('missions:applicant_leaves', array($user_entity->name),'en')." | ". elgg_echo('missions:applicant_leaves', array($user_entity->name),'fr'); |
534
|
|
|
|
535
|
|
|
$withdrawnEn .= elgg_echo('missions:applicant_leaves_more', array($user_entity->name),'en') . $mission_link . '.' . "\n"; |
|
|
|
|
536
|
|
|
$withdrawnReasonEn .= elgg_echo('missions:reason_given', array($reasonEn),'en'); |
|
|
|
|
537
|
|
|
|
538
|
|
|
$withdrawnFr .= elgg_echo('missions:applicant_leaves_more', array($user_entity->name),'fr') . $mission_link . '.' . "\n"; |
|
|
|
|
539
|
|
|
$withdrawnReasonFr .= elgg_echo('missions:reason_given', array($reasonFr),'fr'); |
|
|
|
|
540
|
|
|
|
541
|
|
|
mm_notify_user($entity->guid, $user_entity->guid, $subject, $withdrawnEn, $withdrawnFr,$withdrawnReasonEn ,$withdrawnReasonFr ); |
542
|
|
|
|
543
|
|
|
|
544
|
|
|
return elgg_echo($message_return, array($entity->job_title)); |
|
|
|
|
545
|
|
|
|
546
|
|
|
|
547
|
|
|
} |
548
|
|
|
|
549
|
|
|
function accept_post($user, $guid, $lang) |
550
|
|
|
{ |
551
|
|
|
$user_entity = is_numeric($user) ? get_user($user) : (strpos($user, '@') !== false ? get_user_by_email($user)[0] : get_user_by_username($user)); |
552
|
|
|
if (!$user_entity) { |
553
|
|
|
return "User was not found. Please try a different GUID, username, or email address"; |
554
|
|
|
} |
555
|
|
|
if (!$user_entity instanceof ElggUser) { |
556
|
|
|
return "Invalid user. Please try a different GUID, username, or email address"; |
557
|
|
|
} |
558
|
|
|
|
559
|
|
|
if (!elgg_is_logged_in()) { |
560
|
|
|
login($user_entity); |
561
|
|
|
} |
562
|
|
|
|
563
|
|
|
$entity = get_entity($guid); |
564
|
|
|
if (!$entity) { |
565
|
|
|
return "Opportunity was not found. Please try a different GUID"; |
566
|
|
|
} |
567
|
|
|
if (!elgg_instanceof($entity, 'object', 'mission')) { |
568
|
|
|
return "Invalid opportunity. Please try a different GUID"; |
569
|
|
|
} |
570
|
|
|
|
571
|
|
View Code Duplication |
if(check_entity_relationship($entity->guid, 'mission_offered', $user_entity->guid)) { |
572
|
|
|
|
573
|
|
|
remove_entity_relationship($entity->guid, 'mission_offered', $user_entity->guid); |
574
|
|
|
add_entity_relationship($entity->guid, 'mission_accepted', $user_entity->guid); |
575
|
|
|
} |
576
|
|
|
|
577
|
|
|
return elgg_echo('missions:now_participating_in_mission', array($entity->job_title)); |
578
|
|
|
} |
579
|
|
|
|
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: