Switch mentors to only be "edit" instead of "add and edit"

If a id exists, it is updated
If no id exists, it is created

edit now returns the full mentor view array
This commit is contained in:
james 2011-03-02 17:18:13 +00:00
parent e538262cc6
commit 46f292ba16
2 changed files with 34 additions and 44 deletions

66
api.php
View File

@ -981,8 +981,9 @@ switch($request[0]) {
break;
/* APIDOC: project/view
description(Displays the current project information. project array: project_id integer, projectdivisions_id integer, title varchar(255), language char(2), req_electricity enum('no', 'yes'), req_table enum('no', 'yes'), req_special varchar(128), summary text)
description(Displays the current project information)
return(project array)
object(project: {project_id integer, projectdivisions_id integer, title varchar(255), language char(2), req_electricity enum('no', 'yes'), req_table enum('no', 'yes'), req_special varchar(128), summary text})
*/
case 'view':
if($u=user_load($_SESSION['users_id'])) {
@ -1003,7 +1004,7 @@ switch($request[0]) {
break;
/* APIDOC: project/edit
post(project array)
description(Edit an existing project. "language" notes the language a participant wishes to be judged in. "req_electricity" notes whethor or not the project requires an electrical outlet. "req_table" states whether or not the project needs a table. "req_special" is a field for special requirements. project array: project_id integer, projectdivisions_id integer, title varchar(255), language char(2), req_electricity enum('no', 'yes'), req_table enum('no', 'yes'), req_special varchar(128), summary text)
description(Edit an existing project. "language" notes the language a participant wishes to be judged in. "req_electricity" notes whethor or not the project requires an electrical outlet. "req_table" states whether or not the project needs a table. "req_special" is a field for special requirements.)
return(project array)
*/
case 'edit':
@ -1069,48 +1070,12 @@ switch($request[0]) {
case 'mentor':
switch($request[2]){
/* APIDOC: project/mentor/add
description(add a project mentor to the current project)
post(mentors array of mentor arrays optional)
return(mentor array (if none passed in, otherwise nothing))
*/
case 'add':
if(!array_key_exists('registration_id', $_SESSION)){
$ret['status'] = "error";
$ret['error'] = 'current user not associated with a project';
break;
}
if($_POST['mentors']) {
$mentors = json_decode($_POST['mentors'],true);
$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'] = '(' . implode('), (', $errors) . ')';
}
} else {
$result = addMentor($_SESSION['registration_id']);
if(is_array($result)){
$ret['status'] = 'ok';
$ret['mentor'] = $result;
}else{
$ret['status'] = 'error';
$ret['error'] = $result;
}
}
break;
/* APIDOC: project/mentor/edit
post(mentors array of mentor arrays)
description(edit a list of project mentors)
object(mentor: {id,registrations_id,firstname,lastname,email,phone,organization,position,description})
object(mentors: {mentor,...})
description(edit a list of project mentors or add new ones if a mentor array has no id)
return(mentors array of mentor arrays)
*/
case 'edit':
if(!array_key_exists('mentors', $_POST)){
@ -1120,16 +1085,29 @@ switch($request[0]) {
}
$errors = array();
$mentorList = json_decode($_POST['mentors'],true);
if(!$is_array($mentorList)) {
$ret['status'] = "error";
$ret['error'] = "mentors array parameter must be an array of mentors (or an empty array if no mentors)";
break;
}
foreach($mentorList as $mentor){
if(!is_array($mentor)){
$errors[] = "Invalid mentor data: $mentor";
continue;
}
$result = saveMentorData($mentor);
if($mentor['id']) {
$result = saveMentorData($mentor);
}
else {
$result = addMentor($_SESSION['registration_id']);
$mentor['id']=$result['id'];
$result = saveMentorData($mentor);
}
if($result != 'ok') $errors[] = $result;
}
if(!count($errors)){
$ret['status'] = 'ok';
$ret['mentors']= getMentors($_SESSION['registration_id']);
}else{
$ret['status'] = 'error';
$ret['error'] = '(' . implode('), (', $errors) . ')';
@ -1157,7 +1135,7 @@ switch($request[0]) {
/* APIDOC: project/mentor/view
description(list project mentors)
return(mentors array)
return(mentors array of mentor arrays)
*/
case 'view':
if(!array_key_exists('registration_id', $_SESSION)){

View File

@ -35,6 +35,10 @@ $nicommands=array();
$returns=explode(",",$matches[1]);
$cmd['return']=$returns;
}
if($incmd==true && preg_match("/object\((.*)\)/",$line,$matches)) {
$objects=explode(":",$matches[1],2);
$cmd['object'][]=$objects;
}
if($incmd==true && $line=="notimplemented") {
$cmd['implemented']=false;
}
@ -95,6 +99,14 @@ foreach($commands AS $c=>$com) {
}
echo "</ul>";
}
if(count($com['object'])) {
echo "<h3>Objects Referenced</h3>\n";
echo "<ul>";
foreach($com['object'] AS $o) {
echo "<li><b>{$o[0]}</b>: {$o[1]}</li>\n";
}
echo "</ul>";
}
echo "<br />";
echo "</div>";
}