Should fix bug when updating/adding works in gradebooks see #5168

skala
Julio Montoya 13 years ago
parent 98019b6d63
commit d756830524
  1. 10
      main/gradebook/gradebook.php
  2. 5
      main/gradebook/lib/be/abstractlink.class.php
  3. 4
      main/gradebook/lib/be/evaluation.class.php
  4. 10
      main/gradebook/lib/be/forumthreadlink.class.php
  5. 2
      main/gradebook/lib/be/linkfactory.class.php
  6. 15
      main/gradebook/lib/be/studentpublicationlink.class.php
  7. 66
      main/gradebook/lib/gradebook_functions.inc.php
  8. 5
      main/inc/lib/gradebook.lib.php
  9. 82
      main/work/work.lib.php
  10. 8
      main/work/work.php

@ -58,13 +58,6 @@ $filter_confirm_msg = true;
$filter_warning_msg = true;
// ACTIONS
$my_selectcat =isset($_GET['selectcat']) ? Security::remove_XSS($_GET['selectcat']) : '';
if ($my_selectcat!='') {
$course_id = get_course_id_by_link_id($my_selectcat);
$tbl_forum_thread = Database :: get_course_table(TABLE_FORUM_THREAD);
$tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
}
//this is called when there is no data for the course admin
if (isset ($_GET['createallcategories'])) {
block_students();
@ -262,9 +255,6 @@ if (isset ($_GET['deletelink'])) {
if (!empty($_GET['deletelink'])) {
$link= LinkFactory :: load($_GET['deletelink']);
if ($link[0] != null) {
$sql = 'UPDATE '.$tbl_forum_thread.' SET thread_qualify_max=0,thread_weight=0,thread_title_qualify=""
WHERE c_id = '.$course_id.' AND thread_id=(SELECT ref_id FROM '.$tbl_grade_links.' WHERE c_id = '.$course_id.' AND id='.intval($_GET['deletelink']).');';
Database::query($sql);
$link[0]->delete();
}
unset ($link);

@ -240,11 +240,14 @@ abstract class AbstractLink implements GradebookItem {
$sql .= ','.'"'.$date_current=api_get_local_time().'"';
$sql .= ")";
Database::query($sql);
$this->set_id(Database::insert_id());
$inserted_id = Database::insert_id();
$this->set_id($inserted_id);
return $inserted_id;
}
} else {
die('Error in AbstractLink add: required field empty');
}
return false;
}
/**

@ -606,4 +606,8 @@ class Evaluation implements GradebookItem
}
}
}
function delete_linked_data() {
}
}

@ -257,4 +257,14 @@ class ForumThreadLink extends AbstractLink
public function get_icon_name() {
return 'forum';
}
function delete_linked_data() {
$ref_id = $this->get_ref_id();
if (!empty($ref_id)) {
//Cleans forum
$sql = 'UPDATE '.$this->get_forum_thread_table().' SET thread_qualify_max=0,thread_weight=0,thread_title_qualify=""
WHERE c_id = '.$this->course_id.' AND thread_id= '.$ref_id;
Database::query($sql);
}
}
}

@ -15,7 +15,7 @@
define('LINK_EXERCISE', 1);
define('LINK_DROPBOX', 2);
define('LINK_STUDENTPUBLICATION', 3);
define('LINK_LEARNPATH', 4);
define('LINK_LEARNPATH', 4);
define('LINK_FORUM_THREAD', 5);
//define('LINK_WORK',6);
define('LINK_ATTENDANCE', 7);

@ -264,10 +264,7 @@ class StudentPublicationLink extends AbstractLink
}
public function is_valid_link() {
/* $sql = 'SELECT count(id) from '.$this->get_studpub_table().'
WHERE c_id = "'.$this->course_id.'" AND id = '.intval($this->get_ref_id()).' AND session_id='.api_get_session_id();
*/
$sql = 'SELECT count(id) from '.$this->get_studpub_table().'
$sql = 'SELECT count(id) FROM '.$this->get_studpub_table().'
WHERE c_id = "'.$this->course_id.'" AND id = '.intval($this->get_ref_id()).'';
$result = Database::query($sql);
$number = Database::fetch_row($result);
@ -277,4 +274,14 @@ class StudentPublicationLink extends AbstractLink
public function get_icon_name() {
return 'studentpublication';
}
function delete_linked_data() {
$ref_id = $this->get_ref_id();
if (!empty($ref_id)) {
//Cleans works
$sql = 'UPDATE '.$this->get_studpub_table().' SET weight=0
WHERE c_id = '.$this->course_id.' AND id ='.$ref_id;
Database::query($sql);
}
}
}

