Improve documentation in advsub ajax script - refs BT#9092

1.10.x
Daniel Barreto 11 years ago
parent 995b26dcec
commit 5576ccd2d1
  1. 49
      plugin/advancedsubscription/ajax/advsub.ajax.php

@ -12,7 +12,9 @@
require_once __DIR__ . '/../config.php';
$plugin = AdvancedSubscriptionPlugin::create();
// Get validation hash
$hash = Security::remove_XSS($_REQUEST['v']);
// Get data from request (GET or POST)
$data['a'] = Security::remove_XSS($_REQUEST['a']);
$data['s'] = intval($_REQUEST['s']);
$data['current_user_id'] = intval($_REQUEST['current_user_id']);
@ -21,9 +23,10 @@ $data['q'] = intval($_REQUEST['q']);
$data['e'] = intval($_REQUEST['e']);
$data['is_connected'] = isset($_REQUEST['is_connected']) ? boolval($_REQUEST['is_connected']) : false;
$data['profile_completed'] = isset($_REQUEST['profile_completed']) ? floatval($_REQUEST['profile_completed']) : 0;
$verified = $plugin->checkHash($data, $hash) || $data['a'] == 'subscribe';
// Init result array
$result = array('error' => true, 'errorMessage' => 'There was an error');
$result = array('error' => true, 'errorMessage' => get_lang('ThereWasAnError'));
// Check if data is valid or is for start subscription
$verified = $plugin->checkHash($data, $hash) || $data['a'] == 'subscribe';
if ($verified) {
switch($data['a']) {
case 'check': // Check minimum requirements
@ -42,10 +45,12 @@ if ($verified) {
}
break;
case 'subscribe': // Subscription
$bossId = UserManager::getStudentBoss($data['u']);
// Start subscription to queue
$res = AdvancedSubscriptionPlugin::create()->startSubscription($data['u'], $data['s'], $data);
// Check if queue subscription was successful
if ($res === true) {
// send mail to superior
// Prepare data
// Get session data
$sessionArray = api_get_session_info($data['s']);
$extraSession = new ExtraFieldValue('session');
$var = $extraSession->get_values_by_handler_and_field_variable($data['s'], 'description');
@ -58,20 +63,24 @@ if ($verified) {
$sessionArray['publication_end_date'] = $var['field_value'];
$var = $extraSession->get_values_by_handler_and_field_variable($data['s'], 'recommended_number_of_participants');
$sessionArray['recommended_number_of_participants'] = $var['field_valiue'];
// Get student data
$studentArray = api_get_user_info($data['u']);
$studentArray['picture'] = UserManager::get_user_picture_path_by_id($studentArray['user_id'], 'web', false, true);
$studentArray['picture'] = UserManager::get_picture_user($studentArray['user_id'], $studentArray['picture']['file'], 22, USER_IMAGE_SIZE_MEDIUM);
// Get superior data if exist
$superiorId = UserManager::getStudentBoss($data['u']);
if (!empty($superiorId)) {
$superiorArray = api_get_user_info($superiorId);
} else {
$superiorArray = null;
}
// Get admin data
$adminsArray = UserManager::get_all_administrators();
foreach ($adminsArray as &$admin) {
$admin['complete_name'] = $admin['lastname'] . ', ' . $admin['firstname'];
}
unset($admin);
// Set data
$data['a'] = 'confirm';
$data['student'] = $studentArray;
$data['superior'] = $superiorArray;
@ -79,15 +88,23 @@ if ($verified) {
$data['session'] = $sessionArray;
$data['signature'] = api_get_setting('Institution');
if (empty($superiorId)) { // Does not have boss
// Check if student boss exists
if (empty($superiorId)) {
// Student boss does not exist
// Update status to accepted by boss
$res = $plugin->updateQueueStatus($data, ADV_SUB_QUEUE_STATUS_BOSS_APPROVED);
if (!empty($res)) {
$data['admin_view_url'] = api_get_path(WEB_PLUGIN_PATH) . 'advancedsubscription/src/admin_view.php?s=' . $data['s'];
// Prepare admin url
$data['admin_view_url'] = api_get_path(WEB_PLUGIN_PATH) .
'advancedsubscription/src/admin_view.php?s=' . $data['s'];
// Send mails
$result['mailIds'] = $plugin->sendMail($data, ADV_SUB_ACTION_STUDENT_REQUEST_NO_BOSS);
// Check if mails were sent
if (!empty($result['mailIds'])) {
$result['error'] = false;
$result['errorMessage'] = 'No error';
$result['pass'] = true;
// Check if exist an email to render
if (isset($result['mailIds']['render'])) {
// Render mail
$message = MessageManager::get_message_by_id($result['mailIds']['render']);
@ -98,15 +115,21 @@ if ($verified) {
}
}
} else {
// Student boss does exist
// Get url to be accepted by boss
$data['e'] = ADV_SUB_QUEUE_STATUS_BOSS_APPROVED;
$data['student']['acceptUrl'] = $plugin->getQueueUrl($data);
// Get url to be rejected by boss
$data['e'] = ADV_SUB_QUEUE_STATUS_BOSS_DISAPPROVED;
$data['student']['rejectUrl'] = $plugin->getQueueUrl($data);
// Send mails
$result['mailIds'] = $plugin->sendMail($data, ADV_SUB_ACTION_STUDENT_REQUEST);
// Check if mails were sent
if (!empty($result['mailIds'])) {
$result['error'] = false;
$result['errorMessage'] = 'No error';
$result['pass'] = true;
// Check if exist an email to render
if (isset($result['mailIds']['render'])) {
// Render mail
$message = MessageManager::get_message_by_id($result['mailIds']['render']);
@ -127,9 +150,13 @@ if ($verified) {
break;
case 'confirm':
// Check if is set new status
if (isset($data['e'])) {
// Update queue status
$res = $plugin->updateQueueStatus($data, $data['e']);
if ($res === true) {
// Prepare data
// Prepare session data
$sessionArray = api_get_session_info($data['s']);
$extraSession = new ExtraFieldValue('session');
$var = $extraSession->get_values_by_handler_and_field_variable($data['s'], 'description');
@ -142,27 +169,33 @@ if ($verified) {
$sessionArray['publication_end_date'] = $var['field_value'];
$var = $extraSession->get_values_by_handler_and_field_variable($data['s'], 'recommended_number_of_participants');
$sessionArray['recommended_number_of_participants'] = $var['field_valiue'];
// Prepare student data
$studentArray = api_get_user_info($data['u']);
$studentArray['picture'] = UserManager::get_user_picture_path_by_id($studentArray['user_id'], 'web', false, true);
$studentArray['picture'] = UserManager::get_picture_user($studentArray['user_id'], $studentArray['picture']['file'], 22, USER_IMAGE_SIZE_MEDIUM);
// Prepare superior data
$superiorId = UserManager::getStudentBoss($data['u']);
if (!empty($superiorId)) {
$superiorArray = api_get_user_info($superiorId);
} else {
$superiorArray = null;
}
// Prepare admin data
$adminsArray = UserManager::get_all_administrators();
foreach ($adminsArray as &$admin) {
$admin['complete_name'] = $admin['lastname'] . ', ' . $admin['firstname'];
}
unset($admin);
// Set data
$data['student'] = $studentArray;
$data['superior'] = $superiorArray;
$data['admins'] = $adminsArray;
$data['session'] = $sessionArray;
$data['signature'] = api_get_setting('Institution');
$data['admin_view_url'] = api_get_path(WEB_PLUGIN_PATH) . 'advancedsubscription/src/admin_view.php?s=' . $data['s'];
// Check if exist and action in data
if (empty($data['action'])) {
// set action in data by new status
switch ($data['e']) {
case ADV_SUB_QUEUE_STATUS_BOSS_APPROVED:
$data['action'] = ADV_SUB_ACTION_SUPERIOR_APPROVE;
@ -186,10 +219,13 @@ if ($verified) {
SessionManager::suscribe_users_to_session($data['s'], array($data['u']), null, false);
}
// Send mails
$result['mailIds'] = $plugin->sendMail($data, $data['action']);
// Check if mails were sent
if (!empty($result['mailIds'])) {
$result['error'] = false;
$result['errorMessage'] = 'User has been processed';
// Check if exist mail to render
if (isset($result['mailIds']['render'])) {
// Render mail
$message = MessageManager::get_message_by_id($result['mailIds']['render']);
@ -208,4 +244,5 @@ if ($verified) {
}
}
// Echo result as json
echo json_encode($result);

Loading…
Cancel
Save