parent
65060bef05
commit
52eb3b717f
@ -1,115 +0,0 @@ |
||||
<?php |
||||
/* For license terms, see /license.txt */ |
||||
|
||||
use Chamilo\CoreBundle\Entity\Course; |
||||
use Chamilo\PluginBundle\Entity\ImsLti\ImsLtiTool; |
||||
|
||||
require_once __DIR__.'/../../main/inc/global.inc.php'; |
||||
|
||||
api_protect_course_script(); |
||||
api_protect_teacher_script(); |
||||
|
||||
$plugin = ImsLtiPlugin::create(); |
||||
$em = Database::getManager(); |
||||
$toolsRepo = $em->getRepository('ChamiloPluginBundle:ImsLti\ImsLtiTool'); |
||||
|
||||
/** @var ImsLtiTool $baseTool */ |
||||
$baseTool = isset($_REQUEST['type']) ? $toolsRepo->find($_REQUEST['type']) : null; |
||||
|
||||
/** @var Course $course */ |
||||
$course = $em->find('ChamiloCoreBundle:Course', api_get_course_int_id()); |
||||
$globalTools = $toolsRepo->findBy(['isGlobal' => true]); |
||||
|
||||
if ($baseTool && !$baseTool->isGlobal()) { |
||||
Display::addFlash( |
||||
Display::return_message($plugin->get_lang('ToolNotAvailable'), 'warning') |
||||
); |
||||
|
||||
header('Location: '.api_get_self().'?'.api_get_cidreq()); |
||||
exit; |
||||
} |
||||
|
||||
$form = new FormValidator('ims_lti_add_tool'); |
||||
$form->addHeader($plugin->get_lang('ToolSettings')); |
||||
|
||||
if ($baseTool) { |
||||
$form->addHtml('<p class="lead">'.Security::remove_XSS($baseTool->getDescription()).'</p>'); |
||||
} |
||||
|
||||
$form->addText('name', get_lang('Title')); |
||||
|
||||
if (!$baseTool) { |
||||
$form->addElement('url', 'url', $plugin->get_lang('LaunchUrl')); |
||||
$form->addText('consumer_key', $plugin->get_lang('ConsumerKey'), true); |
||||
$form->addText('shared_secret', $plugin->get_lang('SharedSecret'), true); |
||||
$form->addRule('url', get_lang('Required'), 'required'); |
||||
} |
||||
|
||||
$form->addButtonAdvancedSettings('lti_adv'); |
||||
$form->addHtml('<div id="lti_adv_options" style="display:none;">'); |
||||
$form->addTextarea('description', get_lang('Description'), ['rows' => 3]); |
||||
|
||||
if (!$baseTool) { |
||||
$form->addTextarea('custom_params', [$plugin->get_lang('CustomParams'), $plugin->get_lang('CustomParamsHelp')]); |
||||
$form->addCheckBox('deep_linking', $plugin->get_lang('SupportDeepLinking'), get_lang('Yes')); |
||||
} |
||||
|
||||
if ($baseTool) { |
||||
$form->addHidden('type', $baseTool->getId()); |
||||
} |
||||
|
||||
$form->addHtml('</div>'); |
||||
|
||||
$form->addButtonCreate($plugin->get_lang('AddExternalTool')); |
||||
|
||||
if ($form->validate()) { |
||||
$formValues = $form->getSubmitValues(); |
||||
$tool = null; |
||||
|
||||
if ($baseTool) { |
||||
$tool = clone $baseTool; |
||||
} else { |
||||
$tool = new ImsLtiTool(); |
||||
$tool |
||||
->setLaunchUrl($formValues['url']) |
||||
->setConsumerKey($formValues['consumer_key']) |
||||
->setSharedSecret($formValues['shared_secret']) |
||||
->setCustomParams( |
||||
empty($formValues['custom_params']) ? null : $formValues['custom_params'] |
||||
); |
||||
} |
||||
|
||||
$tool |
||||
->setName($formValues['name']) |
||||
->setDescription( |
||||
empty($formValues['description']) ? null : $formValues['description'] |
||||
) |
||||
->setIsGlobal(false); |
||||
$em->persist($tool); |
||||
$em->flush(); |
||||
|
||||
$plugin->addCourseTool($course, $tool); |
||||
|
||||
Display::addFlash( |
||||
Display::return_message($plugin->get_lang('ToolAdded'), 'success') |
||||
); |
||||
|
||||
header('Location: '.api_get_course_url()); |
||||
exit; |
||||
} |
||||
|
||||
$template = new Template($plugin->get_lang('AddExternalTool')); |
||||
$template->assign('type', $baseTool ? $baseTool->getId() : null); |
||||
$template->assign('tools', $globalTools); |
||||
$template->assign('form', $form->returnForm()); |
||||
|
||||
$content = $template->fetch('ims_lti/view/add.tpl'); |
||||
|
||||
$actions = Display::url( |
||||
Display::return_icon('add.png', $plugin->get_lang('AddExternalTool'), [], ICON_SIZE_MEDIUM), |
||||
api_get_self().'?'.api_get_cidreq() |
||||
); |
||||
|
||||
$template->assign('actions', Display::toolbarAction('lti_toolbar', [$actions])); |
||||
$template->assign('content', $content); |
||||
$template->display_one_col_template(); |
||||
@ -0,0 +1,194 @@ |
||||
<?php |
||||
/* For license terms, see /license.txt */ |
||||
|
||||
use Chamilo\CoreBundle\Entity\Course; |
||||
use Chamilo\PluginBundle\Entity\ImsLti\ImsLtiTool; |
||||
|
||||
require_once __DIR__.'/../../main/inc/global.inc.php'; |
||||
|
||||
api_protect_course_script(); |
||||
api_protect_teacher_script(); |
||||
|
||||
$plugin = ImsLtiPlugin::create(); |
||||
$em = Database::getManager(); |
||||
$toolsRepo = $em->getRepository('ChamiloPluginBundle:ImsLti\ImsLtiTool'); |
||||
|
||||
/** @var ImsLtiTool $baseTool */ |
||||
$baseTool = isset($_REQUEST['type']) ? $toolsRepo->find(intval($_REQUEST['type'])) : null; |
||||
$action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : 'add'; |
||||
|
||||
/** @var Course $course */ |
||||
$course = $em->find('ChamiloCoreBundle:Course', api_get_course_int_id()); |
||||
$addedTools = $toolsRepo->findBy(['course' => $course]); |
||||
$globalTools = $toolsRepo->findBy(['parent' => null, 'course' => null]); |
||||
|
||||
if ($baseTool && !$baseTool->isGlobal()) { |
||||
Display::addFlash( |
||||
Display::return_message($plugin->get_lang('ToolNotAvailable'), 'warning') |
||||
); |
||||
|
||||
header('Location: '.api_get_self().'?'.api_get_cidreq()); |
||||
exit; |
||||
} |
||||
|
||||
switch ($action) { |
||||
case 'add': |
||||
$form = new FrmAdd('ims_lti_add_tool', [], $baseTool); |
||||
$form->build(); |
||||
|
||||
if ($baseTool) { |
||||
$form->addHidden('type', $baseTool->getId()); |
||||
} |
||||
|
||||
if ($form->validate()) { |
||||
$formValues = $form->getSubmitValues(); |
||||
|
||||
$tool = new ImsLtiTool(); |
||||
$tool |
||||
->setName($formValues['name']) |
||||
->setDescription( |
||||
empty($formValues['description']) ? null : $formValues['description'] |
||||
) |
||||
->setLaunchUrl( |
||||
$baseTool ? $baseTool->getLaunchUrl() : $formValues['launch_url'] |
||||
) |
||||
->setConsumerKey( |
||||
$baseTool ? $baseTool->getConsumerKey() : $formValues['consumer_key'] |
||||
) |
||||
->setSharedSecret( |
||||
$baseTool ? $baseTool->getSharedSecret() : $formValues['shared_secret'] |
||||
) |
||||
->setCustomParams( |
||||
empty($formValues['custom_params']) ? null : $formValues['custom_params'] |
||||
) |
||||
->setCourse($course) |
||||
->setActiveDeepLinking(!empty($formValues['deep_linking'])) |
||||
->setPrivacy( |
||||
!empty($formValues['share_name']), |
||||
!empty($formValues['share_email']), |
||||
!empty($formValues['share_picture']) |
||||
); |
||||
|
||||
if (null === $baseTool || |
||||
($baseTool && !$baseTool->isActiveDeepLinking()) |
||||
) { |
||||
$tool |
||||
->setActiveDeepLinking( |
||||
!empty($formValues['deep_linking']) |
||||
); |
||||
} |
||||
|
||||
if ($baseTool) { |
||||
$tool->setParent($baseTool); |
||||
} |
||||
|
||||
$em->persist($tool); |
||||
$em->flush(); |
||||
|
||||
if (!$tool->isActiveDeepLinking()) { |
||||
$plugin->addCourseTool($course, $tool); |
||||
} |
||||
|
||||
Display::addFlash( |
||||
Display::return_message($plugin->get_lang('ToolAdded'), 'success') |
||||
); |
||||
|
||||
header('Location: '.api_get_self().'?'.api_get_cidreq()); |
||||
exit; |
||||
} |
||||
|
||||
$form->setDefaultValues(); |
||||
break; |
||||
case 'edit': |
||||
/** @var ImsLtiTool|null $tool */ |
||||
$tool = null; |
||||
|
||||
if (!empty($_REQUEST['id'])) { |
||||
$tool = $em->find('ChamiloPluginBundle:ImsLti\ImsLtiTool', (int) $_REQUEST['id']); |
||||
} |
||||
|
||||
if (empty($tool) || |
||||
!ImsLtiPlugin::existsToolInCourse($tool->getId(), $course) |
||||
) { |
||||
api_not_allowed( |
||||
true, |
||||
Display::return_message($plugin->get_lang('ToolNotAvailable'), 'error') |
||||
); |
||||
|
||||
break; |
||||
} |
||||
|
||||
$form = new FrmEdit('ims_lti_edit_tool', [], $tool); |
||||
$form->build(false); |
||||
|
||||
if ($form->validate()) { |
||||
$formValues = $form->getSubmitValues(); |
||||
|
||||
$tool |
||||
->setName($formValues['name']) |
||||
->setDescription($formValues['description']) |
||||
->setActiveDeepLinking( |
||||
!empty($formValues['deep_linking']) |
||||
) |
||||
->setCustomParams( |
||||
empty($formValues['custom_params']) ? null : $formValues['custom_params'] |
||||
) |
||||
->setPrivacy( |
||||
!empty($formValues['share_name']), |
||||
!empty($formValues['share_email']), |
||||
!empty($formValues['share_picture']) |
||||
); |
||||
|
||||
if (null === $tool->getParent()) { |
||||
$tool |
||||
->setLaunchUrl($formValues['launch_url']) |
||||
->setConsumerKey($formValues['consumer_key']) |
||||
->setSharedSecret($formValues['shared_secret']); |
||||
} |
||||
|
||||
$em->persist($tool); |
||||
$em->flush(); |
||||
|
||||
$courseTool = $plugin->findCourseToolByLink($course, $tool); |
||||
|
||||
if ($courseTool) { |
||||
$plugin->updateCourseTool($courseTool, $tool); |
||||
} |
||||
|
||||
Display::addFlash( |
||||
Display::return_message($plugin->get_lang('ToolEdited'), 'success') |
||||
); |
||||
|
||||
header('Location: '.api_get_self().'?'.api_get_cidreq()); |
||||
exit; |
||||
} |
||||
|
||||
$form->setDefaultValues(); |
||||
break; |
||||
} |
||||
|
||||
$categories = Category::load(null, null, $course->getCode()); |
||||
|
||||
$template = new Template($plugin->get_lang('AddExternalTool')); |
||||
$template->assign('type', $baseTool ? $baseTool->getId() : null); |
||||
$template->assign('added_tools', $addedTools); |
||||
$template->assign('global_tools', $globalTools); |
||||
$template->assign('form', $form->returnForm()); |
||||
|
||||
$content = $template->fetch('ims_lti/view/add.tpl'); |
||||
|
||||
$actions = Display::url( |
||||
Display::return_icon('add.png', $plugin->get_lang('AddExternalTool'), [], ICON_SIZE_MEDIUM), |
||||
api_get_self().'?'.api_get_cidreq() |
||||
); |
||||
|
||||
if (!empty($categories)) { |
||||
$actions .= Display::url( |
||||
Display::return_icon('gradebook.png', get_lang('MakeQualifiable'), [], ICON_SIZE_MEDIUM), |
||||
'./gradebook/add_eval.php?selectcat='.$categories[0]->get_id().'&'.api_get_cidreq() |
||||
); |
||||
} |
||||
|
||||
$template->assign('actions', Display::toolbarAction('lti_toolbar', [$actions])); |
||||
$template->assign('content', $content); |
||||
$template->display_one_col_template(); |
||||
@ -0,0 +1,193 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
class OutcomeForm extends EvalForm |
||||
{ |
||||
/** |
||||
* Builds a form containing form items based on a given parameter. |
||||
* |
||||
* @param int $form_type 1=add, 2=edit,3=move,4=result_add |
||||
* @param Evaluation $evaluation_object the category object |
||||
* @param obj $result_object the result object |
||||
* @param string $form_name |
||||
* @param string $method |
||||
* @param string $action |
||||
*/ |
||||
public function __construct( |
||||
$evaluation_object, |
||||
$result_object, |
||||
$form_name, |
||||
$method = 'post', |
||||
$action = null, |
||||
$extra1 = null, |
||||
$extra2 = null |
||||
) { |
||||
parent::__construct( |
||||
-1, |
||||
$evaluation_object, |
||||
$result_object, |
||||
$form_name, |
||||
$method, |
||||
$action, |
||||
$extra1, |
||||
$extra2 |
||||
); |
||||
|
||||
$this->build_add_form(); |
||||
$this->setDefaults(); |
||||
} |
||||
|
||||
/** |
||||
* Builds a basic form that is used in add and edit. |
||||
* |
||||
* @param int $edit |
||||
* |
||||
* @throws Exception |
||||
*/ |
||||
private function build_basic_form($edit = 0) |
||||
{ |
||||
$this->addElement('header', get_plugin_lang('NewOutcomeFormTitle')); |
||||
$this->addElement('hidden', 'hid_user_id'); |
||||
$this->addElement('hidden', 'hid_course_code'); |
||||
|
||||
$this->addText( |
||||
'name', |
||||
get_lang('EvaluationName'), |
||||
true, |
||||
[ |
||||
'maxlength' => '50', |
||||
'id' => 'evaluation_title', |
||||
] |
||||
); |
||||
|
||||
$cat_id = $this->evaluation_object->get_category_id(); |
||||
|
||||
$session_id = api_get_session_id(); |
||||
$course_code = api_get_course_id(); |
||||
$all_categories = Category:: load(null, null, $course_code, null, null, $session_id, false); |
||||
|
||||
if (count($all_categories) == 1) { |
||||
$this->addElement('hidden', 'hid_category_id', $cat_id); |
||||
} else { |
||||
$select_gradebook = $this->addElement( |
||||
'select', |
||||
'hid_category_id', |
||||
get_lang('SelectGradebook'), |
||||
[], |
||||
['id' => 'hid_category_id'] |
||||
); |
||||
$this->addRule('hid_category_id', get_lang('ThisFieldIsRequired'), 'nonzero'); |
||||
$default_weight = 0; |
||||
if (!empty($all_categories)) { |
||||
foreach ($all_categories as $my_cat) { |
||||
if ($my_cat->get_course_code() == api_get_course_id()) { |
||||
$grade_model_id = $my_cat->get_grade_model_id(); |
||||
if (empty($grade_model_id)) { |
||||
if ($my_cat->get_parent_id() == 0) { |
||||
$default_weight = $my_cat->get_weight(); |
||||
$select_gradebook->addoption(get_lang('Default'), $my_cat->get_id()); |
||||
$cats_added[] = $my_cat->get_id(); |
||||
} else { |
||||
$select_gradebook->addoption($my_cat->get_name(), $my_cat->get_id()); |
||||
$cats_added[] = $my_cat->get_id(); |
||||
} |
||||
} else { |
||||
$select_gradebook->addoption(get_lang('Select'), 0); |
||||
} |
||||
if ($this->evaluation_object->get_category_id() == $my_cat->get_id()) { |
||||
$default_weight = $my_cat->get_weight(); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
$this->addFloat( |
||||
'weight_mask', |
||||
[ |
||||
get_lang('Weight'), |
||||
null, |
||||
' [0 .. <span id="max_weight">'.$all_categories[0]->get_weight().'</span>] ', |
||||
], |
||||
true, |
||||
[ |
||||
'size' => '4', |
||||
'maxlength' => '5', |
||||
] |
||||
); |
||||
|
||||
if ($edit) { |
||||
if (!$this->evaluation_object->has_results()) { |
||||
$this->addText( |
||||
'max', |
||||
get_lang('QualificationNumeric'), |
||||
true, |
||||
[ |
||||
'maxlength' => '5', |
||||
] |
||||
); |
||||
} else { |
||||
$this->addText( |
||||
'max', |
||||
[get_lang('QualificationNumeric'), get_lang('CannotChangeTheMaxNote')], |
||||
false, |
||||
[ |
||||
'maxlength' => '5', |
||||
'disabled' => 'disabled', |
||||
] |
||||
); |
||||
} |
||||
} else { |
||||
$this->addText( |
||||
'max', |
||||
get_lang('QualificationNumeric'), |
||||
true, |
||||
[ |
||||
'maxlength' => '5', |
||||
] |
||||
); |
||||
$default_max = api_get_setting('gradebook_default_weight'); |
||||
$defaults['max'] = isset($default_max) ? $default_max : 100; |
||||
$this->setDefaults($defaults); |
||||
} |
||||
|
||||
$this->addElement('textarea', 'description', get_lang('Description')); |
||||
$this->addRule('hid_category_id', get_lang('ThisFieldIsRequired'), 'required'); |
||||
$this->addElement('checkbox', 'visible', null, get_lang('Visible')); |
||||
$this->addRule('max', get_lang('OnlyNumbers'), 'numeric'); |
||||
$this->addRule( |
||||
'max', |
||||
get_lang('NegativeValue'), |
||||
'compare', |
||||
'>=', |
||||
'server', |
||||
false, |
||||
false, |
||||
0 |
||||
); |
||||
$setting = api_get_setting('tool_visible_by_default_at_creation'); |
||||
$visibility_default = 1; |
||||
if (isset($setting['gradebook']) && $setting['gradebook'] == 'false') { |
||||
$visibility_default = 0; |
||||
} |
||||
$this->setDefaults(['visible' => $visibility_default]); |
||||
} |
||||
|
||||
/** |
||||
* |
||||
*/ |
||||
protected function build_add_form() |
||||
{ |
||||
$this->setDefaults( |
||||
[ |
||||
'hid_user_id' => $this->evaluation_object->get_user_id(), |
||||
'hid_category_id' => $this->evaluation_object->get_category_id(), |
||||
'hid_course_code' => $this->evaluation_object->get_course_code(), |
||||
'created_at' => api_get_utc_datetime(), |
||||
] |
||||
); |
||||
$this->build_basic_form(); |
||||
|
||||
$this->addButtonCreate(get_lang('AddAssessment'), 'submit'); |
||||
} |
||||
} |
||||
@ -0,0 +1,144 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
/** |
||||
* @package plugin.ims_lti |
||||
*/ |
||||
|
||||
use Chamilo\CoreBundle\Entity\GradebookEvaluation; |
||||
use Chamilo\PluginBundle\Entity\ImsLti\ImsLtiTool; |
||||
|
||||
require_once __DIR__.'/../../../main/inc/global.inc.php'; |
||||
|
||||
$current_course_tool = TOOL_GRADEBOOK; |
||||
|
||||
api_protect_course_script(true); |
||||
api_block_anonymous_users(); |
||||
GradebookUtils::block_students(); |
||||
|
||||
$select_cat = isset($_GET['selectcat']) ? (int) $_GET['selectcat'] : 0; |
||||
$is_allowedToEdit = $is_courseAdmin; |
||||
|
||||
$em = Database::getManager(); |
||||
/** @var \Chamilo\CoreBundle\Entity\Course $course */ |
||||
$course = $em->find('ChamiloCoreBundle:Course', api_get_course_int_id()); |
||||
$ltiToolRepo = $em->getRepository('ChamiloPluginBundle:ImsLti\ImsLtiTool'); |
||||
|
||||
$categories = Category::load(null, null, $course->getCode()); |
||||
|
||||
if (empty($categories)) { |
||||
$message = Display::return_message( |
||||
get_plugin_lang('GradebookNotSetWarning', 'ImsLtiPlugin'), |
||||
'warning' |
||||
); |
||||
|
||||
api_not_allowed(true, $message); |
||||
} |
||||
|
||||
$evaladd = new Evaluation(); |
||||
$evaladd->set_user_id($_user['user_id']); |
||||
|
||||
if (!empty($select_cat)) { |
||||
$evaladd->set_category_id($_GET['selectcat']); |
||||
$cat = Category::load($_GET['selectcat']); |
||||
$evaladd->set_course_code($cat[0]->get_course_code()); |
||||
} else { |
||||
$evaladd->set_category_id(0); |
||||
} |
||||
|
||||
$form = new EvalForm( |
||||
EvalForm::TYPE_ADD, |
||||
$evaladd, |
||||
null, |
||||
'add_eval_form', |
||||
null, |
||||
api_get_self().'?selectcat='.$select_cat.'&'.api_get_cidreq() |
||||
); |
||||
$form->removeElement('name'); |
||||
$form->removeElement('addresult'); |
||||
$slcLtiTools = $form->createElement('select', 'name', get_lang('Tool')); |
||||
$form->insertElementBefore($slcLtiTools, 'hid_category_id'); |
||||
$form->addRule('name', get_lang('ThisFieldIsRequired'), 'required'); |
||||
|
||||
$ltiTools = $ltiToolRepo->findBy(['course' => $course, 'gradebookEval' => null]); |
||||
|
||||
/** @var ImsLtiTool $ltiTool */ |
||||
foreach ($ltiTools as $ltiTool) { |
||||
$slcLtiTools->addOption($ltiTool->getName(), $ltiTool->getId()); |
||||
} |
||||
|
||||
if ($form->validate()) { |
||||
$values = $form->exportValues(); |
||||
|
||||
/** @var ImsLtiTool $ltiTool */ |
||||
$ltiTool = $ltiToolRepo->find($values['name']); |
||||
|
||||
if (!$ltiTool) { |
||||
api_not_allowed(); |
||||
} |
||||
|
||||
$eval = new Evaluation(); |
||||
$eval->set_name($ltiTool->getName()); |
||||
$eval->set_description($values['description']); |
||||
$eval->set_user_id($values['hid_user_id']); |
||||
|
||||
if (!empty($values['hid_course_code'])) { |
||||
$eval->set_course_code($values['hid_course_code']); |
||||
} |
||||
|
||||
//Always add the gradebook to the course |
||||
$eval->set_course_code(api_get_course_id()); |
||||
$eval->set_category_id($values['hid_category_id']); |
||||
|
||||
$parent_cat = Category::load($values['hid_category_id']); |
||||
$global_weight = $cat[0]->get_weight(); |
||||
//$values['weight'] = $values['weight_mask']/$global_weight*$parent_cat[0]->get_weight(); |
||||
$values['weight'] = $values['weight_mask']; |
||||
|
||||
$eval->set_weight($values['weight']); |
||||
$eval->set_max($values['max']); |
||||
$eval->set_visible(empty($values['visible']) ? 0 : 1); |
||||
$eval->add(); |
||||
|
||||
/** @var GradebookEvaluation $gradebookEval */ |
||||
$gradebookEval = $em->find('ChamiloCoreBundle:GradebookEvaluation', $eval->get_id()); |
||||
$ltiTool->setGradebookEval($gradebookEval); |
||||
|
||||
$em->persist($ltiTool); |
||||
$em->flush(); |
||||
|
||||
header('Location: '.Category::getUrl().'selectcat='.$eval->get_category_id()); |
||||
|
||||
exit; |
||||
} |
||||
|
||||
$interbreadcrumb[] = [ |
||||
'url' => Category::getUrl().'selectcat='.$select_cat, |
||||
'name' => get_lang('Gradebook'), |
||||
]; |
||||
$this_section = SECTION_COURSES; |
||||
|
||||
$htmlHeadXtra[] = '<script> |
||||
$(document).ready( function() { |
||||
$("#hid_category_id").change(function() { |
||||
$("#hid_category_id option:selected").each(function () { |
||||
var cat_id = $(this).val(); |
||||
$.ajax({ |
||||
url: "'.api_get_path(WEB_AJAX_PATH).'gradebook.ajax.php?a=get_gradebook_weight", |
||||
data: "cat_id="+cat_id, |
||||
success: function(return_value) { |
||||
if (return_value != 0 ) { |
||||
$("#max_weight").html(return_value); |
||||
} |
||||
} |
||||
}); |
||||
}); |
||||
}); |
||||
}); |
||||
</script>'; |
||||
|
||||
Display::display_header(get_lang('NewEvaluation')); |
||||
|
||||
$form->display(); |
||||
|
||||
Display::display_footer(); |
||||
@ -0,0 +1,64 @@ |
||||
<?php |
||||
/* For license terms, see /license.txt */ |
||||
|
||||
use Chamilo\PluginBundle\Entity\ImsLti\ImsLtiTool; |
||||
|
||||
require_once __DIR__.'/../../main/inc/global.inc.php'; |
||||
require_once './OAuthSimple.php'; |
||||
|
||||
header('Content-Type: application/xml'); |
||||
|
||||
if (empty($_GET['t'])) { |
||||
exit; |
||||
} |
||||
|
||||
$em = Database::getManager(); |
||||
/** @var ImsLtiTool $tool */ |
||||
$tool = $em->find('ChamiloPluginBundle:ImsLti\ImsLtiTool', (int) $_GET['t']); |
||||
|
||||
if (empty($tool)) { |
||||
exit; |
||||
} |
||||
|
||||
$body = file_get_contents('php://input'); |
||||
$bodyHash = OAuthSimple::generateBodyHash($body); |
||||
|
||||
$url = api_get_path(WEB_PATH).'ims_lti/outcome_service/'.$tool->getId(); |
||||
$headers = getallheaders(); |
||||
|
||||
$params = OAuthSimple::getAuthorizationParams($headers['Authorization']); |
||||
|
||||
if (empty($params)) { |
||||
exit; |
||||
} |
||||
|
||||
$oauth = new OAuthSimple( |
||||
$params['oauth_consumer_key'], |
||||
$tool->getSharedSecret() |
||||
); |
||||
$oauth->setAction('POST'); |
||||
$oauth->setSignatureMethod('HMAC-SHA1'); |
||||
$result = $oauth->sign( |
||||
[ |
||||
'path' => $url, |
||||
'parameters' => [ |
||||
'oauth_body_hash' => $params['oauth_body_hash'], |
||||
'oauth_nonce' => $params['oauth_nonce'], |
||||
'oauth_timestamp' => $params['oauth_timestamp'], |
||||
'oauth_signature_method' => $params['oauth_signature_method'], |
||||
], |
||||
] |
||||
); |
||||
|
||||
$signatureValid = urldecode($result['signature']) == $params['oauth_signature']; |
||||
$bodyHashValid = $bodyHash === $params['oauth_body_hash']; |
||||
|
||||
if (!$signatureValid || !$bodyHashValid) { |
||||
exit; |
||||
} |
||||
|
||||
$plugin = ImsLtiPlugin::create(); |
||||
|
||||
$process = $plugin->processServiceRequest(); |
||||
|
||||
echo $process; |
||||
@ -0,0 +1,94 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
use Chamilo\PluginBundle\Entity\ImsLti\ImsLtiTool; |
||||
|
||||
/** |
||||
* Class FrmAdd. |
||||
*/ |
||||
class FrmAdd extends FormValidator |
||||
{ |
||||
/** |
||||
* @var ImsLtiTool|null |
||||
*/ |
||||
private $baseTool; |
||||
|
||||
/** |
||||
* FrmAdd constructor. |
||||
* |
||||
* @param string $name |
||||
* @param array $attributes |
||||
* @param ImsLtiTool|null $tool |
||||
*/ |
||||
public function __construct( |
||||
$name, |
||||
$attributes = [], |
||||
ImsLtiTool $tool = null |
||||
) { |
||||
parent::__construct($name, 'POST', '', '', $attributes, self::LAYOUT_HORIZONTAL, true); |
||||
|
||||
$this->baseTool = $tool; |
||||
} |
||||
|
||||
/** |
||||
* Build the form |
||||
*/ |
||||
public function build() |
||||
{ |
||||
$plugin = ImsLtiPlugin::create(); |
||||
|
||||
$this->addHeader($plugin->get_lang('ToolSettings')); |
||||
$this->addText('name', get_lang('Name')); |
||||
$this->addTextarea('description', get_lang('Description')); |
||||
|
||||
if (null === $this->baseTool) { |
||||
$this->addElement('url', 'launch_url', $plugin->get_lang('LaunchUrl')); |
||||
$this->addRule('launch_url', get_lang('Required'), 'required'); |
||||
$this->addText('consumer_key', $plugin->get_lang('ConsumerKey')); |
||||
$this->addText('shared_secret', $plugin->get_lang('SharedSecret')); |
||||
} |
||||
|
||||
$this->addButtonAdvancedSettings('lti_adv'); |
||||
$this->addHtml('<div id="lti_adv_options" style="display:none;">'); |
||||
$this->addTextarea( |
||||
'custom_params', |
||||
[$plugin->get_lang('CustomParams'), $plugin->get_lang('CustomParamsHelp')] |
||||
); |
||||
|
||||
if (null === $this->baseTool || |
||||
($this->baseTool && !$this->baseTool->isActiveDeepLinking()) |
||||
) { |
||||
$this->addCheckBox( |
||||
'deep_linking', |
||||
[null, $plugin->get_lang('SupportDeppLinkingHelp'), null], |
||||
$plugin->get_lang('SupportDeepLinking') |
||||
); |
||||
} |
||||
|
||||
$this->addHtml('</div>'); |
||||
$this->addButtonAdvancedSettings('lti_privacy', get_lang('Privacy')); |
||||
$this->addHtml('<div id="lti_privacy_options" style="display:none;">'); |
||||
$this->addCheckBox('share_name', null, $plugin->get_lang('ShareLauncherName')); |
||||
$this->addCheckBox('share_email', null, $plugin->get_lang('ShareLauncherEmail')); |
||||
$this->addCheckBox('share_picture', null, $plugin->get_lang('ShareLauncherPicture')); |
||||
$this->addHtml('</div>'); |
||||
$this->addButtonCreate($plugin->get_lang('AddExternalTool')); |
||||
$this->applyFilter('__ALL__', 'Security::remove_XSS'); |
||||
} |
||||
|
||||
public function setDefaultValues() |
||||
{ |
||||
if (null !== $this->baseTool) { |
||||
$this->setDefaults( |
||||
[ |
||||
'name' => $this->baseTool->getName(), |
||||
'description' => $this->baseTool->getDescription(), |
||||
'custom_params' => $this->baseTool->getCustomParams(), |
||||
'share_name' => $this->baseTool->isSharingName(), |
||||
'share_email' => $this->baseTool->isSharingEmail(), |
||||
'share_picture' => $this->baseTool->isSharingPicture(), |
||||
] |
||||
); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,115 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
use Chamilo\PluginBundle\Entity\ImsLti\ImsLtiTool; |
||||
|
||||
/** |
||||
* Class FrmAdd. |
||||
*/ |
||||
class FrmEdit extends FormValidator |
||||
{ |
||||
/** |
||||
* @var ImsLtiTool|null |
||||
*/ |
||||
private $tool; |
||||
|
||||
/** |
||||
* FrmAdd constructor. |
||||
* |
||||
* @param string $name |
||||
* @param array $attributes |
||||
* @param ImsLtiTool|null $tool |
||||
*/ |
||||
public function __construct( |
||||
$name, |
||||
$attributes = [], |
||||
ImsLtiTool $tool = null |
||||
) { |
||||
parent::__construct($name, 'POST', '', '', $attributes, self::LAYOUT_HORIZONTAL, true); |
||||
|
||||
$this->tool = $tool; |
||||
} |
||||
|
||||
/** |
||||
* Build the form. |
||||
* |
||||
* @param bool $globalMode |
||||
* |
||||
* @throws Exception |
||||
*/ |
||||
public function build($globalMode = true) |
||||
{ |
||||
$plugin = ImsLtiPlugin::create(); |
||||
$course = $this->tool->getCourse(); |
||||
$parent = $this->tool->getParent(); |
||||
|
||||
$this->addHeader($plugin->get_lang('ToolSettings')); |
||||
|
||||
if (null !== $course && $globalMode) { |
||||
$this->addHtml( |
||||
Display::return_message( |
||||
sprintf($plugin->get_lang('ToolAddedOnCourseX'), $course->getTitle()), |
||||
'normal', |
||||
false |
||||
) |
||||
); |
||||
} |
||||
|
||||
$this->addText('name', get_lang('Name')); |
||||
$this->addTextarea('description', get_lang('Description')); |
||||
|
||||
if (null === $parent) { |
||||
$this->addElement('url', 'launch_url', $plugin->get_lang('LaunchUrl')); |
||||
$this->addRule('launch_url', get_lang('Required'), 'required'); |
||||
$this->addText('consumer_key', $plugin->get_lang('ConsumerKey')); |
||||
$this->addText('shared_secret', $plugin->get_lang('SharedSecret')); |
||||
} |
||||
|
||||
$this->addButtonAdvancedSettings('lti_adv'); |
||||
$this->addHtml('<div id="lti_adv_options" style="display:none;">'); |
||||
$this->addTextarea( |
||||
'custom_params', |
||||
[$plugin->get_lang('CustomParams'), $plugin->get_lang('CustomParamsHelp')] |
||||
); |
||||
|
||||
if (null === $parent || |
||||
(null !== $parent && !$parent->isActiveDeepLinking()) |
||||
) { |
||||
$this->addCheckBox( |
||||
'deep_linking', |
||||
[null, $plugin->get_lang('SupportDeppLinkingHelp'), null], |
||||
$plugin->get_lang('SupportDeepLinking') |
||||
); |
||||
} |
||||
|
||||
$this->addHtml('</div>'); |
||||
$this->addButtonAdvancedSettings('lti_privacy', get_lang('Privacy')); |
||||
$this->addHtml('<div id="lti_privacy_options" style="display:none;">'); |
||||
$this->addCheckBox('share_name', null, $plugin->get_lang('ShareLauncherName')); |
||||
$this->addCheckBox('share_email', null, $plugin->get_lang('ShareLauncherEmail')); |
||||
$this->addCheckBox('share_picture', null, $plugin->get_lang('ShareLauncherPicture')); |
||||
$this->addHtml('</div>'); |
||||
$this->addButtonCreate($plugin->get_lang('EditExternalTool')); |
||||
$this->addHidden('id', $this->tool->getId()); |
||||
$this->addHidden('action', 'edit'); |
||||
$this->applyFilter('__ALL__', 'Security::remove_XSS'); |
||||
} |
||||
|
||||
public function setDefaultValues() |
||||
{ |
||||
$this->setDefaults( |
||||
[ |
||||
'name' => $this->tool->getName(), |
||||
'description' => $this->tool->getDescription(), |
||||
'launch_url' => $this->tool->getLaunchUrl(), |
||||
'consumer_key' => $this->tool->getConsumerKey(), |
||||
'shared_secret' => $this->tool->getSharedSecret(), |
||||
'custom_params' => $this->tool->getCustomParams(), |
||||
'deep_linking' => $this->tool->isActiveDeepLinking(), |
||||
'share_name' => $this->tool->isSharingName(), |
||||
'share_email' => $this->tool->isSharingEmail(), |
||||
'share_picture' => $this->tool->isSharingPicture(), |
||||
] |
||||
); |
||||
} |
||||
} |
||||
@ -0,0 +1,65 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
use Chamilo\CoreBundle\Entity\GradebookEvaluation; |
||||
use Chamilo\UserBundle\Entity\User; |
||||
|
||||
/** |
||||
* Class ImsLtiDeleteServiceRequest. |
||||
*/ |
||||
class ImsLtiServiceDeleteRequest extends ImsLtiServiceRequest |
||||
{ |
||||
/** |
||||
* ImsLtiDeleteServiceRequest constructor. |
||||
* |
||||
* @param SimpleXMLElement $xml |
||||
*/ |
||||
public function __construct(SimpleXMLElement $xml) |
||||
{ |
||||
parent::__construct($xml); |
||||
|
||||
$this->responseType = ImsLtiServiceResponse::TYPE_DELETE; |
||||
$this->xmlRequest = $this->xmlRequest->deleteResultRequest; |
||||
} |
||||
|
||||
protected function processBody() |
||||
{ |
||||
$resultRecord = $this->xmlRequest->resultRecord; |
||||
$sourcedId = (string) $resultRecord->sourcedGUID->sourcedId; |
||||
|
||||
$sourcedParts = explode(':', $sourcedId); |
||||
|
||||
$em = Database::getManager(); |
||||
/** @var GradebookEvaluation $evaluation */ |
||||
$evaluation = $em->find('ChamiloCoreBundle:GradebookEvaluation', $sourcedParts[0]); |
||||
/** @var User $user */ |
||||
$user = $em->find('ChamiloUserBundle:User', $sourcedParts[1]); |
||||
|
||||
if (empty($evaluation) || empty($user)) { |
||||
$this->statusInfo |
||||
->setSeverity(ImsLtiServiceResponseStatus::SEVERITY_STATUS) |
||||
->setCodeMajor(ImsLtiServiceResponseStatus::CODEMAJOR_FAILURE); |
||||
|
||||
return; |
||||
} |
||||
|
||||
$results = Result::load(null, $user->getId(), $evaluation->getId()); |
||||
|
||||
if (empty($results)) { |
||||
$this->statusInfo |
||||
->setSeverity(ImsLtiServiceResponseStatus::SEVERITY_STATUS) |
||||
->setCodeMajor(ImsLtiServiceResponseStatus::CODEMAJOR_FAILURE); |
||||
|
||||
return; |
||||
} |
||||
|
||||
/** @var Result $result */ |
||||
$result = $results[0]; |
||||
$result->addResultLog($user->getId(), $evaluation->getId()); |
||||
$result->delete(); |
||||
|
||||
$this->statusInfo |
||||
->setSeverity(ImsLtiServiceResponseStatus::SEVERITY_STATUS) |
||||
->setCodeMajor(ImsLtiServiceResponseStatus::CODEMAJOR_SUCCESS); |
||||
} |
||||
} |
||||
@ -0,0 +1,29 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
/** |
||||
* Class ImsLtiServiceDeleteResponse. |
||||
*/ |
||||
class ImsLtiServiceDeleteResponse extends ImsLtiServiceResponse |
||||
{ |
||||
/** |
||||
* ImsLtiServiceDeleteResponse constructor. |
||||
* |
||||
* @param ImsLtiServiceResponseStatus $statusInfo |
||||
* @param mixed|null $bodyParam |
||||
*/ |
||||
public function __construct(ImsLtiServiceResponseStatus $statusInfo, $bodyParam = null) |
||||
{ |
||||
$statusInfo->setOperationRefIdentifier('deleteResult'); |
||||
|
||||
parent::__construct($statusInfo, $bodyParam); |
||||
} |
||||
|
||||
/** |
||||
* @param SimpleXMLElement $xmlBody |
||||
*/ |
||||
protected function generateBody(SimpleXMLElement $xmlBody) |
||||
{ |
||||
$xmlBody->addChild('deleteResultResponse'); |
||||
} |
||||
} |
||||
@ -0,0 +1,73 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
use Chamilo\CoreBundle\Entity\GradebookEvaluation; |
||||
use Chamilo\UserBundle\Entity\User; |
||||
|
||||
/** |
||||
* Class ImsLtiServiceReadRequest. |
||||
*/ |
||||
class ImsLtiServiceReadRequest extends ImsLtiServiceRequest |
||||
{ |
||||
/** |
||||
* ImsLtiServiceReadRequest constructor. |
||||
* |
||||
* @param SimpleXMLElement $xml |
||||
*/ |
||||
public function __construct(SimpleXMLElement $xml) |
||||
{ |
||||
parent::__construct($xml); |
||||
|
||||
$this->responseType = ImsLtiServiceResponse::TYPE_READ; |
||||
$this->xmlRequest = $this->xmlRequest->readResultRequest; |
||||
} |
||||
|
||||
protected function processBody() |
||||
{ |
||||
$resultRecord = $this->xmlRequest->resultRecord; |
||||
$sourcedId = (string) $resultRecord->sourcedGUID->sourcedId; |
||||
|
||||
$sourcedParts = explode(':', $sourcedId); |
||||
|
||||
$em = Database::getManager(); |
||||
/** @var GradebookEvaluation $evaluation */ |
||||
$evaluation = $em->find('ChamiloCoreBundle:GradebookEvaluation', $sourcedParts[0]); |
||||
/** @var User $user */ |
||||
$user = $em->find('ChamiloUserBundle:User', $sourcedParts[1]); |
||||
|
||||
if (empty($evaluation) || empty($user)) { |
||||
$this->statusInfo |
||||
->setSeverity(ImsLtiServiceResponseStatus::SEVERITY_STATUS) |
||||
->setCodeMajor(ImsLtiServiceResponseStatus::CODEMAJOR_FAILURE); |
||||
|
||||
return; |
||||
} |
||||
|
||||
$results = Result::load(null, $user->getId(), $evaluation->getId()); |
||||
|
||||
$ltiScore = ''; |
||||
$responseDescription = get_plugin_lang('ScoreNotSet', 'ImsLtiPlugin'); |
||||
|
||||
if (!empty($results)) { |
||||
/** @var Result $result */ |
||||
$result = $results[0]; |
||||
|
||||
if (!empty($result->get_score())) { |
||||
$ltiScore = $result->get_score() / $evaluation->getMax(); |
||||
|
||||
$responseDescription = sprintf( |
||||
get_plugin_lang('ScoreForXUserIsYScore', 'ImsLtiPlugin'), |
||||
$user->getId(), |
||||
$ltiScore |
||||
); |
||||
} |
||||
} |
||||
|
||||
$this->statusInfo |
||||
->setSeverity(ImsLtiServiceResponseStatus::SEVERITY_STATUS) |
||||
->setCodeMajor(ImsLtiServiceResponseStatus::CODEMAJOR_SUCCESS) |
||||
->setDescription($responseDescription); |
||||
|
||||
$this->responseBodyParam = (string) $ltiScore; |
||||
} |
||||
} |
||||
@ -0,0 +1,35 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
/** |
||||
* Class ImsLtiReadServiceResponse |
||||
*/ |
||||
class ImsLtiServiceReadResponse extends ImsLtiServiceResponse |
||||
{ |
||||
/** |
||||
* ImsLtiServiceReadResponse constructor. |
||||
* |
||||
* @param ImsLtiServiceResponseStatus $statusInfo |
||||
* @param mixed|null $bodyParam |
||||
*/ |
||||
public function __construct(ImsLtiServiceResponseStatus $statusInfo, $bodyParam = null) |
||||
{ |
||||
$statusInfo->setOperationRefIdentifier('readResult'); |
||||
|
||||
parent::__construct($statusInfo, $bodyParam); |
||||
} |
||||
|
||||
/** |
||||
* @param SimpleXMLElement $xmlBody |
||||
*/ |
||||
protected function generateBody(SimpleXMLElement $xmlBody) |
||||
{ |
||||
$resultResponse = $xmlBody->addChild('readResultResponse'); |
||||
|
||||
$xmlResultScore = $resultResponse->addChild('result') |
||||
->addChild('resultScore'); |
||||
|
||||
$xmlResultScore->addChild('language', 'en'); |
||||
$xmlResultScore->addChild('textString', $this->bodyParams); |
||||
} |
||||
} |
||||
@ -0,0 +1,84 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
use Chamilo\CoreBundle\Entity\GradebookEvaluation; |
||||
use Chamilo\UserBundle\Entity\User; |
||||
|
||||
/** |
||||
* Class ImsLtiReplaceServiceRequest. |
||||
*/ |
||||
class ImsLtiServiceReplaceRequest extends ImsLtiServiceRequest |
||||
{ |
||||
/** |
||||
* ImsLtiReplaceServiceRequest constructor. |
||||
* |
||||
* @param SimpleXMLElement $xml |
||||
*/ |
||||
public function __construct(SimpleXMLElement $xml) |
||||
{ |
||||
parent::__construct($xml); |
||||
|
||||
$this->responseType = ImsLtiServiceResponse::TYPE_DELETE; |
||||
$this->xmlRequest = $this->xmlRequest->replaceResultRequest; |
||||
} |
||||
|
||||
protected function processBody() |
||||
{ |
||||
$resultRecord = $this->xmlRequest->resultRecord; |
||||
$sourcedId = (string) $resultRecord->sourcedGUID->sourcedId; |
||||
$resultScore = (float) $resultRecord->result->resultScore->textString; |
||||
|
||||
if (0 > $resultScore || 1 < $resultScore) { |
||||
$this->statusInfo |
||||
->setSeverity(ImsLtiServiceResponseStatus::SEVERITY_WARNING) |
||||
->setCodeMajor(ImsLtiServiceResponseStatus::CODEMAJOR_FAILURE); |
||||
|
||||
return; |
||||
} |
||||
|
||||
$sourcedParts = explode(':', $sourcedId); |
||||
|
||||
$em = Database::getManager(); |
||||
/** @var GradebookEvaluation $evaluation */ |
||||
$evaluation = $em->find('ChamiloCoreBundle:GradebookEvaluation', $sourcedParts[0]); |
||||
/** @var User $user */ |
||||
$user = $em->find('ChamiloUserBundle:User', $sourcedParts[1]); |
||||
|
||||
if (empty($evaluation) || empty($user)) { |
||||
$this->statusInfo |
||||
->setSeverity(ImsLtiServiceResponseStatus::SEVERITY_STATUS) |
||||
->setCodeMajor(ImsLtiServiceResponseStatus::CODEMAJOR_FAILURE); |
||||
|
||||
return; |
||||
} |
||||
|
||||
$score = $evaluation->getMax() * $resultScore; |
||||
|
||||
$results = Result::load(null, $user->getId(), $evaluation->getId()); |
||||
|
||||
if (empty($results)) { |
||||
$result = new Result(); |
||||
$result->set_evaluation_id($evaluation->getId()); |
||||
$result->set_user_id($user->getId()); |
||||
$result->set_score($score); |
||||
$result->add(); |
||||
} else { |
||||
/** @var Result $result */ |
||||
$result = $results[0]; |
||||
$result->addResultLog($user->getId(), $evaluation->getId()); |
||||
$result->set_score($score); |
||||
$result->save(); |
||||
} |
||||
|
||||
$this->statusInfo |
||||
->setSeverity(ImsLtiServiceResponseStatus::SEVERITY_STATUS) |
||||
->setCodeMajor(ImsLtiServiceResponseStatus::CODEMAJOR_SUCCESS) |
||||
->setDescription( |
||||
sprintf( |
||||
get_plugin_lang('ScoreForXUserIsYScore', 'ImsLtiPlugin'), |
||||
$user->getId(), |
||||
$resultScore |
||||
) |
||||
); |
||||
} |
||||
} |
||||
@ -0,0 +1,29 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
/** |
||||
* Class ImsLtiReplaceServiceResponse. |
||||
*/ |
||||
class ImsLtiServiceReplaceResponse extends ImsLtiServiceResponse |
||||
{ |
||||
/** |
||||
* ImsLtiServiceReplaceResponse constructor. |
||||
* |
||||
* @param ImsLtiServiceResponseStatus $statusInfo |
||||
* @param mixed|null $bodyParam |
||||
*/ |
||||
public function __construct(ImsLtiServiceResponseStatus $statusInfo, $bodyParam = null) |
||||
{ |
||||
$statusInfo->setOperationRefIdentifier('replaceResult'); |
||||
|
||||
parent::__construct($statusInfo, $bodyParam); |
||||
} |
||||
|
||||
/** |
||||
* @param SimpleXMLElement $xmlBody |
||||
*/ |
||||
protected function generateBody(SimpleXMLElement $xmlBody) |
||||
{ |
||||
$xmlBody->addChild('replaceResultResponse'); |
||||
} |
||||
} |
||||
@ -0,0 +1,82 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
/** |
||||
* Class ImsLtiServiceRequest. |
||||
*/ |
||||
abstract class ImsLtiServiceRequest |
||||
{ |
||||
/** |
||||
* @var string |
||||
*/ |
||||
protected $responseType; |
||||
|
||||
/** |
||||
* @var SimpleXMLElement |
||||
*/ |
||||
protected $xmlHeaderInfo; |
||||
|
||||
/** |
||||
* @var SimpleXMLElement |
||||
*/ |
||||
protected $xmlRequest; |
||||
|
||||
/** |
||||
* @var ImsLtiServiceResponseStatus |
||||
*/ |
||||
protected $statusInfo; |
||||
|
||||
/** |
||||
* @var mixed |
||||
*/ |
||||
protected $responseBodyParam; |
||||
|
||||
/** |
||||
* ImsLtiServiceRequest constructor. |
||||
* |
||||
* @param SimpleXMLElement $xml |
||||
*/ |
||||
public function __construct(SimpleXMLElement $xml) |
||||
{ |
||||
$this->statusInfo = new ImsLtiServiceResponseStatus(); |
||||
|
||||
$this->xmlHeaderInfo = $xml->imsx_POXHeader->imsx_POXRequestHeaderInfo; |
||||
$this->xmlRequest = $xml->imsx_POXBody->children(); |
||||
} |
||||
|
||||
protected function processHeader() |
||||
{ |
||||
$info = $this->xmlHeaderInfo; |
||||
|
||||
$this->statusInfo->setMessageRefIdentifier($info->imsx_messageIdentifier); |
||||
|
||||
error_log("Service Request: tool version {$info->imsx_version} message ID {$info->imsx_messageIdentifier}"); |
||||
} |
||||
|
||||
abstract protected function processBody(); |
||||
|
||||
/** |
||||
* @return ImsLtiServiceResponse|null |
||||
*/ |
||||
private function generateResponse() |
||||
{ |
||||
$response = ImsLtiServiceResponseFactory::create( |
||||
$this->responseType, |
||||
$this->statusInfo, |
||||
$this->responseBodyParam |
||||
); |
||||
|
||||
return $response; |
||||
} |
||||
|
||||
/** |
||||
* @return ImsLtiServiceResponse|null |
||||
*/ |
||||
public function process() |
||||
{ |
||||
$this->processHeader(); |
||||
$this->processBody(); |
||||
|
||||
return $this->generateResponse(); |
||||
} |
||||
} |
||||
@ -0,0 +1,31 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
/** |
||||
* Class ImsLtiServiceRequestFactory. |
||||
*/ |
||||
class ImsLtiServiceRequestFactory |
||||
{ |
||||
/** |
||||
* @param SimpleXMLElement $xml |
||||
* |
||||
* @return ImsLtiServiceRequest|null |
||||
*/ |
||||
public static function create(SimpleXMLElement $xml) |
||||
{ |
||||
$bodyChildren = $xml->imsx_POXBody->children(); |
||||
|
||||
if (!empty($bodyChildren)) { |
||||
switch ($bodyChildren->getName()) { |
||||
case 'replaceResultRequest': |
||||
return new ImsLtiServiceReplaceRequest($xml); |
||||
case 'readResultRequest': |
||||
return new ImsLtiServiceReadRequest($xml); |
||||
case 'deleteResultRequest': |
||||
return new ImsLtiServiceDeleteRequest($xml); |
||||
} |
||||
} |
||||
|
||||
return null; |
||||
} |
||||
} |
||||
@ -0,0 +1,64 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
/** |
||||
* Class ImsLtiServiceResponse. |
||||
*/ |
||||
abstract class ImsLtiServiceResponse |
||||
{ |
||||
const TYPE_REPLACE = 'replace'; |
||||
const TYPE_READ = 'read'; |
||||
const TYPE_DELETE = 'delete'; |
||||
|
||||
/** |
||||
* @var mixed |
||||
*/ |
||||
protected $bodyParams; |
||||
/** |
||||
* @var ImsLtiServiceResponseStatus |
||||
*/ |
||||
private $statusInfo; |
||||
|
||||
/** |
||||
* ImsLtiServiceResponse constructor. |
||||
* |
||||
* @param ImsLtiServiceResponseStatus $statusInfo |
||||
* @param mixed|null $bodyParam |
||||
*/ |
||||
public function __construct(ImsLtiServiceResponseStatus $statusInfo, $bodyParam = null) |
||||
{ |
||||
$this->statusInfo = $statusInfo; |
||||
$this->bodyParams = $bodyParam; |
||||
} |
||||
|
||||
/** |
||||
* @return string |
||||
*/ |
||||
public function __toString() |
||||
{ |
||||
$xml = new SimpleXMLElement('<imsx_POXEnvelopeResponse></imsx_POXEnvelopeResponse>'); |
||||
$xml->addAttribute('xmlns', 'http://www.imsglobal.org/services/ltiv1p1/xsd/imsoms_v1p0'); |
||||
|
||||
$headerInfo = $xml->addChild('imsx_POXHeader')->addChild('imsx_POXResponseHeaderInfo'); |
||||
$headerInfo->addChild('imsx_version', 'V1.0'); |
||||
$headerInfo->addChild('imsx_messageIdentifier', time()); |
||||
|
||||
$statusInfo = $headerInfo->addChild('imsx_statusInfo'); |
||||
$statusInfo->addChild('imsx_codeMajor', $this->statusInfo->getCodeMajor()); |
||||
$statusInfo->addChild('imsx_severity', $this->statusInfo->getSeverity()); |
||||
$statusInfo->addChild('imsx_description', $this->statusInfo->getDescription()); |
||||
$statusInfo->addChild('imsx_messageRefIdentifier', $this->statusInfo->getMessageRefIdentifier()); |
||||
$statusInfo->addChild('imsx_operationRefIdentifier', $this->statusInfo->getOperationRefIdentifier()); |
||||
|
||||
$body = $xml->addChild('imsx_POXBody'); |
||||
|
||||
$this->generateBody($body); |
||||
|
||||
return $xml->asXML(); |
||||
} |
||||
|
||||
/** |
||||
* @param SimpleXMLElement $xmlBody |
||||
*/ |
||||
abstract protected function generateBody(SimpleXMLElement $xmlBody); |
||||
} |
||||
@ -0,0 +1,29 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
/** |
||||
* Class ImsLtiServiceResponseFactory. |
||||
*/ |
||||
class ImsLtiServiceResponseFactory |
||||
{ |
||||
/** |
||||
* @param string $type |
||||
* @param ImsLtiServiceResponseStatus $statusInfo |
||||
* @param mixed $bodyParam |
||||
* |
||||
* @return ImsLtiServiceResponse|null |
||||
*/ |
||||
public static function create($type, ImsLtiServiceResponseStatus $statusInfo, $bodyParam = null) |
||||
{ |
||||
switch ($type) { |
||||
case ImsLtiServiceResponse::TYPE_REPLACE: |
||||
return new ImsLtiServiceReplaceResponse($statusInfo, $bodyParam); |
||||
case ImsLtiServiceResponse::TYPE_READ: |
||||
return new ImsLtiServiceReadResponse($statusInfo, $bodyParam); |
||||
case ImsLtiServiceResponse::TYPE_DELETE: |
||||
return new ImsLtiServiceDeleteResponse($statusInfo, $bodyParam); |
||||
} |
||||
|
||||
return null; |
||||
} |
||||
} |
||||
@ -0,0 +1,162 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
/** |
||||
* Class ImsLtiResponseStatus. |
||||
*/ |
||||
class ImsLtiServiceResponseStatus |
||||
{ |
||||
const SEVERITY_STATUS = 'status'; |
||||
const SEVERITY_WARNING = 'warning'; |
||||
const SEVERITY_ERROR = 'error'; |
||||
|
||||
const CODEMAJOR_SUCCESS = 'success'; |
||||
const CODEMAJOR_PROCESSING = 'processing'; |
||||
const CODEMAJOR_FAILURE = 'failure'; |
||||
const CODEMAJOR_UNSUPPORTED = 'supported'; |
||||
|
||||
/** |
||||
* @var string |
||||
*/ |
||||
private $codeMajor = ''; |
||||
|
||||
/** |
||||
* @var string |
||||
*/ |
||||
private $severity = ''; |
||||
|
||||
/** |
||||
* @var string |
||||
*/ |
||||
private $messageRefIdentifier = ''; |
||||
|
||||
/** |
||||
* @var string |
||||
*/ |
||||
private $operationRefIdentifier = ''; |
||||
|
||||
/** |
||||
* @var string |
||||
*/ |
||||
private $description = ''; |
||||
|
||||
/** |
||||
* Get codeMajor. |
||||
* |
||||
* @return string |
||||
*/ |
||||
public function getCodeMajor() |
||||
{ |
||||
return $this->codeMajor; |
||||
} |
||||
|
||||
/** |
||||
* Set codeMajor. |
||||
* |
||||
* @param string $codeMajor |
||||
* |
||||
* @return ImsLtiServiceResponseStatus |
||||
*/ |
||||
public function setCodeMajor($codeMajor) |
||||
{ |
||||
$this->codeMajor = $codeMajor; |
||||
|
||||
return $this; |
||||
} |
||||
|
||||
/** |
||||
* Get severity. |
||||
* |
||||
* @return string |
||||
*/ |
||||
public function getSeverity() |
||||
{ |
||||
return $this->severity; |
||||
} |
||||
|
||||
/** |
||||
* Set severity. |
||||
* |
||||
* @param string $severity |
||||
* |
||||
* @return ImsLtiServiceResponseStatus |
||||
*/ |
||||
public function setSeverity($severity) |
||||
{ |
||||
$this->severity = $severity; |
||||
|
||||
return $this; |
||||
} |
||||
|
||||
/** |
||||
* Get messageRefIdentifier. |
||||
* |
||||
* @return int |
||||
*/ |
||||
public function getMessageRefIdentifier() |
||||
{ |
||||
return $this->messageRefIdentifier; |
||||
} |
||||
|
||||
/** |
||||
* Set messageRefIdentifier. |
||||
* |
||||
* @param int $messageRefIdentifier |
||||
* |
||||
* @return ImsLtiServiceResponseStatus |
||||
*/ |
||||
public function setMessageRefIdentifier($messageRefIdentifier) |
||||
{ |
||||
$this->messageRefIdentifier = $messageRefIdentifier; |
||||
|
||||
return $this; |
||||
} |
||||
|
||||
/** |
||||
* Get operationRefIdentifier. |
||||
* |
||||
* @return int |
||||
*/ |
||||
public function getOperationRefIdentifier() |
||||
{ |
||||
return $this->operationRefIdentifier; |
||||
} |
||||
|
||||
/** |
||||
* Set operationRefIdentifier. |
||||
* |
||||
* @param int $operationRefIdentifier |
||||
* |
||||
* @return ImsLtiServiceResponseStatus |
||||
*/ |
||||
public function setOperationRefIdentifier($operationRefIdentifier) |
||||
{ |
||||
$this->operationRefIdentifier = $operationRefIdentifier; |
||||
|
||||
return $this; |
||||
} |
||||
|
||||
/** |
||||
* Get description. |
||||
* |
||||
* @return string |
||||
*/ |
||||
public function getDescription() |
||||
{ |
||||
return $this->description; |
||||
} |
||||
|
||||
/** |
||||
* Set description. |
||||
* |
||||
* @param string $description |
||||
* |
||||
* @return ImsLtiServiceResponseStatus |
||||
*/ |
||||
public function setDescription($description) |
||||
{ |
||||
$this->description = $description; |
||||
|
||||
return $this; |
||||
} |
||||
} |
||||
Loading…
Reference in new issue