From 7e632cf78559fcb0b5e2f9368f65511307d54255 Mon Sep 17 00:00:00 2001 From: Deon George Date: Wed, 31 Aug 2016 21:51:58 +1000 Subject: [PATCH] Moved functions from OSB and lnAuth --- classes/Model/Currency.php | 4 ++ classes/lnApp/Auth/ORM.php | 22 ----------- classes/lnApp/Controller/User/Account.php | 2 +- classes/lnApp/Model/Account.php | 47 +++++++---------------- classes/lnApp/Model/Auth/UserDefault.php | 2 +- classes/lnApp/Model/Country.php | 8 ++++ classes/lnApp/Model/Currency.php | 19 +++++++++ 7 files changed, 46 insertions(+), 58 deletions(-) create mode 100644 classes/Model/Currency.php create mode 100644 classes/lnApp/Model/Currency.php diff --git a/classes/Model/Currency.php b/classes/Model/Currency.php new file mode 100644 index 0000000..85a1c82 --- /dev/null +++ b/classes/Model/Currency.php @@ -0,0 +1,4 @@ + diff --git a/classes/lnApp/Auth/ORM.php b/classes/lnApp/Auth/ORM.php index 329c898..2d94c99 100644 --- a/classes/lnApp/Auth/ORM.php +++ b/classes/lnApp/Auth/ORM.php @@ -109,28 +109,6 @@ abstract class lnApp_Auth_ORM extends Kohana_Auth_ORM { return is_null($x=$this->get_user()) ? ORM::factory('Group')->where('id','=',0)->find_all() : $x->groups(); } - /** - * Gets the currently logged in user from the session. - * Returns NULL if no user is currently logged in. - * - * @param boolean Check token users too - * @return mixed - */ - public function get_user($default=NULL,$tokenuser=TRUE) { - // If we are a CLI, we are not logged in - if (PHP_SAPI === 'cli') - throw new Kohana_Exception('Calling :method from the CLI is not allowed!',array(':method'=>__METHOD__)); - - // Get the current user - $uo = parent::get_user($default); - - // If we are not logged in, see if there is token for the user - if (is_null($uo) AND $tokenuser AND ($token=Session::instance()->get('token')) OR ($token=Arr::get($_REQUEST,'token'))) - $uo = $this->_get_token_user($token); - - return $uo; - } - // Override Kohana Auth requirement to have a hash_key public function hash($str) { switch ($this->_config['hash_method']) { diff --git a/classes/lnApp/Controller/User/Account.php b/classes/lnApp/Controller/User/Account.php index d737e0a..d54e6c7 100644 --- a/classes/lnApp/Controller/User/Account.php +++ b/classes/lnApp/Controller/User/Account.php @@ -49,7 +49,7 @@ abstract class lnApp_Controller_User_Account extends Controller_Account { // Run validation and save elseif ($this->ao->changed()) - if ($this->ao->save()) { + if ($this->save($this->ao)) { SystemMessage::factory() ->title('Record updated') ->type('success') diff --git a/classes/lnApp/Model/Account.php b/classes/lnApp/Model/Account.php index 6724934..770e4ac 100644 --- a/classes/lnApp/Model/Account.php +++ b/classes/lnApp/Model/Account.php @@ -16,22 +16,22 @@ abstract class lnApp_Model_Account extends Model_Auth_UserDefault { 'group'=>array('through'=>'account_group'), ); - protected $_has_one = array( - 'country'=>array('foreign_key'=>'id'), - 'currency'=>array('foreign_key'=>'id'), - 'language'=>array('foreign_key'=>'id'), + protected $_belongs_to = array( + 'country'=>array(), + 'currency'=>array(), + 'language'=>array(), ); protected $_display_filters = array( + 'active'=>array( + array('StaticList_YesNo::get',array(':value',TRUE)), + ), 'date_orig'=>array( array('Site::Date',array(':value')), ), 'date_last'=>array( array('Site::Date',array(':value')), ), - 'active'=>array( - array('StaticList_YesNo::get',array(':value',TRUE)), - ), ); protected $_form = array('id'=>'id','value'=>'name()'); @@ -40,17 +40,6 @@ abstract class lnApp_Model_Account extends Model_Auth_UserDefault { /** 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 **/ /** @@ -97,24 +86,14 @@ abstract class lnApp_Model_Account extends Model_Auth_UserDefault { } /** - * This function will extract the available methods for this account - * This is used both for menu options and method security + * Return an account name */ - public function methods() { - static $result = array(); + public function name($variable=NULL) { + return trim(sprintf('%s %s',$this->first_name,$this->last_name)); + } - // @todo We may want to optimise this with some session caching. - if ($result) - return $result; - - foreach ($this->groups() as $go) - foreach ($go->module_method->find_all() as $mmo) - if (empty($result[$mmo->id])) - $result[$mmo->id] = $mmo; - - Sort::MAsort($result,array('module->name','menu_display')); - - return $result; + public function refnum($short=FALSE) { + return ($short ? '' : sprintf('%02s-',Site::id())).sprintf('%04s',$this->id); } /** diff --git a/classes/lnApp/Model/Auth/UserDefault.php b/classes/lnApp/Model/Auth/UserDefault.php index a68d83b..6852b7d 100644 --- a/classes/lnApp/Model/Auth/UserDefault.php +++ b/classes/lnApp/Model/Auth/UserDefault.php @@ -14,8 +14,8 @@ abstract class lnApp_Model_Auth_UserDefault extends Model_Auth_User { public function rules() { return array( 'email' => array( - array(array($this, 'unique'), array('email', ':value')), array('not_empty'), + array(array($this, 'unique'), array('email', ':value')), array('min_length', array(':value', 4)), array('max_length', array(':value', 127)), array('email'), diff --git a/classes/lnApp/Model/Country.php b/classes/lnApp/Model/Country.php index fe20968..94f4a7a 100644 --- a/classes/lnApp/Model/Country.php +++ b/classes/lnApp/Model/Country.php @@ -10,6 +10,14 @@ * @license http://dev.leenooks.net/license.html */ abstract class lnApp_Model_Country extends ORM { + protected $_has_one = array( + 'currency'=>array('far_key'=>'id'), + ); + + protected $_has_many = array( + 'tax'=>array('far_key'=>'id'), + ); + protected $_sorting = array( 'name'=>'ASC', ); diff --git a/classes/lnApp/Model/Currency.php b/classes/lnApp/Model/Currency.php new file mode 100644 index 0000000..4f69e0a --- /dev/null +++ b/classes/lnApp/Model/Currency.php @@ -0,0 +1,19 @@ +'ASC', + ); + + protected $_form = array('id'=>'id','value'=>'name'); +} +?>