forked from science-ation/science-ation
A start on adding the special awards API
This commit is contained in:
parent
95bbdab5f6
commit
b9fbc56372
32
api.php
32
api.php
@ -28,6 +28,7 @@ require_once("account.inc.php");
|
||||
require_once("user.inc.php");
|
||||
require_once("schedule.inc.php");
|
||||
require_once("register_participants.inc.php");
|
||||
require_once("projects.inc.php");
|
||||
if($_SERVER['HTTPS']!="on" && !$API_DONT_REQUIRE_SSL) {
|
||||
$ret['status']="error";
|
||||
$ret['error']="SSL is required for API access, please access the API over https";
|
||||
@ -1143,6 +1144,37 @@ switch($request[0]) {
|
||||
$ret['status'] = 'ok';
|
||||
break;
|
||||
|
||||
case 'specialawards':
|
||||
switch($request[2]){
|
||||
/* APIDOC: project/specialawards/view
|
||||
description(view the special awards available, flagged as whether or not they're selected for this user's project.)
|
||||
*/
|
||||
case 'view':
|
||||
$u = user_load($_SESSION['users_id']);
|
||||
$projectId = getProjectId($u['registrations_id']);
|
||||
if($projectId !== null){
|
||||
$ret['status'] = 'ok';
|
||||
$ret['awards'] = getAwardListing($projectId);
|
||||
}else{
|
||||
$ret['status'] = 'error';
|
||||
$ret['error'] = 'could not load project for registriation id #' . $u['registrations_id'];
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
/* APIDOC: project/specialawards/edit
|
||||
description:(update the special awards assigned to this project)
|
||||
post(awards array)
|
||||
description(expects an array in the
|
||||
*/
|
||||
case 'edit':
|
||||
//$nominations = json_decode($_POST['awards'], true);
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
case 'mentor':
|
||||
switch($request[2]){
|
||||
/* APIDOC: project/mentor/edit
|
||||
|
@ -307,4 +307,31 @@ function getProjectCategory($registrations_id){
|
||||
return $projectcategories_id;
|
||||
}
|
||||
|
||||
function getProjectId($registrations_id){
|
||||
$returnval = null;
|
||||
$q = mysql_query("SELECT id FROM projects WHERE registrations_id = " . intval($registrations_id));
|
||||
$row = mysql_fetch_assoc($q);
|
||||
if($row){
|
||||
$returnval = $row['id'];
|
||||
}
|
||||
return $returnval;
|
||||
}
|
||||
|
||||
function getAwardListing($project_id){
|
||||
$returnval = array();
|
||||
$eligibleAwards = getSpecialAwardsEligibleForProject($projectId);
|
||||
$nominatedawards = getSpecialAwardsNominatedForProject($projectId);
|
||||
$nominatedawards_list=array();
|
||||
foreach($nominatedawards AS $naward){
|
||||
$nominatedawards_list[] = $naward['id'];
|
||||
}
|
||||
$idx = 0;
|
||||
foreach($eligibleAwards AS $eaward){
|
||||
$returnval[$idx] = $eaward;
|
||||
if(in_array($eaward['id'],$nominatedawards_list)) $returnval[$idx]['selected'] = true;
|
||||
$idx++;
|
||||
|
||||
}
|
||||
return $returnval;
|
||||
}
|
||||
?>
|
||||
|
Loading…
Reference in New Issue
Block a user