Adding lock support for categories, removing single evaluation lock see BT#4080

skala
Julio Montoya 14 years ago
parent 0f7b5b5e7d
commit f85de3c9fd
  1. 35
      main/gradebook/index.php
  2. 23
      main/gradebook/lib/be/abstractlink.class.php
  3. 50
      main/gradebook/lib/be/category.class.php
  4. 2
      main/gradebook/lib/be/evallink.class.php
  5. 20
      main/gradebook/lib/be/evaluation.class.php
  6. 2
      main/gradebook/lib/fe/gradebooktable.class.php
  7. 15
      main/gradebook/lib/gradebook_functions.inc.php
  8. 17
      main/inc/lib/events.lib.inc.php

@ -49,6 +49,15 @@ $htmlHeadXtra[] = '<script type="text/javascript">
var show_icon = "../img/view_more_stats.gif"; var show_icon = "../img/view_more_stats.gif";
var hide_icon = "../img/view_less_stats.gif"; var hide_icon = "../img/view_less_stats.gif";
function lock_confirmation() {
if (confirm("' . get_lang('ConfirmToLockElement') . '?")) {
return true;
} else {
return false;
}
}
$(document).ready(function() { $(document).ready(function() {
$(".view_children").live("click", function() { $(".view_children").live("click", function() {
@ -67,6 +76,9 @@ $(document).ready(function() {
$(this).find("img").attr("src", show_icon); $(this).find("img").attr("src", show_icon);
}); });
/* /*
var s1 = [["a",25]]; var s1 = [["a",25]];
var s2 = [["a", 0], ["a", 10], ["a", 10], ["a", 5]]; var s2 = [["a", 0], ["a", 10], ["a", 10], ["a", 5]];
@ -342,9 +354,9 @@ if (isset($_GET['lockedeval'])) {
$type_locked = 1; $type_locked = 1;
$confirmation_message = get_lang('EvaluationHasBeenLocked'); $confirmation_message = get_lang('EvaluationHasBeenLocked');
} }
$eval= Evaluation :: load($locked); $eval = Evaluation :: load($locked);
if ($eval[0] != null) { if ($eval[0] != null) {
$eval[0]->locked_evaluation($locked, $type_locked); $eval[0]->lock($type_locked);
} }
$filter_confirm_msg = false; $filter_confirm_msg = false;
@ -423,6 +435,24 @@ if (!empty($course_to_crsind) && !isset($_GET['confirm'])) {
$warning_message = get_lang('MoveWarning').'<br><br>'.$button; $warning_message = get_lang('MoveWarning').'<br><br>'.$button;
$filter_warning_msg = false; $filter_warning_msg = false;
} }
$action = isset($_GET['action']) ? $_GET['action'] : null;
switch ($action) {
case 'lock':
$category_to_lock = Category :: load($_GET['category_id']);
$category_to_lock[0]->lock_all_items(1);
$confirmation_message = get_lang('GradebookLockedAlert');
break;
case 'unlock':
if (api_is_platform_admin()) {
$category_to_lock = Category :: load($_GET['category_id']);
$category_to_lock[0]->lock_all_items(0);
$confirmation_message = get_lang('GradebookUnlockedAlert');
}
break;
}
//actions on the sortabletable //actions on the sortabletable
if (isset ($_POST['action'])) { if (isset ($_POST['action'])) {
block_students(); block_students();
@ -433,6 +463,7 @@ if (isset ($_POST['action'])) {
$filter_warning_msg = false; $filter_warning_msg = false;
} else { } else {
switch ($_POST['action']) { switch ($_POST['action']) {
case 'deleted' : case 'deleted' :
$number_of_deleted_categories= 0; $number_of_deleted_categories= 0;
$number_of_deleted_evaluations= 0; $number_of_deleted_evaluations= 0;

@ -72,6 +72,10 @@ abstract class AbstractLink implements GradebookItem {
return $this->weight; return $this->weight;
} }
public function get_locked() {
return $this->locked;
}
public function is_visible() { public function is_visible() {
return $this->visible; return $this->visible;
} }
@ -115,8 +119,11 @@ abstract class AbstractLink implements GradebookItem {
public function set_session_id($id) { public function set_session_id($id) {
$this->session_id = $id; $this->session_id = $id;
} }
public function set_locked ($locked) {
$this->locked = $locked;
}
// CRUD FUNCTIONS // CRUD FUNCTIONS
/** /**
* Retrieve links and return them as an array of extensions of AbstractLink. * Retrieve links and return them as an array of extensions of AbstractLink.
@ -124,7 +131,7 @@ abstract class AbstractLink implements GradebookItem {
*/ */
public function load ($id = null, $type = null, $ref_id = null, $user_id = null, $course_code = null, $category_id = null, $visible = null) { public function load ($id = null, $type = null, $ref_id = null, $user_id = null, $course_code = null, $category_id = null, $visible = null) {
$tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK); $tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
$sql='SELECT id, type, ref_id, user_id, course_code, category_id, created_at, weight, visible FROM '.$tbl_grade_links; $sql='SELECT * FROM '.$tbl_grade_links;
$paramcount = 0; $paramcount = 0;
if (isset ($id)) { if (isset ($id)) {
$sql.= ' WHERE id = '.Database::escape_string($id); $sql.= ' WHERE id = '.Database::escape_string($id);
@ -416,4 +423,16 @@ abstract class AbstractLink implements GradebookItem {
public function get_view_url ($stud_id) { public function get_view_url ($stud_id) {
return null; return null;
} }
/**
* Locks a link
* @param int locked 1 or unlocked 0
*
* */
function lock($locked) {
$table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
$sql = "UPDATE $table SET locked = '".intval($locked)."' WHERE id='".$this->id."'";
Database::query($sql);
}
} }

@ -70,6 +70,10 @@ class Category implements GradebookItem
return $this->weight; return $this->weight;
} }
public function is_locked() {
return isset($this->locked) && $this->locked == 1 ? true : false ;
}
public function is_visible() { public function is_visible() {
return $this->visible; return $this->visible;
} }
@ -119,7 +123,9 @@ class Category implements GradebookItem
public function set_grade_model_id ($id) { public function set_grade_model_id ($id) {
$this->grade_model_id = $id; $this->grade_model_id = $id;
} }
public function set_locked ($locked) {
$this->locked = $locked;
}
public function get_grade_model_id () { public function get_grade_model_id () {
return $this->grade_model_id; return $this->grade_model_id;
} }
@ -173,7 +179,7 @@ class Category implements GradebookItem
} }
$tbl_grade_categories = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY); $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, grade_model_id FROM '.$tbl_grade_categories; $sql = 'SELECT * FROM '.$tbl_grade_categories;
$paramcount = 0; $paramcount = 0;
if (isset($id)) { if (isset($id)) {
$id = Database::escape_string($id); $id = Database::escape_string($id);
@ -275,6 +281,7 @@ class Category implements GradebookItem
$cat->set_session_id($data['session_id']); $cat->set_session_id($data['session_id']);
$cat->set_certificate_min_score($data['certif_min_score']); $cat->set_certificate_min_score($data['certif_min_score']);
$cat->set_grade_model_id($data['grade_model_id']); $cat->set_grade_model_id($data['grade_model_id']);
$cat->set_locked($data['locked']);
$allcat[]=$cat; $allcat[]=$cat;
} }
return $allcat; return $allcat;
@ -1196,4 +1203,43 @@ class Category implements GradebookItem
} }
return $foundcats; return $foundcats;
} }
/**
* This function, locks a category , only one who can unlock it is the platform administrator.
* @param int locked 1 or unlocked 0
* @return bool
*
* */
function lock($locked) {
$table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
$sql = "UPDATE $table SET locked = '".intval($locked)."' WHERE id='".intval($this->id)."'";
$rs = Database::query($sql);
}
function lock_all_items($locked) {
if (api_get_setting('gradebook_locking_enabled') == 'true') {
$this->lock($locked);
$evals_to_lock = $this->get_evaluations();
if (!empty($evals_to_lock)) {
foreach ($evals_to_lock as $item) {
$item->lock($locked);
}
}
$link_to_lock= $this->get_links();
if (!empty($link_to_lock)) {
foreach ($link_to_lock as $item ) {
$item->lock($locked);
}
}
$event_type = LOG_GRADEBOOK_UNLOCKED;
if ($locked == 1) {
$event_type = LOG_GRADEBOOK_LOCKED;
}
event_system($event_type, LOG_GRADEBOOK_ID, $this->id);
}
}
} }

