Skip to content

Instantly share code, notes, and snippets.

@adahhane
Created July 5, 2011 14:21
Show Gist options
  • Save adahhane/1064922 to your computer and use it in GitHub Desktop.
Save adahhane/1064922 to your computer and use it in GitHub Desktop.
Other
<?php
public function others(){
//OLD METHOD
$group=new Groups();
$allGroups=$group->fetchAll();
$groups=array();
$idGroups=array();
$idMyGroups=array();
$detailGroups=new GroupDetails();
$dGroups=$detailGroups->fetchall();
$detailGroups->setMember($this->get("Security")->getUser()->getId());
$memberGroup=$detailGroups->fetch();
foreach($memberGroup as $gm){
foreach($dGroups as $gr){
$idGroups[]=$gr->getGroups();
if($gm->getGroups()==$gr->getGroups() and $gr->getMember()==$this->get("Security")->getUser()->getId()){
$idMyGroups[]= $gr->getGroups();
}
}
}
$idGroups=array_unique($idGroups);
$idGroup=array_diff($idGroups,$idMyGroups);
foreach($idGroup as $item){
foreach($allGroups as $group){
if($item==$group->getId()){
$groups[]=$group;
}
}
}
//New Method
$query=new QueryBuilder();
$result=$query->query('SELECT * FROM groups where id not in (SELECT groups from groupdetails where member='.$this->get("Security")->getUser()->getId().')');
foreach($result as $item){
echo $item['id'];
}
$this->view('groups','others',compact('groups'));
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment