720, Weekly => 168)
+ *
+ * Example2: comma
+ * LXD, true
+ * IT, false
+ * Becomes (LXD => true, IT => false)
+
+ * Example3: index
+ * LXD
+ * IT
+ * Becomes (0 => LXD, 1 => IT)
+ *
+ * @param string $configstring setting
+ * @param string $arraytype by default multi, comma, use mirror to miror key/value
+ * @param bool $booly is the second param using bool? (see example2)
+ *
+ * @return array
+ */
+ public static function config_to_array($configstring, $arraytype = "multi", $booly = false) {
+
+ $configname = get_config('moodle', $configstring);
+ if ($configname == false) {
+ return false;
+ }
+
+ $final = array();
+
+ if ($arraytype == "multi") {
+ $breakstripped = preg_replace("/\r|\n/", " ", $configname);
+
+ self::quick_string_clean($breakstripped);
+ $exploded = explode(" ", $breakstripped);
+ $explodedcount = count($exploded);
+ // Now convert to array and transform to an assoc. array.
+ for ($i = 0; $i < $explodedcount; $i += 2) {
+ $final[$exploded[$i + 1]] = $exploded[$i];
+ }
+
+ } else if ($arraytype == "comma") {
+ // Replace the line breaks with tilde.
+ $breakstripped = preg_replace("/\r|\n/", "~", $configname);
+ // Clean the string.
+ $breakstripped = self::quick_string_clean($breakstripped);
+ // You might get a double tilde depending on OS
+ $breakstripped = str_replace("~~", "~", $breakstripped);
+ // Now break into chunks
+ $exploded = explode("~", $breakstripped);
+ $explodedcount = count($exploded);
+ // Now convert to array and transform to an assoc. array.
+ for ($i = 0; $i < $explodedcount; $i++) {
+ $temp = explode(",", $exploded[$i]);
+ $temp[1] = $booly ? (bool)$temp[1] : $temp[1];
+ $final[$temp[0]] = $temp[1];
+ }
+ } else if ($arraytype == "index") {
+
+ $final = $exploded;
+ }
+ return $final;
+ }
+
+ public static function role_check_course_size($cid = 0) {
+ global $OUTPUT, $COURSE, $CFG, $USER;
+
+ $found = false;
+ $access = false;
+
+ $context = context_course::instance($cid);
+ $roles = get_user_roles($context, $USER->id, true);
+
+ if (empty($roles)) {
+ return array(
+ "found" => false,
+ "access" => false
+ );
+ }
+ $role = key($roles);
+ $rolename = $roles[$role]->shortname;
+ $customroles = self::config_to_array('report_coursesize_manualroles', "comma", true);
+
+
+ foreach ($customroles as $k => $v) {
+ if (strtolower($k) == strtolower($rolename)) {
+ $found = true;
+ $access = $v;
+ }
+ }
+ return array(
+ "found" => $found,
+ "access" => $access
+ );
+ }
+
+ public static function testy() {
+
+ global $DB;
+
+ $courseid = 38581;
+ $course = $DB->get_record('course', array('id' => $courseid));
+ $info = get_fast_modinfo($course);
+
+ print_object($info);
+ }
+}
\ No newline at end of file
diff --git a/theme/snap/layout/course.php b/theme/snap/layout/course.php
index f520637605ff9..cdb169b9b6f71 100644
--- a/theme/snap/layout/course.php
+++ b/theme/snap/layout/course.php
@@ -80,14 +80,17 @@
if ($showcs) {
include_once($CFG->dirroot. "/theme/lsu.php");
$showcssnippet = new lsu_theme_snippets();
+ $roles = get_config('report_coursesize', 'report_coursesize/roles');
// Was calling this func twice so call once and send to show_course_size.
$isadmin = is_siteadmin();
- // Then later in code:
- if (!$showcssnippet->are_you_student($isadmin)) {
+ $isspeshul = lsu_snippets::role_check_course_size($COURSE->id);
+ // Checks if they are a student or someone that can edit grades
+ // Also checks if they match a role in the settings that is allowed.
+ if (!$showcssnippet->are_you_student()) {
// User does NOT have a student role in a course.
echo '';
- echo $showcssnippet->show_course_size($isadmin);
+ echo $showcssnippet->show_course_size($isadmin ?: $isspeshul["access"]);
echo '
';
}
}