From 9eb32301077ae92d071a587d539832e36a7d486a Mon Sep 17 00:00:00 2001 From: Luuk Verhoeven Date: Mon, 18 Dec 2023 14:54:00 +0100 Subject: [PATCH] Refactor for MOODLE41 & PHP 7.4 --- .../columns/coursestats/plugin.class.php | 5 +- .../filters/fsearchuserfield/plugin.class.php | 6 + lib/pChart/pCache.class.php | 115 ------------------ locallib.php | 1 - 4 files changed, 9 insertions(+), 118 deletions(-) delete mode 100644 lib/pChart/pCache.class.php diff --git a/components/columns/coursestats/plugin.class.php b/components/columns/coursestats/plugin.class.php index 4a204a99..2b05fd1d 100755 --- a/components/columns/coursestats/plugin.class.php +++ b/components/columns/coursestats/plugin.class.php @@ -92,17 +92,18 @@ public function execute($data, $row, $user, $courseid, $starttime = 0, $endtime $endtime = ($filterendtime) ? $filterendtime : $endtime; $limit = 0; + $numericroles = array_filter($data->roles, 'is_numeric'); switch ($data->stat) { case 'activityview': $total = 'SUM(stat1)'; $stattype = 'activity'; - $extrasql = " AND roleid IN (" . implode(',', $data->roles) . ")"; + $extrasql = " AND roleid IN (" . implode(',', $numericroles ). ")"; break; case 'activitypost': $total = 'SUM(stat2)'; $stattype = 'activity'; - $extrasql = " AND roleid IN (" . implode(',', $data->roles) . ")"; + $extrasql = " AND roleid IN (" . implode(',', $numericroles) . ")"; break; case 'activeenrolments': $total = 'stat2'; diff --git a/components/filters/fsearchuserfield/plugin.class.php b/components/filters/fsearchuserfield/plugin.class.php index 4e1c2fbc..212cf2f1 100755 --- a/components/filters/fsearchuserfield/plugin.class.php +++ b/components/filters/fsearchuserfield/plugin.class.php @@ -199,6 +199,12 @@ public function print_filter(MoodleQuickForm $mform, $formdata = false): void { $selectname = get_string($formdata->field); [$usql, $params] = $remotedb->get_in_or_equal($userlist); + $columns = $remotedb->get_columns('user'); + + if (!array_key_exists($formdata->field, $columns)) { + throw new moodle_exception('nosuchcolumn', 'error', '', null, "The column '{$formdata->field}' does not exist in the user table."); + } + $sql = "SELECT DISTINCT(" . $formdata->field . ") as ufield FROM {user} WHERE id $usql ORDER BY ufield ASC"; if ($rs = $remotedb->get_recordset_sql($sql, $params)) { foreach ($rs as $u) { diff --git a/lib/pChart/pCache.class.php b/lib/pChart/pCache.class.php deleted file mode 100644 index 6f900491..00000000 --- a/lib/pChart/pCache.class.php +++ /dev/null @@ -1,115 +0,0 @@ -. - - Class initialisation : - pCache($CacheFolder="Cache/") - Cache management : - IsInCache($Data) - GetFromCache($ID,$Data) - WriteToCache($ID,$Data,$Picture) - DeleteFromCache($ID,$Data) - ClearCache() - Inner functions : - GetHash($ID,$Data) -*/ - -/* pCache class definition */ - -class pCache { - - var $HashKey = ""; - var $CacheFolder = "Cache/"; - - /* Create the pCache object */ - function __construct($CacheFolder = "Cache/") { - $this->CacheFolder = $CacheFolder; - } - - /* This function is clearing the cache folder */ - function ClearCache() { - if ($handle = opendir($this->CacheFolder)) { - while (false !== ($file = readdir($handle))) { - if ($file != "." && $file != "..") { - unlink($this->CacheFolder . $file); - } - } - closedir($handle); - } - } - - /* This function is checking if we have an offline version of this chart */ - function IsInCache($ID, $Data, $Hash = "") { - if ($Hash == "") { - $Hash = $this->GetHash($ID, $Data); - } - - if (file_exists($this->CacheFolder . $Hash)) { - return (true); - } else { - return (false); - } - } - - /* This function is making a copy of drawn chart in the cache folder */ - function WriteToCache($ID, $Data, $Picture) { - $Hash = $this->GetHash($ID, $Data); - $FileName = $this->CacheFolder . $Hash; - - imagepng($Picture->Picture, $FileName); - } - - /* This function is removing any cached copy of this chart */ - function DeleteFromCache($ID, $Data) { - $Hash = $this->GetHash($ID, $Data); - $FileName = $this->CacheFolder . $Hash; - - if (file_exists($FileName)) { - unlink($FileName); - } - } - - /* This function is retrieving the cached picture if applicable */ - function GetFromCache($ID, $Data) { - $Hash = $this->GetHash($ID, $Data); - if ($this->IsInCache("", "", $Hash)) { - $FileName = $this->CacheFolder . $Hash; - - header('Content-type: image/png'); - @readfile($FileName); - exit(); - } - } - - /* This function is building the graph unique hash key */ - function GetHash($ID, $Data) { - $mKey = "$ID"; - foreach ($Data as $key => $Values) { - $tKey = ""; - foreach ($Values as $Serie => $Value) { - $tKey = $tKey . $Serie . $Value; - } - $mKey = $mKey . md5($tKey); - } - - return (md5($mKey)); - } - -} \ No newline at end of file diff --git a/locallib.php b/locallib.php index 65dc3369..c757797d 100755 --- a/locallib.php +++ b/locallib.php @@ -623,7 +623,6 @@ function cr_import_xml(string $xml, object $course) { * @return array */ function cr_logging_info(): array { - global $CFG; static $uselegacyreader; static $useinternalreader;