projects
/
Pman.Core
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
DataObjects/Core_group.php
[Pman.Core]
/
DataObjects
/
Core_group.php
diff --git
a/DataObjects/Core_group.php
b/DataObjects/Core_group.php
index
037308f
..
a9434e1
100644
(file)
--- a/
DataObjects/Core_group.php
+++ b/
DataObjects/Core_group.php
@@
-10,11
+10,11
@@
*
*
* NOTE - used to be called Groups ....
*
*
* NOTE - used to be called Groups ....
- *
+ *
*/
*/
-require_once 'DB/DataObject.php';
+
class_exists('DB_DataObject') ? '' :
require_once 'DB/DataObject.php';
-class Pman_Core_DataObjects_Core_group extends DB_DataObject
+class Pman_Core_DataObjects_Core_group extends DB_DataObject
{
###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */
{
###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */
@@
-22,21
+22,21
@@
class Pman_Core_DataObjects_Core_group extends DB_DataObject
public $__table = 'core_group'; // table name
public $id; // int(11) not_null primary_key auto_increment
public $name; // string(64) not_null
public $__table = 'core_group'; // table name
public $id; // int(11) not_null primary_key auto_increment
public $name; // string(64) not_null
- public $type; // int(11)
+ public $type; // int(11)
public $leader; // int(11) not_null
public $is_system; // used by timesheets?
public $leader; // int(11) not_null
public $is_system; // used by timesheets?
-
+
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
-
-
+
+
function personTable()
{
$ff = HTML_FlexyFramework::get();
return empty($ff->Pman['authTable']) ? 'core_person' : $ff->Pman['authTable'];
}
function personTable()
{
$ff = HTML_FlexyFramework::get();
return empty($ff->Pman['authTable']) ? 'core_person' : $ff->Pman['authTable'];
}
-
-
+
+
// group types??
function applyFilters($q, $au, $roo)
{
// group types??
function applyFilters($q, $au, $roo)
{
@@
-44,12
+44,22
@@
class Pman_Core_DataObjects_Core_group extends DB_DataObject
$v = $this->escape($q['query']['name_starts']);
$this->whereAdd("{$this->tableName()}.name like '{$v}%'");
}
$v = $this->escape($q['query']['name_starts']);
$this->whereAdd("{$this->tableName()}.name like '{$v}%'");
}
+
+ if(!empty($q['_count_member_by_name'])){
+
+ $core_group = DB_DataObject::factory('core_group');
+
+ if($core_group->get('name', $q['_count_member_by_name'])){
+ $roo->jdata($core_group->memberCount());
+ }
+ }
+
}
}
-
+
function toEventString() {
return $this->name;
}
function toEventString() {
return $this->name;
}
-
+
function beforeInsert($q,$roo)
{
if (isset($q['_action'])) {
function beforeInsert($q,$roo)
{
if (isset($q['_action'])) {
@@
-62,7
+72,7
@@
class Pman_Core_DataObjects_Core_group extends DB_DataObject
foreach(explode(',', $q['user_ids']) as $uid) {
switch($q['_action']) {
case 'add':
foreach(explode(',', $q['user_ids']) as $uid) {
switch($q['_action']) {
case 'add':
- $g->addMember($uid);
+ $g->addMember($uid
,$roo
);
break;
case 'sub':
$g->removeMember($uid);
break;
case 'sub':
$g->removeMember($uid);
@@
-72,16
+82,12
@@
class Pman_Core_DataObjects_Core_group extends DB_DataObject
}
}
$roo->jok('updated');
}
}
$roo->jok('updated');
-
-
-
-
+
}
}
-
-
+
}
}
-
-
+
+
function beforeDelete()
{
$x = DB_DataObject::factory('core_group_right');
function beforeDelete()
{
$x = DB_DataObject::factory('core_group_right');
@@
-92,10
+98,10
@@
class Pman_Core_DataObjects_Core_group extends DB_DataObject
/**
* check who is trying to access this. false == access denied..
*/
/**
* check who is trying to access this. false == access denied..
*/
- function checkPerm($lvl, $au)
+ function checkPerm($lvl, $au)
{
{
- return $au->hasPerm("Core.Groups", $lvl);
- }
+ return $au->hasPerm("Core.Groups", $lvl);
+ }
function onUpdate($old, $req, $roo)
{
$this->ensureLeaderMembership($roo);
function onUpdate($old, $req, $roo)
{
$this->ensureLeaderMembership($roo);
@@
-106,42
+112,42
@@
class Pman_Core_DataObjects_Core_group extends DB_DataObject
}
function ensureLeaderMembership($roo)
{
}
function ensureLeaderMembership($roo)
{
-
+
// groups - make sure the leader is a member...
if (!$this->type || !$this->leader)
{
return true;
}
// groups - make sure the leader is a member...
if (!$this->type || !$this->leader)
{
return true;
}
-
+
$pi = DB_DataObject::factory('core_person');
$pi->get($this->leader);
$pi = DB_DataObject::factory('core_person');
$pi->get($this->leader);
-
+
$p = DB_DataObject::factory('core_group_member');
$p->group_id = $this->id;
$p->user_id = $this->leader;
//$p->type = 1; //???????
if (!$p->count()) {
$p = DB_DataObject::factory('core_group_member');
$p->group_id = $this->id;
$p->user_id = $this->leader;
//$p->type = 1; //???????
if (!$p->count()) {
-
+
$p->insert();
$roo->addEvent("ADD", $p, $this->toEventString(). " Added " . $pi->toEventString());
}
$p->insert();
$roo->addEvent("ADD", $p, $this->toEventString(). " Added " . $pi->toEventString());
}
-
+
}
}
-
-
+
+
function memberCount()
{
$gm = DB_Dataobject::factory('core_group_member');
$gm->group_id = $this->id;
return $gm->count();
}
function memberCount()
{
$gm = DB_Dataobject::factory('core_group_member');
$gm->group_id = $this->id;
return $gm->count();
}
-
+
function memberIds()
{
$gm = DB_Dataobject::factory('core_group_member');
$gm->group_id = $this->id;
return $gm->fetchAll('user_id');
function memberIds()
{
$gm = DB_Dataobject::factory('core_group_member');
$gm->group_id = $this->id;
return $gm->fetchAll('user_id');
-
+
}
function isMember($person)
{
}
function isMember($person)
{
@@
-150,9
+156,12
@@
class Pman_Core_DataObjects_Core_group extends DB_DataObject
$gm->user_id = is_object($person) ? $person->id : $person;
return $gm->count();
}
$gm->user_id = is_object($person) ? $person->id : $person;
return $gm->count();
}
-
- function addMember($person)
+
+ function addMember($person
,$roo = false
)
{
{
+ if ($this->name == "Empty Group") {
+ $roo->jerr('Cannot add the person into Empty Group');
+ }
$gm = DB_Dataobject::factory('core_group_member');
$gm->group_id = $this->id;
$gm->user_id = is_object($person) ? $person->id : $person;
$gm = DB_Dataobject::factory('core_group_member');
$gm->group_id = $this->id;
$gm->user_id = is_object($person) ? $person->id : $person;
@@
-160,17
+169,18
@@
class Pman_Core_DataObjects_Core_group extends DB_DataObject
$gm->insert();
}
}
$gm->insert();
}
}
-
+
function removeMember($person)
{
$gm = DB_Dataobject::factory('core_group_member');
$gm->group_id = $this->id;
$gm->user_id = is_object($person) ? $person->id : $person;
function removeMember($person)
{
$gm = DB_Dataobject::factory('core_group_member');
$gm->group_id = $this->id;
$gm->user_id = is_object($person) ? $person->id : $person;
- if ($gm->count()) {
+
+ if ($gm->find(true)) {
$gm->delete();
}
}
$gm->delete();
}
}
-
+
/**
*
* grab a list of members - default is the array of person objects..
/**
*
* grab a list of members - default is the array of person objects..
@@
-178,7
+188,7
@@
class Pman_Core_DataObjects_Core_group extends DB_DataObject
*
*
*/
*
*
*/
-
+
function members($what = false)
{
$ids = $this->memberIds();
function members($what = false)
{
$ids = $this->memberIds();
@@
-188,17
+198,17
@@
class Pman_Core_DataObjects_Core_group extends DB_DataObject
//$p = DB_Dataobject::factory(empty($ff->Pman['authTable']) ? 'Person' : $ff->Pman['authTable']);
// groups databse is hard coded to person.. so this should not be used for other tables.????
$p = DB_Dataobject::factory( 'core_person' );
//$p = DB_Dataobject::factory(empty($ff->Pman['authTable']) ? 'Person' : $ff->Pman['authTable']);
// groups databse is hard coded to person.. so this should not be used for other tables.????
$p = DB_Dataobject::factory( 'core_person' );
-
-
-
+
$p->whereAdd('id IN ('. implode(',', $ids) .')');
$p->active = 1;
$p->whereAdd('id IN ('. implode(',', $ids) .')');
$p->active = 1;
+
+ $p->orderBy('name');
return $p->fetchAll($what);
}
return $p->fetchAll($what);
}
-
-
-
-
+
+
+
+
function lookup($k,$v = false) {
if ($v === false) {
$v = $k;
function lookup($k,$v = false) {
if ($v === false) {
$v = $k;
@@
-207,74
+217,86
@@
class Pman_Core_DataObjects_Core_group extends DB_DataObject
$this->get($k,$v);
return $this;
$this->get($k,$v);
return $this;
- }
-
+ }
+
function lookUpMembers($name, $what=false)
{
if (!$this->get('name', $name)) {
return array();
}
return $this->members($what);
function lookUpMembers($name, $what=false)
{
if (!$this->get('name', $name)) {
return array();
}
return $this->members($what);
-
+
}
}
-
+
function lookupMembersByGroupId($id, $what=false)
{
if (!$this->get($id)) {
return array();
}
function lookupMembersByGroupId($id, $what=false)
{
if (!$this->get($id)) {
return array();
}
-
+
return $this->members($what);
}
return $this->members($what);
}
-
+
function postListFilter($ar, $au, $req)
function postListFilter($ar, $au, $req)
- {
+ {
if(empty($req['_add_everyone'])){
return $ar;
}
if(empty($req['_add_everyone'])){
return $ar;
}
-
+
$ret[] = array( 'id' => 0, 'name' => 'EVERYONE');
$ret[] = array( 'id' => -1, 'name' => 'NOT_IN_GROUP');
return array_merge($ret, $ar);
}
$ret[] = array( 'id' => 0, 'name' => 'EVERYONE');
$ret[] = array( 'id' => -1, 'name' => 'NOT_IN_GROUP');
return array_merge($ret, $ar);
}
-
+
function initGroups()
{
function initGroups()
{
-
+
$g = DB_DataObject::factory($this->tableName());
$g->type = 0;
$g->name = 'Administrators';
if ($g->count()) {
$g = DB_DataObject::factory($this->tableName());
$g->type = 0;
$g->name = 'Administrators';
if ($g->count()) {
- return;
+ $g->find(true);;
+ } else {
+ $g->insert();
+ $gr = DB_DataObject::factory('core_group_right');
+ $gr->genDefault();
+ }
+ $m = $g->members();
+ if (empty($m)) {
+ $p = DB_DAtaObject::factory('core_person');
+ $p->orderBy('id ASC');
+ $p->limit(1);
+ if ($p->find(true)) {
+ $g->addMember($p);
+ }
+
+
}
}
- $g->insert();
- $gr = DB_DataObject::factory('core_group_right');
- $gr->genDefault();
}
}
-
+
function initDatabase($roo, $data)
{
$this->initGroups();
function initDatabase($roo, $data)
{
$this->initGroups();
-
+
foreach($data as $gi) {
$g = DB_DataObject::factory($this->tableName());
$g->setFrom($gi);
foreach($data as $gi) {
$g = DB_DataObject::factory($this->tableName());
$g->setFrom($gi);
-
+
if(!$g->find(true)){
$g->insert();
}
if(!$g->find(true)){
$g->insert();
}
-
+
if(count($g->members()) || empty($gi['members'])){
continue;
}
if(count($g->members()) || empty($gi['members'])){
continue;
}
-
+
foreach ($gi['members'] as $m){
$g->addMember($m);
}
foreach ($gi['members'] as $m){
$g->addMember($m);
}
-
+
}
}
-
+
}
}
-
+
}
}