@ -28,7 +28,7 @@ require_once 'gradebook_functions_users.inc.php';
* @param int Session ID (optional or 0 if not defined)
* @return boolean True on success, false on failure
*/
function add_resource_to_course_gradebook($category_id, $course_code, $resource_type, $resource_id, $resource_name='', $weight=0, $max=0, $resource_description='', $visible=0, $session_id = 0) {
function add_resource_to_course_gradebook($category_id, $course_code, $resource_type, $resource_id, $resource_name='', $weight=0, $max=0, $resource_description='', $visible = 0, $session_id = 0, $link_id = null) {
$link = LinkFactory :: create($resource_type);
$link->set_user_id(api_get_user_id());
$link->set_course_code($course_code);
@ -60,6 +60,38 @@ function add_resource_to_course_gradebook($category_id, $course_code, $resource_
return true;
}
/**
* Update a resource weight
* @param int Link/Resource ID
* @return bool false on error, true on success
*/
function update_resource_from_course_gradebook($link_id, $course_code, $weight) {
$course_code = Database::escape_string($course_code);
if (!empty($link_id)) {
$link_id = intval($link_id);
$sql = 'UPDATE '.Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK).'
SET weight = '."'".Database::escape_string((float)$weight)."'".'
WHERE course_code = "'.$course_code.'" AND id = '.$link_id;
Database::query($sql);
}
return true;
}
/**
* Remove a resource from the unique gradebook of a given course
* @param int Link/Resource ID
* @return bool false on error, true on success
*/
function remove_resource_from_course_gradebook($link_id) {
if ( empty($link_id) ) { return false; }
// TODO find the corresponding category (the first one for this course, ordered by ID)
$l = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
$sql = "DELETE FROM $l WHERE id = ".(int)$link_id;
$res = Database::query($sql);
return true;
}
function block_students() {
if (!api_is_allowed_to_edit()) {
api_not_allowed();
@ -280,19 +312,12 @@ function build_edit_icons_link($link, $selectcat) {
$modify_icons .= '&nbsp;<a href="gradebook_showlog_link.php?visiblelink=' . $link->get_id() . '&amp;selectcat=' . $selectcat . '&amp;cidReq='.$link->get_course_code().'">'.Display::return_icon('history.png', get_lang('GradebookQualifyLog'),'',ICON_SIZE_SMALL).'</a>';
//If a work is added in a gradebook you can only delete the link in the work tool
$show_delete = true;
if ($link->get_type() == 3) {
$show_delete = false;
}
if ($show_delete) {
if ($is_locked && !api_is_platform_admin()) {
$modify_icons .= '&nbsp;'.Display::return_icon('delete_na.png', get_lang('Delete'),'',ICON_SIZE_SMALL);
} else {
$modify_icons .= '&nbsp;<a href="' . api_get_self() . '?deletelink=' . $link->get_id() . '&selectcat=' . $selectcat . ' &amp;cidReq='.$link->get_course_code().'" onclick="return confirmation();">'.Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>';
}
} else {
$modify_icons .= '&nbsp;'.Display::return_icon('delete_na.png', get_lang('Delete'),'',ICON_SIZE_SMALL);
}
if ($is_locked && !api_is_platform_admin()) {
$modify_icons .= '&nbsp;'.Display::return_icon('delete_na.png', get_lang('Delete'),'',ICON_SIZE_SMALL);
} else {
$modify_icons .= '&nbsp;<a href="' . api_get_self() . '?deletelink=' . $link->get_id() . '&selectcat=' . $selectcat . ' &amp;cidReq='.$link->get_course_code().'" onclick="return confirmation();">'.Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>';
}
return $modify_icons;
}
}
@ -351,19 +376,6 @@ function get_resource_from_course_gradebook($link_id) {
return $row;
}
/**
* Remove a resource from the unique gradebook of a given course
* @param int Link/Resource ID
* @return bool false on error, true on success
*/
function remove_resource_from_course_gradebook($link_id) {
if ( empty($link_id) ) { return false; }
// TODO find the corresponding category (the first one for this course, ordered by ID)
$l = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
$sql = "DELETE FROM $l WHERE id = ".(int)$link_id;
$res = Database::query($sql);
return true;
}
/**
* Return the database name
* @param int

@ -25,16 +25,17 @@ class Gradebook extends Model {
$setting = ResultSet::create($sql)->first();
$setting = $setting ? $setting : array();
$inactive = isset($setting['selected_value']) && $setting['selected_value'] == 'true';
if ($inactive) {
return false;
}
$c_id = $c_id ? intval($c_id) : api_get_course_int_id();
$table = Database::get_course_table(TABLE_TOOL_LIST);
$sql = "SELECT * from $table WHERE c_id = $c_id and name='$name'";
$item = ResultSet::create($sql)->first();
$item = ResultSet::create($sql)->first();
if (empty($item)) {
return true;
}
}
return $item['visibility'] == '1';
}

@ -503,35 +503,37 @@ function display_student_publications_list($id, $link_target_parameter, $dateFor
list($d_year, $d_month, $d_day) = explode('-', $parts[0]);
list($d_hour, $d_minute) = explode(':', $parts[1]);
if(Gradebook::is_active()){
if (Gradebook::is_active()) {
$link_info = is_resource_in_course_gradebook(api_get_course_id(), LINK_STUDENTPUBLICATION, $id2);
$qualification_input[] = FormValidator :: createElement('text', 'qualification');
$form_folder -> addGroup($qualification_input, 'qualification', get_lang('QualificationNumeric'));
if ((int)$row['weight'] == 0) {
$form_folder -> addElement('checkbox', 'make_calification', null, get_lang('MakeQualifiable'), 'onclick="javascript: if(this.checked){document.getElementById(\'option3\').style.display = \'block\';}else{document.getElementById(\'option3\').style.display = \'none\';}"');
$form_folder -> addElement('checkbox', 'make_calification', null, get_lang('MakeQualifiable'), 'onclick="javascript: if(this.checked){document.getElementById(\'option3\').style.display = \'block\';}else{document.getElementById(\'option3\').style.display = \'none\';}"');
if (!empty($link_info)) {
$form_folder -> addElement('html', '<div id=\'option3\' style="display:block">');
} else {
$form_folder -> addElement('html', '<div id=\'option3\' style="display:none">');
}
//Loading gradebook select
load_gradebook_select_in_tool($form_folder);
$weight_input2[] = FormValidator :: createElement('text', 'weight');
$form_folder -> addGroup($weight_input2, 'weight', get_lang('WeightInTheGradebook'), 'size="10"');
//Loading gradebook select
load_gradebook_select_in_tool($form_folder);
$form_folder -> addElement('html', '</div>');
} else {
$weight_input[] = FormValidator :: createElement('text', 'weight');
//Loading gradebook select
load_gradebook_select_in_tool($form_folder);
$form_folder -> addGroup($weight_input, 'weight', get_lang('WeightInTheGradebook'), 'size="10"');
}
$weight_input2[] = FormValidator :: createElement('text', 'weight');
$form_folder -> addGroup($weight_input2, 'weight', get_lang('WeightInTheGradebook'), 'size="10"');
$link_info = is_resource_in_course_gradebook(api_get_course_id(), LINK_STUDENTPUBLICATION, $id2);
$defaults['category_id'] = $link_info['category_id'];
}else{
$form_folder -> addElement('html', '</div>');
$defaults['weight[weight]'] = $link_info['weight'];
if (!empty($link_info)) {
var_dump($link_info);
$defaults['category_id'] = $link_info['category_id'];
$defaults['make_calification'] = 1;
}
} else {
$defaults['category_id'] = '';
}
@ -606,10 +608,8 @@ function display_student_publications_list($id, $link_target_parameter, $dateFor
if (!empty($row['qualification'])) {
$defaults = array_merge($defaults, array('qualification[qualification]' => $row['qualification']));
}
if (!empty($row['weight'])) {
$defaults = array_merge($defaults, array('weight[weight]' => $row['weight']));
}
}
$defaults['allow_text_assignment'] = $row['allow_text_assignment'];
$form_folder -> setDefaults($defaults);
$display_edit_form = true;
@ -671,23 +671,25 @@ function display_student_publications_list($id, $link_target_parameter, $dateFor
Database::query($sql);
require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/gradebook_functions.inc.php';
if (isset($_POST['make_calification']) && $_POST['make_calification'] == 1 && !empty($_POST['category_id'])) {
$link_info = is_resource_in_course_gradebook(api_get_course_id(), 3 , $row['id'], api_get_session_id());
require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be/gradebookitem.class.php';
require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be/evaluation.class.php';
require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be/abstractlink.class.php';
$link_info = is_resource_in_course_gradebook(api_get_course_id(), LINK_STUDENTPUBLICATION, $row['id'], api_get_session_id());
$link_id = null;
if (!empty($link_info)) {
$link_id = $link_info['id'];
if ($link_info !== false) {
$course_code = api_get_course_id();
Database::query('UPDATE '.Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK).' SET weight = '."'".Database::escape_string((float)$_POST['weight']['weight'])."'".'
WHERE course_code = "'.$course_code.'" AND id = '.$link_id);
}
if (isset($_POST['make_calification']) && $_POST['make_calification'] == 1 && !empty($_POST['category_id'])) {
if (empty($link_id)) {
add_resource_to_course_gradebook($_POST['category_id'], api_get_course_id(), LINK_STUDENTPUBLICATION, $row['id'], $_POST['dir_name'], (float)$_POST['weight']['weight'], (float)$_POST['qualification']['qualification'], $_POST['description'], 1, api_get_session_id(), $link_id);
} else {
update_resource_from_course_gradebook($link_id, api_get_course_id(), $_POST['weight']['weight']);
}
require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be/gradebookitem.class.php';
require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be/evaluation.class.php';
require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be/abstractlink.class.php';
require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/gradebook_functions.inc.php';
$resource_name = $_POST['dir_name'];
add_resource_to_course_gradebook($_POST['category_id'], api_get_course_id(), 3, $row['id'], $resource_name, (float)$_POST['weight']['weight'], (float)$_POST['qualification']['qualification'], $_POST['description'], 1, api_get_session_id());
} else {
//Delete everything of the gradebook
remove_resource_from_course_gradebook($link_id);
}
update_dir_name($work_data, $dir_name, $values['dir_name']);

@ -780,14 +780,12 @@ switch ($action) {
$form->addElement('advanced_settings', '<a href="javascript: void(0);" onclick="javascript: return plus();"><span id="plus">'.Display::return_icon('div_show.gif',get_lang('AdvancedParameters'), array('style' => 'vertical-align:center')).' '.get_lang('AdvancedParameters').'</span></a>');
$form->addElement('html', '<div id="options" style="display: none;">');
if(Gradebook::is_active()){
if (Gradebook::is_active()) {
//QualificationOfAssignment
$form->addElement('text', 'qualification_value', get_lang('QualificationNumeric'));
$form->addElement('checkbox', 'make_calification', null, get_lang('MakeQualifiable'), array('id' =>'make_calification_id', 'onclick' => "javascript: if(this.checked){document.getElementById('option1').style.display='block';}else{document.getElementById('option1').style.display='none';}"));
}else{
} else {
//QualificationOfAssignment
$form->addElement('hidden', 'qualification_value',0);
$form->addElement('hidden', 'make_calification', false);

Loading…
Cancel
Save