Moved functions from OSB and lnAuth

This commit is contained in:
Deon George 2016-08-31 21:51:58 +10:00
parent f5bc5dfa29
commit 7e632cf785
7 changed files with 46 additions and 58 deletions

View File

@ -0,0 +1,4 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
class Model_Currency extends lnApp_Model_Currency {}
?>

View File

@ -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']) {

View File

@ -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')

View File

@ -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);
}
/**

View File

@ -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'),

View File

@ -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',
);

View File

@ -0,0 +1,19 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* OSB Currency Model
*
* @package lnApp
* @category Models
* @author Deon George
* @copyright (c) 2009-2013 Deon George
* @license http://dev.leenooks.net/license.html
*/
abstract class lnApp_Model_Currency extends ORM {
protected $_sorting = array(
'name'=>'ASC',
);
protected $_form = array('id'=>'id','value'=>'name');
}
?>