Updated OSB to work with KH 3.1

This commit is contained in:
Deon George
2011-05-14 17:35:33 +10:00
parent 6d256839fc
commit 9dda9f43f4
42 changed files with 397 additions and 347 deletions

View File

@@ -15,80 +15,32 @@ abstract class ORMOSB extends ORM {
* @var string Database to connect to
*/
protected $_db = 'default';
protected $_object_formated = array();
protected $_formated = FALSE;
protected $_formats = array();
/**
* @var boolean Database names plural configuration
*/
protected $_table_names_plural = false;
protected $_created_column = array('column'=>'date_orig','format'=>TRUE);
protected $_updated_column = array('column'=>'date_last','format'=>TRUE);
protected $_callbacks = array(
'id'=>array('get_next_id'),
'site_id'=>array('set_site_id'),
);
/**
* Format fields for display purposes
*
* @param string column name
* @return mixed
*/
protected function _format() {
$format = Validate::factory($this->_object);
foreach ($this->_formats as $column => $formats)
$format->filters($column,$formats);
if ($format->check())
foreach ($format as $column => $value)
$this->_object_formated[$column] = $value;
$this->_formated = TRUE;
}
/**
* Return a formated columns, as per the model definition
*/
public function display($column) {
// Trigger a load of the record.
$value = $this->__get($column);
// If some of our fields need to be formated for display purposes.
if ($this->_loaded AND ! $this->_formated AND $this->_formats)
$this->_format();
if (isset($this->_object_formated[$column]))
return $this->_object_formated[$column];
else
return $value;
// @todo Rules are no longer used?
public function rules() {
return array(
'id'=>array(
array('ORMOSB::get_next_id',array(':validation',':model',':field')),
),
'site_id'=>array(
array('ORMOSB::set_site_id',array(':validation',':model',':field')),
),
);
}
/**
* Our child models should provide an invoice display, this is shown
* on printed invoices.
*
* @todo This is no longer used I think?
*/
public function invoice_display() {
throw new Kohana_Exception(':module has not configured an :method, but has made the call',array(':module'=>get_class($this),'method'=>__METHOD__));
}
/**
* Override the _load_result() function so that our site ID is automatically
* added to the SQL query
* @todo This is not picked up by all queries. Need to investigate why
* @todo This is not being done by inserts
*/
protected function _load_result($multiple = FALSE)
{
$this->_db_builder->where($this->_table_name.'.site_id','=',Config::siteid());
return parent::_load_result($multiple);
}
/**
* This function will enhance the [Validate::filter], since it always passes
* the value as the first argument and sometimes functions need that to not
@@ -105,6 +57,7 @@ abstract class ORMOSB extends ORM {
* @param mixed $val Value to be processed
* @param string $func Name of function to call
* @param string $arg Other arguments for the function
* @todo This has probably changed in KH 3.1
*/
final public static function _filters($val,$func,$arg) {
switch ($func) {
@@ -121,31 +74,30 @@ abstract class ORMOSB extends ORM {
* @param array Validate object
* @param string Primary Key
*/
public function get_next_id(Validate $array,$field) {
if (! is_null($array[$field]))
public static function get_next_id(Validation $array,$model,$field) {
if (! is_null($model->$field))
return TRUE;
$this->_changed[$field] = $field;
$model->_changed[$field] = $field;
$ido = ORM::factory('module')
->where('name','=',$this->_table_name)
->where('name','=',$model->_table_name)
->find();
if (! $ido->loaded())
throw new Kohana_Exception('Problem getting record_id for :table',array(':table'=>$this->_table_name));
throw new Kohana_Exception('Problem getting record_id for :table',array(':table'=>$model->_table_name));
$array[$field] = $ido->record_id->next_id($ido->id);
$model->$field = $ido->record_id->next_id($ido->id);
return TRUE;
}
public function set_site_id(Validate $array,$field) {
if (! is_null($array[$field]))
public static function set_site_id(Validation $array,$model,$field) {
if (! is_null($model->$field))
return TRUE;
// @todo This should be a config item
$this->_changed[$field] = $field;
$array[$field] = Config::siteid();
$model->_changed[$field] = $field;
$model->$field = Config::siteid();
return TRUE;
}