• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

classes/class.ilObjGroup.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00035 //TODO: function getRoleId($groupRole) returns the object-id of grouprole
00036 
00037 require_once "class.ilObject.php";
00038 
00039 class ilObjGroup extends ilObject
00040 {
00041         var $m_grpStatus;
00042 
00043         var $m_roleMemberId;
00044 
00045         var $m_roleAdminId;
00046 
00053         function ilObjGroup($a_id = 0,$a_call_by_reference = true)
00054         {
00055                 global $tree;
00056 
00057                 $this->tree =& $tree;
00058 
00059                 $this->type = "grp";
00060                 $this->ilObject($a_id,$a_call_by_reference);
00061                 $this->setRegisterMode(true);
00062         }
00063 
00069         function join($a_user_id, $a_mem_role="")
00070         {
00071                 global $rbacadmin;
00072 
00073                 if (is_array($a_mem_role))
00074                 {
00075                         foreach ($a_mem_role as $role)
00076                         {
00077                                 $rbacadmin->assignUser($role,$a_user_id, false);
00078                         }
00079                 }
00080                 else
00081                 {
00082                         $rbacadmin->assignUser($a_mem_role,$a_user_id, false);
00083                 }
00084 
00085                 ilObjUser::updateActiveRoles($a_user_id);
00086                 return true;
00087         }
00088 
00093         function getDefaultMemberRole()
00094         {
00095                 $local_group_Roles = $this->getLocalGroupRoles();
00096 
00097                 return $local_group_Roles["il_grp_member_".$this->getRefId()];
00098         }
00099 
00104         function getDefaultAdminRole()
00105         {
00106                 $local_group_Roles = $this->getLocalGroupRoles();
00107 
00108                 return $local_group_Roles["il_grp_admin_".$this->getRefId()];
00109         }
00110 
00117         function addMember($a_user_id, $a_mem_role)
00118         {
00119                 global $rbacadmin;
00120 
00121                 if (isset($a_user_id) && isset($a_mem_role) )
00122                 {
00123                         $this->join($a_user_id,$a_mem_role);
00124                         return true;
00125                 }
00126                 else
00127                 {
00128                         $this->ilias->raiseError(get_class($this)."::addMember(): Missing parameters !",$this->ilias->error_obj->WARNING);
00129                         return false;
00130                 }
00131         }
00132 
00137         function getNewRegistrations()
00138         {
00139                 $appList = array();
00140                 $q = "SELECT * FROM grp_registration WHERE grp_id=".$this->getId();
00141                 $res = $this->ilias->db->query($q);
00142 
00143                 while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00144                 {
00145                         array_push($appList,$row);
00146                 }
00147 
00148                 return ($appList) ? $appList : false;
00149         }
00150 
00155         function deleteApplicationListEntry($a_userId)
00156         {
00157                 $q = "DELETE FROM grp_registration WHERE user_id=".$a_userId." AND grp_id=".$this->getId();
00158                 $res = $this->ilias->db->query($q);
00159         }
00160 
00167         function leaveGroup()
00168         {
00169                 global $rbacadmin, $rbacreview;
00170 
00171                 $member_ids = $this->getGroupMemberIds();
00172 
00173                 if (count($member_ids) <= 1 || !in_array($this->ilias->account->getId(), $member_ids))
00174                 {
00175                         return 2;
00176                 }
00177                 else
00178                 {
00179                         if (!$this->isAdmin($this->ilias->account->getId()))
00180                         {
00181                                 $this->leave($this->ilias->account->getId());
00182                                 $member = new ilObjUser($this->ilias->account->getId());
00183                                 $member->dropDesktopItem($this->getRefId(), "grp");
00184 
00185                                 return 0;
00186                         }
00187                         else if (count($this->getGroupAdminIds()) == 1)
00188                         {
00189                                 return 1;
00190                         }
00191                 }
00192         }
00193 
00198         function leave($a_user_id)
00199         {
00200                 global $rbacadmin;
00201 
00202                 $arr_groupRoles = $this->getMemberRoles($a_user_id);
00203 
00204                 if (is_array($arr_groupRoles))
00205                 {
00206                         foreach ($arr_groupRoles as $groupRole)
00207                         {
00208                                 $rbacadmin->deassignUser($groupRole, $a_user_id);
00209                         }
00210                 }
00211                 else
00212                 {
00213                         $rbacadmin->deassignUser($arr_groupRoles, $a_user_id);
00214                 }
00215 
00216                 ilObjUser::updateActiveRoles($a_user_id);
00217 
00218                 return true;
00219         }
00220 
00225         function removeMember($a_user_id, $a_grp_id="")
00226         {
00227                 if (isset($a_user_id) && isset($a_grp_id) && $this->isMember($a_user_id))
00228                 {
00229                         if (count($this->getGroupMemberIds()) > 1)
00230                         {
00231                                 if ($this->isAdmin($a_user_id) && count($this->getGroupAdminIds()) < 2)
00232                                 {
00233                                         return "grp_err_administrator_required";
00234                                 }
00235                                 else
00236                                 {
00237                                         $this->leave($a_user_id);
00238                                         $member = new ilObjUser($a_user_id);
00239                                         $member->dropDesktopItem($this->getRefId(), "grp");
00240 
00241                                         return "";
00242                                 }
00243                         }
00244                         else
00245                         {
00246                                 return "grp_err_last_member";
00247                         }
00248                 }
00249                 else
00250                 {
00251                         $this->ilias->raiseError(get_class($this)."::removeMember(): Missing parameters !",$this->ilias->error_obj->WARNING);
00252                 }
00253         }
00254 
00261         function getGroupMemberIds()
00262         {
00263                 global $rbacadmin, $rbacreview;
00264 
00265                 $usr_arr= array();
00266 
00267                 $rol  = $this->getLocalGroupRoles();
00268 
00269                 foreach ($rol as $value)
00270                 {
00271                         foreach ($rbacreview->assignedUsers($value) as $member_id)
00272                         {
00273                                 array_push($usr_arr,$member_id);
00274                         }
00275                 }
00276 
00277                 $mem_arr = array_unique($usr_arr);
00278                 
00279                 return $mem_arr ? $mem_arr : array();
00280         }
00281         
00289         function getGroupMemberData($a_mem_ids, $active = 1)
00290         {
00291                 global $rbacadmin, $rbacreview, $ilBench, $ilDB;
00292 
00293                 $usr_arr= array();
00294                 
00295                 $q = "SELECT login,firstname,lastname,title,usr_id,last_login ".
00296                          "FROM usr_data ".
00297                          "WHERE usr_id IN (".implode(',',$a_mem_ids).")";
00298                          
00299                 if (is_numeric($active) && $active > -1)
00300                         $q .= "AND active = '$active'";                  
00301                 
00302                 $r = $ilDB->query($q);
00303                 
00304                 while($row = $r->fetchRow(DB_FETCHMODE_OBJECT))
00305                 {
00306                         $mem_arr[] = array("id" => $row->usr_id,
00307                                                                 "login" => $row->login,
00308                                                                 "firstname" => $row->firstname,
00309                                                                 "lastname" => $row->lastname,
00310                                                                 "last_login" => $row->last_login
00311                                                                 );
00312                 }
00313 
00314                 return $mem_arr ? $mem_arr : array();
00315         }
00316 
00317         function getCountMembers()
00318         {
00319                 return count($this->getGroupMemberIds());
00320         }
00321 
00328         function getGroupAdminIds($a_grpId="")
00329         {
00330                 global $rbacreview;
00331 
00332                 if (!empty($a_grpId))
00333                 {
00334                         $grp_id = $a_grpId;
00335                 }
00336                 else
00337                 {
00338                         $grp_id = $this->getRefId();
00339                 }
00340 
00341                 $usr_arr = array();
00342                 $roles = $this->getDefaultGroupRoles($this->getRefId());
00343 
00344                 foreach ($rbacreview->assignedUsers($this->getDefaultAdminRole()) as $member_id)
00345                 {
00346                         array_push($usr_arr,$member_id);
00347                 }
00348 
00349                 return $usr_arr;
00350         }
00351 
00357         function getDefaultGroupRoles($a_grp_id="")
00358         {
00359                 global $rbacadmin, $rbacreview;
00360 
00361                 if (strlen($a_grp_id) > 0)
00362                 {
00363                         $grp_id = $a_grp_id;
00364                 }
00365                 else
00366                 {
00367                         $grp_id = $this->getRefId();
00368                 }
00369 
00370                 $rolf      = $rbacreview->getRoleFolderOfObject($grp_id);
00371                 $role_arr  = $rbacreview->getRolesOfRoleFolder($rolf["ref_id"]);
00372 
00373                 foreach ($role_arr as $role_id)
00374                 {
00375                         $role_Obj =& $this->ilias->obj_factory->getInstanceByObjId($role_id);
00376 
00377                         $grp_Member ="il_grp_member_".$grp_id;
00378                         $grp_Admin  ="il_grp_admin_".$grp_id;
00379 
00380                         if (strcmp($role_Obj->getTitle(), $grp_Member) == 0 )
00381                         {
00382                                 $arr_grpDefaultRoles["grp_member_role"] = $role_Obj->getId();
00383                         }
00384 
00385                         if (strcmp($role_Obj->getTitle(), $grp_Admin) == 0)
00386                         {
00387                                 $arr_grpDefaultRoles["grp_admin_role"] = $role_Obj->getId();
00388                         }
00389                 }
00390 
00391                 return $arr_grpDefaultRoles;
00392         }
00393 
00400         function getLocalGroupRoles($a_translate = false)
00401         {
00402                 global $rbacadmin,$rbacreview;
00403                 
00404                 if (empty($this->local_roles))
00405                 {
00406                         $this->local_roles = array();
00407                         $rolf      = $rbacreview->getRoleFolderOfObject($this->getRefId());
00408                         $role_arr  = $rbacreview->getRolesOfRoleFolder($rolf["ref_id"]);
00409 
00410                         foreach ($role_arr as $role_id)
00411                         {
00412                                 if ($rbacreview->isAssignable($role_id,$rolf["ref_id"]) == true)
00413                                 {
00414                                         $role_Obj =& $this->ilias->obj_factory->getInstanceByObjId($role_id);
00415                                         
00416                                         if ($a_translate)
00417                                         {
00418                                                 $role_name = ilObjRole::_getTranslation($role_Obj->getTitle());
00419                                         }
00420                                         else
00421                                         {
00422                                                 $role_name = $role_Obj->getTitle();
00423                                         }
00424                                         
00425                                         $this->local_roles[$role_name] = $role_Obj->getId();
00426                                 }
00427                         }
00428                 }
00429                 
00430                 return $this->local_roles;
00431         }
00432 
00438         function getGrpStatusClosedTemplateId()
00439         {
00440                 $q = "SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_grp_status_closed'";
00441                 $res = $this->ilias->db->query($q);
00442                 $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
00443 
00444                 return $row["obj_id"];
00445         }
00446 
00452         function getGrpStatusOpenTemplateId()
00453         {
00454                 $q = "SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_grp_status_open'";
00455                 $res = $this->ilias->db->query($q);
00456                 $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
00457 
00458                 return $row["obj_id"];
00459         }
00460         
00466         function setRegistrationFlag($a_regFlag="")
00467         {
00468                 $q = "SELECT * FROM grp_data WHERE grp_id='".$this->getId()."'";
00469                 $res = $this->ilias->db->query($q);
00470 
00471                 if (!isset($a_regFlag))
00472                 {
00473                         $a_regFlag = 0;
00474                 }
00475 
00476                 if ($res->numRows() == 0)
00477                 {
00478                         $q = "INSERT INTO grp_data (grp_id, register) VALUES(".$this->getId().",".$a_regFlag.")";
00479                         $res = $this->ilias->db->query($q);
00480                 }
00481                 else
00482                 {
00483                         $q = "UPDATE grp_data SET register=".$a_regFlag." WHERE grp_id=".$this->getId()."";
00484                         $res = $this->ilias->db->query($q);
00485                 }
00486         }
00487 
00493         function getRegistrationFlag()
00494         {
00495                 $q = "SELECT * FROM grp_data WHERE grp_id='".$this->getId()."'";
00496                 $res = $this->ilias->db->query($q);
00497                 $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
00498 
00499                 return $row["register"];
00500         }
00501 
00507         function getPassword()
00508         {
00509                 $q = "SELECT * FROM grp_data WHERE grp_id='".$this->getId()."'";
00510                 $res = $this->ilias->db->query($q);
00511                 $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
00512 
00513                 return $row["password"];
00514         }
00515         
00521         function setPassword($a_password="")
00522         {
00523                 $q = "SELECT * FROM grp_data WHERE grp_id='".$this->getId()."'";
00524                 $res = $this->ilias->db->query($q);
00525 
00526                 if ($res->numRows() == 0)
00527                 {
00528                         $q = "INSERT INTO grp_data (grp_id, password) VALUES(".$this->getId().",'".$a_password."')";
00529                         $res = $this->ilias->db->query($q);
00530                 }
00531                 else
00532                 {
00533                         $q = "UPDATE grp_data SET password='".$a_password."' WHERE grp_id=".$this->getId()."";
00534                         $res = $this->ilias->db->query($q);
00535                 }
00536         }
00537 
00543         function setExpirationDateTime($a_date)
00544         {
00545                 $q = "SELECT * FROM grp_data WHERE grp_id='".$this->getId()."'";
00546                 $res = $this->ilias->db->query($q);
00547                 $date = ilFormat::input2date($a_date);
00548 
00549                 if ($res->numRows() == 0)
00550                 {
00551                         $q = "INSERT INTO grp_data (grp_id, expiration) VALUES(".$this->getId().",'".$date."')";
00552                         $res = $this->ilias->db->query($q);
00553                 }
00554                 else
00555                 {
00556                         $q = "UPDATE grp_data SET expiration='".$date."' WHERE grp_id=".$this->getId()."";
00557                         $res = $this->ilias->db->query($q);
00558                 }
00559         }
00560 
00566         function getExpirationDateTime()
00567         {
00568                 $q = "SELECT * FROM grp_data WHERE grp_id='".$this->getId()."'";
00569                 $res = $this->ilias->db->query($q);
00570                 $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
00571                 $datetime = $row["expiration"];
00572                 $date = ilFormat::fdateDB2dateDE($datetime);
00573                 $time = substr($row["expiration"], -8);
00574                 $datetime = array(0=>$date, 1=>$time);
00575 
00576                 return $datetime;
00577         }
00578 
00579         function registrationPossible()
00580         {
00581                 $datetime = $this->getExpirationDateTime();
00582                 $today_date = ilFormat::getDateDE();
00583                 $today_time = date("H:i:s");
00584        
00585                 $ts_exp_date = ilFormat::dateDE2timestamp($datetime[0]);
00586                 $ts_today_date = ilFormat::dateDE2timestamp($today_date);
00587         
00588                 $ts_exp_time = substr($datetime[1], 0, 2).
00589                                                 substr($datetime[1], 3, 2).
00590                                                 substr($datetime[1], 6, 2);
00591                 
00592                 $ts_today_time = substr($today_time, 0, 2).
00593                                                 substr($today_time, 3, 2).
00594                                                 substr($today_time, 6, 2);
00595                                                 
00596                 // no timelimit given -> unlimited
00597                 if ($ts_exp_date == 0)
00598                 {
00599                         return true;
00600                 }
00601                 
00602                 if ($ts_today_date < $ts_exp_date) 
00603                 {
00604                         return true;
00605                 }
00606                 elseif (($ts_today_date == $ts_exp_date) and (strcmp($ts_exp_time,$ts_today_time) >= 0)) 
00607                 {
00608                         return true;
00609                 }
00610                 else 
00611                 {
00612                         return false;
00613                 }
00614         }
00615 
00634         function setGroupStatus($a_grpStatus)
00635         {
00636                 global $rbacadmin, $rbacreview, $rbacsystem;
00637 
00638                 //get Rolefolder of group
00639                 $rolf_data = $rbacreview->getRoleFolderOfObject($this->getRefId());
00640 
00641                 //define all relevant roles that rights are needed to be changed
00642                 $arr_parentRoles = $rbacreview->getParentRoleIds($this->getRefId());
00643                 $arr_relevantParentRoleIds = array_diff(array_keys($arr_parentRoles),$this->getDefaultGroupRoles());
00644 
00645                 //group status open (aka public) or group status closed
00646                 if ($a_grpStatus == 0 || $a_grpStatus == 1)
00647                 {
00648                         if ($a_grpStatus == 0)
00649                         {
00650                                 $template_id = $this->getGrpStatusOpenTemplateId();
00651                         } else {
00652                                 $template_id = $this->getGrpStatusClosedTemplateId();
00653                         }
00654                         //get defined operations from template
00655                         $template_ops = $rbacreview->getOperationsOfRole($template_id, 'grp', ROLE_FOLDER_ID);
00656 
00657                         foreach ($arr_relevantParentRoleIds as $parentRole)
00658                         {
00659                                 $granted_permissions = array();
00660 
00661                                 // Delete the linked role for the parent role
00662                                 // (just in case if it already exists).
00663                                 $rbacadmin->deleteLocalRole($parentRole,$rolf_data["child"]);
00664 
00665                                 // Grant permissions on the group object for 
00666                                 // the parent role. In the foreach loop we
00667                                 // compute the intersection of the role     
00668                                 // template il_grp_status_open/_closed and the 
00669                                 // permission template of the parent role.
00670                                 $current_ops = $rbacreview->getRoleOperationsOnObject($parentRole, $this->getRefId());
00671                                 $rbacadmin->revokePermission($this->getRefId(), $parentRole);
00672                                 foreach ($template_ops as $template_op) 
00673                                 {
00674                                         if (in_array($template_op,$current_ops)) 
00675                                         {
00676                                                 array_push($granted_permissions,$template_op);
00677                                         }
00678                                 }
00679                                 if (!empty($granted_permissions))
00680                                 {
00681                                         $rbacadmin->grantPermission($parentRole, $granted_permissions, $this->getRefId());
00682                                 }
00683 
00684                                 // Create a linked role for the parent role and
00685                                 // initialize it with the intersection of 
00686                                 // il_grp_status_open/_closed and the permission
00687                                 // template of the parent role
00688                                 $rbacadmin->copyRolePermissionIntersection(
00689                                         $template_id, ROLE_FOLDER_ID, 
00690                                         $parentRole, $arr_parentRoles[$parentRole]['parent'], 
00691                                         $rolf_data["child"], $parentRole
00692                                 );      
00693                                 $rbacadmin->assignRoleToFolder($parentRole,$rolf_data["child"],"false");
00694                         }//END foreach
00695                 }
00696         }
00697 
00703         function getGroupStatus()
00704         {
00705                 global $rbacsystem,$rbacreview;
00706 
00707                 $role_folder = $rbacreview->getRoleFolderOfObject($this->getRefId());
00708                 $local_roles = $rbacreview->getRolesOfRoleFolder($role_folder["ref_id"]);
00709 
00710                 //get Rolefolder of group
00711                 $rolf_data = $rbacreview->getRoleFolderOfObject($this->getRefId());
00712                 //get all relevant roles
00713                 $arr_globalRoles = array_diff($local_roles, $this->getDefaultGroupRoles());
00714 
00715                 //if one global role has no permission to join the group is officially closed !
00716                 foreach ($arr_globalRoles as $globalRole)
00717                 {
00718                         $ops_of_role = $rbacreview->getOperationsOfRole($globalRole,"grp", ROLE_FOLDER_ID);
00719 
00720                         if ($rbacsystem->checkPermission($this->getRefId(), $globalRole ,"join"))
00721                         {
00722                                 return 0;
00723                         }
00724                 }
00725 
00726                 return 1;
00727         }
00728 
00735         function getMemberRoles($a_user_id)
00736         {
00737                 global $rbacadmin, $rbacreview,$ilBench;
00738 
00739                 $ilBench->start("Group", "getMemberRoles");
00740 
00741                 $arr_assignedRoles = array();
00742 
00743                 $arr_assignedRoles = array_intersect($rbacreview->assignedRoles($a_user_id),$this->getLocalGroupRoles());
00744 
00745                 $ilBench->stop("Group", "getMemberRoles");
00746 
00747                 return $arr_assignedRoles;
00748         }
00749         
00756         function getMemberRolesTitle($a_user_id)
00757         {
00758                 global $ilDB,$ilBench;
00759                 
00760                 include_once ('class.ilObjRole.php');
00761 
00762                 $ilBench->start("Group", "getMemberRolesTitle");
00763                 
00764                 $str_member_roles ="";
00765 
00766                 $q = "SELECT title ".
00767                          "FROM object_data ".
00768                          "LEFT JOIN rbac_ua ON object_data.obj_id=rbac_ua.rol_id ".
00769                          "WHERE object_data.type = 'role' ".
00770                          "AND rbac_ua.usr_id = ".$ilDB->quote($a_user_id)." ".
00771                          "AND rbac_ua.rol_id IN (".implode(',',$this->getLocalGroupRoles()).")";
00772 
00773                 $r = $ilDB->query($q);
00774 
00775                 while($row = $r->fetchRow(DB_FETCHMODE_ASSOC))
00776                 {
00777                         // display human readable role names for autogenerated roles
00778                         $str_member_roles .= ilObjRole::_getTranslation($row["title"]).", ";
00779                 }
00780 
00781                 $ilBench->stop("Group", "getMemberRolesTitle");
00782                                 
00783                 return substr($str_member_roles,0,-2);
00784         }
00785         
00792         function setMemberStatus($a_user_id, $a_member_role)
00793         {
00794                 if (isset($a_user_id) && isset($a_member_role))
00795                 {
00796                         $this->removeMember($a_user_id);
00797                         $this->addMember($a_user_id, $a_member_role);
00798                 }
00799         }
00800 
00807         function isMember($a_userId = "")
00808         {
00809                 if (strlen($a_userId) == 0)
00810                 {
00811                         $user_id = $this->ilias->account->getId();
00812                 }
00813                 else 
00814                 {
00815                         $user_id = $a_userId;
00816                 }
00817                 
00818                 if ($this->getType() == "grp")
00819                 {
00820                         $arr_members = $this->getGroupMemberIds();
00821 
00822                         if (in_array($user_id, $arr_members))
00823                         {
00824                                 return true;
00825                         }
00826                         else
00827                         {
00828                                 return false;
00829                         }
00830                 }
00831         }
00832 
00839         function isAdmin($a_userId)
00840         {
00841                 global $rbacreview;
00842 
00843                 $grp_Roles = $this->getDefaultGroupRoles();
00844 
00845                 if (in_array($a_userId,$rbacreview->assignedUsers($grp_Roles["grp_admin_role"])))
00846                 {
00847                         return true;
00848                 }
00849                 else
00850                 {
00851                         return false;
00852                 }
00853         }
00854 
00863         function ilClone($a_parent_ref)
00864         {
00865                 global $rbacadmin;
00866 
00867                 // always call parent ilClone function first!!
00868                 $new_ref_id = parent::ilClone($a_parent_ref);
00869                 
00870                 // get object instance of cloned group
00871                 $groupObj =& $this->ilias->obj_factory->getInstanceByRefId($new_ref_id);
00872                 
00873                 // find a free number
00874                 for ($n = 1;$n < 99;$n++)
00875                 {
00876                         $groupname_copy = $groupObj->getTitle()."_(copy_".$n.")";
00877 
00878                         if (!ilUtil::groupNameExists($groupname_copy))
00879                         {
00880                                 $groupObj->setTitle($groupname_copy);
00881                                 $groupObj->update();
00882                                 break;
00883                         }
00884                 }
00885 
00886                 // setup rolefolder & default local roles (admin & member)
00887                 $roles = $groupObj->initDefaultRoles();
00888 
00889                 // ...finally assign groupadmin role to creator of group object
00890                 $rbacadmin->assignUser($roles[0], $groupObj->getOwner(), "n");
00891                 ilObjUser::updateActiveRoles($groupObj->getOwner());
00892 
00893                 // TODO: function getGroupStatus returns integer but setGroupStatus expects a string.
00894                 // I disabled this function. Please investigate
00895                 // shofmann@databay.de  4.7.03
00896                 // copy group status
00897                 // 0=public/visible for all,1=closed/invisible for all
00898                 $groupObj->setGroupStatus($this->getGroupStatus());
00899 
00900                 // always destroy objects in ilClone method because clone() is recursive and creates instances for each object in subtree!
00901                 unset($groupObj);
00902                 unset($rfoldObj);
00903                 unset($roleObj);
00904 
00905                 // ... and finally always return new reference ID!!
00906                 return $new_ref_id;
00907         }
00908 
00917         function delete()
00918         {
00919                 // always call parent delete function first!!
00920                 if (!parent::delete())
00921                 {
00922                         return false;
00923                 }
00924                 
00925                 $query = "DELETE FROM grp_data WHERE grp_id=".$this->getId();
00926                 $this->ilias->db->query($query);
00927 
00928                 return true;
00929         }
00930 
00936         function initDefaultRoles()
00937         {
00938                 global $rbacadmin, $rbacreview;
00939 
00940                 // create a local role folder
00941                 $rfoldObj =& $this->createRoleFolder();
00942 
00943                 // ADMIN ROLE
00944                 // create role and assign role to rolefolder...
00945                 $roleObj = $rfoldObj->createRole("il_grp_admin_".$this->getRefId(),"Groupadmin of group obj_no.".$this->getId());
00946                 $this->m_roleAdminId = $roleObj->getId();
00947 
00948                 //set permission template of new local role
00949                 $q = "SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_grp_admin'";
00950                 $r = $this->ilias->db->getRow($q, DB_FETCHMODE_OBJECT);
00951                 $rbacadmin->copyRolePermission($r->obj_id,ROLE_FOLDER_ID,$rfoldObj->getRefId(),$roleObj->getId());
00952 
00953                 // set object permissions of group object
00954                 $ops = $rbacreview->getOperationsOfRole($roleObj->getId(),"grp",$rfoldObj->getRefId());
00955                 $rbacadmin->grantPermission($roleObj->getId(),$ops,$this->getRefId());
00956 
00957                 // set object permissions of role folder object
00958                 $ops = $rbacreview->getOperationsOfRole($roleObj->getId(),"rolf",$rfoldObj->getRefId());
00959                 $rbacadmin->grantPermission($roleObj->getId(),$ops,$rfoldObj->getRefId());
00960 
00961                 // MEMBER ROLE
00962                 // create role and assign role to rolefolder...
00963                 $roleObj = $rfoldObj->createRole("il_grp_member_".$this->getRefId(),"Groupmember of group obj_no.".$this->getId());
00964                 $this->m_roleMemberId = $roleObj->getId();
00965 
00966                 //set permission template of new local role
00967                 $q = "SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_grp_member'";
00968                 $r = $this->ilias->db->getRow($q, DB_FETCHMODE_OBJECT);
00969                 $rbacadmin->copyRolePermission($r->obj_id,ROLE_FOLDER_ID,$rfoldObj->getRefId(),$roleObj->getId());
00970                 
00971                 // set object permissions of group object
00972                 $ops = $rbacreview->getOperationsOfRole($roleObj->getId(),"grp",$rfoldObj->getRefId());
00973                 $rbacadmin->grantPermission($roleObj->getId(),$ops,$this->getRefId());
00974 
00975                 // set object permissions of role folder object
00976                 $ops = $rbacreview->getOperationsOfRole($roleObj->getId(),"rolf",$rfoldObj->getRefId());
00977                 $rbacadmin->grantPermission($roleObj->getId(),$ops,$rfoldObj->getRefId());
00978 
00979                 unset($rfoldObj);
00980                 unset($roleObj);
00981 
00982                 $roles[] = $this->m_roleAdminId;
00983                 $roles[] = $this->m_roleMemberId;
00984                 return $roles ? $roles : array();
00985         }
00986 
00997         function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
00998         {
00999                 global $tree;
01000                 
01001                 $parent_id = (int) $tree->getParentId($a_node_id);
01002                 
01003                 if ($parent_id != 0)
01004                 {
01005                         $obj_data =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
01006                         $obj_data->notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$parent_id,$a_params);
01007                 }
01008                                 
01009                 return true;
01010         }
01011 
01020         function _search(&$a_search_obj)
01021         {
01022                 global $ilBench;
01023 
01024                 // NO CLASS VARIABLES IN STATIC METHODS
01025 
01026                 $where_condition = $a_search_obj->getWhereCondition("like",array("title","description"));
01027                 $in = $a_search_obj->getInStatement("ore.ref_id");
01028 
01029                 $query = "SELECT ore.ref_id AS ref_id FROM object_data AS od, object_reference AS ore ".
01030                         $where_condition." ".
01031                         $in." ".
01032                         "AND od.obj_id = ore.obj_id ".
01033                         "AND od.type = 'grp' ";
01034 
01035                 $ilBench->start("Search", "ilObjGroup_search");
01036                 $res = $a_search_obj->ilias->db->query($query);
01037                 $ilBench->stop("Search", "ilObjGroup_search");
01038 
01039                 $counter = 0;
01040 
01041                 while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
01042                 {
01043                         $result_data[$counter++]["id"]                          =  $row->ref_id;
01044                         #$result_data[$counter]["link"]                         =  "group.php?cmd=view&ref_id=".$row->ref_id;
01045                         #$result_data[$counter++]["target"]                     =  "";
01046                 }
01047 
01048                 return $result_data ? $result_data : array();
01049         }
01050 
01059         function _getLinkToObject($a_id)
01060         {
01061                 return array("repository.php?ref_id=".$a_id."&set_mode=flat&cmdClass=ilobjgroupgui","");
01062         }
01063         
01064         function isUserRegistered($a_user_id = 0)
01065         {
01066                 global $rbacsystem;
01067                 
01068                 // exclude system role from check
01069                 /*if (in_array(SYSTEM_ROLE_ID,$_SESSION["RoleId"]))
01070                 {
01071                         return true;            
01072                 }*/
01073 
01074                 if (!$this->isMember() or !$rbacsystem->checkAccess("join", $this->ref_id))
01075                 {
01076                         return false;
01077                 }
01078                 
01079                 return true;
01080         }
01081         
01082         function _isMember($a_user_id,$a_ref_id)
01083         {
01084                 global $rbacreview;
01085                 
01086                 $rolf = $rbacreview->getRoleFolderOfObject($a_ref_id);
01087                 $local_roles = $rbacreview->getRolesOfRoleFolder($rolf["ref_id"],false);
01088                 $user_roles = $rbacreview->assignedRoles($a_user_id);
01089                 
01090                 if (!array_intersect($local_roles,$user_roles))
01091                 {
01092                         return false;
01093                 }
01094                 
01095                 return true;
01096         }
01097 } //END class.ilObjGroup
01098 ?>

Generated on Fri Dec 13 2013 10:18:28 for ILIAS Release_3_5_x_branch .rev 46805 by  doxygen 1.7.1