From 97b868a31cc4396ac629a50374b62ee85cd80bb5 Mon Sep 17 00:00:00 2001 From: nicolasconnault Date: Tue, 1 May 2007 05:47:10 +0000 Subject: [PATCH] MDL-9506 Forgot to add the grade_scale.php file. --- lib/grade/grade_scale.php | 127 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 lib/grade/grade_scale.php diff --git a/lib/grade/grade_scale.php b/lib/grade/grade_scale.php new file mode 100644 index 0000000000..4d5e4bc112 --- /dev/null +++ b/lib/grade/grade_scale.php @@ -0,0 +1,127 @@ +scale_items = explode(',', $this->scale); + } elseif (is_array($items)) { + $this->scale_items = $items; + } else { + $this->scale_items = explode(',', $items); + } + + // Trim whitespace around each value + foreach ($this->scale_items as $key => $val) { + $this->scale_items[$key] = trim($val); + } + + return $this->scale_items; + } + + /** + * Compacts (implodes) the array of items in $scale_items into a comma-separated string, $scale. + * There are three ways to achieve this: + * 1. No argument given: The $scale_items array is already loaded and imploded to a string of items. + * 2. An array is given and is imploded into a string of items. + * 3. A string of items is given and saved directly as the $scale variable. + * NOTE: This method is the exact reverse of load_items, and their input/output should be interchangeable. However, + * because load_items() trims the whitespace around the items, when the string is reconstructed these whitespaces will + * be missing. This is not an issue, but should be kept in mind when comparing the two strings. + * + * @param mixed $items Could be null, a string or an array. The method behaves differently for each case. + * @return array The resulting string of scale items or null if the method failed to produce one. + */ + function compact_items($items=NULL) { + if (empty($items)) { + $this->scale = implode(',', $this->scale_items); + } elseif (is_array($items)) { + $this->scale = implode(',', $items); + } else { + $this->scale = $items; + } + + return $this->scale; + } +} +?> -- 2.39.5