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

Commit 6064278

Browse files
committed
adds params and shallow load logic back in
1 parent 02c1248 commit 6064278

File tree

7 files changed

+58
-8
lines changed

7 files changed

+58
-8
lines changed

lib/modules/dosomething/dosomething_api/resources/reportback_item_resource.inc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ function _reportback_item_resource_definition() {
7575
'source' => array('param' => 'page'),
7676
'default value' => 1,
7777
),
78+
array(
79+
'name' => 'load_user',
80+
'description' => 'Flag to indicate whether to make call to northstar to retrieve full user data.',
81+
'optional' => TRUE,
82+
'type' => 'boolean',
83+
'source' => array('param' => 'load_user'),
84+
'default value' => FALSE,
85+
),
7886
),
7987
'access callback' => '_reportback_item_resource_access',
8088
'access arguments' => array('index'),
@@ -108,13 +116,14 @@ function _reportback_item_resource_access($op) {
108116
}
109117

110118

111-
function _reportback_item_resource_index($campaigns, $status, $count, $random, $page) {
119+
function _reportback_item_resource_index($campaigns, $status, $count, $random, $page, $load_user) {
112120
$parameters = array(
113121
'campaigns' => $campaigns,
114122
'status' => $status,
115123
'count' => $count,
116124
'random' => $random,
117125
'page' => $page,
126+
'load_user' => $load_user,
118127
);
119128

120129
$reportbackItems = new ReportbackItemTransformer;

lib/modules/dosomething/dosomething_api/resources/reportback_resource.inc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ function _reportback_resource_definition() {
7575
'source' => array('param' => 'page'),
7676
'default value' => 1,
7777
),
78+
array(
79+
'name' => 'load_user',
80+
'description' => 'Flag to indicate whether to make call to northstar to retrieve full user data.',
81+
'optional' => TRUE,
82+
'type' => 'boolean',
83+
'source' => array('param' => 'load_user'),
84+
'default value' => FALSE,
85+
),
7886
),
7987
'access callback' => '_reportback_resource_access',
8088
'access arguments' => array('index'),
@@ -108,13 +116,14 @@ function _reportback_resource_access($op) {
108116
}
109117

110118

111-
function _reportback_resource_index($campaigns, $status, $count, $random, $page) {
119+
function _reportback_resource_index($campaigns, $status, $count, $random, $page, $load_user) {
112120
$parameters = array(
113121
'campaigns' => $campaigns,
114122
'status' => $status,
115123
'count' => $count,
116124
'random' => $random,
117125
'page' => $page,
126+
'load_user' => $load_user,
118127
);
119128

120129
$reportbacks = new ReportbackTransformer;

lib/modules/dosomething/dosomething_northstar/dosomething_northstar.module

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,21 +128,33 @@ function dosomething_northstar_update_user($form_state) {
128128
}
129129

130130
/**
131-
*Get user data from northstar.
131+
* Get user data from northstar.
132+
*
133+
* @param int $id Drupal user id.
134+
* @return object
132135
*/
133136
function dosomething_northstar_get_northstar_user($id) {
134-
if (!empty($northstar_user_info)) {
135-
$northstar_user_info = cache_get('northstar_user_info_' . $id, 'cache_northstar_user_info');
136-
} else {
137+
$northstar_user_info = cache_get('northstar_user_info_' . $id, 'cache_northstar_user_info');
138+
$northstar_user_info = $northstar_user_info->data;
139+
140+
if (empty($northstar_user_info)) {
137141
$client = _dosomething_northstar_build_http_client();
138142

139143
$northstar_user_info = drupal_http_request($client['base_url'] . '/users/drupal_id/' . $id, array(
140144
'headers' => $client['headers'],
141145
'method' => 'GET',
142146
));
143147

144-
cache_set('northstar_user_info_' . $id, $northstar_user_info, 'cache_northstar_user_info', REQUEST_TIME + 60*60*24);
148+
$northstar_user_info = $northstar_user_info->data;
149+
150+
if (!empty($northstar_user_info->error)) {
151+
$error = sprintf("Error fetching Northstar user data, uid=%d: '%s'", $id, $northstar_user_info->error);
152+
watchdog_exception('northstar', new Exception($error));
153+
} else {
154+
cache_set('northstar_user_info_' . $id, $northstar_user_info, 'cache_northstar_user_info', REQUEST_TIME + 60*60*24);
155+
}
145156
}
157+
146158
return $northstar_user_info;
147159
}
148160

lib/modules/dosomething/dosomething_reportback/includes/Reportback.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,15 @@ private function build($data, $full = false) {
169169
}
170170
}
171171

172+
// $this->user = [
173+
// 'drupal_id' => $data->uid,
174+
// 'id' => dosomething_helpers_isset($northstar_user->_id),
175+
// 'first_name' => dosomething_helpers_isset($northstar_user->first_name),
176+
// 'last_name' => dosomething_helpers_isset($northstar_user->last_name),
177+
// 'photo' => dosomething_helpers_isset($northstar_user->photo),
178+
// 'country' => dosomething_helpers_isset($northstar_user->country),
179+
// ];
180+
172181
$this->user = [
173182
'drupal_id' => $data->uid,
174183
'id' => (empty($northstar_user->_id)) ? NULL : $northstar_user->_id,

lib/modules/dosomething/dosomething_reportback/includes/ReportbackItem.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public static function find(array $filters = []) {
8080
$reportbackItem = new static(['ignore' => true]);
8181
$reportbackItem->build($item, $load_user);
8282

83-
$reportbacks[] = $reportback;
83+
$reportbackItems[] = $reportbackItem;
8484
}
8585

8686
return $reportbackItems;
@@ -127,6 +127,15 @@ private function build($data, $full = false) {
127127
}
128128
}
129129

130+
// $this->user = [
131+
// 'drupal_id' => $data->uid,
132+
// 'id' => dosomething_helpers_isset($northstar_user->_id),
133+
// 'first_name' => dosomething_helpers_isset($northstar_user->first_name),
134+
// 'last_name' => dosomething_helpers_isset($northstar_user->last_name),
135+
// 'photo' => dosomething_helpers_isset($northstar_user->photo),
136+
// 'country' => dosomething_helpers_isset($northstar_user->country),
137+
// ];
138+
130139
$this->user = [
131140
'drupal_id' => $data->uid,
132141
'id' => (empty($northstar_user->_id)) ? NULL : $northstar_user->_id,

lib/modules/dosomething/dosomething_reportback/includes/ReportbackItemTransformer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public function index($parameters) {
2020
// Not ideal that this is NULL instead of FALSE but due to how logic happens in original query function. It should be updated!
2121
// Logic currently checks for isset() instead of just boolean, so won't change until endpoints switched.
2222
$filters['random'] = $parameters['random'] === 'true' ? TRUE : NULL;
23+
$filters['load_user'] = $parameters['load_user'] === 'true' ? TRUE : NULL;
2324

2425
try {
2526
$reportbackItems = ReportbackItem::find($filters);

lib/modules/dosomething/dosomething_reportback/includes/ReportbackTransformer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public function index($parameters) {
4343
// Not ideal that this is NULL instead of FALSE but due to how logic happens in original query function. It should be updated!
4444
// Logic currently checks for isset() instead of just boolean, so won't change until endpoints switched.
4545
$filters['random'] = $parameters['random'] === 'true' ? TRUE : NULL;
46+
$filters['load_user'] = $parameters['load_user'] === 'true' ? TRUE : NULL;
4647

4748
try {
4849
$reportbacks = Reportback::find($filters);

0 commit comments

Comments
 (0)