This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
khosb/application/classes/Model/Group.php

85 lines
1.9 KiB
PHP
Raw Normal View History

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) {
$return = array();
if (! $this->loaded())
return $return;
2012-11-09 23:13:57 +00:00
foreach (ORM::factory('Group')->where_active()->and_where('parent_id','=',$this)->find_all() as $go) {
2011-09-17 10:45:08 +00:00
array_push($return,$go);
$return = array_merge($return,$go->list_childgrps());
}
if ($incParent)
array_push($return,$this);
return $return;
}
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) {
$return = array();
if (! $this->loaded())
return $return;
2012-11-09 23:13:57 +00:00
foreach (ORM::factory('Group')->where_active()->and_where('id','=',$this->parent_id)->find_all() as $go) {
2011-09-24 13:13:38 +00:00
array_push($return,$go);
$return = array_merge($return,$go->list_parentgrps());
}
if ($incParent)
array_push($return,$this);
return $return;
}
2010-11-29 22:41:08 +00:00
}
?>