@ -20,7 +20,7 @@ abstract class EvalLink extends AbstractLink
function __construct() { function __construct() {
parent::__construct(); parent::__construct();
} }
// Functions implementing AbstractLink // Functions implementing AbstractLink
public function has_results() { public function has_results() {
$eval = $this->get_evaluation(); $eval = $this->get_evaluation();

@ -580,21 +580,15 @@ class Evaluation implements GradebookItem
public function get_icon_name() { public function get_icon_name() {
return $this->has_results() ? 'evalnotempty' : 'evalempty'; return $this->has_results() ? 'evalnotempty' : 'evalempty';
} }
/***
* This function, locks an evaluation, only one who can unlock it is the platform administrator. /**
* @param int evaluation id * Locks an evaluation, only one who can unlock it is the platform administrator.
* @param int locked 1 or unlocked 0 * @param int locked 1 or unlocked 0
* @return bool
* *
* */ **/
function locked_evaluation($id_evaluation, $locked) { function lock($locked) {
$table_evaluation = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); $table_evaluation = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
$sql = "UPDATE $table_evaluation SET locked = '".intval($locked)."' WHERE id='".intval($id_evaluation)."'"; $sql = "UPDATE $table_evaluation SET locked = '".intval($locked)."' WHERE id='".intval($this->id)."'";
$rs = Database::query($sql); Database::query($sql);
$affected_rows = Database::affected_rows();
if (!empty($affected_rows)) {
return true;
}
} }
} }

