2010-11-29 22:41:08 +00:00
|
|
|
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
|
|
|
|
|
|
/**
|
2013-03-19 22:35:19 +00:00
|
|
|
*
|
|
|
|
* @package OSB
|
2010-11-29 22:41:08 +00:00
|
|
|
* @category Models
|
|
|
|
* @author Deon George
|
2013-03-19 22:35:19 +00:00
|
|
|
* @copyright (c) 2009-2013 Open Source Billing
|
|
|
|
* @license http://dev.osbill.net/license.html
|
2010-11-29 22:41:08 +00:00
|
|
|
*/
|
|
|
|
class Model_Group extends Model_Auth_RoleDefault {
|
|
|
|
// Relationships
|
|
|
|
protected $_has_many = array(
|
|
|
|
'account'=>array('through'=>'account_group'),
|
2011-09-24 13:13:38 +00:00
|
|
|
'module_method'=>array('through'=>'group_method','far_key'=>'method_id'),
|
2010-11-29 22:41:08 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
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),
|
|
|
|
),
|
|
|
|
);
|
2011-08-16 02:27:19 +00:00
|
|
|
|
|
|
|
protected $_display_filters = array(
|
|
|
|
'status'=>array(
|
|
|
|
array('StaticList_YesNo::display',array(':value')),
|
|
|
|
),
|
|
|
|
);
|
2011-09-17 10:45:08 +00:00
|
|
|
|
2011-09-24 13:13:38 +00:00
|
|
|
/**
|
|
|
|
* This function will, given a group, list all of the children that
|
|
|
|
* are also related to this group, in the group heirarchy.
|
|
|
|
*/
|
2011-09-17 10:45:08 +00:00
|
|
|
public function list_childgrps($incParent=FALSE) {
|
2013-04-05 12:50:08 +00:00
|
|
|
$result = array();
|
2011-09-17 10:45:08 +00:00
|
|
|
|
|
|
|
if (! $this->loaded())
|
2013-04-05 12:50:08 +00:00
|
|
|
return $result;
|
2011-09-17 10:45:08 +00:00
|
|
|
|
2012-11-09 23:13:57 +00:00
|
|
|
foreach (ORM::factory('Group')->where_active()->and_where('parent_id','=',$this)->find_all() as $go) {
|
2013-04-05 12:50:08 +00:00
|
|
|
array_push($result,$go);
|
2011-09-17 10:45:08 +00:00
|
|
|
|
2013-04-05 12:50:08 +00:00
|
|
|
$result = array_merge($result,$go->list_childgrps());
|
2011-09-17 10:45:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($incParent)
|
2013-04-05 12:50:08 +00:00
|
|
|
array_push($result,$this);
|
2011-09-17 10:45:08 +00:00
|
|
|
|
2013-04-05 12:50:08 +00:00
|
|
|
return $result;
|
2011-09-17 10:45:08 +00:00
|
|
|
}
|
2011-09-24 13:13:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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) {
|
2013-04-05 12:50:08 +00:00
|
|
|
$result = array();
|
2011-09-24 13:13:38 +00:00
|
|
|
|
|
|
|
if (! $this->loaded())
|
2013-04-05 12:50:08 +00:00
|
|
|
return $result;
|
2011-09-24 13:13:38 +00:00
|
|
|
|
2012-11-09 23:13:57 +00:00
|
|
|
foreach (ORM::factory('Group')->where_active()->and_where('id','=',$this->parent_id)->find_all() as $go) {
|
2013-04-05 12:50:08 +00:00
|
|
|
array_push($result,$go);
|
2011-09-24 13:13:38 +00:00
|
|
|
|
2013-04-05 12:50:08 +00:00
|
|
|
$result = array_merge($result,$go->list_parentgrps());
|
2011-09-24 13:13:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($incParent)
|
2013-04-05 12:50:08 +00:00
|
|
|
array_push($result,$this);
|
2011-09-24 13:13:38 +00:00
|
|
|
|
2013-04-05 12:50:08 +00:00
|
|
|
return $result;
|
2011-09-24 13:13:38 +00:00
|
|
|
}
|
2010-11-29 22:41:08 +00:00
|
|
|
}
|
|
|
|
?>
|