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]){
/* APIDOC: project/mentor/add
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))
*/
case 'add':
@ -1078,18 +1078,23 @@ switch($request[0]) {
break;
}
$result = addMentor($_SESSION['registration_id']);
if($_POST['mentor']) {
$md=json_decode($_POST['mentor']);
$md['id']=$result['id'];
$result = saveMentorData($md);
if($result == 'ok'){
if($_POST['mentors']) {
$mentors = json_decode($_POST['mentors']);
$errors = array();
foreach($mentors as $md){
$result = addMentor($_SESSION['registration_id']);
$md['id']=$result['id'];
$result = saveMentorData($md);
if($result != 'ok') $errors[] = $result;
}
if(!count($errors)){
$ret['status'] = 'ok';
}else{
$ret['status'] = 'error';
$ret['error'] = $result;
$ret['error'] = '(' . implode('), (', $errors) . ')';
}
} else {
$result = addMentor($_SESSION['registration_id']);
if(is_array($result)){
$ret['status'] = 'ok';
$ret['mentor'] = $result;
@ -1101,21 +1106,30 @@ switch($request[0]) {
break;
/* APIDOC: project/mentor/edit
post(mentor array)
description(edit a project mentor)
post(mentors array)
description(edit a list of project mentors)
*/
case 'edit':
if(!array_key_exists('mentor', $_POST)){
if(!array_key_exists('mentors', $_POST)){
$ret['status'] = "error";
$ret['error'] = "mentor array parameter required";
$ret['error'] = "mentors array parameter required";
break;
}
$result = saveMentorData(json_decode($_POST['mentor']));
if($result == 'ok'){
$errors = array();
$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';
}else{
$ret['status'] = 'error';
$ret['error'] = $result;
$ret['error'] = '(' . implode('), (', $errors) . ')';
}
break;