mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
MDL-1883 - /course/scales.php very slow. "Backported" the fix by Petr from 1.9 to 1.8. Not a direct merge as the code has been refactored.
This commit is contained in:
parent
f99ed7c86d
commit
186b0a1537
8 changed files with 129 additions and 41 deletions
|
@ -146,15 +146,15 @@
|
|||
$scale->description = "";
|
||||
}
|
||||
|
||||
//Calculate the uses
|
||||
//Check if the scale is in use
|
||||
if ($scale->courseid == 0) {
|
||||
$scale_uses = site_scale_used($scale->id,$courses);
|
||||
$scale_used = site_scale_used($scale->id,$courses);
|
||||
} else {
|
||||
$scale_uses = course_scale_used($course->id,$scale->id);
|
||||
$scale_used = course_scale_used($course->id,$scale->id);
|
||||
}
|
||||
|
||||
//Check for scale_uses
|
||||
if (!empty($scale_uses)) {
|
||||
//Check for scale use
|
||||
if ($scale_used)) {
|
||||
error("Scale is in use and cannot be modified",$CFG->wwwroot.'/course/scales.php?id='.$course->id);
|
||||
}
|
||||
|
||||
|
@ -210,7 +210,7 @@
|
|||
echo "<tr valign=\"top\">";
|
||||
echo "<td align=\"right\">";
|
||||
echo "</td>";
|
||||
echo "<td>".get_string("usedinnplaces","",$scale_uses);
|
||||
echo "<td>$stractivities: ".($scale_used ? get_string("yes") : get_string("no"));
|
||||
echo "</td>";
|
||||
echo "</tr>";
|
||||
}
|
||||
|
@ -240,15 +240,15 @@
|
|||
error("Scale ID was incorrect");
|
||||
}
|
||||
|
||||
//Calculate the uses
|
||||
//Check if the scale is in use
|
||||
if ($scale->courseid == 0) {
|
||||
$scale_uses = site_scale_used($scale->id,$courses);
|
||||
$scale_used = site_scale_used($scale->id,$courses);
|
||||
} else {
|
||||
$scale_uses = course_scale_used($course->id,$scale->id);
|
||||
$scale_used = course_scale_used($course->id,$scale->id);
|
||||
}
|
||||
|
||||
//Check for scale_uses
|
||||
if (!empty($scale_uses)) {
|
||||
//Check for scale use
|
||||
if ($scale_used) {
|
||||
error("Scale is in use and cannot be deleted",$CFG->wwwroot.'/course/scales.php?id='.$course->id);
|
||||
}
|
||||
|
||||
|
@ -271,15 +271,15 @@
|
|||
error("Scale ID was incorrect");
|
||||
}
|
||||
|
||||
//Calculate the uses
|
||||
//Check if the scale is in use
|
||||
if ($scale->courseid == 0) {
|
||||
$scale_uses = site_scale_used($scale->id,$courses);
|
||||
$scale_used = site_scale_used($scale->id,$courses);
|
||||
} else {
|
||||
$scale_uses = course_scale_used($course->id,$scale->id);
|
||||
$scale_used = course_scale_used($course->id,$scale->id);
|
||||
}
|
||||
|
||||
//Check for scale_uses
|
||||
if (!empty($scale_uses)) {
|
||||
//Check for scale use
|
||||
if ($scale_used)) {
|
||||
error("Scale is in use and cannot be moved",$CFG->wwwroot.'/course/scales.php?id='.$course->id);
|
||||
}
|
||||
|
||||
|
@ -424,18 +424,18 @@
|
|||
$line = array();
|
||||
$line[] = "<a target=\"scale\" title=\"$scale->name\" href=\"$CFG->wwwroot/course/scales.php?id=$course->id&scaleid=$scale->id&action=details\" "."onclick=\"return openpopup('/course/scales.php?id=$course->id\&scaleid=$scale->id&action=details', 'scale', 'menubar=0,location=0,scrollbars,resizable,width=600,height=450', 0);\">".$scale->name."</a><br /><font size=\"-1\">".str_replace(",",", ",$scale->scale)."</font>";
|
||||
if (!empty($scale->courseid)) {
|
||||
$scales_uses = course_scale_used($course->id,$scale->id);
|
||||
$scale_used = course_scale_used($course->id,$scale->id);
|
||||
} else {
|
||||
$scales_uses = site_scale_used($scale->id,$courses);
|
||||
$scale_used = site_scale_used($scale->id,$courses);
|
||||
}
|
||||
$line[] = $scales_uses;
|
||||
$line[] = $scale_used ? get_string("yes") : get_string("no");
|
||||
if ($incustom) {
|
||||
$line[] = $strcustomscale;
|
||||
} else {
|
||||
$line[] = $strstandardscale;
|
||||
}
|
||||
$buttons = "";
|
||||
if (empty($scales_uses) && ($incustom || has_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM, SITEID)))) {
|
||||
if (!$scale_used && ($incustom || has_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM, SITEID)))) {
|
||||
$buttons .= "<a title=\"$stredit\" href=\"$path/scales.php?id=$course->id&scaleid=$scale->id&action=edit\"><img".
|
||||
" src=\"$CFG->pixpath/t/edit.gif\" class=\"iconsmall\" alt=\"$stredit\" /></a> ";
|
||||
if ($incustom && has_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
|
||||
|
|
|
@ -5953,12 +5953,11 @@ function make_grades_menu($gradingtype) {
|
|||
}
|
||||
|
||||
/**
|
||||
* This function returns the nummber of activities
|
||||
* using scaleid in a courseid
|
||||
* Returns true if a scale is in use in the given course.
|
||||
*
|
||||
* @param int $courseid ?
|
||||
* @param int $scaleid ?
|
||||
* @return int
|
||||
* @param int $courseid The course to be checked.
|
||||
* @param int $scaleid The scale to be checked.
|
||||
* @return boolean
|
||||
* @todo Finish documenting this function
|
||||
*/
|
||||
function course_scale_used($courseid, $scaleid) {
|
||||
|
@ -5976,42 +5975,69 @@ function course_scale_used($courseid, $scaleid) {
|
|||
$function_name = $cm->modname.'_scale_used';
|
||||
if (function_exists($function_name)) {
|
||||
if ($function_name($cm->instance,$scaleid)) {
|
||||
$return++;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $return;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function returns the nummber of activities
|
||||
* using scaleid in the entire site
|
||||
* Returns true if a scale is in use anywhere on the site.
|
||||
*
|
||||
* @param int $scaleid ?
|
||||
* @return int
|
||||
* @todo Finish documenting this function. Is return type correct?
|
||||
* @param int $scaleid The scale to be checked.
|
||||
* @param array $courses The site courses, needed is the old way to check has to be used.
|
||||
* @return boolean
|
||||
*/
|
||||
function site_scale_used($scaleid,&$courses) {
|
||||
|
||||
if (empty($scaleid)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
global $CFG;
|
||||
|
||||
$return = 0;
|
||||
|
||||
if (!is_array($courses) || count($courses) == 0) {
|
||||
$courses = get_courses("all",false,"c.id,c.shortname");
|
||||
}
|
||||
|
||||
if (!empty($scaleid)) {
|
||||
if (is_array($courses) && count($courses) > 0) {
|
||||
foreach ($courses as $course) {
|
||||
$return += course_scale_used($course->id,$scaleid);
|
||||
$legacy_mods = false;
|
||||
if ($mods = get_records('modules', 'visible', 1)) {
|
||||
foreach ($mods as $mod) {
|
||||
//Check $mod->name/lib.php exists
|
||||
if (file_exists($CFG->dirroot.'/mod/'.$mod->name.'/lib.php')) {
|
||||
include_once($CFG->dirroot.'/mod/'.$mod->name.'/lib.php');
|
||||
$function_name = $mod->name.'_scale_used_anywhere';
|
||||
$old_function_name = $mod->name.'_scale_used';
|
||||
if (function_exists($function_name)) {
|
||||
if ($function_name($scaleid)) {
|
||||
return true;
|
||||
}
|
||||
} else if (function_exists($old_function_name)) {
|
||||
$legacy_mods = true;
|
||||
debugging('Please notify the developer of module "'.$mod->name.'" that new function module_scale_used_anywhere() should be implemented.', DEBUG_DEVELOPER);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $return;
|
||||
|
||||
// some mods are missing the new xxx_scale_used_anywhere() - use the really slow old way
|
||||
if ($legacy_mods) {
|
||||
if (!is_array($courses) || count($courses) == 0) {
|
||||
$courses = get_courses("all",false,"c.id,c.shortname");
|
||||
}
|
||||
if (is_array($courses) && count($courses) > 0) {
|
||||
foreach ($courses as $course) {
|
||||
if (course_scale_used($course->id,$scaleid)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1980,6 +1980,16 @@ function assignment_scale_used ($assignmentid, $scaleid) {
|
|||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the scale is in use in the system.
|
||||
*
|
||||
* @param $scaleid int The scale to be counted.
|
||||
* @return boolean
|
||||
*/
|
||||
function assignment_scale_used_anywhere($scaleid) {
|
||||
return record_exists("assignment","grade","-$scaleid");
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure up-to-date events are created for all assignment instances
|
||||
*
|
||||
|
|
|
@ -1222,6 +1222,16 @@ function forum_scale_used ($forumid,$scaleid) {
|
|||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the scale is in use in the system.
|
||||
*
|
||||
* @param $scaleid int The scale to be counted.
|
||||
* @return boolean
|
||||
*/
|
||||
function forum_scale_used_anywhere($scaleid) {
|
||||
return record_exists("forum","scale","-$scaleid");
|
||||
}
|
||||
|
||||
// SQL FUNCTIONS ///////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
|
|
|
@ -401,6 +401,16 @@ function glossary_scale_used ($glossaryid,$scaleid) {
|
|||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the scale is in use in the system.
|
||||
*
|
||||
* @param $scaleid int The scale to be counted.
|
||||
* @return boolean
|
||||
*/
|
||||
function glossary_scale_used_anywhere($scaleid) {
|
||||
return record_exists("glossary","scale","-$scaleid");
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////
|
||||
/// Any other glossary functions go here. Each of them must have a name that
|
||||
/// starts with glossary_
|
||||
|
|
|
@ -1225,6 +1225,17 @@ function hotpot_scale_used ($hotpotid, $scaleid) {
|
|||
return $report;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the scale is in use in the system.
|
||||
*
|
||||
* @param $scaleid int The scale to be counted.
|
||||
* @return boolean
|
||||
*/
|
||||
function hotpot_scale_used_anywhere($scaleid) {
|
||||
// return record_exists("hotpot","scale","-$scaleid");
|
||||
return false; // Scales are not used by Hotpot module
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
/// Any other hotpot functions go here.
|
||||
/// Each of them must have a name that starts with hotpot
|
||||
|
|
|
@ -307,6 +307,16 @@ function journal_scale_used ($journalid,$scaleid) {
|
|||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the scale is in use in the system.
|
||||
*
|
||||
* @param $scaleid int The scale to be counted.
|
||||
* @return boolean
|
||||
*/
|
||||
function journal_scale_used_anywhere($scaleid) {
|
||||
return record_exists("journal","assessed","-$scaleid");
|
||||
}
|
||||
|
||||
// SQL FUNCTIONS ///////////////////////////////////////////////////////////////////
|
||||
|
||||
function journal_get_users_done($journal) {
|
||||
|
|
|
@ -140,6 +140,17 @@ function lams_scale_used ($lamsid,$scaleid) {
|
|||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the scale is in use in the system.
|
||||
*
|
||||
* @param $scaleid int The scale to be counted.
|
||||
* @return boolean
|
||||
*/
|
||||
function lams_scale_used_anywhere($scaleid) {
|
||||
// return record_exists("lams","scale","-$scaleid");
|
||||
return false;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////
|
||||
/// Any other lams functions go here. Each of them must have a name that
|
||||
/// starts with lams_
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue