Major work to domain and hosting
Minor updates for ADSL services Updates to Sort::MAsort() Move core OSB items under application/ Moved ACCOUNT functions under application Minor updates to task
This commit is contained in:
127
application/classes/model/account.php
Normal file
127
application/classes/model/account.php
Normal file
@@ -0,0 +1,127 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* @package lnApp
|
||||
* @subpackage Auth
|
||||
* @category Models
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
class Model_Account extends Model_Auth_UserDefault {
|
||||
// Relationships
|
||||
protected $_has_many = array(
|
||||
'user_tokens' => array('model' => 'user_token'),
|
||||
'email_log' => array('far_key'=>'id'),
|
||||
'group' => array('through' => 'account_group'),
|
||||
'invoice' => array('far_key'=>'id'),
|
||||
'payment'=>array('far_key'=>'id'),
|
||||
'service' => array('far_key'=>'id'),
|
||||
);
|
||||
protected $_has_one = array(
|
||||
'affiliate' => array('far_key'=>'id'),
|
||||
);
|
||||
|
||||
protected $_display_filters = array(
|
||||
'date_orig'=>array(
|
||||
array('Config::date',array(':value')),
|
||||
),
|
||||
'date_last'=>array(
|
||||
array('Config::date',array(':value')),
|
||||
),
|
||||
'status'=>array(
|
||||
array('StaticList_YesNo::display',array(':value')),
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Return an account name
|
||||
*/
|
||||
public function name($withcompany=FALSE) {
|
||||
if ($withcompany)
|
||||
return sprintf('%s %s (%s)',$this->first_name,$this->last_name,$this->company);
|
||||
else
|
||||
return sprintf('%s %s',$this->first_name,$this->last_name);
|
||||
}
|
||||
|
||||
public function accnum() {
|
||||
return sprintf('%02s-%04s',Config::siteid(),$this->id);
|
||||
}
|
||||
|
||||
public function title($name) {
|
||||
return StaticList_Title::form($name,$this->title);
|
||||
}
|
||||
|
||||
public function currency($name) {
|
||||
return StaticListModule::form($name,'currency',$this->currency_id,'id','name',array());
|
||||
}
|
||||
|
||||
public function country($name) {
|
||||
return StaticListModule::form($name,'country',$this->country_id,'id','name',array());
|
||||
}
|
||||
|
||||
public function language($name) {
|
||||
// @todo To setup
|
||||
return 'en';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the groups that an account belongs to
|
||||
*/
|
||||
public function groups() {
|
||||
return $this->group->find_all();
|
||||
}
|
||||
|
||||
public function isAdmin() {
|
||||
// @todo Define admins in the config file or DB
|
||||
$admins = array(ORM::factory('group',array('name'=>'Root')));
|
||||
|
||||
return $this->has('group',$admins);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all invoices for this account
|
||||
*/
|
||||
public function invoices() {
|
||||
return $this->invoice->distinct('id')->find_all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of due invoices for this account
|
||||
*
|
||||
* @param int Date (in secs) to only retrieve invoices prior to this date
|
||||
*/
|
||||
public function invoices_due($date=NULL) {
|
||||
$return = array();
|
||||
|
||||
foreach ($this->invoices() as $io)
|
||||
if ((is_null($date) OR $io->date_orig < $date) AND $io->due())
|
||||
$return[$io->id] = $io;
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the total of invoices due for this account
|
||||
*/
|
||||
public function invoices_due_total($date=NULL,$format=FALSE) {
|
||||
$result = 0;
|
||||
|
||||
foreach ($this->invoices_due($date) as $io)
|
||||
$result += $io->due();
|
||||
|
||||
return $format ? Currency::display($result) : $result;
|
||||
}
|
||||
|
||||
public function log($message) {
|
||||
// Log the logout
|
||||
$alo = ORM::factory('account_log');
|
||||
$alo->account_id = $this->id;
|
||||
$alo->ip = $_SERVER['REMOTE_ADDR'];
|
||||
$alo->details = $message;
|
||||
$alo->save();
|
||||
|
||||
return $alo->saved();
|
||||
}
|
||||
}
|
||||
?>
|
24
application/classes/model/account/log.php
Normal file
24
application/classes/model/account/log.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class supports Account Login Logging
|
||||
*
|
||||
* @package OSB
|
||||
* @subpackage Account
|
||||
* @category Models
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Model_Account_Log extends ORMOSB {
|
||||
protected $_belongs_to = array(
|
||||
'account'=>array(),
|
||||
);
|
||||
|
||||
protected $_display_filters = array(
|
||||
'date_orig'=>array(
|
||||
array('Config::datetime',array(':value')),
|
||||
),
|
||||
);
|
||||
}
|
||||
?>
|
13
application/classes/model/auth/roledefault.php
Normal file
13
application/classes/model/auth/roledefault.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* @package lnApp
|
||||
* @subpackage Auth
|
||||
* @category Models
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
class Model_Auth_RoleDefault extends Model_Auth_Role {
|
||||
}
|
||||
?>
|
83
application/classes/model/auth/userdefault.php
Normal file
83
application/classes/model/auth/userdefault.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* @package lnApp
|
||||
* @subpackage Auth
|
||||
* @category Models
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
class Model_Auth_UserDefault extends Model_Auth_User {
|
||||
// Validation rules
|
||||
public function rules() {
|
||||
return array(
|
||||
'username' => array(
|
||||
array('not_empty'),
|
||||
array('min_length', array(':value', 4)),
|
||||
array('max_length', array(':value', 32)),
|
||||
),
|
||||
'password' => array(
|
||||
array('not_empty'),
|
||||
array('min_length', array(':value', 5)),
|
||||
array('max_length', array(':value', 32)),
|
||||
),
|
||||
'email' => array(
|
||||
array('not_empty'),
|
||||
array('min_length', array(':value', 4)),
|
||||
array('max_length', array(':value', 127)),
|
||||
array('email'),
|
||||
),
|
||||
// @todo To test
|
||||
'password_confirm' => array(
|
||||
array('matches_ifset', array(':validation', 'password', 'password_confirm')),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Validation callbacks
|
||||
// @todo _callbacks no longer used
|
||||
protected $_callbacks = array(
|
||||
'username' => array('username_available'),
|
||||
'email' => array('email_available'),
|
||||
);
|
||||
|
||||
// Columns to ignore
|
||||
protected $_ignored_columns = array('password_confirm');
|
||||
|
||||
/*
|
||||
* Complete our login
|
||||
*
|
||||
* For some database logins, we may not want to record the user last login
|
||||
* details in the repository, so we just override that parent function
|
||||
* here.
|
||||
*
|
||||
* We can also do some other post-login actions here.
|
||||
* @todo Maybe we can do our session update here.
|
||||
*/
|
||||
public function complete_login() {
|
||||
return $this->log('Logged In');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to see if a record has been changed
|
||||
*/
|
||||
public function changed() {
|
||||
return ! (empty($this->_changed));
|
||||
}
|
||||
|
||||
/**
|
||||
* Debug function to see that has() finds
|
||||
* @todo This function could be removed
|
||||
*/
|
||||
public function has_list($alias, $model) {
|
||||
// Return list of matches
|
||||
return DB::select()
|
||||
->from($this->_has_many[$alias]['through'])
|
||||
->where($this->_has_many[$alias]['foreign_key'], '=', $this->pk())
|
||||
->where($this->_has_many[$alias]['far_key'], '=', $model->pk())
|
||||
->execute($this->_db)
|
||||
->as_array();
|
||||
}
|
||||
}
|
||||
?>
|
15
application/classes/model/country.php
Normal file
15
application/classes/model/country.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* OSB Country Model
|
||||
*
|
||||
* @package OSB
|
||||
* @subpackage Modules
|
||||
* @category Models
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
class Model_Country extends ORMOSB {
|
||||
}
|
||||
?>
|
84
application/classes/model/group.php
Normal file
84
application/classes/model/group.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* @package lnApp
|
||||
* @subpackage Auth
|
||||
* @category Models
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
class Model_Group extends Model_Auth_RoleDefault {
|
||||
// Relationships
|
||||
protected $_has_many = array(
|
||||
'account'=>array('through'=>'account_group'),
|
||||
'module_method'=>array('through'=>'group_method','far_key'=>'method_id'),
|
||||
);
|
||||
|
||||
protected $_sorting = array(
|
||||
'name'=>'ASC',
|
||||
);
|
||||
|
||||
// Validation rules
|
||||
protected $_rules = array(
|
||||
'name' => array(
|
||||
'not_empty' => NULL,
|
||||
'min_length' => array(4),
|
||||
'max_length' => array(32),
|
||||
),
|
||||
'description' => array(
|
||||
'max_length' => array(255),
|
||||
),
|
||||
);
|
||||
|
||||
protected $_display_filters = array(
|
||||
'status'=>array(
|
||||
array('StaticList_YesNo::display',array(':value')),
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* This function will, given a group, list all of the children that
|
||||
* are also related to this group, in the group heirarchy.
|
||||
*/
|
||||
public function list_childgrps($incParent=FALSE) {
|
||||
$return = array();
|
||||
|
||||
if (! $this->loaded())
|
||||
return $return;
|
||||
|
||||
foreach (ORM::factory('group')->where('status','=',1)->and_where('parent_id','=',$this)->find_all() as $go) {
|
||||
array_push($return,$go);
|
||||
|
||||
$return = array_merge($return,$go->list_childgrps());
|
||||
}
|
||||
|
||||
if ($incParent)
|
||||
array_push($return,$this);
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will, given a group, list all of the parent that
|
||||
* are also related to this group, in the group heirarchy.
|
||||
*/
|
||||
public function list_parentgrps($incParent=FALSE) {
|
||||
$return = array();
|
||||
|
||||
if (! $this->loaded())
|
||||
return $return;
|
||||
|
||||
foreach (ORM::factory('group')->where('status','=',1)->and_where('id','=',$this->parent_id)->find_all() as $go) {
|
||||
array_push($return,$go);
|
||||
|
||||
$return = array_merge($return,$go->list_parentgrps());
|
||||
}
|
||||
|
||||
if ($incParent)
|
||||
array_push($return,$this);
|
||||
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
?>
|
21
application/classes/model/setup.php
Normal file
21
application/classes/model/setup.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* OSB Setup Model
|
||||
*
|
||||
* This module must remain in applications/ as it is used very early in the
|
||||
* OSB initialisation.
|
||||
*
|
||||
* @package OSB
|
||||
* @subpackage Modules
|
||||
* @category Models
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
class Model_Setup extends ORMOSB {
|
||||
protected $_has_one = array(
|
||||
'country'=>array('foreign_key'=>'id','far_key'=>'country_id'),
|
||||
);
|
||||
}
|
||||
?>
|
Reference in New Issue
Block a user