Standardisation work, changed accnum() to refnum()

This commit is contained in:
Deon George 2016-08-02 09:54:18 +10:00
parent c57e166834
commit 01f6c7ba5e
2 changed files with 47 additions and 41 deletions

View File

@ -25,7 +25,7 @@ abstract class lnApp_Controller_User_Account extends Controller_Account {
$this->ao->reload(); $this->ao->reload();
Block::factory() Block::factory()
->title(sprintf('Account: %s',$this->ao->accnum())) ->title(sprintf('Account: %s',$this->ao->refnum()))
->title_icon('fa-wrench') ->title_icon('fa-wrench')
->type('form-horizontal') ->type('form-horizontal')
->body(View::factory('account/user/edit')->set('o',$this->ao)); ->body(View::factory('account/user/edit')->set('o',$this->ao));
@ -64,7 +64,7 @@ abstract class lnApp_Controller_User_Account extends Controller_Account {
} }
Block::factory() Block::factory()
->title(sprintf('Password Reset: %s',$this->ao->accnum())) ->title(sprintf('Password Reset: %s',$this->ao->refnum()))
->title_icon('fa-cog') ->title_icon('fa-cog')
->id('reset') ->id('reset')
->type('form-horizontal') ->type('form-horizontal')

View File

@ -34,19 +34,30 @@ abstract class lnApp_Model_Account extends Model_Auth_UserDefault {
), ),
); );
protected $_form = array('id'=>'id','value'=>'name(TRUE)'); protected $_form = array('id'=>'id','value'=>'name()');
protected $_save_message = TRUE; protected $_save_message = TRUE;
/** REQUIRED ABSTRACT METHODS **/
/**
* Return an account name
*/
public function name($variable=NULL) {
return trim(sprintf('%s %s',$this->first_name,$this->last_name));
}
public function refnum($short=FALSE) {
return ($short ? '' : sprintf('%02s-',Site::id())).sprintf('%04s',$this->id);
}
/** LOCAL METHODS **/
/** /**
* Our account number format * Our account number format
*/ */
public function accnum() {
return sprintf('%s-%04s',Company::instance()->site(TRUE),$this->id);
}
public function activate_code() { public function activate_code() {
return md5(sprintf('%s-%s-%s-%s',$this->accnum(),$this->date_orig,$this->date_last,$this->email)); return md5(sprintf('%s-%s-%s-%s',$this->refnum(),$this->date_orig,$this->date_last,$this->email));
} }
public function activated() { public function activated() {
@ -101,61 +112,56 @@ abstract class lnApp_Model_Account extends Model_Auth_UserDefault {
if (empty($result[$mmo->id])) if (empty($result[$mmo->id]))
$result[$mmo->id] = $mmo; $result[$mmo->id] = $mmo;
Sort::MAsort($result,'module->name,menu_display'); Sort::MAsort($result,array('module->name','menu_display'));
return $result; return $result;
} }
/**
* Return an account name
*/
public function name() {
return trim(sprintf('%s %s',$this->first_name,$this->last_name));
}
/** /**
* Return a token valid for this user * Return a token valid for this user
*/ */
public function token($token_expire,$module,$method,$uses) { public function token($token_expire,$module,$method,$uses) {
return $this->id.':'.md5(sprintf('%s-%s',$this->accnum(),$this->date_last)); return $this->id.':'.md5(sprintf('%s-%s',$this->refnum(),$this->date_last));
} }
/** /**
* Search for accounts matching a term * 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=NULL) {
$ao = Auth::instance()->get_user(); if (! isset($options['parentbypass'])) {
$ao = Auth::instance()->get_user();
$this->clear(); $this->clear();
$this->where_active(); $this->where_active();
// Build our where clause // Build our where clause
// First Name, Last name // First Name, Last name
if (preg_match('/\ /',$term)) { if (preg_match('/\ /',$term)) {
list($fn,$ln) = explode(' ',$term,2); list($fn,$ln) = explode(' ',$term,2);
$this->where_open() $this->where_open()
->where('first_name','like','%'.$fn.'%') ->where('first_name','like','%'.$fn.'%')
->and_where('last_name','like','%'.$ln.'%') ->and_where('last_name','like','%'.$ln.'%')
->where_close(); ->where_close();
} elseif (is_numeric($term)) { } elseif (is_numeric($term)) {
$this->where('id','like','%'.$term.'%'); $this->where('id','like','%'.$term.'%');
} elseif (preg_match('/\@/',$term)) { } elseif (preg_match('/\@/',$term)) {
$this->where('email','like','%'.$term.'%'); $this->where('email','like','%'.$term.'%');
} else { } else {
$this->where_open() $this->where_open()
->or_where('first_name','like','%'.$term.'%') ->or_where('first_name','like','%'.$term.'%')
->or_where('last_name','like','%'.$term.'%') ->or_where('last_name','like','%'.$term.'%')
->or_where('email','like','%'.$term.'%') ->or_where('email','like','%'.$term.'%')
->where_close(); ->where_close();
}
// Restrict results to authorised accounts
// @todo
} }
// Restrict results to authorised accounts
// @todo
return parent::list_autocomplete($term,$index,$value,$label,$limit,$options); return parent::list_autocomplete($term,$index,$value,$label,$limit,$options);
} }
} }