forked from science-ation/science-ation
allow project/add and project/mentor/add to pass in an corresponding input array, and save that into the newly created project/mentor
This commit is contained in:
parent
2eeff8d688
commit
69bc561055
66
api.php
66
api.php
@ -919,7 +919,8 @@ switch($request[0]) {
|
||||
*/
|
||||
switch($request[1]){
|
||||
/* APIDOC: project/add
|
||||
description(add a project)
|
||||
post(project array optional)
|
||||
description(add a project. Will create a blank project if there's no input, otherwise, creates a project based on the project array passed in)
|
||||
return(project array)
|
||||
*/
|
||||
case 'add':
|
||||
@ -940,18 +941,40 @@ switch($request[0]) {
|
||||
}
|
||||
|
||||
// now we add a project to that registration
|
||||
$project = addProject($regdat['registrations_id']);
|
||||
if(!is_array($project)){
|
||||
$newproject = addProject($regdat['registrations_id']);
|
||||
if(!is_array($newproject)){
|
||||
$ret['status'] = 'error';
|
||||
$ret['error'] = $project;
|
||||
$ret['error'] = $newproject;
|
||||
break;
|
||||
}
|
||||
|
||||
// if we got this far, then all's good and we can return the project data
|
||||
$_SESSION['registration_id'] = $regdat['registrations_id'];
|
||||
$_SESSION['registration_number'] = $regdat['registration_number'];
|
||||
$ret['status'] = 'ok';
|
||||
$ret['project'] = getProject($_SESSION['users_id']);
|
||||
|
||||
if($_POST['project']) {
|
||||
$project=json_decode($_POST['project'],true);
|
||||
if(!is_array($project)) {
|
||||
$ret['status']="error";
|
||||
$ret['error']="project needs to be a project array";
|
||||
break;
|
||||
}
|
||||
$project['id']=$newproject['id'];
|
||||
|
||||
$message = saveProjectData($project);
|
||||
if($message == 'success'){
|
||||
$ret['status'] = 'ok';
|
||||
$ret['project'] = getProject($_SESSION['users_id']);
|
||||
}else{
|
||||
$ret['status'] = 'error';
|
||||
$ret['error'] = $message;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$ret['status'] = 'ok';
|
||||
$ret['project'] = getProject($_SESSION['users_id']);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
/* APIDOC: project/view
|
||||
@ -1045,7 +1068,8 @@ switch($request[0]) {
|
||||
switch($request[2]){
|
||||
/* APIDOC: project/mentor/add
|
||||
description(add a project mentor to the current project)
|
||||
return(mentor array)
|
||||
post(mentor array optional)
|
||||
return(mentor array (if none passed in, otherwise nothing))
|
||||
*/
|
||||
case 'add':
|
||||
if(!array_key_exists('registration_id', $_SESSION)){
|
||||
@ -1055,23 +1079,35 @@ switch($request[0]) {
|
||||
}
|
||||
|
||||
$result = addMentor($_SESSION['registration_id']);
|
||||
if(is_array($result)){
|
||||
$ret['status'] = 'ok';
|
||||
$ret['mentor'] = $result;
|
||||
}else{
|
||||
$ret['status'] = 'error';
|
||||
$ret['error'] = $result;
|
||||
if($_POST['mentor']) {
|
||||
$md=json_decode($_POST['mentor']);
|
||||
$md['id']=$result['id'];
|
||||
$result = saveMentorData($md);
|
||||
if($result == 'ok'){
|
||||
$ret['status'] = 'ok';
|
||||
}else{
|
||||
$ret['status'] = 'error';
|
||||
$ret['error'] = $result;
|
||||
}
|
||||
} else {
|
||||
if(is_array($result)){
|
||||
$ret['status'] = 'ok';
|
||||
$ret['mentor'] = $result;
|
||||
}else{
|
||||
$ret['status'] = 'error';
|
||||
$ret['error'] = $result;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
/* APIDOC: project/mentor/edit
|
||||
post(mentor object)
|
||||
post(mentor array)
|
||||
description(edit a project mentor)
|
||||
*/
|
||||
case 'edit':
|
||||
if(!array_key_exists('mentor', $_POST)){
|
||||
$ret['status'] = "error";
|
||||
$ret['error'] = "mentor object parameter required";
|
||||
$ret['error'] = "mentor array parameter required";
|
||||
break;
|
||||
}
|
||||
$result = saveMentorData(json_decode($_POST['mentor']));
|
||||
|
@ -245,6 +245,10 @@ This section is for project/registration related functions **/
|
||||
|
||||
function saveProjectData($data){
|
||||
global $conference, $config;
|
||||
|
||||
//inconsistency here, we give the objecet to them with an "id" but we expect a "project_id" back
|
||||
if($data['id'] && !$data['project_id']) $data['project_id']=$data['id'];
|
||||
|
||||
$requiredFields = array('project_id', 'title', 'projectdivisions_id', 'language');
|
||||
if($config['participant_short_title_enable'] == 'yes')
|
||||
$requiredFields[] = 'shorttitle';
|
||||
@ -423,7 +427,8 @@ function getProject($userId){
|
||||
// relationship in projects to registrations (so remove that LIMIT 1)
|
||||
$fields = implode(',', array(
|
||||
'projects.id',
|
||||
'registrations.num',
|
||||
'projects.id AS project_id',
|
||||
'registrations.num AS registration_number',
|
||||
'projects.projectdivisions_id',
|
||||
'projects.title',
|
||||
'projects.language',
|
||||
|
Loading…
x
Reference in New Issue
Block a user