This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
khosb/application/classes/StaticList.php
2013-10-10 13:44:53 +11:00

72 lines
1.7 KiB
PHP

<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This is class renders standard lists and their values
*
* @package OSB
* @category Helpers
* @author Deon George
* @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
abstract class StaticList {
// This is our list of items that will be rendered
protected $list = array();
/**
* Each static list type must provide the table function that contains
* the table of list and values.
*/
abstract protected function table();
public static function factory() {
throw new Kohana_Exception(':class is calling :method, when it should have its own method',
array(':class'=>get_called_class(),':method'=>__METHOD__));
}
/**
* Display a static name for a value
*
* @param key $id value to render
* @see _display()
*/
public static function display($value) {
return static::_display($value);
}
// Due to static scope, sometimes we need to call this function from the child class.
protected static function _display($id) {
$table = static::factory()->table();
if (! $table)
return 'No Table';
elseif (empty($table[$id]))
return sprintf('No Value (%s)',$id);
else
return $table[$id];
}
/**
* Lists our available keys
*/
public static function keys() {
return array_keys(static::factory()->table());
}
/**
* Renders form input
*
* @param string Form name to render
* @param string Default value to populate in the Form input.
*/
public static function form($name,$default='',$addblank=FALSE) {
$table = static::factory()->table();
if ($addblank)
$table = array_merge(array(''=>'&nbsp;'),$table);
return Form::Select($name,$table,$default);
}
}
?>