Actualización
This commit is contained in:
190
plugin/ims_lti/gradebook/OutcomeForm.php
Normal file
190
plugin/ims_lti/gradebook/OutcomeForm.php
Normal file
@@ -0,0 +1,190 @@
|
||||
<?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();
|
||||
}
|
||||
|
||||
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');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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]);
|
||||
}
|
||||
}
|
||||
145
plugin/ims_lti/gradebook/add_eval.php
Normal file
145
plugin/ims_lti/gradebook/add_eval.php
Normal file
@@ -0,0 +1,145 @@
|
||||
<?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;
|
||||
$sessionId = isset($_GET['id_session']) ? (int) $_GET['id_session'] : null;
|
||||
$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(), null, null, $sessionId);
|
||||
|
||||
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();
|
||||
Reference in New Issue
Block a user