protected function ensureCacheData($grp=false) { if (!$this->id) throw new RuntimeException("Need an id!"); if (isset($this->cacheData['id']) && $this->cacheData['id']==$this->id) return; if (!$grp) $grp=new LPC_Group($this->id); $this->cacheData=array( 'id'=>$this->id, 'name'=>$grp->getAttr('name'), 'isPermission'=>$grp->getAttr('type')=='permission', 'project'=>$grp->getAttr('project'), ); }
function addToGroup($group,$project=false) { if (is_numeric($group)) $groupID=$group; elseif ($group instanceof LPC_Group) $groupID=$group->id; else throw new RuntimeException("Unknown parameter \$group type! Expecting an integer or a LPC_Group instance."); if ($project===false) $projectID=LPC_Project::getCurrent()->id; elseif (is_numeric($project)) $projectID=$project; elseif ($project instanceof LPC_Project) $projectID=$project->id; else throw new RuntimeException("Unknown parameter \$project type! Expecting boolean false, an integer or a LPC_Project instance; received ".print_r($project,1)); $rs=$this->query(" SELECT COUNT(*) FROM LPC_user_membership WHERE user_member=".$this->id." AND member_to=".$groupID." AND project IN (0,".$projectID.") "); if ($rs->fields[0]) return NULL; $expireProjectID=$projectID; if (!$expireProjectID) { $group=new LPC_Group($groupID); $expireProjectID=$group->getAttr('project'); } self::expireCache($expireProjectID,$this->id); return (bool) $this->query(" INSERT INTO LPC_user_membership (user_member, member_to, project) VALUES (".$this->id.", ".$groupID.", $projectID) "); }