Gradebook: Adding ajax calls to update the category weight see BT#3004

skala
Julio Montoya 14 years ago
parent b06f7bbf8e
commit 0a2d7dc65a
  1. 3
      main/gradebook/gradebook_add_cat.php
  2. 24
      main/gradebook/gradebook_add_eval.php
  3. 22
      main/gradebook/gradebook_add_link.php
  4. 22
      main/gradebook/gradebook_edit_link.php
  5. 16
      main/gradebook/index.php
  6. 6
      main/gradebook/lib/be/category.class.php
  7. 11
      main/gradebook/lib/fe/catform.class.php
  8. 62
      main/gradebook/lib/fe/evalform.class.php
  9. 1
      main/gradebook/lib/fe/gradebooktable.class.php
  10. 51
      main/gradebook/lib/fe/linkaddeditform.class.php
  11. 1
      main/gradebook/lib/fe/linkform.class.php
  12. 31
      main/inc/ajax/gradebook.ajax.php
  13. 2
      main/inc/lib/main_api.lib.php

@ -21,9 +21,6 @@ require_once 'lib/fe/catform.class.php';
api_block_anonymous_users();
block_students();
$htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/tag/jquery.fcbkcomplete.js" type="text/javascript" language="javascript"></script>';
$htmlHeadXtra[] = '<link href="'.api_get_path(WEB_LIBRARY_PATH).'javascript/tag/style.css" rel="stylesheet" type="text/css" />';

