Updated the api for api/project/mentor/add and api/project/mentor/edit. Both now accept an array of

mentor arrays (now referred to as 'mentors' instead of 'mentor').  /edit will only accept an array,
but /add will accept that or no parameters to generate a fresh empty record.
This commit is contained in:
jacob 2011-03-01 19:57:05 +00:00
parent 3419f06b0b
commit e10d31f2c8

44
api.php
View File

@ -1068,7 +1068,7 @@ switch($request[0]) {
switch($request[2]){ switch($request[2]){
/* APIDOC: project/mentor/add /* APIDOC: project/mentor/add
description(add a project mentor to the current project) description(add a project mentor to the current project)
post(mentor array optional) post(mentors array optional)
return(mentor array (if none passed in, otherwise nothing)) return(mentor array (if none passed in, otherwise nothing))
*/ */
case 'add': case 'add':
@ -1078,18 +1078,23 @@ switch($request[0]) {
break; break;
} }
$result = addMentor($_SESSION['registration_id']); if($_POST['mentors']) {
if($_POST['mentor']) { $mentors = json_decode($_POST['mentors']);
$md=json_decode($_POST['mentor']); $errors = array();
$md['id']=$result['id']; foreach($mentors as $md){
$result = saveMentorData($md); $result = addMentor($_SESSION['registration_id']);
if($result == 'ok'){ $md['id']=$result['id'];
$result = saveMentorData($md);
if($result != 'ok') $errors[] = $result;
}
if(!count($errors)){
$ret['status'] = 'ok'; $ret['status'] = 'ok';
}else{ }else{
$ret['status'] = 'error'; $ret['status'] = 'error';
$ret['error'] = $result; $ret['error'] = '(' . implode('), (', $errors) . ')';
} }
} else { } else {
$result = addMentor($_SESSION['registration_id']);
if(is_array($result)){ if(is_array($result)){
$ret['status'] = 'ok'; $ret['status'] = 'ok';
$ret['mentor'] = $result; $ret['mentor'] = $result;
@ -1101,21 +1106,30 @@ switch($request[0]) {
break; break;
/* APIDOC: project/mentor/edit /* APIDOC: project/mentor/edit
post(mentor array) post(mentors array)
description(edit a project mentor) description(edit a list of project mentors)
*/ */
case 'edit': case 'edit':
if(!array_key_exists('mentor', $_POST)){ if(!array_key_exists('mentors', $_POST)){
$ret['status'] = "error"; $ret['status'] = "error";
$ret['error'] = "mentor array parameter required"; $ret['error'] = "mentors array parameter required";
break; break;
} }
$result = saveMentorData(json_decode($_POST['mentor'])); $errors = array();
if($result == 'ok'){ $mentorList = json_decode($_POST['mentors']);
foreach($mentorList as $mentor){
if(!is_array($mentor)){
$errors[] = "Invalid mentor data: $mentor";
continue;
}
$result = saveMentorData($mentor);
if($result != 'ok') $errors[] = $result;
}
if(!count($errors)){
$ret['status'] = 'ok'; $ret['status'] = 'ok';
}else{ }else{
$ret['status'] = 'error'; $ret['status'] = 'error';
$ret['error'] = $result; $ret['error'] = '(' . implode('), (', $errors) . ')';
} }
break; break;