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