@ -78,9 +78,31 @@ $interbreadcrumb[] = array (
'name' => get_lang('Gradebook'
));
$this_section = SECTION_COURSES;
$htmlHeadXtra[] = '<script type="text/javascript">
$(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'));
if ($evaladd->get_course_code() == null) {
Display :: display_normal_message(get_lang('CourseIndependentEvaluation'),false);
}
$form->display();
Display :: display_footer();
Display :: display_footer();

@ -105,6 +105,28 @@ if (isset($_GET['typeselected']) && $_GET['typeselected'] != '0') {
$interbreadcrumb[]= array ('url' => $_SESSION['gradebook_dest'].'?selectcat=' .Security::remove_XSS($_GET['selectcat']),'name' => get_lang('Gradebook'));
$this_section = SECTION_COURSES;
$htmlHeadXtra[] = '<script type="text/javascript">
$(document).ready( function() {
$("#hide_category_id").change(function(){
$("#hide_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('MakeLink'));
if (isset ($typeform)) {
$typeform->display();

@ -60,6 +60,28 @@ if ($form->validate()) {
$interbreadcrumb[] = array ('url' => Security::remove_XSS($_SESSION['gradebook_dest']).'?selectcat='.$linkcat,'name' => get_lang('Gradebook'));
$htmlHeadXtra[] = '<script type="text/javascript">
$(document).ready( function() {
$("#hide_category_id").change(function(){
$("#hide_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('EditLink'));
$form->display();
Display :: display_footer();

@ -240,9 +240,9 @@ if (isset ($_GET['visiblecat'])) {
$filter_confirm_msg = false;
}
}
if (isset ($_GET['deletecat'])) {
if (isset($_GET['deletecat'])) {
block_students();
$cats= Category :: load($_GET['deletecat']);
$cats = Category :: load($_GET['deletecat']);
//delete all categories,subcategories and results
if ($cats[0] != null) {
if ($cats[0]->get_id() != 0) {
@ -251,7 +251,7 @@ if (isset ($_GET['deletecat'])) {
}
}
$confirmation_message = get_lang('CategoryDeleted');
$filter_confirm_msg = false;
$filter_confirm_msg = false;
}
//parameters for evaluations
if (isset ($_GET['visibleeval'])) {
@ -618,11 +618,12 @@ if (isset ($_GET['studentoverview'])) {
// one) category for this course or for this session.
//hack for delete a gradebook from inside course
/*
$clean_deletecat = isset($_GET['deletecat']) ? intval($_GET['deletecat']) : null;
if (!empty($clean_deletecat)) {
exit;
}
//end hack
//end hack*/
$cats = Category :: load(null, null, $course_code, null, null, $session_id, false);
if (empty($cats)) {
@ -789,6 +790,7 @@ if (api_is_allowed_to_edit(null, true)) {
}
}
}
if (isset($first_time) && $first_time==1 && api_is_allowed_to_edit(null,true)) {
echo '<meta http-equiv="refresh" content="0;url='.api_get_self().'?cidReq='.$course_code.'" />';
} else {
@ -811,7 +813,7 @@ if (isset($first_time) && $first_time==1 && api_is_allowed_to_edit(null,true)) {
if (!empty($cats)) {
$items = $grading_contents['items'];
$i = 0;
$i = 0;
foreach ($cats as $cat) {
$allcat = $cat->get_subcategories($stud_id, $course_code, $session_id);
@ -823,12 +825,12 @@ if (isset($first_time) && $first_time==1 && api_is_allowed_to_edit(null,true)) {
} else {
//This is the father
//Create gradebook/add gradebook links
DisplayGradebook::display_header_gradebook($cat, 0, $cat->get_id(), $is_course_admin, $is_platform_admin, $simple_search_form, false, true);
DisplayGradebook::display_header_gradebook($cat, 0, $cat->get_id(), $is_course_admin, $is_platform_admin, $simple_search_form, false, true);
if (api_is_allowed_to_edit(null,true)) {
//Showing the grading system
if (!empty($grading_string)) {
Display::display_normal_message($grading_string);
Display::display_normal_message(get_lang('GradeModel').': '.$grading_string);
}
}
$gradebooktable = new GradebookTable($cat, $allcat, $alleval, $alllink, $addparams);

@ -132,7 +132,7 @@ class Category implements GradebookItem
return $skills;
}
function get_skills_for_select() {
public function get_skills_for_select() {
$skills = $this->get_skills();
$skill_select = array();
if (!empty($skills)) {
@ -165,7 +165,7 @@ class Category implements GradebookItem
}
$tbl_grade_categories = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
$sql='SELECT id,name,description,user_id,course_code,parent_id,weight,visible,certif_min_score,session_id FROM '.$tbl_grade_categories;
$sql = 'SELECT id, name, description, user_id, course_code, parent_id, weight, visible, certif_min_score, session_id FROM '.$tbl_grade_categories;
$paramcount = 0;
if (isset($id)) {
$id = Database::escape_string($id);
@ -219,7 +219,7 @@ class Category implements GradebookItem
$sql .= ' visible = '.intval($visible);
$paramcount ++;
}
//echo $sql.'<br />';
$result = Database::query($sql);
$allcat = array();
if (Database::num_rows($result) > 0) {

@ -9,7 +9,6 @@
*/
require_once dirname(__FILE__).'/../../../inc/global.inc.php';
require_once dirname(__FILE__).'/../be.inc.php';
require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
/**
* Extends formvalidator with add&edit forms
@ -136,6 +135,7 @@ class CatForm extends FormValidator {
private function build_basic_form() {
$this->addElement('hidden', 'zero', 0);
$this->add_textfield('name', get_lang('CategoryName'), true,array('size'=>'54','maxlength'=>'50'));
$this->addRule('name', get_lang('ThisFieldIsRequired'), 'required');
if (isset($this->category_object) && $this->category_object->get_parent_id() == 0) {
@ -163,9 +163,12 @@ class CatForm extends FormValidator {
///direct access to one evaluation
$cats = Category :: load(null, null, $course_code, null, null, $session_id, false); //already init
$count = count($cats) - 1;
$value = intval($grading_contents['items'][$count]['percentage']);
$value = intval($grading_contents['items'][$count]['percentage']);
if ($value == 0) {
//Display::display_warning_message(get_lang('GradingModelBlocks'));
}
$this->add_textfield('weight', get_lang('TotalWeight'),true,array('value'=>$value,'size'=>'4','maxlength'=>'5'));
$this->add_textfield('weight', get_lang('TotalWeight'), true, array('value'=> $value,'size'=>'4','maxlength'=>'5'));
//$this->addRule('weight',get_lang('ThisFieldIsRequired'),'required');
$this->freeze('weight');
} else {
@ -200,7 +203,7 @@ class CatForm extends FormValidator {
$this->addElement('hidden','hid_user_id');
$this->addElement('hidden','hid_parent_id');
$this->addElement('textarea', 'description', get_lang('Description'),array('rows'=>'3','cols' => '34'));
$this->addElement('checkbox', 'visible',get_lang('Visible'));
$this->addElement('checkbox', 'visible', null, get_lang('Visible'));
if ($this->form_type == self :: TYPE_ADD) {
$this->addElement('style_submit_button', null, get_lang('AddCategory'), 'class="save"');
} else {

@ -11,7 +11,7 @@ require_once dirname(__FILE__).'/../../../inc/global.inc.php';
require_once dirname(__FILE__).'/../be.inc.php';
require_once dirname(__FILE__).'/../gradebook_functions.inc.php';
require_once api_get_path(LIBRARY_PATH) . 'groupmanager.lib.php';
require_once api_get_path(LIBRARY_PATH) . 'formvalidator/FormValidator.class.php';
/**
* Extends formvalidator with add&edit forms for evaluations
* @author Stijn Konings
@ -375,9 +375,9 @@ class EvalForm extends FormValidator
'hid_course_code' => $this->evaluation_object->get_course_code(), 'created_at' => api_get_utc_datetime()));
$this->build_basic_form(0);
if ($this->evaluation_object->get_course_code() == null) {
$this->addElement('checkbox', 'adduser', get_lang('AddUserToEval'));
$this->addElement('checkbox', 'adduser', null, get_lang('AddUserToEval'));
} else {
$this->addElement('checkbox', 'addresult', get_lang('AddResult'));
$this->addElement('checkbox', 'addresult', null, get_lang('AddResult'));
}
$this->addElement('style_submit_button', 'submit', get_lang('AddAssessment'),'class="add"');
}
@ -403,8 +403,8 @@ class EvalForm extends FormValidator
*/
private function build_basic_form($edit= 0) {
$form_title = get_lang('NewEvaluation');
if ($_GET['editeval']==1)
{
if ($_GET['editeval']==1) {
$form_title = get_lang('EditEvaluation');
}
@ -418,10 +418,36 @@ class EvalForm extends FormValidator
'maxlength' => '50',
'id' => 'evaluation_title'
));
$this->add_textfield('weight', get_lang('Weight'), true, array (
$select_gradebook = $this->addElement('select', 'hid_category_id', get_lang('SelectGradebook'), array(), array('id' => 'hid_category_id'));
$all_categories = Category :: load();
$default_weight = 0;
if (!empty($all_categories)) {
foreach($all_categories as $my_cat) {
if ($my_cat->get_course_code() == api_get_course_id()) {
if ($my_cat->get_parent_id() == 0 ) {
$default_weight = $my_cat->get_weight();
$select_gradebook->addoption(get_lang('Default'), $my_cat->get_id());
} else {
$select_gradebook->addoption($my_cat->get_name(), $my_cat->get_id());
}
if ($this->evaluation_object->get_category_id() == $my_cat->get_id()) {
$default_weight = $my_cat->get_weight();
}
}
}
}
$this->add_textfield('weight', array(get_lang('Weight'), null, '/ <span id="max_weight">'.$default_weight.'</span>'), true, array (
'size' => '4',
'maxlength' => '5'
));
if ($edit) {
if (!$this->evaluation_object->has_results()) {
$this->add_textfield('max', get_lang('QualificationNumeric'), true, array (
@ -441,37 +467,23 @@ class EvalForm extends FormValidator
'size' => '4',
'maxlength' => '5'
));
}
}
$this->addElement('textarea', 'description', get_lang('Description'), array (
'rows' => '3',
'cols' => '34'
));
$this->addElement('checkbox', 'visible', get_lang('Visible'));
$this->addElement('checkbox', 'visible', null, get_lang('Visible'));
$this->addRule('weight', get_lang('OnlyNumbers'), 'numeric');
$this->addRule(array ('weight', 'zero'), get_lang('NegativeValue'), 'compare', '>=');
$this->addRule('max', get_lang('OnlyNumbers'), 'numeric');
$this->addRule(array ('max', 'zero'), get_lang('NegativeValue'), 'compare', '>=');
$select_gradebook = $this->addElement('select', 'hid_category_id', get_lang('SelectGradebook'));
$all_categories = Category :: load();
if (!empty($all_categories)) {
foreach($all_categories as $my_cat) {
if ($my_cat->get_course_code() == api_get_course_id()) {
if ($my_cat->get_parent_id() == 0 ) {
$select_gradebook->addoption(get_lang('Default'), $my_cat->get_id());
} else {
$select_gradebook->addoption($my_cat->get_name(), $my_cat->get_id());
}
}
}
}
}
function display() {
parent :: display();
}
function setDefaults($defaults= array ()) {
parent :: setDefaults($defaults);
}

@ -289,6 +289,7 @@ class GradebookTable extends SortableTable {
$course_code = $this->build_course_code($category[0]);
if ($weight_total_links > $weight_category) {
$warning_message = get_lang('TotalWeightMustNotBeMoreThan').'&nbsp;'.$weight_category;
Display::display_warning_message($warning_message,false);
}

@ -11,7 +11,6 @@ require_once dirname(__FILE__).'/../../../inc/global.inc.php';
require_once dirname(__FILE__).'/../be.inc.php';
require_once dirname(__FILE__).'/../gradebook_functions.inc.php';
require_once api_get_path(LIBRARY_PATH) . 'groupmanager.lib.php';
require_once api_get_path(LIBRARY_PATH) . 'formvalidator/FormValidator.class.php';
/**
* Form used to add or edit links
@ -69,14 +68,42 @@ class LinkAddEditForm extends FormValidator
} else {
$this->addElement('static','label',get_lang('Name'), $link->get_name().' ['.$link->get_type_name().']');
$this->addElement('hidden','name_link',$link->get_name(),array('id'=>'name_link'));
}
}
$select_gradebook = $this->addElement('select', 'select_gradebook', get_lang('SelectGradebook'), array(), array('id' => 'hide_category_id'));
$default_weight = 0;
if (!empty($category_object)) {
foreach($category_object as $my_cat) {
if ($my_cat->get_course_code() == api_get_course_id()) {
if ($my_cat->get_parent_id() == 0 ) {
$default_weight = $my_cat->get_weight();
$select_gradebook->addoption(get_lang('Default'), $my_cat->get_id());
} else {
$select_gradebook->addoption($my_cat->get_name(), $my_cat->get_id());
}
if ($link->get_category_id() == $my_cat->get_id()) {
$default_weight = $my_cat->get_weight();
}
}
}
}
// ELEMENT: weight
$this->add_textfield('weight', get_lang('Weight'),true,array('size'=>'4','maxlength'=>'5'));
$this->add_textfield('weight', array(get_lang('Weight'), null, '/ <span id="max_weight">'.$default_weight.'</span>'), true, array (
'size' => '4',
'maxlength' => '5'
));
$this->addRule('weight',get_lang('OnlyNumbers'),'numeric');
$this->addRule(array ('weight', 'zero'), get_lang('NegativeValue'), 'compare', '>=');
if ($form_type == self :: TYPE_EDIT) {
$defaults['weight'] = $link->get_weight();
$defaults['weight'] = $link->get_weight();
$defaults['select_gradebook'] = $link->get_category_id();
}
// ELEMENT: max
if ($link->needs_max()) {
@ -108,24 +135,12 @@ class LinkAddEditForm extends FormValidator
// ELEMENT: visible
$visible = ($form_type == self :: TYPE_EDIT && $link->is_visible()) ? '1' : '0';
$this->addElement('checkbox', 'visible',get_lang('Visible'),null,$visible);
$this->addElement('checkbox', 'visible', null, get_lang('Visible'), $visible);
if ($form_type == self :: TYPE_EDIT) {
$defaults['visible'] = $link->is_visible();
}
$select_gradebook = $this->addElement('select', 'select_gradebook', get_lang('SelectGradebook'));
if (!empty($category_object)) {
foreach($category_object as $my_cat) {
if ($my_cat->get_course_code() == api_get_course_id()) {
if ($my_cat->get_parent_id() == 0 ) {
$select_gradebook->addoption(get_lang('Default'), $my_cat->get_id());
} else {
$select_gradebook->addoption($my_cat->get_name(), $my_cat->get_id());
}
}
}
}
// ELEMENT: add results
if ($form_type == self :: TYPE_ADD && $link->needs_results()) {

@ -11,7 +11,6 @@ require_once dirname(__FILE__).'/../../../inc/global.inc.php';
require_once dirname(__FILE__).'/../be.inc.php';
require_once dirname(__FILE__).'/../gradebook_functions.inc.php';
require_once api_get_path(LIBRARY_PATH) . 'groupmanager.lib.php';
require_once api_get_path(LIBRARY_PATH) . 'formvalidator/FormValidator.class.php';
/**
* Forms related to links

@ -0,0 +1,31 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Responses to AJAX calls
*/
require_once '../global.inc.php';
require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be.inc.php';
require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/gradebook_functions.inc.php';
api_protect_course_script(true);
$action = $_REQUEST['a'];
switch ($action) {
case 'get_gradebook_weight':
if (api_is_allowed_to_edit(null, true)) {
$cat_id = $_GET['cat_id'];
$cat = Category :: load($cat_id);
if ($cat && isset($cat[0])) {
echo $cat[0]->get_weight();
} else {
echo 0;
}
}
break;
default:
echo '';
}
exit;

@ -5524,7 +5524,7 @@ function api_grading_model_functions($grading_model, $action = 'to_array') {
if (empty($grading_model)) {
return null;
}
$elements = array('A','B','C','D','E', 'F', 'G', 'H','I','J', 'K');
$elements = array('A','B','C','D','E','F','G','H','I','J','K','L','M');
if (in_array($action, array('to_array', 'decorate'))) {
$parts = explode('/', $grading_model);

Loading…
Cancel
Save