Skip to content
This repository was archived by the owner on Oct 29, 2020. It is now read-only.

Commit 5674559

Browse files
committed
creates convertDate helper function and adds field_mobile_app_date to api response for a campaign
1 parent bc08f2a commit 5674559

File tree

3 files changed

+42
-8
lines changed

3 files changed

+42
-8
lines changed

lib/modules/dosomething/dosomething_api/includes/Transformer.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ protected function transformCollection($items, $method = 'transform') {
226226
* - tags: (array)
227227
* - timing: (array)
228228
* - reportback_info: (array)
229+
* - mobile_app: (array)
229230
* @return array
230231
*/
231232
protected function transformCampaign($data) {
@@ -278,6 +279,8 @@ protected function transformCampaign($data) {
278279

279280
$output['timing']['high_season'] = $data->timing['high_season'];
280281
$output['timing']['low_season'] = $data->timing['low_season'];
282+
283+
$output['mobile_app']['dates'] = $data->mobile_app['dates'];
281284
}
282285

283286
$output['reportback_info'] = $data->reportback_info;

lib/modules/dosomething/dosomething_campaign/includes/Campaign.php

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class Campaign {
2525
public $tags;
2626
public $timing;
2727
public $reportback_info;
28+
public $mobile_app;
2829

2930

3031
/**
@@ -141,6 +142,10 @@ private function build($data, $display = 'teaser') {
141142

142143
$timing = $this->getTiming();
143144
$this->timing = $timing;
145+
146+
$mobile_app = $this->getMobileAppDate();
147+
$this->mobile_app = $mobile_app;
148+
144149
}
145150

146151
$this->reportback_info = $this->getReportbackInfo();
@@ -335,6 +340,25 @@ protected function getIssue() {
335340
}
336341

337342

343+
/**
344+
* Get the start and end dates for when campaign will be displayed on the mobile app if available.
345+
* Dates formatted as ISO-8601 datetime.
346+
*
347+
* @return array
348+
*/
349+
350+
protected function getMobileAppDate() {
351+
$timezone = new DateTimeZone('UTC');
352+
353+
$timing = [];
354+
$timing['dates'] = (dosomething_helpers_extract_field_data($this->node->field_mobile_app_date));
355+
356+
dosomething_helpers_convert_date($timing);
357+
358+
return $timing;
359+
}
360+
361+
338362
/**
339363
* Get Reportback content info used in the campaign.
340364
*
@@ -446,14 +470,7 @@ protected function getTiming() {
446470
$timing['high_season'] = dosomething_helpers_extract_field_data($this->node->field_high_season);
447471
$timing['low_season'] = dosomething_helpers_extract_field_data($this->node->field_low_season);
448472

449-
foreach ($timing as $season => $dates) {
450-
if ($timing[$season]) {
451-
foreach ($timing[$season] as $key => $date) {
452-
$date = new DateTime($date, $timezone);
453-
$timing[$season][$key] = $date->format(DateTime::ISO8601);
454-
}
455-
}
456-
}
473+
dosomething_helpers_convert_date($timing);
457474

458475
return $timing;
459476
}

lib/modules/dosomething/dosomething_helpers/dosomething_helpers.module

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,20 @@ function dosomething_helpers_menu() {
4949
return $items;
5050
}
5151

52+
/**
53+
* Utility function to convert dates to ISO-8601 datetime.
54+
*/
55+
function dosomething_helpers_convert_date($timing) {
56+
foreach ($timing as $season => $dates) {
57+
if ($timing[$season]) {
58+
foreach ($timing[$season] as $key => $date) {
59+
$date = new DateTime($date, $timezone);
60+
$timing[$season][$key] = $date->format(DateTime::ISO8601);
61+
}
62+
}
63+
}
64+
}
65+
5266
/**
5367
* Utility function to delete automated test data.
5468
*/

0 commit comments

Comments
 (0)