parent
a0d240855d
commit
5de2273999
@ -0,0 +1,146 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php'; |
||||
|
||||
if (api_get_configuration_value('allow_exercise_categories') === false) { |
||||
api_not_allowed(); |
||||
} |
||||
|
||||
api_protect_course_script(); |
||||
|
||||
if (!api_is_allowed_to_edit()) { |
||||
api_not_allowed(true); |
||||
} |
||||
|
||||
$interbreadcrumb[] = [ |
||||
'url' => api_get_path(WEB_CODE_PATH).'exercise/exercise.php?'.api_get_cidreq(), |
||||
'name' => get_lang('Exercises'), |
||||
]; |
||||
|
||||
$courseId = api_get_course_int_id(); |
||||
|
||||
$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_exercise_categories&c_id='.$courseId.'&'.api_get_cidreq(); |
||||
$action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : ''; |
||||
|
||||
$obj = new ExerciseCategoryManager(); |
||||
|
||||
$check = Security::check_token('request'); |
||||
$token = Security::get_token(); |
||||
|
||||
//Add the JS needed to use the jqgrid |
||||
$htmlHeadXtra[] = api_get_jqgrid_js(); |
||||
|
||||
//The order is important you need to check the the $column variable in the model.ajax.php file |
||||
$columns = [ |
||||
get_lang('Name'), |
||||
get_lang('Actions'), |
||||
]; |
||||
|
||||
// Column config |
||||
$column_model = [ |
||||
[ |
||||
'name' => 'name', |
||||
'index' => 'name', |
||||
'width' => '140', |
||||
'align' => 'left', |
||||
], |
||||
[ |
||||
'name' => 'actions', |
||||
'index' => 'actions', |
||||
'width' => '40', |
||||
'align' => 'left', |
||||
'formatter' => 'action_formatter', |
||||
'sortable' => 'false', |
||||
], |
||||
]; |
||||
|
||||
// Autowidth |
||||
$extra_params['autowidth'] = 'true'; |
||||
// height auto |
||||
$extra_params['height'] = 'auto'; |
||||
|
||||
$action_links = $obj->getJqgridActionLinks($token); |
||||
|
||||
$htmlHeadXtra[] = '<script> |
||||
$(function() { |
||||
// grid definition see the $obj->display() function |
||||
'.Display::grid_js( |
||||
'categories', |
||||
$url, |
||||
$columns, |
||||
$column_model, |
||||
$extra_params, |
||||
[], |
||||
$action_links, |
||||
true |
||||
).' |
||||
}); |
||||
</script>'; |
||||
|
||||
$url = api_get_self().'?'.api_get_cidreq(); |
||||
|
||||
switch ($action) { |
||||
case 'add': |
||||
$interbreadcrumb[] = ['url' => $url, 'name' => get_lang('Categories')]; |
||||
$interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Add')]; |
||||
$form = $obj->return_form($url.'&action=add', 'add'); |
||||
// The validation or display |
||||
if ($form->validate()) { |
||||
$values = $form->exportValues(); |
||||
unset($values['id']); |
||||
$res = $obj->save($values); |
||||
if ($res) { |
||||
Display::addFlash(Display::return_message(get_lang('ItemAdded'), 'confirmation')); |
||||
} |
||||
header('Location: '.$url); |
||||
exit; |
||||
} else { |
||||
$content = '<div class="actions">'; |
||||
$content .= '<a href="'.$url.'">'. |
||||
Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM).'</a>'; |
||||
$content .= '</div>'; |
||||
$form->addElement('hidden', 'sec_token'); |
||||
$form->setConstants(['sec_token' => $token]); |
||||
$content .= $form->returnForm(); |
||||
} |
||||
break; |
||||
case 'edit': |
||||
$interbreadcrumb[] = ['url' => $url, 'name' => get_lang('Categories')]; |
||||
$interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Edit')]; |
||||
$form = $obj->return_form($url.'&action=edit&id='.intval($_GET['id']), 'edit'); |
||||
|
||||
// The validation or display |
||||
if ($form->validate()) { |
||||
$values = $form->exportValues(); |
||||
$res = $obj->update($values); |
||||
if ($res) { |
||||
Display::addFlash(Display::return_message(get_lang('ItemUpdated'), 'confirmation')); |
||||
} |
||||
header('Location: '.$url); |
||||
exit; |
||||
} else { |
||||
$content = '<div class="actions">'; |
||||
$content .= '<a href="'.$url.'">'. |
||||
Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM).'</a>'; |
||||
$content .= '</div>'; |
||||
$form->addElement('hidden', 'sec_token'); |
||||
$form->setConstants(['sec_token' => $token]); |
||||
$content .= $form->returnForm(); |
||||
} |
||||
break; |
||||
case 'delete': |
||||
$res = $obj->delete($_GET['id']); |
||||
if ($res) { |
||||
Display::addFlash(Display::return_message(get_lang('ItemDeleted'), 'confirmation')); |
||||
} |
||||
header('Location: '.$url); |
||||
exit; |
||||
break; |
||||
default: |
||||
$content = $obj->display(); |
||||
break; |
||||
} |
||||
|
||||
Display::display_header(); |
||||
echo $content; |
@ -0,0 +1,268 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
use Chamilo\CourseBundle\Entity\CExerciseCategory; |
||||
|
||||
/** |
||||
* Class ExtraFieldValue |
||||
* Declaration for the ExtraFieldValue class, managing the values in extra |
||||
* fields for any data type. |
||||
* |
||||
* @package chamilo.library |
||||
*/ |
||||
class ExerciseCategoryManager extends Model |
||||
{ |
||||
public $type = ''; |
||||
public $columns = [ |
||||
'id', |
||||
'name', |
||||
'c_id', |
||||
'description', |
||||
'created_at', |
||||
'updated_at', |
||||
]; |
||||
|
||||
/** |
||||
* Formats the necessary elements for the given datatype. |
||||
* |
||||
* @param string $type The type of data to which this extra field |
||||
* applies (user, course, session, ...) |
||||
* |
||||
* @assert (-1) === false |
||||
*/ |
||||
public function __construct() |
||||
{ |
||||
parent::__construct(); |
||||
$this->is_course_model = true; |
||||
$this->table = Database::get_course_table('exercise_category'); |
||||
} |
||||
|
||||
/** |
||||
* Gets the number of values stored in the table (all fields together) |
||||
* for this type of resource. |
||||
* |
||||
* @param int $courseId |
||||
* |
||||
* @return int Number of rows in the table |
||||
*/ |
||||
public function getCourseCount($courseId) |
||||
{ |
||||
$em = Database::getManager(); |
||||
$query = $em->getRepository('ChamiloCourseBundle:CExerciseCategory')->createQueryBuilder('e'); |
||||
$query->select('count(e.id)'); |
||||
$query->where('e.cId = :cId'); |
||||
$query->setParameter('cId', $courseId); |
||||
|
||||
return $query->getQuery()->getSingleScalarResult(); |
||||
} |
||||
|
||||
/** |
||||
* @param int $courseId |
||||
* |
||||
* @return array |
||||
*/ |
||||
public function getCategories($courseId) |
||||
{ |
||||
$em = Database::getManager(); |
||||
$query = $em->getRepository('ChamiloCourseBundle:CExerciseCategory')->createQueryBuilder('e'); |
||||
$query->where('e.cId = :cId'); |
||||
$query->setParameter('cId', $courseId); |
||||
$query->orderBy('e.position'); |
||||
|
||||
return $query->getQuery()->getResult(); |
||||
} |
||||
|
||||
/** |
||||
* @param int $courseId |
||||
* |
||||
* @return array |
||||
*/ |
||||
public function getCategoriesForSelect($courseId) |
||||
{ |
||||
$categories = $this->getCategories($courseId); |
||||
$options = []; |
||||
|
||||
if (!empty($categories)) { |
||||
/** @var CExerciseCategory $category */ |
||||
foreach ($categories as $category) { |
||||
$options[$category->getId()] = $category->getName(); |
||||
} |
||||
} |
||||
|
||||
return $options; |
||||
} |
||||
|
||||
/** |
||||
* @param int $id |
||||
*/ |
||||
public function delete($id) |
||||
{ |
||||
$em = Database::getManager(); |
||||
$repo = Database::getManager()->getRepository('ChamiloCourseBundle:CExerciseCategory'); |
||||
$category = $repo->find($id); |
||||
if ($category) { |
||||
$em->remove($category); |
||||
$em->flush(); |
||||
|
||||
$courseId = api_get_course_int_id(); |
||||
$table = Database::get_course_table(TABLE_QUIZ_TEST); |
||||
$id = (int) $id; |
||||
|
||||
$sql = "UPDATE $table SET exercise_category_id = 0 |
||||
WHERE c_id = $courseId AND exercise_category_id = $id"; |
||||
Database::query($sql); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Save values in the *_field_values table. |
||||
* |
||||
* @param array $params Structured array with the values to save |
||||
* @param bool $showQuery Whether to show the insert query (passed to the parent save() method) |
||||
*/ |
||||
public function save($params, $showQuery = false) |
||||
{ |
||||
$courseId = api_get_course_int_id(); |
||||
$em = Database::getManager(); |
||||
$category = new CExerciseCategory(); |
||||
$category |
||||
->setName($params['name']) |
||||
->setCId(api_get_course_int_id()) |
||||
->setDescription($params['name']) |
||||
; |
||||
/* |
||||
// Update position |
||||
$query = $em->getRepository('ChamiloCourseBundle:CExerciseCategory')->createQueryBuilder('e'); |
||||
$query |
||||
->where('e.cId = :cId') |
||||
->setParameter('cId', $courseId) |
||||
->setMaxResults(1) |
||||
->orderBy('e.position', 'DESC'); |
||||
$last = $query->getQuery()->getOneOrNullResult(); |
||||
$position = 0; |
||||
if (!empty($last)) { |
||||
$position = $last->getPosition() + 1; |
||||
} |
||||
$category->setPosition($position); |
||||
*/ |
||||
$em->persist($category); |
||||
$em->flush(); |
||||
|
||||
return $category; |
||||
} |
||||
|
||||
/** |
||||
* @param $token |
||||
* |
||||
* @return string |
||||
*/ |
||||
public function getJqgridActionLinks($token) |
||||
{ |
||||
//With this function we can add actions to the jgrid (edit, delete, etc) |
||||
$editIcon = Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL); |
||||
$deleteIcon = Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL); |
||||
$confirmMessage = addslashes( |
||||
api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES) |
||||
); |
||||
|
||||
$courseParams = api_get_cidreq(); |
||||
|
||||
$editButton = <<<JAVASCRIPT |
||||
<a href="?action=edit&{$courseParams}&id=' + options.rowId + '" class="btn btn-link btn-xs">\ |
||||
$editIcon\ |
||||
</a> |
||||
JAVASCRIPT; |
||||
$deleteButton = <<<JAVASCRIPT |
||||
<a \ |
||||
onclick="if (!confirm(\'$confirmMessage\')) {return false;}" \ |
||||
href="?sec_token=$token&{$courseParams}&id=' + options.rowId + '&action=delete" \ |
||||
class="btn btn-link btn-xs">\ |
||||
$deleteIcon\ |
||||
</a> |
||||
JAVASCRIPT; |
||||
|
||||
return "function action_formatter(cellvalue, options, rowObject) { |
||||
return '$editButton $deleteButton'; |
||||
}"; |
||||
} |
||||
|
||||
/** |
||||
* @param string $url |
||||
* @param string $action |
||||
* |
||||
* @return FormValidator |
||||
*/ |
||||
public function return_form($url, $action) |
||||
{ |
||||
$form = new FormValidator('category', 'post', $url); |
||||
$id = isset($_GET['id']) ? (int) $_GET['id'] : null; |
||||
$form->addElement('hidden', 'id', $id); |
||||
|
||||
// Setting the form elements |
||||
$header = get_lang('Add'); |
||||
$defaults = []; |
||||
|
||||
if ($action === 'edit') { |
||||
$header = get_lang('Modify'); |
||||
// Setting the defaults |
||||
$defaults = $this->get($id, false); |
||||
} |
||||
|
||||
$form->addElement('header', $header); |
||||
|
||||
$form->addText( |
||||
'name', |
||||
get_lang('Name') |
||||
); |
||||
|
||||
$form->addHtmlEditor('description', get_lang('Description')); |
||||
|
||||
if ($action === 'edit') { |
||||
$form->addButtonUpdate(get_lang('Modify')); |
||||
} else { |
||||
$form->addButtonCreate(get_lang('Add')); |
||||
} |
||||
|
||||
/*if (!empty($defaults['created_at'])) { |
||||
$defaults['created_at'] = api_convert_and_format_date($defaults['created_at']); |
||||
} |
||||
if (!empty($defaults['updated_at'])) { |
||||
$defaults['updated_at'] = api_convert_and_format_date($defaults['updated_at']); |
||||
}*/ |
||||
$form->setDefaults($defaults); |
||||
|
||||
// Setting the rules |
||||
$form->addRule('name', get_lang('ThisFieldIsRequired'), 'required'); |
||||
|
||||
return $form; |
||||
} |
||||
|
||||
/** |
||||
* @return string |
||||
*/ |
||||
public function display() |
||||
{ |
||||
// action links |
||||
$content = '<div class="actions">'; |
||||
$content .= '<a href="'.api_get_path(WEB_CODE_PATH).'exercise/exercise.php?'.api_get_cidreq().'">'; |
||||
$content .= Display::return_icon( |
||||
'back.png', |
||||
get_lang('BackTo').' '.get_lang('PlatformAdmin'), |
||||
'', |
||||
ICON_SIZE_MEDIUM |
||||
); |
||||
$content .= '</a>'; |
||||
$content .= '<a href="'.api_get_self().'?action=add&'.api_get_cidreq().'">'; |
||||
$content .= Display::return_icon( |
||||
'add.png', |
||||
get_lang('Add'), |
||||
'', |
||||
ICON_SIZE_MEDIUM |
||||
); |
||||
$content .= '</a>'; |
||||
$content .= '</div>'; |
||||
$content .= Display::grid_html('categories'); |
||||
|
||||
return $content; |
||||
} |
||||
} |
@ -0,0 +1,209 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php'; |
||||
|
||||
api_block_anonymous_users(); |
||||
|
||||
// Access restrictions. |
||||
$is_allowedToTrack = api_is_platform_admin(true, true) || |
||||
api_is_teacher() || api_is_course_tutor(); |
||||
|
||||
if (!$is_allowedToTrack) { |
||||
api_not_allowed(true); |
||||
exit; |
||||
} |
||||
|
||||
// the section (for the tabs) |
||||
$this_section = SECTION_TRACKING; |
||||
$quote_simple = "'"; |
||||
|
||||
$userId = isset($_REQUEST['user_id']) ? (int) $_REQUEST['user_id'] : 0; |
||||
$userInfo = api_get_user_info($userId); |
||||
if (empty($userInfo)) { |
||||
api_not_allowed(true); |
||||
} |
||||
|
||||
$sessions = SessionManager::getSessionsFollowedByUser($userId, |
||||
null, |
||||
null, |
||||
null, |
||||
false, |
||||
false, |
||||
false, |
||||
'ORDER BY s.access_end_date' |
||||
); |
||||
|
||||
$startDate = ''; |
||||
$endDate = ''; |
||||
if (!empty($sessions)) { |
||||
foreach ($sessions as $session) { |
||||
$startDate = api_get_local_time( |
||||
$session['access_start_date'], |
||||
null, |
||||
null, |
||||
true, |
||||
false |
||||
); |
||||
$endDate = api_get_local_time( |
||||
$session['access_end_date'], |
||||
null, |
||||
null, |
||||
true, |
||||
false |
||||
); |
||||
} |
||||
} |
||||
|
||||
$form = new FormValidator( |
||||
'myform', |
||||
'get', |
||||
api_get_self().'?user_id='.$userId, |
||||
null, |
||||
['id' => 'myform'] |
||||
); |
||||
$form->addElement('text', 'from', get_lang('From'), ['id' => 'date_from']); |
||||
$form->addElement('text', 'to', get_lang('Until'), ['id' => 'date_to']); |
||||
/*$form->addElement( |
||||
'select', |
||||
'type', |
||||
get_lang('Type'), |
||||
['day' => get_lang('Day'), 'month' => get_lang('Month')], |
||||
['id' => 'type'] |
||||
);*/ |
||||
$form->addElement('hidden', 'user_id', $userId); |
||||
$form->addRule('from', get_lang('ThisFieldIsRequired'), 'required'); |
||||
$form->addRule('to', get_lang('ThisFieldIsRequired'), 'required'); |
||||
$form->addButtonSearch(get_lang('GenerateReport')); |
||||
|
||||
if ($form->validate()) { |
||||
$values = $form->getSubmitValues(); |
||||
$from = $values['from']; |
||||
$to = $values['to']; |
||||
$sessionCategories = UserManager::get_sessions_by_category($userId, false); |
||||
|
||||
$sessionCourseList = []; |
||||
$report = []; |
||||
foreach ($sessionCategories as $category) { |
||||
foreach ($category['sessions'] as $session) { |
||||
$sessionId = $session['session_id']; |
||||
$courseList = $session['courses']; |
||||
foreach ($courseList as $course) { |
||||
$courseInfo = api_get_course_info_by_id($course['real_id']); |
||||
$result = MySpace::get_connections_to_course_by_date( |
||||
$userId, |
||||
$course, |
||||
$sessionId, |
||||
$from, |
||||
$to |
||||
); |
||||
|
||||
foreach ($result as $item) { |
||||
$record = [ |
||||
$courseInfo['title'], |
||||
$session['session_name'], |
||||
api_get_local_time($item['login']), |
||||
api_get_local_time($item['logout']), |
||||
api_format_time($item['duration'], 'js'), |
||||
]; |
||||
$report[] = $record; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
$courses = CourseManager::returnCourses($userId); |
||||
$courses = array_merge($courses['in_category'], $courses['not_category']); |
||||
|
||||
foreach ($courses as $course) { |
||||
$result = MySpace::get_connections_to_course_by_date( |
||||
$userId, |
||||
$course, |
||||
0, |
||||
$from, |
||||
$to |
||||
); |
||||
|
||||
foreach ($result as $item) { |
||||
$record = [ |
||||
$course['title'], |
||||
'', |
||||
api_get_local_time($item['login']), |
||||
api_get_local_time($item['logout']), |
||||
api_format_time($item['duration'], 'js'), |
||||
]; |
||||
$report[] = $record; |
||||
} |
||||
} |
||||
|
||||
$table = new HTML_Table(['class' => 'data_table']); |
||||
$headers = [ |
||||
get_lang('Course'), |
||||
get_lang('Session'), |
||||
get_lang('StartDate'), |
||||
get_lang('EndDate'), |
||||
get_lang('Duration'), |
||||
]; |
||||
$row = 0; |
||||
$column = 0; |
||||
foreach ($headers as $header) { |
||||
$table->setHeaderContents($row, $column, $header); |
||||
$column++; |
||||
} |
||||
$row++; |
||||
foreach ($report as $record) { |
||||
$column = 0; |
||||
foreach ($record as $item) { |
||||
$table->setCellContents($row, $column++, $item); |
||||
} |
||||
$row++; |
||||
} |
||||
|
||||
$tpl = new Template('', false, false, false, true, false, false); |
||||
$tpl->assign('title', get_lang('AttestationOfAttendance')); |
||||
$tpl->assign('student', $userInfo['complete_name']); |
||||
$tpl->assign('table_progress', $table->toHtml()); |
||||
$content = $tpl->fetch($tpl->get_template('my_space/pdf_export_student.tpl')); |
||||
$params = [ |
||||
'pdf_title' => get_lang('Resume'), |
||||
//'session_info' => $sessionInfo, |
||||
'course_info' => '', |
||||
'pdf_date' => '', |
||||
'student_info' => $userInfo, |
||||
'show_grade_generated_date' => true, |
||||
'show_real_course_teachers' => false, |
||||
'show_teacher_as_myself' => false, |
||||
'orientation' => 'P', |
||||
]; |
||||
|
||||
$pdf = new PDF('A4', $params['orientation'], $params); |
||||
|
||||
$pdf->setBackground($tpl->theme); |
||||
@$pdf->content_to_pdf( |
||||
$content, |
||||
'', |
||||
'', |
||||
null, |
||||
'D', |
||||
false, |
||||
null, |
||||
false, |
||||
true, |
||||
false |
||||
); |
||||
exit; |
||||
} |
||||
|
||||
$interbreadcrumb[] = ['url' => '#', 'name' => get_lang('AccessDetails')]; |
||||
|
||||
Display::display_header(''); |
||||
$userInfo = api_get_user_info($userId); |
||||
$result_to_print = ''; |
||||
echo Display::page_header(get_lang('DetailsStudentInCourse')); |
||||
echo Display::page_subheader( |
||||
get_lang('User').': '.$userInfo['complete_name'] |
||||
); |
||||
|
||||
$form->setDefaults(['from' => $startDate, 'to' => $endDate]); |
||||
$form->display(); |
||||
Display::display_footer(); |
@ -0,0 +1,519 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
use Skill as SkillManager; |
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php'; |
||||
|
||||
ini_set('memory_limit', -1); |
||||
|
||||
/* |
||||
ini_set('upload_max_filesize', '4000M'); |
||||
ini_set('post_max_size', '4000M'); |
||||
ini_set('max_execution_time', '80000'); |
||||
ini_set('max_input_time', '80000'); |
||||
*/ |
||||
|
||||
$debug = true; |
||||
|
||||
define('WS_ERROR_SECRET_KEY', 1); |
||||
|
||||
function return_error($code) |
||||
{ |
||||
$fault = null; |
||||
switch ($code) { |
||||
case WS_ERROR_SECRET_KEY: |
||||
$fault = new soap_fault('Server', '', 'Secret key is not correct or params are not correctly set'); |
||||
break; |
||||
} |
||||
|
||||
return $fault; |
||||
} |
||||
|
||||
function WSHelperVerifyKey($params) |
||||
{ |
||||
global $_configuration, $debug; |
||||
if (is_array($params)) { |
||||
$secret_key = $params['secret_key']; |
||||
} else { |
||||
$secret_key = $params; |
||||
} |
||||
//error_log(print_r($params,1)); |
||||
$check_ip = false; |
||||
$ip_matches = false; |
||||
$ip = trim($_SERVER['REMOTE_ADDR']); |
||||
// if we are behind a reverse proxy, assume it will send the |
||||
// HTTP_X_FORWARDED_FOR header and use this IP instead |
||||
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
||||
list($ip1) = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); |
||||
$ip = trim($ip1); |
||||
} |
||||
if ($debug) { |
||||
error_log("ip: $ip"); |
||||
} |
||||
// Check if a file that limits access from webservices exists and contains |
||||
// the restraining check |
||||
if (is_file('webservice-auth-ip.conf.php')) { |
||||
include 'webservice-auth-ip.conf.php'; |
||||
if ($debug) { |
||||
error_log("webservice-auth-ip.conf.php file included"); |
||||
} |
||||
if (!empty($ws_auth_ip)) { |
||||
$check_ip = true; |
||||
$ip_matches = api_check_ip_in_range($ip, $ws_auth_ip); |
||||
if ($debug) { |
||||
error_log("ip_matches: $ip_matches"); |
||||
} |
||||
} |
||||
} |
||||
|
||||
if ($debug) { |
||||
error_log("checkip ".intval($check_ip)); |
||||
} |
||||
|
||||
if ($check_ip) { |
||||
$security_key = $_configuration['security_key']; |
||||
} else { |
||||
$security_key = $ip.$_configuration['security_key']; |
||||
//error_log($secret_key.'-'.$security_key); |
||||
} |
||||
$result = api_is_valid_secret_key($secret_key, $security_key); |
||||
//error_log($secret_key.'-'.$security_key); |
||||
if ($debug) { |
||||
error_log('WSHelperVerifyKey result: '.intval($result)); |
||||
} |
||||
|
||||
return $result; |
||||
} |
||||
|
||||
// Create the server instance |
||||
$server = new soap_server(); |
||||
//$server->soap_defencoding = 'UTF-8'; |
||||
|
||||
// Initialize WSDL support |
||||
$server->configureWSDL('WSGradebook', 'urn:WSGradebook'); |
||||
|
||||
$server->wsdl->addComplexType( |
||||
'WSGradebookScoreParams', |
||||
'complexType', |
||||
'struct', |
||||
'all', |
||||
'', |
||||
[ |
||||
'item_id' => [ |
||||
'name' => 'item_id', |
||||
'type' => 'xsd:string', |
||||
], |
||||
'item_type' => [ |
||||
'name' => 'item_type', |
||||
'type' => 'xsd:string', |
||||
], |
||||
'email' => [ |
||||
'name' => 'email', |
||||
'type' => 'xsd:string', |
||||
], |
||||
'secret_key' => ['name' => 'secret_key', 'type' => 'xsd:string'], |
||||
] |
||||
); |
||||
|
||||
$server->wsdl->addComplexType( |
||||
'returnItemScore', |
||||
'complexType', |
||||
'struct', |
||||
'sequence', |
||||
'', |
||||
[ |
||||
'score' => ['name' => 'score', 'type' => 'xsd:string'], |
||||
'date' => ['name' => 'date', 'type' => 'xsd:string'], |
||||
'counter' => ['name' => 'counter', 'type' => 'xsd:string'], |
||||
] |
||||
); |
||||
|
||||
// Register the method to expose |
||||
$server->register( |
||||
'WSGetGradebookUserItemScore', // method name |
||||
['params' => 'tns:WSGradebookScoreParams'], // input parameters |
||||
['return' => 'tns:returnItemScore'], // output parameters |
||||
'urn:WSGradebook', // namespace |
||||
'urn:WSGradebook#WSGetGradebookUserItemScore', // soapaction |
||||
'rpc', // style |
||||
'encoded', // use |
||||
'get gradebook item user result' |
||||
); |
||||
|
||||
/** |
||||
* @param array $params |
||||
* |
||||
* @return int|string |
||||
*/ |
||||
function WSGetGradebookUserItemScore($params) |
||||
{ |
||||
if (!WSHelperVerifyKey($params)) { |
||||
return return_error(WS_ERROR_SECRET_KEY); |
||||
} |
||||
|
||||
$itemId = $params['item_id']; |
||||
$itemType = $params['item_type']; |
||||
$email = $params['email']; |
||||
$userInfo = api_get_user_info_from_email($email); |
||||
|
||||
if (empty($userInfo)) { |
||||
return new soap_fault('Server', '', 'User not found'); |
||||
} |
||||
|
||||
$em = Database::getManager(); |
||||
|
||||
$score = []; |
||||
switch ($itemType) { |
||||
case 'link': |
||||
/** @var \Chamilo\CoreBundle\Entity\GradebookLink $link */ |
||||
$link = $em->getRepository('ChamiloCoreBundle:GradebookLink')->find($itemId); |
||||
if (empty($link)) { |
||||
return new soap_fault('Server', '', 'gradebook link not found'); |
||||
} |
||||
|
||||
$links = AbstractLink::load($link->getId()); |
||||
switch ($link->getType()) { |
||||
case LINK_EXERCISE: |
||||
/** @var ExerciseLink $link */ |
||||
foreach ($links as $link) { |
||||
$link->set_session_id($link->getCategory()->get_session_id()); |
||||
$score = $link->calc_score($userInfo['user_id']); |
||||
break; |
||||
} |
||||
break; |
||||
case LINK_STUDENTPUBLICATION: |
||||
/** @var StudentPublicationLink $link */ |
||||
foreach ($links as $link) { |
||||
$link->set_session_id($link->getCategory()->get_session_id()); |
||||
$score = $link->calc_score($userInfo['user_id']); |
||||
break; |
||||
} |
||||
break; |
||||
} |
||||
break; |
||||
case 'evaluation': |
||||
//$evaluation = $em->getRepository('ChamiloCoreBundle:GradebookEvaluation')->find($itemId); |
||||
break; |
||||
} |
||||
|
||||
if (!empty($score)) { |
||||
$result = ExerciseLib::show_score($score[0], $score[1], false); |
||||
$result = strip_tags($result); |
||||
|
||||
return ['score' => $result, 'date' => $score[2], 'counter' => $score[3]]; |
||||
} |
||||
|
||||
return new soap_fault('Server', '', 'Score not found'); |
||||
} |
||||
|
||||
$server->wsdl->addComplexType( |
||||
'WSGradebookCategoryScoreParams', |
||||
'complexType', |
||||
'struct', |
||||
'all', |
||||
'', |
||||
[ |
||||
'course_code' => [ |
||||
'name' => 'course_code', |
||||
'type' => 'xsd:string', |
||||
], |
||||
'session_id' => [ |
||||
'name' => 'session_id', |
||||
'type' => 'xsd:string', |
||||
], |
||||
'email' => [ |
||||
'name' => 'email', |
||||
'type' => 'xsd:string', |
||||
], |
||||
'secret_key' => ['name' => 'secret_key', 'type' => 'xsd:string'], |
||||
] |
||||
); |
||||
|
||||
// Register the method to expose |
||||
$server->register( |
||||
'WSGetGradebookCategoryUserScore', // method name |
||||
['params' => 'tns:WSGradebookCategoryScoreParams'], // input parameters |
||||
['return' => 'xsd:string'], // output parameters |
||||
'urn:WSGradebook', // namespace |
||||
'urn:WSGradebook#WSGetGradebookCategoryUserScore', // soapaction |
||||
'rpc', // style |
||||
'encoded' |
||||
); |
||||
|
||||
/** |
||||
* @param array $params |
||||
* |
||||
* @return int|string |
||||
*/ |
||||
function WSGetGradebookCategoryUserScore($params) |
||||
{ |
||||
if (!WSHelperVerifyKey($params)) { |
||||
return return_error(WS_ERROR_SECRET_KEY); |
||||
} |
||||
$courseCode = $params['course_code']; |
||||
$sessionId = (int) $params['session_id']; |
||||
if (!empty($sessionId)) { |
||||
$sessionInfo = api_get_session_info($sessionId); |
||||
if (empty($sessionInfo)) { |
||||
return new soap_fault('Server', '', 'Session not found'); |
||||
} |
||||
} |
||||
|
||||
$email = $params['email']; |
||||
$userInfo = api_get_user_info_from_email($email); |
||||
|
||||
if (empty($userInfo)) { |
||||
return new soap_fault('Server', '', 'User not found'); |
||||
} |
||||
$userId = $userInfo['user_id']; |
||||
$courseInfo = api_get_course_info($courseCode); |
||||
if (empty($courseInfo)) { |
||||
return new soap_fault('Server', '', 'Course not found'); |
||||
} |
||||
|
||||
$cats = Category::load(null, |
||||
null, |
||||
$courseCode, |
||||
null, |
||||
null, |
||||
$sessionId |
||||
); |
||||
|
||||
/** @var Category $category */ |
||||
$category = isset($cats[0]) ? $cats[0] : null; |
||||
$scorecourse_display = null; |
||||
|
||||
if (!empty($category)) { |
||||
$categoryCourse = Category::load($category->get_id()); |
||||
$category = isset($categoryCourse[0]) ? $categoryCourse[0] : null; |
||||
$allevals = $category->get_evaluations($userId, true); |
||||
$alllinks = $category->get_links($userId, true); |
||||
|
||||
$allEvalsLinks = array_merge($allevals, $alllinks); |
||||
$main_weight = $category->get_weight(); |
||||
$scoredisplay = ScoreDisplay::instance(); |
||||
$item_value_total = 0; |
||||
/** @var AbstractLink $item */ |
||||
foreach ($allEvalsLinks as $item) { |
||||
$item->set_session_id($sessionId); |
||||
$item->set_course_code($courseCode); |
||||
$score = $item->calc_score($userId); |
||||
if (!empty($score)) { |
||||
$divide = $score[1] == 0 ? 1 : $score[1]; |
||||
$item_value = $score[0] / $divide * $item->get_weight(); |
||||
$item_value_total += $item_value; |
||||
} |
||||
} |
||||
|
||||
$item_total = $main_weight; |
||||
$total_score = [$item_value_total, $item_total]; |
||||
$score = $scoredisplay->display_score($total_score, SCORE_DIV_PERCENT); |
||||
$score = strip_tags($score); |
||||
|
||||
return $score; |
||||
} |
||||
|
||||
if (empty($category)) { |
||||
return new soap_fault('Server', '', 'Gradebook category not found'); |
||||
} |
||||
|
||||
return new soap_fault('Server', '', 'Score not found'); |
||||
} |
||||
|
||||
$server->wsdl->addComplexType( |
||||
'WSLpProgressParams', |
||||
'complexType', |
||||
'struct', |
||||
'all', |
||||
'', |
||||
[ |
||||
'course_code' => [ |
||||
'name' => 'course_code', |
||||
'type' => 'xsd:string', |
||||
], |
||||
'session_id' => [ |
||||
'name' => 'session_id', |
||||
'type' => 'xsd:string', |
||||
], |
||||
'lp_id' => [ |
||||
'name' => 'lp_id', |
||||
'type' => 'xsd:string', |
||||
], |
||||
'email' => [ |
||||
'name' => 'email', |
||||
'type' => 'xsd:string', |
||||
], |
||||
'secret_key' => ['name' => 'secret_key', 'type' => 'xsd:string'], |
||||
] |
||||
); |
||||
|
||||
// Register the method to expose |
||||
$server->register( |
||||
'WSGetLpProgress', // method name |
||||
['params' => 'tns:WSLpProgressParams'], // input parameters |
||||
['return' => 'xsd:string'], // output parameters |
||||
'urn:WSGradebook', // namespace |
||||
'urn:WSGradebook#WSGetLpProgress', // soapaction |
||||
'rpc', // style |
||||
'encoded' |
||||
); |
||||
|
||||
/** |
||||
* @param array $params |
||||
* |
||||
* @return int|string |
||||
*/ |
||||
function WSGetLpProgress($params) |
||||
{ |
||||
if (!WSHelperVerifyKey($params)) { |
||||
return return_error(WS_ERROR_SECRET_KEY); |
||||
} |
||||
|
||||
$courseCode = $params['course_code']; |
||||
$courseInfo = api_get_course_info($courseCode); |
||||
if (empty($courseInfo)) { |
||||
return new soap_fault('Server', '', 'Course not found'); |
||||
} |
||||
|
||||
$sessionId = (int) $params['session_id']; |
||||
if (!empty($sessionId)) { |
||||
$sessionInfo = api_get_session_info($sessionId); |
||||
if (empty($sessionInfo)) { |
||||
return new soap_fault('Server', '', 'Session not found'); |
||||
} |
||||
} |
||||
|
||||
$email = $params['email']; |
||||
$userInfo = api_get_user_info_from_email($email); |
||||
$userId = $userInfo['user_id']; |
||||
|
||||
if (empty($userInfo)) { |
||||
return new soap_fault('Server', '', 'User not found'); |
||||
} |
||||
|
||||
$lpId = $params['lp_id']; |
||||
$lp = new learnpath($courseCode, $lpId, $userId); |
||||
|
||||
if (empty($lp)) { |
||||
return new soap_fault('Server', '', 'LP not found'); |
||||
} |
||||
|
||||
return $lp->progress_db; |
||||
} |
||||
|
||||
$server->wsdl->addComplexType( |
||||
'WSAssignSkillParams', |
||||
'complexType', |
||||
'struct', |
||||
'all', |
||||
'', |
||||
[ |
||||
'skill_id' => [ |
||||
'name' => 'skill_id', |
||||
'type' => 'xsd:string', |
||||
], |
||||
'level' => [ |
||||
'name' => 'level', |
||||
'type' => 'xsd:string', |
||||
], |
||||
'justification' => [ |
||||
'name' => 'justification', |
||||
'type' => 'xsd:string', |
||||
], |
||||
'email' => [ |
||||
'name' => 'email', |
||||
'type' => 'xsd:string', |
||||
], |
||||
'author_email' => [ |
||||
'name' => 'author_email', |
||||
'type' => 'xsd:string', |
||||
], |
||||
'secret_key' => ['name' => 'secret_key', 'type' => 'xsd:string'], |
||||
] |
||||
); |
||||
|
||||
// Register the method to expose |
||||
$server->register( |
||||
'WSAssignSkill', // method name |
||||
['params' => 'tns:WSAssignSkillParams'], // input parameters |
||||
['return' => 'xsd:string'], // output parameters |
||||
'urn:WSGradebook', // namespace |
||||
'urn:WSGradebook:WSAssignSkill', // soapaction |
||||
'rpc', // style |
||||
'encoded' |
||||
); |
||||
|
||||
/** |
||||
* @param array $params |
||||
* |
||||
* @return int|string |
||||
*/ |
||||
function WSAssignSkill($params) |
||||
{ |
||||
if (!WSHelperVerifyKey($params)) { |
||||
return return_error(WS_ERROR_SECRET_KEY); |
||||
} |
||||
|
||||
$em = Database::getManager(); |
||||
$skillManager = new SkillManager(); |
||||
|
||||
$skillId = isset($params['skill_id']) ? $params['skill_id'] : 0; |
||||
$skillRepo = $em->getRepository('ChamiloCoreBundle:Skill'); |
||||
$skill = $skillRepo->find($skillId); |
||||
|
||||
if (empty($skill)) { |
||||
return new soap_fault('Server', '', 'Skill not found'); |
||||
} |
||||
|
||||
$justification = $params['justification']; |
||||
|
||||
if (strlen($justification) < 10) { |
||||
return new soap_fault('Server', '', 'Justification smaller than 10 chars'); |
||||
} |
||||
|
||||
$level = (int) $params['level']; |
||||
|
||||
$email = $params['email']; |
||||
$userInfo = api_get_user_info_from_email($email); |
||||
|
||||
if (empty($userInfo)) { |
||||
return new soap_fault('Server', '', 'User not found'); |
||||
} |
||||
|
||||
$email = $params['author_email']; |
||||
$authorInfo = api_get_user_info_from_email($email); |
||||
|
||||
if (empty($authorInfo)) { |
||||
return new soap_fault('Server', '', 'Author not found'); |
||||
} |
||||
|
||||
$userId = $userInfo['user_id']; |
||||
$user = api_get_user_entity($userId); |
||||
$skillUser = $skillManager->addSkillToUserBadge( |
||||
$user, |
||||
$skill, |
||||
$level, |
||||
$justification, |
||||
$authorInfo['id'] |
||||
); |
||||
|
||||
if (!empty($skillUser)) { |
||||
return 1; |
||||
} |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
// Use the request to (try to) invoke the service |
||||
$GLOBALS['HTTP_RAW_POST_DATA'] = file_get_contents('php://input'); |
||||
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : ''; |
||||
|
||||
// If you send your data in utf8 then this value must be false. |
||||
$decodeUTF8 = api_get_setting('registration.soap.php.decode_utf8'); |
||||
if ($decodeUTF8 === 'true') { |
||||
$server->decode_utf8 = true; |
||||
} else { |
||||
$server->decode_utf8 = false; |
||||
} |
||||
$server->service($HTTP_RAW_POST_DATA); |
Loading…
Reference in new issue