$value) { $this->$param = $value; } return $this; } else { $grade_scale = new grade_scale($grade_scale); return $grade_scale; } } else { return false; } } /** * Loads the scale's items into the $scale_items array. * There are three ways to achieve this: * 1. No argument given: The $scale string is already loaded and exploded to an array of items. * 2. A string is given: A comma-separated list of items is exploded into an array of items. * 3. An array of items is given and saved directly as the array of items for this scale. * * @param mixed $items Could be null, a string or an array. The method behaves differently for each case. * @return array The resulting array of scale items or null if the method failed to produce one. */ function load_items($items=NULL) { if (empty($items)) { $this->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; } } ?>