2013-10-10 02:44:53 +00:00
|
|
|
<?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 {
|
2013-04-26 01:42:09 +00:00
|
|
|
// Our Static Items List
|
|
|
|
abstract protected function _table();
|
2013-10-10 02:44:53 +00:00
|
|
|
|
|
|
|
// Due to static scope, sometimes we need to call this function from the child class.
|
2013-04-26 01:42:09 +00:00
|
|
|
protected function _get($id) {
|
|
|
|
$table = $this->_table();
|
2013-10-10 02:44:53 +00:00
|
|
|
|
|
|
|
if (! $table)
|
|
|
|
return 'No Table';
|
2013-10-09 05:43:41 +00:00
|
|
|
elseif (! $id AND empty($table[$id]))
|
|
|
|
return '';
|
2013-10-10 02:44:53 +00:00
|
|
|
elseif (empty($table[$id]))
|
|
|
|
return sprintf('No Value (%s)',$id);
|
|
|
|
else
|
|
|
|
return $table[$id];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-04-26 01:42:09 +00:00
|
|
|
* Setup our class instantiation
|
|
|
|
* @note This must be declared in the child class due to static scope
|
2013-10-10 02:44:53 +00:00
|
|
|
*/
|
2013-04-26 01:42:09 +00:00
|
|
|
public static function factory() {
|
|
|
|
$x = get_called_class();
|
|
|
|
|
|
|
|
return new $x;
|
2013-10-10 02:44:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders form input
|
|
|
|
*
|
|
|
|
* @param string Form name to render
|
|
|
|
* @param string Default value to populate in the Form input.
|
|
|
|
*/
|
2013-04-26 01:42:09 +00:00
|
|
|
public static function form($name,$default='',$addblank=FALSE,array $attributes=NULL) {
|
2013-12-19 23:00:32 +00:00
|
|
|
$table = self::factory()->_table();
|
2013-10-10 02:44:53 +00:00
|
|
|
|
|
|
|
if ($addblank)
|
|
|
|
$table = array_merge(array(''=>' '),$table);
|
|
|
|
|
2013-04-26 01:42:09 +00:00
|
|
|
return Form::Select($name,$table,$default,$attributes);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Lists our available keys
|
|
|
|
*/
|
|
|
|
public static function keys() {
|
2013-12-19 23:00:32 +00:00
|
|
|
return array_keys(self::factory()->_table());
|
2013-04-26 01:42:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function table() {
|
2013-12-19 23:00:32 +00:00
|
|
|
return self::factory()->_table();
|
2013-10-10 02:44:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|