| @@ 183-262 (lines=80) @@ | ||
| 180 | return $opportunity; |
|
| 181 | } |
|
| 182 | ||
| 183 | function get_opportunities($user, $limit, $offset, $filters, $lang) |
|
| 184 | { |
|
| 185 | $user_entity = is_numeric($user) ? get_user($user) : (strpos($user, '@') !== false ? get_user_by_email($user)[0] : get_user_by_username($user)); |
|
| 186 | if (!$user_entity) { |
|
| 187 | return "User was not found. Please try a different GUID, username, or email address"; |
|
| 188 | } |
|
| 189 | if (!$user_entity instanceof ElggUser) { |
|
| 190 | return "Invalid user. Please try a different GUID, username, or email address"; |
|
| 191 | } |
|
| 192 | ||
| 193 | if (!elgg_is_logged_in()) { |
|
| 194 | login($user_entity); |
|
| 195 | } |
|
| 196 | ||
| 197 | $filter_data = json_decode($filters); |
|
| 198 | if (!empty($filter_data)) { |
|
| 199 | $params = array( |
|
| 200 | 'type' => 'object', |
|
| 201 | 'subtype' => 'mission', |
|
| 202 | 'limit' => $limit, |
|
| 203 | 'offset' => $offset |
|
| 204 | ); |
|
| 205 | ||
| 206 | if ($filter_data->type) { |
|
| 207 | $params['metadata_name'] = 'job_type'; |
|
| 208 | $params['metadata_value'] = $filter_data->type; |
|
| 209 | } |
|
| 210 | ||
| 211 | if ($filter_data->name) { |
|
| 212 | $db_prefix = elgg_get_config('dbprefix'); |
|
| 213 | $params['joins'] = array("JOIN {$db_prefix}objects_entity oe ON e.guid = oe.guid"); |
|
| 214 | $params['wheres'] = array("(oe.title LIKE '%" . $filter_data->name . "%' OR oe.description LIKE '%" . $filter_data->name . "%')"); |
|
| 215 | } |
|
| 216 | ||
| 217 | if ($filter_data->mine) { |
|
| 218 | $all_opportunities = elgg_list_entities_from_relationship($params); |
|
| 219 | } else { |
|
| 220 | $all_opportunities = elgg_list_entities_from_metadata($params); |
|
| 221 | } |
|
| 222 | } else { |
|
| 223 | $all_opportunities = elgg_list_entities(array( |
|
| 224 | 'type' => 'object', |
|
| 225 | 'subtype' => 'mission', |
|
| 226 | 'limit' => $limit, |
|
| 227 | 'offset' => $offset |
|
| 228 | )); |
|
| 229 | } |
|
| 230 | ||
| 231 | $opportunities = json_decode($all_opportunities); |
|
| 232 | ||
| 233 | foreach ($opportunities as $opportunity) { |
|
| 234 | $opportunity->title = gc_explode_translation($opportunity->title, $lang); |
|
| 235 | ||
| 236 | $likes = elgg_get_annotations(array( |
|
| 237 | 'guid' => $opportunity->guid, |
|
| 238 | 'annotation_name' => 'likes' |
|
| 239 | )); |
|
| 240 | $opportunity->likes = count($likes); |
|
| 241 | ||
| 242 | $liked = elgg_get_annotations(array( |
|
| 243 | 'guid' => $opportunity->guid, |
|
| 244 | 'annotation_owner_guid' => $user_entity->guid, |
|
| 245 | 'annotation_name' => 'likes' |
|
| 246 | )); |
|
| 247 | $opportunity->liked = count($liked) > 0; |
|
| 248 | ||
| 249 | $opportunityObj = get_entity($opportunity->guid); |
|
| 250 | $opportunity->jobtype = elgg_echo($opportunityObj->job_type); |
|
| 251 | $opportunity->roletype = elgg_echo($opportunityObj->role_type); |
|
| 252 | $opportunity->deadline = $opportunityObj->deadline; |
|
| 253 | $opportunity->programArea = elgg_echo($opportunityObj->program_area); |
|
| 254 | $opportunity->owner = ($opportunityObj->getOwnerEntity() == $user_entity); |
|
| 255 | $opportunity->iconURL = $opportunityObj->getIconURL(); |
|
| 256 | ||
| 257 | $opportunity->userDetails = get_user_block($opportunity->owner_guid, $lang); |
|
| 258 | $opportunity->description = clean_text(gc_explode_translation($opportunity->description, $lang)); |
|
| 259 | } |
|
| 260 | ||
| 261 | return $opportunities; |
|
| 262 | } |
|
| 263 | ||
| @@ 183-262 (lines=80) @@ | ||
| 180 | return $opportunity; |
|
| 181 | } |
|
| 182 | ||
| 183 | function get_opportunities_test($user, $limit, $offset, $filters, $lang) |
|
| 184 | { |
|
| 185 | $user_entity = is_numeric($user) ? get_user($user) : (strpos($user, '@') !== false ? get_user_by_email($user)[0] : get_user_by_username($user)); |
|
| 186 | if (!$user_entity) { |
|
| 187 | return "User was not found. Please try a different GUID, username, or email address"; |
|
| 188 | } |
|
| 189 | if (!$user_entity instanceof ElggUser) { |
|
| 190 | return "Invalid user. Please try a different GUID, username, or email address"; |
|
| 191 | } |
|
| 192 | ||
| 193 | if (!elgg_is_logged_in()) { |
|
| 194 | login($user_entity); |
|
| 195 | } |
|
| 196 | ||
| 197 | $filter_data = json_decode($filters); |
|
| 198 | if (!empty($filter_data)) { |
|
| 199 | $params = array( |
|
| 200 | 'type' => 'object', |
|
| 201 | 'subtype' => 'mission', |
|
| 202 | 'limit' => $limit, |
|
| 203 | 'offset' => $offset |
|
| 204 | ); |
|
| 205 | ||
| 206 | if ($filter_data->type) { |
|
| 207 | $params['metadata_name'] = 'job_type'; |
|
| 208 | $params['metadata_value'] = $filter_data->type; |
|
| 209 | } |
|
| 210 | ||
| 211 | if ($filter_data->name) { |
|
| 212 | $db_prefix = elgg_get_config('dbprefix'); |
|
| 213 | $params['joins'] = array("JOIN {$db_prefix}objects_entity oe ON e.guid = oe.guid"); |
|
| 214 | $params['wheres'] = array("(oe.title LIKE '%" . $filter_data->name . "%' OR oe.description LIKE '%" . $filter_data->name . "%')"); |
|
| 215 | } |
|
| 216 | ||
| 217 | if ($filter_data->mine) { |
|
| 218 | $all_opportunities = elgg_list_entities_from_relationship($params); |
|
| 219 | } else { |
|
| 220 | $all_opportunities = elgg_list_entities_from_metadata($params); |
|
| 221 | } |
|
| 222 | } else { |
|
| 223 | $all_opportunities = elgg_list_entities(array( |
|
| 224 | 'type' => 'object', |
|
| 225 | 'subtype' => 'mission', |
|
| 226 | 'limit' => $limit, |
|
| 227 | 'offset' => $offset |
|
| 228 | )); |
|
| 229 | } |
|
| 230 | ||
| 231 | $opportunities = json_decode($all_opportunities); |
|
| 232 | ||
| 233 | foreach ($opportunities as $opportunity) { |
|
| 234 | $opportunity->title = gc_explode_translation($opportunity->title, $lang); |
|
| 235 | ||
| 236 | $likes = elgg_get_annotations(array( |
|
| 237 | 'guid' => $opportunity->guid, |
|
| 238 | 'annotation_name' => 'likes' |
|
| 239 | )); |
|
| 240 | $opportunity->likes = count($likes); |
|
| 241 | ||
| 242 | $liked = elgg_get_annotations(array( |
|
| 243 | 'guid' => $opportunity->guid, |
|
| 244 | 'annotation_owner_guid' => $user_entity->guid, |
|
| 245 | 'annotation_name' => 'likes' |
|
| 246 | )); |
|
| 247 | $opportunity->liked = count($liked) > 0; |
|
| 248 | ||
| 249 | $opportunityObj = get_entity($opportunity->guid); |
|
| 250 | $opportunity->jobtype = elgg_echo($opportunityObj->job_type); |
|
| 251 | $opportunity->roletype = elgg_echo($opportunityObj->role_type); |
|
| 252 | $opportunity->deadline = $opportunityObj->deadline; |
|
| 253 | $opportunity->programArea = elgg_echo($opportunityObj->program_area); |
|
| 254 | $opportunity->owner = ($opportunityObj->getOwnerEntity() == $user_entity); |
|
| 255 | $opportunity->iconURL = $opportunityObj->getIconURL(); |
|
| 256 | ||
| 257 | $opportunity->userDetails = get_user_block($opportunity->owner_guid, $lang); |
|
| 258 | $opportunity->description = clean_text(gc_explode_translation($opportunity->description, $lang)); |
|
| 259 | } |
|
| 260 | ||
| 261 | return $opportunities; |
|
| 262 | } |
|
| 263 | ||