Example #1
0
 /**
  * Get a "many-to-many" map that holds for all members their group
  * memberships
  *
  * @return Member_GroupSet Returns a map holding for all members their
  *                         group memberships.
  */
 public function Groups()
 {
     $groups = $this->getManyManyComponents("Groups");
     $groupIDs = $groups->column();
     $collatedGroups = array();
     if ($groups) {
         foreach ($groups as $group) {
             $collatedGroups = array_merge((array) $collatedGroups, $group->collateAncestorIDs());
         }
     }
     $table = "Group_Members";
     if (count($collatedGroups) > 0) {
         $collatedGroups = implode(", ", array_unique($collatedGroups));
         $unfilteredGroups = singleton('Group')->instance_get("\"Group\".\"ID\" IN ({$collatedGroups})", "\"Group\".\"ID\"", "", "", "Member_GroupSet");
         $result = new ComponentSet();
         // Only include groups where allowedIPAddress() returns true
         $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null;
         foreach ($unfilteredGroups as $group) {
             if ($group->allowedIPAddress($ip)) {
                 $result->push($group);
             }
         }
     } else {
         $result = new Member_GroupSet();
     }
     $result->setComponentInfo("many-to-many", $this, "Member", $table, "Group");
     return $result;
 }
Example #2
0
 /**
  * Get a "many-to-many" map that holds for all members their group
  * memberships
  *
  * @return Member_GroupSet Returns a map holding for all members their
  *                         group memberships.
  */
 public function Groups()
 {
     $groups = $this->getManyManyComponents("Groups");
     $unsecure = DataObject::get("Group_Unsecure", "");
     if ($unsecure) {
         foreach ($unsecure as $unsecureItem) {
             $groups->push($unsecureItem);
         }
     }
     $groupIDs = $groups->column();
     $collatedGroups = array();
     foreach ($groups as $group) {
         $collatedGroups = array_merge((array) $collatedGroups, $group->collateAncestorIDs());
     }
     $table = "Group_Members";
     if (count($collatedGroups) > 0) {
         $collatedGroups = implode(", ", array_unique($collatedGroups));
         $result = singleton('Group')->instance_get("`ID` IN ({$collatedGroups})", "ID", "", "", "Member_GroupSet");
     } else {
         $result = new Member_GroupSet();
     }
     $result->setComponentInfo("many-to-many", $this, "Member", $table, "Group");
     return $result;
 }