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. 27
      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. 19
      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 hide_icon = "../img/view_less_stats.gif";
function lock_confirmation() {
if (confirm("' . get_lang('ConfirmToLockElement') . '?")) {
return true;
} else {
return false;
}
}
$(document).ready(function() {
$(".view_children").live("click", function() {
@ -66,6 +75,9 @@ $(document).ready(function() {
$(this).addClass("view_children");
$(this).find("img").attr("src", show_icon);
});
/*
var s1 = [["a",25]];
@ -342,9 +354,9 @@ if (isset($_GET['lockedeval'])) {
$type_locked = 1;
$confirmation_message = get_lang('EvaluationHasBeenLocked');
}
$eval= Evaluation :: load($locked);
$eval = Evaluation :: load($locked);
if ($eval[0] != null) {
$eval[0]->locked_evaluation($locked, $type_locked);
$eval[0]->lock($type_locked);
}
$filter_confirm_msg = false;
@ -423,6 +435,24 @@ if (!empty($course_to_crsind) && !isset($_GET['confirm'])) {
$warning_message = get_lang('MoveWarning').'<br><br>'.$button;
$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
if (isset ($_POST['action'])) {
block_students();
@ -433,6 +463,7 @@ if (isset ($_POST['action'])) {
$filter_warning_msg = false;
} else {
switch ($_POST['action']) {
case 'deleted' :
$number_of_deleted_categories= 0;
$number_of_deleted_evaluations= 0;

@ -71,6 +71,10 @@ abstract class AbstractLink implements GradebookItem {
public function get_weight() {
return $this->weight;
}
public function get_locked() {
return $this->locked;
}
public function is_visible() {
return $this->visible;
@ -115,8 +119,11 @@ abstract class AbstractLink implements GradebookItem {
public function set_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.
@ -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) {
$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;
if (isset ($id)) {
$sql.= ' WHERE id = '.Database::escape_string($id);
@ -196,7 +203,7 @@ abstract class AbstractLink implements GradebookItem {
$link->set_category_id($data['category_id']);
$link->set_date($data['created_at']);
$link->set_weight($data['weight']);
$link->set_visible($data['visible']);
$link->set_visible($data['visible']);
//session id should depend of the category --> $data['category_id']
$session_id = api_get_session_id();
@ -415,5 +422,17 @@ abstract class AbstractLink implements GradebookItem {
}
public function get_view_url ($stud_id) {
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);
}
}

@ -69,6 +69,10 @@ class Category implements GradebookItem
public function get_weight() {
return $this->weight;
}
public function is_locked() {
return isset($this->locked) && $this->locked == 1 ? true : false ;
}
public function is_visible() {
return $this->visible;
@ -119,7 +123,9 @@ class Category implements GradebookItem
public function set_grade_model_id ($id) {
$this->grade_model_id = $id;
}
public function set_locked ($locked) {
$this->locked = $locked;
}
public function get_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);
$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;
if (isset($id)) {
$id = Database::escape_string($id);
@ -275,6 +281,7 @@ class Category implements GradebookItem
$cat->set_session_id($data['session_id']);
$cat->set_certificate_min_score($data['certif_min_score']);
$cat->set_grade_model_id($data['grade_model_id']);
$cat->set_locked($data['locked']);
$allcat[]=$cat;
}
return $allcat;
@ -1196,4 +1203,43 @@ class Category implements GradebookItem
}
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() {
parent::__construct();
}
// Functions implementing AbstractLink
// Functions implementing AbstractLink
public function has_results() {
$eval = $this->get_evaluation();

@ -580,21 +580,15 @@ class Evaluation implements GradebookItem
public function get_icon_name() {
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
* @return bool
*
* */
function locked_evaluation($id_evaluation, $locked) {
**/
function lock($locked) {
$table_evaluation = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
$sql = "UPDATE $table_evaluation SET locked = '".intval($locked)."' WHERE id='".intval($id_evaluation)."'";
$rs = Database::query($sql);
$affected_rows = Database::affected_rows();
if (!empty($affected_rows)) {
return true;
}
$sql = "UPDATE $table_evaluation SET locked = '".intval($locked)."' WHERE id='".intval($this->id)."'";
Database::query($sql);
}
}

@ -63,7 +63,7 @@ class GradebookTable extends SortableTable {
//admins get an edit column
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
$this->set_form_actions(array (
'setvisible' => get_lang('SetVisible'),

@ -211,7 +211,15 @@ function build_edit_icons_cat($cat, $selectcat) {
//Locking button
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
@ -264,15 +272,16 @@ function build_edit_icons_eval($eval, $selectcat) {
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>';
}
/*
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>";
} else {
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 {
$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>';
return $modify_icons;
}

@ -549,22 +549,6 @@ function exercise_attempt_hotspot($exe_id, $question_id, $answer_id, $correct, $
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>
* @desc Record information for common (or admin) events (in the track_e_default table)
@ -601,8 +585,7 @@ function event_system($event_type, $event_value_type, $event_value, $datetime =
if (!empty($course_info)) {
$course_id = $course_info['real_id'];
$course_code = $course_info['code'];
$course_code = $course_info['code'];
$course_code = Database::escape_string($course_code);
} else {
$course_id = null;

Loading…
Cancel
Save