67 lines
1.5 KiB
PHP
67 lines
1.5 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 {
|
|
// Our Static Items List
|
|
abstract protected function _table();
|
|
|
|
// Due to static scope, sometimes we need to call this function from the child class.
|
|
protected function _get($id) {
|
|
$table = $this->_table();
|
|
|
|
if (! $table)
|
|
return 'No Table';
|
|
elseif (! $id AND empty($table[$id]))
|
|
return '';
|
|
elseif (empty($table[$id]))
|
|
return sprintf('No Value (%s)',$id);
|
|
else
|
|
return $table[$id];
|
|
}
|
|
|
|
/**
|
|
* Setup our class instantiation
|
|
* @note This must be declared in the child class due to static scope
|
|
*/
|
|
public static function factory() {
|
|
$x = get_called_class();
|
|
|
|
return new $x;
|
|
}
|
|
|
|
/**
|
|
* 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,array $attributes=NULL) {
|
|
$table = static::factory()->_table();
|
|
|
|
if ($addblank)
|
|
$table = array_merge(array(''=>' '),$table);
|
|
|
|
return Form::Select($name,$table,$default,$attributes);
|
|
}
|
|
|
|
/**
|
|
* Lists our available keys
|
|
*/
|
|
public static function keys() {
|
|
return array_keys(static::factory()->_table());
|
|
}
|
|
|
|
public static function table() {
|
|
return static::factory()->_table();
|
|
}
|
|
}
|
|
?>
|