More Standardisation work.

This commit is contained in:
Deon George
2016-08-03 14:00:51 +10:00
parent 85f08bbb0a
commit 5f84d2c14f
38 changed files with 276 additions and 100 deletions

View File

@@ -21,12 +21,15 @@ class Model_Account extends lnApp_Model_Account {
);
protected $_has_one = array(
'country'=>array('foreign_key'=>'id'),
'currency'=>array('foreign_key'=>'id'),
'language'=>array('foreign_key'=>'id'),
'RTM'=>array('far_key'=>'id'),
);
protected $_belongs_to = array(
'country'=>array(),
'currency'=>array(),
'language'=>array(),
);
protected $_display_filters = array(
'date_orig'=>array(
array('Site::Date',array(':value')),
@@ -39,6 +42,22 @@ class Model_Account extends lnApp_Model_Account {
),
);
/** REQUIRED ABSTRACT METHODS **/
/**
* Returns the company name if it exists, otherwise the persons name
*/
public function name($variable=NULL) {
return $this->isCompany() ? $this->company : $this->namesub();
}
/*
* Returns the persons name
*/
public function namesub($variable=NULL) {
return trim(sprintf('%s %s',$this->first_name,$this->last_name));
}
/** OTHER METHODS **/
public function activated() {
@@ -85,15 +104,15 @@ class Model_Account extends lnApp_Model_Account {
return ($this->RTM->loaded() AND is_null($this->RTM->parent_id));
}
public function isReseller() {
return $this->RTM->loaded();
/**
* Is this account a company account
*/
public function isCompany() {
return strlen($this->company) > 0;
}
/**
* Return an account name
*/
public function name($withcompany=FALSE) {
return trim(sprintf('%s %s',$this->first_name,$this->last_name).(($withcompany AND $this->company) ? sprintf(' (%s)',$this->company) : ''));
public function isReseller() {
return $this->RTM->loaded();
}
/**
@@ -111,7 +130,7 @@ class Model_Account extends lnApp_Model_Account {
/**
* Search for accounts matching a term
*/
public function list_autocomplete($term,$index,$value,array $label,array $limit=array(),array $options=NULL) {
public function list_autocomplete($term,$index,$value,array $label,array $limit=array(),array $options=array()) {
$ao = Auth::instance()->get_user();
$this->clear();
@@ -147,7 +166,7 @@ class Model_Account extends lnApp_Model_Account {
// Restrict results to authorised accounts
array_push($limit,array('id','IN',$ao->RTM->customers($ao->RTM)));
return parent::list_autocomplete($term,$index,$value,$label,$limit,$options);
return parent::list_autocomplete($term,$index,$value,$label,$limit,array_merge($options,array('parentbypass'=>TRUE)));
}
}
?>