Skip to content

Commit

Permalink
OneSignal integration
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanbarroca committed Aug 7, 2017
1 parent ed23936 commit eb2005e
Showing 1 changed file with 44 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ function markaspot_open311_find_locations($parameters) {
$query->fieldCondition('field_area', 'value', $parameters['area'], '=');
}

if (isset($parameters['quarter'])) {
$query->fieldCondition('field_quarter', 'value', $parameters['quarter'], '=');
}


$result = $query->execute();

Expand Down Expand Up @@ -154,7 +150,7 @@ function markaspot_open311_people_retrieve($request_id, $parameters) {
}
}

$bairro_tid = markaspot_open311_neighbourhood_map_tax($node->field_nbhood[$node->language][0]['value']);
$bairro_tid = markaspot_open311_neighbourhood_map_tax($node->field_neighbourhood[$node->language][0]['value']);

$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
Expand Down Expand Up @@ -287,6 +283,42 @@ function markaspot_open311_requests_create($data) {
}
$service_request[0]['service_notice'] = "";
}

$curl = curl_init();
$service_request_url = 'http:https://www.mopa.co.mz/reports/'.$service_request[0]['service_request_id'];

$json = <<<json
{
"app_id": "8c492b14-4577-4478-9422-6a19a6553e55",
"included_segments": ["All"],
"url": "$service_request_url",
"contents": {"en": "$service_request[0]['description']"},
"headings": {"en": "$service_request[0]['service_request_id']"}
}
json;

curl_setopt_array($curl, array(
CURLOPT_URL => "https://onesignal.com/api/v1/notifications",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $json,
CURLOPT_HTTPHEADER => array(
"authorization: Basic YjgzZGEzNjgtOWYxZS00MTBkLTliNGMtODhhOGY2NDQ3ZGU4",
"cache-control: no-cache",
"content-type: application/json",
"postman-token: 8be9d18c-cc37-b68c-2e76-620fc6e7cbbb"
),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

return $service_request;
}

Expand Down Expand Up @@ -496,7 +528,7 @@ function markaspot_open311_requests_index($page, $parameters) {
}

if (isset($parameters['neighbourhood'])) {
$query->fieldCondition('field_nbhood', 'value', $parameters['neighbourhood'], '=');
$query->fieldCondition('field_neighbourhood', 'value', $parameters['neighbourhood'], '=');
}

if (isset($parameters['address_id'])) {
Expand Down Expand Up @@ -644,11 +676,14 @@ function markaspot_open311_node_map_request($node, $status, $parameters) {
$request['media_url'] = $image_uri;
}
// Non Open311 compliant fields can be added here:
if (isset($node->field_nbhood[$node->language][0]['value'])) $request['neighbourhood'] = $node->field_nbhood[$node->language][0]['value'];
if (isset($node->field_neighbourhood[$node->language][0]['value'])) $request['neighbourhood'] = $node->field_neighbourhood[$node->language][0]['value'];
if (isset($parameters['phone_key'])) if ($parameters['phone_key']==666554 && isset($node->field_phone[$node->language][0]['value'])) $request['phone'] = $node->field_phone[$node->language][0]['value'];

$request['validated'] = $node->field_validatedcmm[$node->language][0]['value'];

$request['reopen'] = $node->field_reaberto[$node->language][0]['value'];


return $request;
}

Expand Down Expand Up @@ -710,10 +745,10 @@ function markaspot_open311_request_map_node($request) {
$params = array();
$params['id']=$node->field_address_id[$node->language][0]['value'];
$results = markaspot_open311_find_locations($params);
if($results) $node->field_nbhood[$node->language][0]['value'] = $results[0]['neighbourhood'][0];
if($results) $node->field_neighbourhood[$node->language][0]['value'] = $results[0]['neighbourhood'][0];
}

if (!isset($node->field_nbhood[$node->language][0]['value']) && isset($request->neighbourhood)) $node->field_nbhood[$node->language][0]['value'] = $request->neighbourhood;
if (!isset($node->field_neighbourhood[$node->language][0]['value']) && isset($request->neighbourhood)) $node->field_neighbourhood[$node->language][0]['value'] = $request->neighbourhood;

if (isset($request->email)) $node->field_e_mail[$node->language][0]['value'] = $request->email;
if (isset($request->phone)) $node->field_phone[$node->language][0]['value'] = $request->phone;
Expand Down

0 comments on commit eb2005e

Please sign in to comment.