/** * returns all available classes for a customlabel * @uses $CFG * @param int $context if a context is given, filters out any type that is not allowed against * roles held by the current user. Returns all types otherwise. */ function customlabel_get_classes($context = null) { global $CFG; $classes = array(); $basetypedir = $CFG->dirroot . "/mod/customlabel/type"; $classdir = opendir($basetypedir); while ($entry = readdir($classdir)) { if (preg_match("/^[.!]/", $entry)) { continue; } // ignore what need to be ignored if (!is_dir($basetypedir . '/' . $entry)) { continue; } // ignore real files unset($obj); $obj->id = $entry; $obj->name = get_string($entry, 'customlabel'); $classes[] = $obj; } if ($context) { customlabel_filter_role_disabled($classes, $context); // filter against roles } return $classes; }
/** * returns all available classes for a customlabel * @uses $CFG * @param int $context if a context is given, filters out any type that is not allowed against * roles held by the current user. Returns all types otherwise. * @param bool $ignoredisabled * @return a sorted array of class definitions as objects */ function customlabel_get_classes($context = null, $ignoredisabled = true, $asarray = false) { global $CFG; static $classes = array(); static $classarr = array(); if (empty($classes)) { $basetypedir = $CFG->dirroot . "/mod/customlabel/type"; $disabled = @$CFG->list_customlabel_disabled; $disabledarr = explode(',', $disabled); $classdir = opendir($basetypedir); while ($entry = readdir($classdir)) { if (preg_match("/^[.!]/", $entry)) { continue; } // ignore what needs to be ignored if (!is_dir($basetypedir . '/' . $entry)) { continue; } // ignore real files if (preg_match('/^CVS$/', $entry)) { continue; } // ignore versionning files if ($entry == 'NEWTYPE') { continue; } // discard plugin prototype $enabledkey = "customlabel_{$entry}_enabled"; if (!isset($CFG->{$enabledkey})) { $CFG->{$enabledkey} = true; } // open all possibilities by default if (!$CFG->{$enabledkey} && $ignoredisabled) { continue; } // check admin config if (in_array($entry, $disabledarr) && $ignoredisabled) { continue; } // ignore config.php disabled $obj = new StdClass(); $obj->id = $entry; $obj->name = get_string('typename', 'customlabeltype_' . $entry); $classes[] = $obj; $classarr[$obj->id] = $obj->name; } } if ($asarray) { return $classarr; } // sort result against localized names $function = create_function('$a, $b', 'return strnatcmp($a->name, $b->name);'); uasort($classes, $function); if ($context) { customlabel_filter_role_disabled($classes, $context); // filter against roles } return $classes; }