Skip to content

Commit

Permalink
Start fetching task types from the API
Browse files Browse the repository at this point in the history
Instead of having them hardcoded
  • Loading branch information
anarute committed Jul 20, 2023
1 parent 29141d2 commit 02c5cf6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 30 deletions.
13 changes: 7 additions & 6 deletions web/services/WebServicesFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,25 @@ function authenticate($login, $sid = NULL)
function makeAPIRequest($path, $params = null, $method = 'GET', $data = null)
{
$requestUri = ConfigurationParametersManager::getParameter('API_BASE_URL') . $path;
$api_token = $_SESSION['api_token'];

if ($params) {
$requestUri .= '?' . http_build_query($params);
}
$ch = curl_init();

// TODO add Bearer Token
$headers = array(
"Content-type: application/json",
"Authorization: Bearer " . $api_token,
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $requestUri);
curl_setopt($ch, CURLOPT_SSH_COMPRESSION, true);

if ($method == 'POST') {
$headers = array(
"Content-type: application/json",
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
}

curl_setopt_array($ch, [
Expand Down
33 changes: 9 additions & 24 deletions web/services/getTaskTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/

define('PHPREPORT_ROOT', __DIR__ . '/../../');
include_once(PHPREPORT_ROOT . '/web/services/WebServicesFunctions.php');

$sid = $_GET['sid'] ?? NULL;

Expand Down Expand Up @@ -54,31 +55,15 @@
break;
}

// Hard-coded data
$response['success'] = true;
$response['records'] = array(
array('value' => 'administration', 'displayText' => 'Administration', 'active' => true),
array('value' => 'analysis', 'displayText' => 'Analysis', 'active' => true),
array('value' => 'community', 'displayText' => 'Community', 'active' => true),
array('value' => 'coordination', 'displayText' => 'Coordination', 'active' => true),
array('value' => 'demonstration', 'displayText' => 'Demonstration', 'active' => true),
array('value' => 'deployment', 'displayText' => 'Deployment', 'active' => true),
array('value' => 'design', 'displayText' => 'Design', 'active' => true),
array('value' => 'documentation', 'displayText' => 'Documentation', 'active' => true),
array('value' => 'environment', 'displayText' => 'Environment', 'active' => true),
array('value' => 'implementation', 'displayText' => 'Implementation', 'active' => true),
array('value' => 'maintenance', 'displayText' => 'Maintenance', 'active' => true),
array('value' => 'publication', 'displayText' => 'Publication', 'active' => false),
array('value' => 'requirements', 'displayText' => 'Requirements', 'active' => true),
array('value' => 'sales', 'displayText' => 'Sales', 'active' => true),
array('value' => 'sys_maintenance', 'displayText' => 'Systems maintenance', 'active' => true),
array('value' => 'teaching', 'displayText' => 'Teaching', 'active' => true),
array('value' => 'technology', 'displayText' => 'Technology', 'active' => true),
array('value' => 'test', 'displayText' => 'Test', 'active' => true),
array('value' => 'training', 'displayText' => 'Training', 'active' => true),
array('value' => 'traveling', 'displayText' => 'Traveling', 'active' => true),
array('value' => 'deprecated_type', 'displayText' => 'Deprecated Type', 'active' => false),
);
$taskTypes = makeAPIRequest("/v1/timelog/task_types/");
$response['records'] = array_map(function ($item) {
return array(
'value' => $item->slug,
'displayText' => $item->name,
'active' => $item->active
);
}, $taskTypes);

} while (False);

Expand Down

0 comments on commit 02c5cf6

Please sign in to comment.