@ -63,7 +63,7 @@ class GradebookTable extends SortableTable {
//admins get an edit column //admins get an edit column
if (api_is_allowed_to_edit(null, true)) { if (api_is_allowed_to_edit(null, true)) {
$this->set_header($column++, get_lang('Modify'), false, 'width="120px"'); $this->set_header($column++, get_lang('Modify'), false, 'width="150px"');
//actions on multiple selected documents //actions on multiple selected documents
$this->set_form_actions(array ( $this->set_form_actions(array (
'setvisible' => get_lang('SetVisible'), 'setvisible' => get_lang('SetVisible'),

@ -211,7 +211,15 @@ function build_edit_icons_cat($cat, $selectcat) {
//Locking button //Locking button
if (api_get_setting('gradebook_locking_enabled') == 'true') { if (api_get_setting('gradebook_locking_enabled') == 'true') {
//$modify_icons .= '&nbsp;<a class="view_children" data-cat-id="'.$cat->get_id().'" href="javascript:void(0);">'.Display::return_icon('lock.png', get_lang('Lock'),'',ICON_SIZE_SMALL).'</a>'; if ($cat->is_locked()) {
if (api_is_platform_admin()) {
$modify_icons .= '&nbsp;<a onclick="javascrip:lock_confirmation()" href="' . api_get_self() . '?'. api_get_cidreq().'&category_id=' . $cat->get_id() . '&action=unlock">'.Display::return_icon('unlock.png', get_lang('Unlock'),'',ICON_SIZE_SMALL).'</a>';
} else {
$modify_icons .= '&nbsp;<a href="#">'.Display::return_icon('unlock_na.png', get_lang('Unlock'),'',ICON_SIZE_SMALL).'</a>';
}
} else {
$modify_icons .= '&nbsp;<a onclick="javascrip:lock_confirmation()" href="' . api_get_self() . '?'. api_get_cidreq().'&category_id=' . $cat->get_id() . '&action=lock">'.Display::return_icon('lock.png', get_lang('Lock'),'',ICON_SIZE_SMALL).'</a>';
}
} }
//PDF //PDF
@ -264,15 +272,16 @@ function build_edit_icons_eval($eval, $selectcat) {
if (api_is_allowed_to_edit(null, true)){ if (api_is_allowed_to_edit(null, true)){
$modify_icons .= '&nbsp;<a href="gradebook_showlog_eval.php?visiblelog=' . $eval->get_id() . '&amp;selectcat=' . $selectcat . ' &amp;cidReq='.$eval->get_course_code().'">'.Display::return_icon('history.png', get_lang('GradebookQualifyLog'),'',ICON_SIZE_SMALL).'</a>'; $modify_icons .= '&nbsp;<a href="gradebook_showlog_eval.php?visiblelog=' . $eval->get_id() . '&amp;selectcat=' . $selectcat . ' &amp;cidReq='.$eval->get_course_code().'">'.Display::return_icon('history.png', get_lang('GradebookQualifyLog'),'',ICON_SIZE_SMALL).'</a>';
} }
/*
if ($locked_status == 0){ if ($locked_status == 0){
$modify_icons .= "&nbsp;<a href=\"javascript:if (confirm('".addslashes(get_lang('AreYouSureToLockedTheEvaluation'))."')) { location.href='".api_get_self().'?lockedeval=' . $eval->get_id() . '&amp;selectcat=' . $selectcat . ' &amp;cidReq='.$eval->get_course_code()."'; }\">".Display::return_icon('unlock.png',get_lang('LockEvaluation'), array(), ICON_SIZE_SMALL)."</a>"; $modify_icons .= "&nbsp;<a href=\"javascript:if (confirm('".addslashes(get_lang('AreYouSureToLockedTheEvaluation'))."')) { location.href='".api_get_self().'?lockedeval=' . $eval->get_id() . '&amp;selectcat=' . $selectcat . ' &amp;cidReq='.$eval->get_course_code()."'; }\">".Display::return_icon('unlock.png',get_lang('LockEvaluation'), array(), ICON_SIZE_SMALL)."</a>";
} else { } else {
if (api_is_platform_admin()){ if (api_is_platform_admin()){
$modify_icons .= "&nbsp;<a href=\"javascript:if (confirm('".addslashes(get_lang('AreYouSureToUnLockedTheEvaluation'))."')) { location.href='".api_get_self().'?lockedeval=' . $eval->get_id() . '&amp;typelocked=&amp;selectcat=' . $selectcat . ' &amp;cidReq='.$eval->get_course_code()."'; }\">".Display::return_icon('lock.png',get_lang('UnLockEvaluation'), array(), ICON_SIZE_SMALL)."</a>"; $modify_icons .= "&nbsp;<a href=\"javascript:if (confirm('".addslashes(get_lang('AreYouSureToUnLockedTheEvaluation'))."')) { location.href='".api_get_self().'?lockedeval=' . $eval->get_id() . '&amp;typelocked=&amp;selectcat=' . $selectcat . ' &amp;cidReq='.$eval->get_course_code()."';\">".Display::return_icon('lock.png',get_lang('UnLockEvaluation'), array(), ICON_SIZE_SMALL)."</a>";
} else { } else {
$modify_icons .= '&nbsp;<img src="../img/locked_na.png" border="0" title="' . get_lang('TheEvaluationIsLocked') . '" alt="" />'; $modify_icons .= '&nbsp;<img src="../img/locked_na.png" border="0" title="' . get_lang('TheEvaluationIsLocked') . '" alt="" />';
} }
} }*/
$modify_icons .= '&nbsp;<a href="' . api_get_self() . '?deleteeval=' . $eval->get_id() . '&selectcat=' . $selectcat . ' &amp;cidReq='.$eval->get_course_code().'" onclick="return confirmation();">'.Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>'; $modify_icons .= '&nbsp;<a href="' . api_get_self() . '?deleteeval=' . $eval->get_id() . '&selectcat=' . $selectcat . ' &amp;cidReq='.$eval->get_course_code().'" onclick="return confirmation();">'.Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>';
return $modify_icons; return $modify_icons;
} }

@ -549,22 +549,6 @@ function exercise_attempt_hotspot($exe_id, $question_id, $answer_id, $correct, $
return $result = Database::query($sql); return $result = Database::query($sql);
} }
/**
*
* @param type $status LOG_GRADEBOOK_LOCKED - LOG_GRADEBOOK_UNLOCKED
* @param type $course_id
* @param type $session_id
* @param type $item_id
* @param type $tool_id
* @return boolean
*/
function event_change_gradebook_lock_status($status, $course_code, $gradebook_id) {
if (api_get_setting('gradebook_locking_enabled') == 'true') {
event_system($status, LOG_GRADEBOOK_ID, $gradebook_id, null, null, $course_code);
}
return false;
}
/** /**
* @author Yannick Warnier <yannick.warnier@dokeos.com> * @author Yannick Warnier <yannick.warnier@dokeos.com>
* @desc Record information for common (or admin) events (in the track_e_default table) * @desc Record information for common (or admin) events (in the track_e_default table)
@ -602,7 +586,6 @@ function event_system($event_type, $event_value_type, $event_value, $datetime =
if (!empty($course_info)) { if (!empty($course_info)) {
$course_id = $course_info['real_id']; $course_id = $course_info['real_id'];
$course_code = $course_info['code']; $course_code = $course_info['code'];
$course_code = Database::escape_string($course_code); $course_code = Database::escape_string($course_code);
} else { } else {
$course_id = null; $course_id = null;

Loading…
Cancel
Save