Application cleanup

This commit is contained in:
Deon George
2013-05-10 20:48:10 +10:00
parent 970b2ef4f0
commit c0ba6d4e98
36 changed files with 284 additions and 544 deletions

View File

@@ -19,6 +19,20 @@ abstract class ORM extends Kohana_ORM {
private $_formated = FALSE;
// Our filters used to display values in a friendly format
protected $_display_filters = array();
// Tables that do not have a site_id column
public static $no_site_id_tables = array('setup','country','currency','language','tax');
/**
* Add our OSB site_id to each SELECT query
* @see parent::__build()
*/
final protected function _build($type) {
// Exclude tables without site ID's
if (! in_array($this->_table_name,ORM::$no_site_id_tables))
$this->where($this->_object_name.'.site_id','=',Company::instance()->site());
return parent::_build($type);
}
/**
* Format fields for display purposes
@@ -33,6 +47,13 @@ abstract class ORM extends Kohana_ORM {
$this->_formated = TRUE;
}
/**
* Function help to find records that are active
*/
protected function _where_active() {
return $this->where('status','=',TRUE);
}
public function clear() {
$this->_formated = FALSE;
$this->_object_formated = array();
@@ -40,23 +61,6 @@ abstract class ORM extends Kohana_ORM {
return parent::clear();
}
/**
* 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->_formated AND $this->_display_filters)
$this->_format();
if (isset($this->_object_formated[$column]))
return $this->_object_formated[$column];
else
return $value;
}
/**
* Override KH's ORM count_relations() function, to include our site_id in the query.
*
@@ -94,21 +98,21 @@ abstract class ORM extends Kohana_ORM {
return (int) $count;
}
/** OSB SPECIFIC ENHANCEMENTS **/
// Tables that do not have a site_id column
public static $no_site_id_tables = array('setup','country','currency','language','tax');
/**
* Add our OSB site_id to each SELECT query
* @see parent::__build()
* Return a formated columns, as per the model definition
*/
final protected function _build($type) {
// Exclude tables without site ID's
if (! in_array($this->_table_name,ORM::$no_site_id_tables))
$this->where($this->_object_name.'.site_id','=',Company::instance()->site());
public function display($column) {
// Trigger a load of the record.
$value = $this->__get($column);
return parent::_build($type);
// If some of our fields need to be formated for display purposes.
if (! $this->_formated AND $this->_display_filters)
$this->_format();
if (isset($this->_object_formated[$column]))
return $this->_object_formated[$column];
else
return $value;
}
/**
@@ -118,6 +122,9 @@ abstract class ORM extends Kohana_ORM {
return $this->_where_active()->find_all();
}
/**
* This function is our AJAX helper, used by module list_autocomplete()
*/
public function list_autocomplete($term,$index,$value,array $label,array $limit=array(),array $options=NULL) {
$result = array();
@@ -174,13 +181,6 @@ abstract class ORM extends Kohana_ORM {
return $x;
}
/**
* Function help to find records that are active
*/
protected function _where_active() {
return $this->where('status','=',TRUE);
}
public function where_active() {
return $this->_where_active();
}