mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +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 = "";
|
$scale->description = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
//Calculate the uses
|
//Check if the scale is in use
|
||||||
if ($scale->courseid == 0) {
|
if ($scale->courseid == 0) {
|
||||||
$scale_uses = site_scale_used($scale->id,$courses);
|
$scale_used = site_scale_used($scale->id,$courses);
|
||||||
} else {
|
} else {
|
||||||
$scale_uses = course_scale_used($course->id,$scale->id);
|
$scale_used = course_scale_used($course->id,$scale->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Check for scale_uses
|
//Check for scale use
|
||||||
if (!empty($scale_uses)) {
|
if ($scale_used)) {
|
||||||
error("Scale is in use and cannot be modified",$CFG->wwwroot.'/course/scales.php?id='.$course->id);
|
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 "<tr valign=\"top\">";
|
||||||
echo "<td align=\"right\">";
|
echo "<td align=\"right\">";
|
||||||
echo "</td>";
|
echo "</td>";
|
||||||
echo "<td>".get_string("usedinnplaces","",$scale_uses);
|
echo "<td>$stractivities: ".($scale_used ? get_string("yes") : get_string("no"));
|
||||||
echo "</td>";
|
echo "</td>";
|
||||||
echo "</tr>";
|
echo "</tr>";
|
||||||
}
|
}
|
||||||
|
@ -240,15 +240,15 @@
|
||||||
error("Scale ID was incorrect");
|
error("Scale ID was incorrect");
|
||||||
}
|
}
|
||||||
|
|
||||||
//Calculate the uses
|
//Check if the scale is in use
|
||||||
if ($scale->courseid == 0) {
|
if ($scale->courseid == 0) {
|
||||||
$scale_uses = site_scale_used($scale->id,$courses);
|
$scale_used = site_scale_used($scale->id,$courses);
|
||||||
} else {
|
} else {
|
||||||
$scale_uses = course_scale_used($course->id,$scale->id);
|
$scale_used = course_scale_used($course->id,$scale->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Check for scale_uses
|
//Check for scale use
|
||||||
if (!empty($scale_uses)) {
|
if ($scale_used) {
|
||||||
error("Scale is in use and cannot be deleted",$CFG->wwwroot.'/course/scales.php?id='.$course->id);
|
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");
|
error("Scale ID was incorrect");
|
||||||
}
|
}
|
||||||
|
|
||||||
//Calculate the uses
|
//Check if the scale is in use
|
||||||
if ($scale->courseid == 0) {
|
if ($scale->courseid == 0) {
|
||||||
$scale_uses = site_scale_used($scale->id,$courses);
|
$scale_used = site_scale_used($scale->id,$courses);
|
||||||
} else {
|
} else {
|
||||||
$scale_uses = course_scale_used($course->id,$scale->id);
|
$scale_used = course_scale_used($course->id,$scale->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Check for scale_uses
|
//Check for scale use
|
||||||
if (!empty($scale_uses)) {
|
if ($scale_used)) {
|
||||||
error("Scale is in use and cannot be moved",$CFG->wwwroot.'/course/scales.php?id='.$course->id);
|
error("Scale is in use and cannot be moved",$CFG->wwwroot.'/course/scales.php?id='.$course->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -424,18 +424,18 @@
|
||||||
$line = array();
|
$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>";
|
$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)) {
|
if (!empty($scale->courseid)) {
|
||||||
$scales_uses = course_scale_used($course->id,$scale->id);
|
$scale_used = course_scale_used($course->id,$scale->id);
|
||||||
} else {
|
} 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) {
|
if ($incustom) {
|
||||||
$line[] = $strcustomscale;
|
$line[] = $strcustomscale;
|
||||||
} else {
|
} else {
|
||||||
$line[] = $strstandardscale;
|
$line[] = $strstandardscale;
|
||||||
}
|
}
|
||||||
$buttons = "";
|
$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".
|
$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> ";
|
" src=\"$CFG->pixpath/t/edit.gif\" class=\"iconsmall\" alt=\"$stredit\" /></a> ";
|
||||||
if ($incustom && has_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
|
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
|
* Returns true if a scale is in use in the given course.
|
||||||
* using scaleid in a courseid
|
|
||||||
*
|
*
|
||||||
* @param int $courseid ?
|
* @param int $courseid The course to be checked.
|
||||||
* @param int $scaleid ?
|
* @param int $scaleid The scale to be checked.
|
||||||
* @return int
|
* @return boolean
|
||||||
* @todo Finish documenting this function
|
* @todo Finish documenting this function
|
||||||
*/
|
*/
|
||||||
function course_scale_used($courseid, $scaleid) {
|
function course_scale_used($courseid, $scaleid) {
|
||||||
|
@ -5976,42 +5975,69 @@ function course_scale_used($courseid, $scaleid) {
|
||||||
$function_name = $cm->modname.'_scale_used';
|
$function_name = $cm->modname.'_scale_used';
|
||||||
if (function_exists($function_name)) {
|
if (function_exists($function_name)) {
|
||||||
if ($function_name($cm->instance,$scaleid)) {
|
if ($function_name($cm->instance,$scaleid)) {
|
||||||
$return++;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function returns the nummber of activities
|
* Returns true if a scale is in use anywhere on the site.
|
||||||
* using scaleid in the entire site
|
|
||||||
*
|
*
|
||||||
* @param int $scaleid ?
|
* @param int $scaleid The scale to be checked.
|
||||||
* @return int
|
* @param array $courses The site courses, needed is the old way to check has to be used.
|
||||||
* @todo Finish documenting this function. Is return type correct?
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
function site_scale_used($scaleid,&$courses) {
|
function site_scale_used($scaleid,&$courses) {
|
||||||
|
|
||||||
|
if (empty($scaleid)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
global $CFG;
|
global $CFG;
|
||||||
|
|
||||||
$return = 0;
|
$return = 0;
|
||||||
|
|
||||||
if (!is_array($courses) || count($courses) == 0) {
|
$legacy_mods = false;
|
||||||
$courses = get_courses("all",false,"c.id,c.shortname");
|
if ($mods = get_records('modules', 'visible', 1)) {
|
||||||
}
|
foreach ($mods as $mod) {
|
||||||
|
//Check $mod->name/lib.php exists
|
||||||
if (!empty($scaleid)) {
|
if (file_exists($CFG->dirroot.'/mod/'.$mod->name.'/lib.php')) {
|
||||||
if (is_array($courses) && count($courses) > 0) {
|
include_once($CFG->dirroot.'/mod/'.$mod->name.'/lib.php');
|
||||||
foreach ($courses as $course) {
|
$function_name = $mod->name.'_scale_used_anywhere';
|
||||||
$return += course_scale_used($course->id,$scaleid);
|
$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;
|
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
|
* Make sure up-to-date events are created for all assignment instances
|
||||||
*
|
*
|
||||||
|
|
|
@ -1222,6 +1222,16 @@ function forum_scale_used ($forumid,$scaleid) {
|
||||||
return $return;
|
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 ///////////////////////////////////////////////////////////
|
// SQL FUNCTIONS ///////////////////////////////////////////////////////////
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -401,6 +401,16 @@ function glossary_scale_used ($glossaryid,$scaleid) {
|
||||||
return $return;
|
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
|
/// Any other glossary functions go here. Each of them must have a name that
|
||||||
/// starts with glossary_
|
/// starts with glossary_
|
||||||
|
|
|
@ -1225,6 +1225,17 @@ function hotpot_scale_used ($hotpotid, $scaleid) {
|
||||||
return $report;
|
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.
|
/// Any other hotpot functions go here.
|
||||||
/// Each of them must have a name that starts with hotpot
|
/// Each of them must have a name that starts with hotpot
|
||||||
|
|
|
@ -307,6 +307,16 @@ function journal_scale_used ($journalid,$scaleid) {
|
||||||
return $return;
|
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 ///////////////////////////////////////////////////////////////////
|
// SQL FUNCTIONS ///////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
function journal_get_users_done($journal) {
|
function journal_get_users_done($journal) {
|
||||||
|
|
|
@ -140,6 +140,17 @@ function lams_scale_used ($lamsid,$scaleid) {
|
||||||
return $return;
|
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
|
/// Any other lams functions go here. Each of them must have a name that
|
||||||
/// starts with lams_
|
/// starts with lams_
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue