• Main Page
  • Related Pages
  • Modules
  • 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-2006 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.ilContainer.php";
00038 
00039 define('GRP_REGISTRATION_DIRECT',0);
00040 define('GRP_REGISTRATION_REQUEST',1);
00041 define('GRP_REGISTRATION_PASSWORD',2);
00042 
00043 
00044 class ilObjGroup extends ilContainer
00045 {
00049         var $file_obj = null;
00050 
00051         var $m_grpStatus;
00052 
00053         var $m_roleMemberId;
00054 
00055         var $m_roleAdminId;
00056 
00063         function ilObjGroup($a_id = 0,$a_call_by_reference = true)
00064         {
00065                 global $tree;
00066 
00067                 $this->tree =& $tree;
00068 
00069                 $this->type = "grp";
00070                 $this->ilObject($a_id,$a_call_by_reference);
00071                 $this->setRegisterMode(true);
00072         }
00073 
00077         function create()
00078         {
00079                 global $ilDB;
00080 
00081                 parent::create();
00082 
00083                 $query = "INSERT INTO grp_data (".
00084                         " grp_id".
00085                         ", latitude".
00086                         ", longitude".
00087                         ", location_zoom".
00088                         ", enable_group_map".
00089                         " ) VALUES (".
00090                         $ilDB->quote($this->getId())
00091                         .",".$ilDB->quote($this->getLatitude())
00092                         .",".$ilDB->quote($this->getLongitude())
00093                         .",".$ilDB->quote($this->getLocationZoom())
00094                         .",".$ilDB->quote($this->getEnableGroupMap())
00095                         .")";
00096                 $ilDB->query($query);
00097         }
00098 
00102         function update()
00103         {
00104                 global $ilDB;
00105 
00106                 if (!parent::update())
00107                 {
00108                         return false;
00109                 }
00110 
00111                 // update group data
00112                 $query = "UPDATE grp_data SET ".
00113                         " latitude = ".$ilDB->quote($this->getLatitude()).
00114                         ", longitude = ".$ilDB->quote($this->getLongitude()).
00115                         ", location_zoom = ".$ilDB->quote($this->getLocationZoom()).
00116                         ", enable_group_map = ".$ilDB->quote($this->getEnableGroupMap()).
00117                         " WHERE grp_id = ".$ilDB->quote($this->getId());
00118 
00119                 $ilDB->query($query);
00120 
00121                 return true;
00122 
00123         }
00124 
00128         function read()
00129         {
00130                 global $ilDB;
00131 
00132                 parent::read();
00133 
00134                 $query = "SELECT * FROM grp_data WHERE grp_id = ".
00135                         $ilDB->quote($this->getId());
00136                 $set = $ilDB->query($query);
00137                 $rec = $set->fetchRow(DB_FETCHMODE_ASSOC);
00138 
00139                 $this->setLatitude($rec["latitude"]);
00140                 $this->setLongitude($rec["longitude"]);
00141                 $this->setLocationZoom($rec["location_zoom"]);
00142                 $this->setEnableGroupMap($rec["enable_group_map"]);
00143         }
00144 
00153         public function cloneObject($a_target_id,$a_copy_id = 0)
00154         {
00155                 global $ilDB,$ilUser;
00156 
00157                 $new_obj = parent::cloneObject($a_target_id,$a_copy_id);
00158                 $new_obj->setGroupStatus($this->readGroupStatus());
00159                 $new_obj->initGroupStatus($this->readGroupStatus());
00160 
00161                 $this->cloneAutoGeneratedRoles($new_obj);
00162 
00163                 $new_obj->setLatitude($this->getLatitude());
00164                 $new_obj->setLongitude($this->getLongitude());
00165                 $new_obj->setLocationZoom($this->getLocationZoom());
00166                 $new_obj->setEnableGroupMap($this->getEnableGroupMap());
00167                 $new_obj->update();
00168 
00169 
00170                 // Copy settings
00171                 $new_obj->setRegistrationFlag($this->getRegistrationFlag());
00172                 $new_obj->setPassword($this->getPassword());
00173                 $new_obj->updateExpiration($this->getExpiration());
00174 
00175                 // Assign user as admin
00176                 $new_obj->addMember($ilUser->getId(),$new_obj->getDefaultAdminRole());
00177 
00178                 // Copy learning progress settings
00179                 include_once('Services/Tracking/classes/class.ilLPObjSettings.php');
00180                 $obj_settings = new ilLPObjSettings($this->getId());
00181                 $obj_settings->cloneSettings($new_obj->getId());
00182                 unset($obj_settings);
00183 
00184                 return $new_obj;
00185         }
00186 
00195         public function cloneDependencies($a_target_id,$a_copy_id)
00196         {
00197                 global $tree;
00198 
00199                 if($course_ref_id = $tree->checkForParentType($this->getRefId(),'crs') and
00200                         $new_course_ref_id = $tree->checkForParentType($a_target_id,'crs'))
00201                 {
00202                         include_once('Modules/Course/classes/class.ilCourseItems.php');
00203                         $course_obj =& ilObjectFactory::getInstanceByRefId($course_ref_id,false);
00204                         $course_items = new ilCourseItems($course_obj,$this->getRefId());
00205                         $course_items->cloneDependencies($a_target_id,$a_copy_id);
00206                 }
00207 
00208                 include_once('Services/Tracking/classes/class.ilLPCollections.php');
00209                 $lp_collection = new ilLPCollections($this->getId());
00210                 $lp_collection->cloneCollections($a_target_id,$a_copy_id);
00211 
00212                 return true;
00213         }
00214 
00222         public function cloneAutoGeneratedRoles($new_obj)
00223         {
00224                 global $ilLog,$rbacadmin,$rbacreview;
00225 
00226                 $admin = $this->getDefaultAdminRole();
00227                 $new_admin = $new_obj->getDefaultAdminRole();
00228                 $source_rolf = $rbacreview->getRoleFolderIdOfObject($this->getRefId());
00229                 $target_rolf = $rbacreview->getRoleFolderIdOfObject($new_obj->getRefId());
00230 
00231                 if(!$admin || !$new_admin || !$source_rolf || !$target_rolf)
00232                 {
00233                         $ilLog->write(__METHOD__.' : Error cloning auto generated role: il_grp_admin');
00234                 }
00235                 $rbacadmin->copyRolePermissions($admin,$source_rolf,$target_rolf,$new_admin,true);
00236                 $ilLog->write(__METHOD__.' : Finished copying of role il_grp_admin.');
00237 
00238                 $member = $this->getDefaultMemberRole();
00239                 $new_member = $new_obj->getDefaultMemberRole();
00240                 if(!$member || !$new_member)
00241                 {
00242                         $ilLog->write(__METHOD__.' : Error cloning auto generated role: il_grp_member');
00243                 }
00244                 $rbacadmin->copyRolePermissions($member,$source_rolf,$target_rolf,$new_member,true);
00245                 $ilLog->write(__METHOD__.' : Finished copying of role grp_member.');
00246         }
00247 
00253         function setLatitude($a_latitude)
00254         {
00255                 $this->latitude = $a_latitude;
00256         }
00257 
00263         function getLatitude()
00264         {
00265                 return $this->latitude;
00266         }
00267 
00273         function setLongitude($a_longitude)
00274         {
00275                 $this->longitude = $a_longitude;
00276         }
00277 
00283         function getLongitude()
00284         {
00285                 return $this->longitude;
00286         }
00287 
00293         function setLocationZoom($a_locationzoom)
00294         {
00295                 $this->locationzoom = $a_locationzoom;
00296         }
00297 
00303         function getLocationZoom()
00304         {
00305                 return $this->locationzoom;
00306         }
00307 
00313         function setEnableGroupMap($a_enablemap)
00314         {
00315                 $this->enablemap = $a_enablemap;
00316         }
00317 
00323         function getEnableGroupMap()
00324         {
00325                 return $this->enablemap;
00326         }
00327 
00333         function join($a_user_id, $a_mem_role="")
00334         {
00335                 global $rbacadmin;
00336 
00337                 if (is_array($a_mem_role))
00338                 {
00339                         foreach ($a_mem_role as $role)
00340                         {
00341                                 $rbacadmin->assignUser($role,$a_user_id, false);
00342                         }
00343                 }
00344                 else
00345                 {
00346                         $rbacadmin->assignUser($a_mem_role,$a_user_id, false);
00347                 }
00348 
00349                 return true;
00350         }
00351 
00356         function getDefaultMemberRole()
00357         {
00358                 $local_group_Roles = $this->getLocalGroupRoles();
00359 
00360                 return $local_group_Roles["il_grp_member_".$this->getRefId()];
00361         }
00362 
00367         function getDefaultAdminRole()
00368         {
00369                 $local_group_Roles = $this->getLocalGroupRoles();
00370 
00371                 return $local_group_Roles["il_grp_admin_".$this->getRefId()];
00372         }
00373 
00380         function addMember($a_user_id, $a_mem_role)
00381         {
00382                 global $rbacadmin;
00383 
00384                 if (isset($a_user_id) && isset($a_mem_role) )
00385                 {
00386                         $this->join($a_user_id,$a_mem_role);
00387                         return true;
00388                 }
00389                 else
00390                 {
00391                         $this->ilias->raiseError(get_class($this)."::addMember(): Missing parameters !",$this->ilias->error_obj->WARNING);
00392                         return false;
00393                 }
00394         }
00395 
00400         function getNewRegistrations()
00401         {
00402                 global $ilDB;
00403                 
00404                 $appList = array();
00405                 $q = "SELECT * FROM grp_registration WHERE grp_id=".$ilDB->quote($this->getId());
00406                 $res = $this->ilias->db->query($q);
00407                 while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00408                 {
00409                         if (ilObject::_exists($row->user_id) &&
00410                                 ilObject::_lookupType($row->user_id) == "usr")
00411                         {
00412                                 array_push($appList,$row);
00413                         }
00414                 }
00415 
00416                 return ($appList) ? $appList : false;
00417         }
00418 
00423         function deleteApplicationListEntry($a_userId)
00424         {
00425                 global $ilDB;
00426 
00427                 $q = "DELETE FROM grp_registration WHERE user_id=".
00428                         $ilDB->quote($a_userId)." AND grp_id=".$ilDB->quote($this->getId());
00429                 $res = $this->ilias->db->query($q);
00430         }
00431 
00438         function leaveGroup()
00439         {
00440                 global $rbacadmin, $rbacreview;
00441 
00442                 $member_ids = $this->getGroupMemberIds();
00443 
00444                 if (count($member_ids) <= 1 || !in_array($this->ilias->account->getId(), $member_ids))
00445                 {
00446                         return 2;
00447                 }
00448                 else
00449                 {
00450                         if (!$this->isAdmin($this->ilias->account->getId()))
00451                         {
00452                                 $this->leave($this->ilias->account->getId());
00453                                 $member = new ilObjUser($this->ilias->account->getId());
00454                                 $member->dropDesktopItem($this->getRefId(), "grp");
00455 
00456                                 return 0;
00457                         }
00458                         else if (count($this->getGroupAdminIds()) == 1)
00459                         {
00460                                 return 1;
00461                         }
00462                 }
00463         }
00464 
00469         function leave($a_user_id)
00470         {
00471                 global $rbacadmin;
00472 
00473                 $arr_groupRoles = $this->getMemberRoles($a_user_id);
00474 
00475                 if (is_array($arr_groupRoles))
00476                 {
00477                         foreach ($arr_groupRoles as $groupRole)
00478                         {
00479                                 $rbacadmin->deassignUser($groupRole, $a_user_id);
00480                         }
00481                 }
00482                 else
00483                 {
00484                         $rbacadmin->deassignUser($arr_groupRoles, $a_user_id);
00485                 }
00486 
00487                 return true;
00488         }
00489 
00494         function removeMember($a_user_id, $a_grp_id="")
00495         {
00496                 if (isset($a_user_id) && isset($a_grp_id) && $this->isMember($a_user_id))
00497                 {
00498                         if (count($this->getGroupMemberIds()) > 1)
00499                         {
00500                                 if ($this->isAdmin($a_user_id) && count($this->getGroupAdminIds()) < 2)
00501                                 {
00502                                         return "grp_err_administrator_required";
00503                                 }
00504                                 else
00505                                 {
00506                                         $this->leave($a_user_id);
00507                                         #$member = new ilObjUser($a_user_id);
00508                                         #$member->dropDesktopItem($this->getRefId(), "grp");
00509 
00510                                         return "";
00511                                 }
00512                         }
00513                         else
00514                         {
00515                                 return "grp_err_last_member";
00516                         }
00517                 }
00518                 else
00519                 {
00520                         $this->ilias->raiseError(get_class($this)."::removeMember(): Missing parameters !",$this->ilias->error_obj->WARNING);
00521                 }
00522         }
00523 
00530         function getGroupMemberIds()
00531         {
00532                 global $rbacadmin, $rbacreview;
00533 
00534                 $usr_arr= array();
00535 
00536                 $rol  = $this->getLocalGroupRoles();
00537 
00538                 foreach ($rol as $value)
00539                 {
00540                         foreach ($rbacreview->assignedUsers($value) as $member_id)
00541                         {
00542                                 array_push($usr_arr,$member_id);
00543                         }
00544                 }
00545 
00546                 $mem_arr = array_unique($usr_arr);
00547 
00548                 return $mem_arr ? $mem_arr : array();
00549         }
00550 
00558         function getGroupMemberData($a_mem_ids, $active = 1)
00559         {
00560                 global $rbacadmin, $rbacreview, $ilBench, $ilDB;
00561 
00562                 $usr_arr= array();
00563 
00564                 $q = "SELECT login,firstname,lastname,title,usr_id,last_login ".
00565                          "FROM usr_data ".
00566                          "WHERE usr_id IN (".implode(',',ilUtil::quoteArray($a_mem_ids)).")";
00567 
00568                 if (is_numeric($active) && $active > -1)
00569                         $q .= "AND active = '$active'";
00570 
00571                 $r = $ilDB->query($q);
00572 
00573                 while($row = $r->fetchRow(DB_FETCHMODE_OBJECT))
00574                 {
00575                         $mem_arr[] = array("id" => $row->usr_id,
00576                                                                 "login" => $row->login,
00577                                                                 "firstname" => $row->firstname,
00578                                                                 "lastname" => $row->lastname,
00579                                                                 "last_login" => $row->last_login
00580                                                                 );
00581                 }
00582 
00583                 return $mem_arr ? $mem_arr : array();
00584         }
00585 
00586         function getCountMembers()
00587         {
00588                 return count($this->getGroupMemberIds());
00589         }
00590 
00597         function getGroupAdminIds($a_grpId="")
00598         {
00599                 global $rbacreview;
00600 
00601                 if (!empty($a_grpId))
00602                 {
00603                         $grp_id = $a_grpId;
00604                 }
00605                 else
00606                 {
00607                         $grp_id = $this->getRefId();
00608                 }
00609 
00610                 $usr_arr = array();
00611                 $roles = $this->getDefaultGroupRoles($this->getRefId());
00612 
00613                 foreach ($rbacreview->assignedUsers($this->getDefaultAdminRole()) as $member_id)
00614                 {
00615                         array_push($usr_arr,$member_id);
00616                 }
00617 
00618                 return $usr_arr;
00619         }
00620 
00626         function getDefaultGroupRoles($a_grp_id="")
00627         {
00628                 global $rbacadmin, $rbacreview;
00629 
00630                 if (strlen($a_grp_id) > 0)
00631                 {
00632                         $grp_id = $a_grp_id;
00633                 }
00634                 else
00635                 {
00636                         $grp_id = $this->getRefId();
00637                 }
00638 
00639                 $rolf      = $rbacreview->getRoleFolderOfObject($grp_id);
00640                 $role_arr  = $rbacreview->getRolesOfRoleFolder($rolf["ref_id"]);
00641 
00642                 foreach ($role_arr as $role_id)
00643                 {
00644                         $role_Obj =& $this->ilias->obj_factory->getInstanceByObjId($role_id);
00645 
00646                         $grp_Member ="il_grp_member_".$grp_id;
00647                         $grp_Admin  ="il_grp_admin_".$grp_id;
00648 
00649                         if (strcmp($role_Obj->getTitle(), $grp_Member) == 0 )
00650                         {
00651                                 $arr_grpDefaultRoles["grp_member_role"] = $role_Obj->getId();
00652                         }
00653 
00654                         if (strcmp($role_Obj->getTitle(), $grp_Admin) == 0)
00655                         {
00656                                 $arr_grpDefaultRoles["grp_admin_role"] = $role_Obj->getId();
00657                         }
00658                 }
00659 
00660                 return $arr_grpDefaultRoles;
00661         }
00662 
00669         function getLocalGroupRoles($a_translate = false)
00670         {
00671                 global $rbacadmin,$rbacreview;
00672 
00673                 if (empty($this->local_roles))
00674                 {
00675                         $this->local_roles = array();
00676                         $rolf      = $rbacreview->getRoleFolderOfObject($this->getRefId());
00677                         $role_arr  = $rbacreview->getRolesOfRoleFolder($rolf["ref_id"]);
00678 
00679                         foreach ($role_arr as $role_id)
00680                         {
00681                                 if ($rbacreview->isAssignable($role_id,$rolf["ref_id"]) == true)
00682                                 {
00683                                         $role_Obj =& $this->ilias->obj_factory->getInstanceByObjId($role_id);
00684 
00685                                         if ($a_translate)
00686                                         {
00687                                                 $role_name = ilObjRole::_getTranslation($role_Obj->getTitle());
00688                                         }
00689                                         else
00690                                         {
00691                                                 $role_name = $role_Obj->getTitle();
00692                                         }
00693 
00694                                         $this->local_roles[$role_name] = $role_Obj->getId();
00695                                 }
00696                         }
00697                 }
00698 
00699                 return $this->local_roles;
00700         }
00701 
00707         function getGrpStatusClosedTemplateId()
00708         {
00709                 $q = "SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_grp_status_closed'";
00710                 $res = $this->ilias->db->query($q);
00711                 $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
00712 
00713                 return $row["obj_id"];
00714         }
00715 
00721         function getGrpStatusOpenTemplateId()
00722         {
00723                 $q = "SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_grp_status_open'";
00724                 $res = $this->ilias->db->query($q);
00725                 $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
00726 
00727                 return $row["obj_id"];
00728         }
00729 
00735         function setRegistrationFlag($a_regFlag="")
00736         {
00737                 global $ilDB;
00738 
00739                 $q = "SELECT * FROM grp_data WHERE grp_id= ".
00740                         $ilDB->quote($this->getId());
00741                 $res = $this->ilias->db->query($q);
00742 
00743                 if (!isset($a_regFlag))
00744                 {
00745                         $a_regFlag = 0;
00746                 }
00747 
00748                 if ($res->numRows() == 0)
00749                 {
00750                         $q = "INSERT INTO grp_data (grp_id, register) VALUES(".
00751                                 $ilDB->quote($this->getId()).",".
00752                                 $ilDB->quote($a_regFlag).")";
00753                         $res = $this->ilias->db->query($q);
00754                 }
00755                 else
00756                 {
00757                         $q = "UPDATE grp_data SET register=".
00758                                 $ilDB->quote($a_regFlag)." WHERE grp_id=".
00759                                 $ilDB->quote($this->getId());
00760                         $res = $this->ilias->db->query($q);
00761                 }
00762         }
00763 
00769         function getRegistrationFlag()
00770         {
00771                 global $ilDB;
00772                 
00773                 $q = "SELECT * FROM grp_data WHERE grp_id=".
00774                         $ilDB->quote($this->getId());
00775                 $res = $this->ilias->db->query($q);
00776                 $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
00777 
00778                 return $row["register"];
00779         }
00780 
00786         function getPassword()
00787         {
00788                 global $ilDB;
00789 
00790                 $q = "SELECT * FROM grp_data WHERE grp_id= ".
00791                         $ilDB->quote($this->getId());
00792                 $res = $this->ilias->db->query($q);
00793                 $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
00794 
00795                 return $row["password"];
00796         }
00797 
00803         function setPassword($a_password="")
00804         {
00805                 global $ilDB;
00806                 
00807                 $q = "SELECT * FROM grp_data WHERE grp_id=".$ilDB->quote($this->getId());
00808 
00809                 $res = $this->ilias->db->query($q);
00810 
00811                 if ($res->numRows() == 0)
00812                 {
00813                         $q = "INSERT INTO grp_data (grp_id, password) VALUES(".
00814                                 $ilDB->quote($this->getId()).",".$ilDB->quote($a_password).")";
00815                         $res = $this->ilias->db->query($q);
00816                 }
00817                 else
00818                 {
00819                         $q = "UPDATE grp_data SET password=".$ilDB->quote($a_password)." WHERE grp_id=".
00820                                 $ilDB->quote($this->getId());
00821                         $res = $this->ilias->db->query($q);
00822                 }
00823         }
00824 
00832         public function updateExpiration($a_date)
00833         {
00834                 global $ilDB;
00835 
00836                 $q = "SELECT * FROM grp_data WHERE grp_id= ".
00837                         $ilDB->quote($this->getId());
00838                 $res = $this->ilias->db->query($q);
00839                 $date = $a_date;
00840 
00841                 if ($res->numRows() == 0)
00842                 {
00843                         $q = "INSERT INTO grp_data (grp_id, expiration) VALUES(".
00844                                 $ilDB->quote($this->getId()).",".$ilDB->quote($date).")";
00845                         $res = $this->ilias->db->query($q);
00846                 }
00847                 else
00848                 {
00849                         $q = "UPDATE grp_data SET expiration=".
00850                                 $ilDB->quote($date)." WHERE grp_id=".$ilDB->quote($this->getId());
00851                         $res = $this->ilias->db->query($q);
00852                 }
00853 
00854         }
00855 
00861         function setExpirationDateTime($a_date)
00862         {
00863                 global $ilDB;
00864 
00865                 $q = "SELECT * FROM grp_data WHERE grp_id= ".
00866                         $ilDB->quote($this->getId());
00867                 $res = $this->ilias->db->query($q);
00868                 $date = ilFormat::input2date($a_date);
00869 
00870                 if ($res->numRows() == 0)
00871                 {
00872                         $q = "INSERT INTO grp_data (grp_id, expiration) VALUES(".
00873                                 $ilDB->quote($this->getId()).",".$ilDB->quote($date).")";
00874                         $res = $this->ilias->db->query($q);
00875                 }
00876                 else
00877                 {
00878                         $q = "UPDATE grp_data SET expiration=".
00879                                 $ilDB->quote($date)." WHERE grp_id=".$ilDB->quote($this->getId());
00880                         $res = $this->ilias->db->query($q);
00881                 }
00882         }
00883 
00891         public function getExpiration()
00892         {
00893                 global $ilDB;
00894 
00895                 $q = "SELECT * FROM grp_data WHERE grp_id= ".
00896                         $ilDB->quote($this->getId());
00897                 $res = $this->ilias->db->query($q);
00898                 $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
00899                 return $datetime = $row["expiration"];
00900         }
00901 
00907         function getExpirationDateTime()
00908         {
00909                 global $ilDB;
00910 
00911                 $q = "SELECT * FROM grp_data WHERE grp_id= ".
00912                         $ilDB->quote($this->getId());
00913                 $res = $this->ilias->db->query($q);
00914                 $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
00915                 $datetime = $row["expiration"];
00916                 $date = ilFormat::fdateDB2dateDE($datetime);
00917                 $time = substr($row["expiration"], -8);
00918                 $datetime = array(0=>$date, 1=>$time);
00919 
00920                 return $datetime;
00921         }
00922 
00923         function getExpirationTimestamp()
00924         {
00925                 global $ilDB;
00926 
00927                 $query = "SELECT UNIX_TIMESTAMP(expiration) as timest FROM grp_data WHERE grp_id = ".
00928                         $ilDB->quote($this->getId());
00929 
00930                 $res = $this->ilias->db->query($query);
00931                 $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
00932                 return $row['timest'];
00933         }
00934 
00935 
00936         function registrationPossible()
00937         {
00938                 $datetime = $this->getExpirationDateTime();
00939                 $today_date = ilFormat::getDateDE();
00940                 $today_time = date("H:i:s");
00941 
00942                 $ts_exp_date = ilFormat::dateDE2timestamp($datetime[0]);
00943                 $ts_today_date = ilFormat::dateDE2timestamp($today_date);
00944 
00945                 $ts_exp_time = substr($datetime[1], 0, 2).
00946                                                 substr($datetime[1], 3, 2).
00947                                                 substr($datetime[1], 6, 2);
00948 
00949                 $ts_today_time = substr($today_time, 0, 2).
00950                                                 substr($today_time, 3, 2).
00951                                                 substr($today_time, 6, 2);
00952 
00953                 // no timelimit given -> unlimited
00954                 if ($ts_exp_date == 0)
00955                 {
00956                         return true;
00957                 }
00958 
00959                 if ($ts_today_date < $ts_exp_date)
00960                 {
00961                         return true;
00962                 }
00963                 elseif (($ts_today_date == $ts_exp_date) and (strcmp($ts_exp_time,$ts_today_time) >= 0))
00964                 {
00965                         return true;
00966                 }
00967                 else
00968                 {
00969                         return false;
00970                 }
00971         }
00972 
00991         function initGroupStatus($a_grpStatus = 0)
00992         {
00993                 global $rbacadmin, $rbacreview, $rbacsystem;
00994 
00995                 //get Rolefolder of group
00996                 $rolf_data = $rbacreview->getRoleFolderOfObject($this->getRefId());
00997 
00998                 //define all relevant roles that rights are needed to be changed
00999                 $arr_parentRoles = $rbacreview->getParentRoleIds($this->getRefId());
01000                 $arr_relevantParentRoleIds = array_diff(array_keys($arr_parentRoles),$this->getDefaultGroupRoles());
01001 
01002                 //group status open (aka public) or group status closed
01003                 if ($a_grpStatus == 0 || $a_grpStatus == 1)
01004                 {
01005                         if ($a_grpStatus == 0)
01006                         {
01007                                 $template_id = $this->getGrpStatusOpenTemplateId();
01008                         } else {
01009                                 $template_id = $this->getGrpStatusClosedTemplateId();
01010                         }
01011                         //get defined operations from template
01012                         $template_ops = $rbacreview->getOperationsOfRole($template_id, 'grp', ROLE_FOLDER_ID);
01013 
01014                         foreach ($arr_relevantParentRoleIds as $parentRole)
01015                         {
01016                                 if ($rbacreview->isProtected($arr_parentRoles[$parentRole]['parent'],$parentRole))
01017                                 {
01018                                         continue;
01019                                 }
01020 
01021                                 $granted_permissions = array();
01022 
01023                                 // Delete the linked role for the parent role
01024                                 // (just in case if it already exists).
01025                                 $rbacadmin->deleteLocalRole($parentRole,$rolf_data["child"]);
01026 
01027                                 // Grant permissions on the group object for
01028                                 // the parent role. In the foreach loop we
01029                                 // compute the intersection of the role
01030                                 // template il_grp_status_open/_closed and the
01031                                 // permission template of the parent role.
01032                                 $current_ops = $rbacreview->getRoleOperationsOnObject($parentRole, $this->getRefId());
01033                                 $rbacadmin->revokePermission($this->getRefId(), $parentRole);
01034                                 foreach ($template_ops as $template_op)
01035                                 {
01036                                         if (in_array($template_op,$current_ops))
01037                                         {
01038                                                 array_push($granted_permissions,$template_op);
01039                                         }
01040                                 }
01041                                 if (!empty($granted_permissions))
01042                                 {
01043                                         $rbacadmin->grantPermission($parentRole, $granted_permissions, $this->getRefId());
01044                                 }
01045 
01046                                 // Create a linked role for the parent role and
01047                                 // initialize it with the intersection of
01048                                 // il_grp_status_open/_closed and the permission
01049                                 // template of the parent role
01050                                 $rbacadmin->copyRolePermissionIntersection(
01051                                         $template_id, ROLE_FOLDER_ID,
01052                                         $parentRole, $arr_parentRoles[$parentRole]['parent'],
01053                                         $rolf_data["child"], $parentRole
01054                                 );
01055                                 $rbacadmin->assignRoleToFolder($parentRole,$rolf_data["child"],"false");
01056                         }//END foreach
01057                 }
01058         }
01059 
01067         public function setGroupStatus($a_status)
01068         {
01069                 $this->group_status = $a_status;
01070         }
01071 
01079         public function getGroupStatus()
01080         {
01081                 return $this->group_status;
01082         }
01083 
01089         function readGroupStatus()
01090         {
01091                 global $rbacsystem,$rbacreview;
01092 
01093                 $role_folder = $rbacreview->getRoleFolderOfObject($this->getRefId());
01094                 $local_roles = $rbacreview->getRolesOfRoleFolder($role_folder["ref_id"]);
01095 
01096                 //get Rolefolder of group
01097                 $rolf_data = $rbacreview->getRoleFolderOfObject($this->getRefId());
01098                 //get all relevant roles
01099                 $arr_globalRoles = array_diff($local_roles, $this->getDefaultGroupRoles());
01100 
01101                 //if one global role has no permission to join the group is officially closed !
01102                 foreach ($arr_globalRoles as $globalRole)
01103                 {
01104                         $ops_of_role = $rbacreview->getOperationsOfRole($globalRole,"grp", ROLE_FOLDER_ID);
01105 
01106                         if ($rbacsystem->checkPermission($this->getRefId(), $globalRole ,"join"))
01107                         {
01108                                 return $this->group_status = 0;
01109                         }
01110                 }
01111 
01112                 return $this->group_status = 2;
01113         }
01114 
01121         function getMemberRoles($a_user_id)
01122         {
01123                 global $rbacadmin, $rbacreview,$ilBench;
01124 
01125                 $ilBench->start("Group", "getMemberRoles");
01126 
01127                 $arr_assignedRoles = array();
01128 
01129                 $arr_assignedRoles = array_intersect($rbacreview->assignedRoles($a_user_id),$this->getLocalGroupRoles());
01130 
01131                 $ilBench->stop("Group", "getMemberRoles");
01132 
01133                 return $arr_assignedRoles;
01134         }
01135 
01142         function getMemberRolesTitle($a_user_id)
01143         {
01144                 global $ilDB,$ilBench;
01145 
01146                 include_once ('class.ilObjRole.php');
01147 
01148                 $ilBench->start("Group", "getMemberRolesTitle");
01149 
01150                 $str_member_roles ="";
01151 
01152                 $q = "SELECT title ".
01153                          "FROM object_data ".
01154                          "LEFT JOIN rbac_ua ON object_data.obj_id=rbac_ua.rol_id ".
01155                          "WHERE object_data.type = 'role' ".
01156                          "AND rbac_ua.usr_id = ".$ilDB->quote($a_user_id)." ".
01157                          "AND rbac_ua.rol_id IN (".implode(',',ilUtil::quoteArray($this->getLocalGroupRoles())).")";
01158 
01159                 $r = $ilDB->query($q);
01160 
01161                 while($row = $r->fetchRow(DB_FETCHMODE_ASSOC))
01162                 {
01163                         // display human readable role names for autogenerated roles
01164                         $str_member_roles .= ilObjRole::_getTranslation($row["title"]).", ";
01165                 }
01166 
01167                 $ilBench->stop("Group", "getMemberRolesTitle");
01168 
01169                 return substr($str_member_roles,0,-2);
01170         }
01171 
01178         function setMemberStatus($a_user_id, $a_member_role)
01179         {
01180                 if (isset($a_user_id) && isset($a_member_role))
01181                 {
01182                         $this->removeMember($a_user_id);
01183                         $this->addMember($a_user_id, $a_member_role);
01184                 }
01185         }
01186 
01193         function isMember($a_userId = "")
01194         {
01195                 if (strlen($a_userId) == 0)
01196                 {
01197                         $user_id = $this->ilias->account->getId();
01198                 }
01199                 else
01200                 {
01201                         $user_id = $a_userId;
01202                 }
01203 
01204                 if ($this->getType() == "grp")
01205                 {
01206                         $arr_members = $this->getGroupMemberIds();
01207                         if (in_array($user_id, $arr_members))
01208                         {
01209                                 return true;
01210                         }
01211                         else
01212                         {
01213                                 return false;
01214                         }
01215                 }
01216         }
01217 
01224         function isAdmin($a_userId)
01225         {
01226                 global $rbacreview;
01227 
01228                 $grp_Roles = $this->getDefaultGroupRoles();
01229 
01230                 if (in_array($a_userId,$rbacreview->assignedUsers($grp_Roles["grp_admin_role"])))
01231                 {
01232                         return true;
01233                 }
01234                 else
01235                 {
01236                         return false;
01237                 }
01238         }
01239 
01240 
01249         function delete()
01250         {
01251                 global $ilDB;
01252 
01253                 // always call parent delete function first!!
01254                 if (!parent::delete())
01255                 {
01256                         return false;
01257                 }
01258 
01259                 $query = "DELETE FROM grp_data WHERE grp_id = ".
01260                         $ilDB->quote($this->getId());
01261                 $this->ilias->db->query($query);
01262 
01263                 return true;
01264         }
01265 
01271         function initDefaultRoles()
01272         {
01273                 global $rbacadmin, $rbacreview;
01274 
01275                 // create a local role folder
01276                 $rfoldObj =& $this->createRoleFolder();
01277 
01278                 // ADMIN ROLE
01279                 // create role and assign role to rolefolder...
01280                 $roleObj = $rfoldObj->createRole("il_grp_admin_".$this->getRefId(),"Groupadmin of group obj_no.".$this->getId());
01281                 $this->m_roleAdminId = $roleObj->getId();
01282 
01283                 //set permission template of new local role
01284                 $q = "SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_grp_admin'";
01285                 $r = $this->ilias->db->getRow($q, DB_FETCHMODE_OBJECT);
01286                 $rbacadmin->copyRoleTemplatePermissions($r->obj_id,ROLE_FOLDER_ID,$rfoldObj->getRefId(),$roleObj->getId());
01287 
01288                 // set object permissions of group object
01289                 $ops = $rbacreview->getOperationsOfRole($roleObj->getId(),"grp",$rfoldObj->getRefId());
01290                 $rbacadmin->grantPermission($roleObj->getId(),$ops,$this->getRefId());
01291 
01292                 // set object permissions of role folder object
01293                 //$ops = $rbacreview->getOperationsOfRole($roleObj->getId(),"rolf",$rfoldObj->getRefId());
01294                 //$rbacadmin->grantPermission($roleObj->getId(),$ops,$rfoldObj->getRefId());
01295 
01296                 // MEMBER ROLE
01297                 // create role and assign role to rolefolder...
01298                 $roleObj = $rfoldObj->createRole("il_grp_member_".$this->getRefId(),"Groupmember of group obj_no.".$this->getId());
01299                 $this->m_roleMemberId = $roleObj->getId();
01300 
01301                 //set permission template of new local role
01302                 $q = "SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_grp_member'";
01303                 $r = $this->ilias->db->getRow($q, DB_FETCHMODE_OBJECT);
01304                 $rbacadmin->copyRoleTemplatePermissions($r->obj_id,ROLE_FOLDER_ID,$rfoldObj->getRefId(),$roleObj->getId());
01305 
01306                 // set object permissions of group object
01307                 $ops = $rbacreview->getOperationsOfRole($roleObj->getId(),"grp",$rfoldObj->getRefId());
01308                 $rbacadmin->grantPermission($roleObj->getId(),$ops,$this->getRefId());
01309 
01310                 // set object permissions of role folder object
01311                 //$ops = $rbacreview->getOperationsOfRole($roleObj->getId(),"rolf",$rfoldObj->getRefId());
01312                 //$rbacadmin->grantPermission($roleObj->getId(),$ops,$rfoldObj->getRefId());
01313 
01314                 unset($rfoldObj);
01315                 unset($roleObj);
01316 
01317                 $roles[] = $this->m_roleAdminId;
01318                 $roles[] = $this->m_roleMemberId;
01319 
01320                 return $roles ? $roles : array();
01321         }
01322 
01333         function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
01334         {
01335                 global $tree;
01336 
01337                 $parent_id = (int) $tree->getParentId($a_node_id);
01338 
01339                 if ($parent_id != 0)
01340                 {
01341                         $obj_data =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
01342                         $obj_data->notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$parent_id,$a_params);
01343                 }
01344 
01345                 return true;
01346         }
01347 
01348 
01349         function exportXML()
01350         {
01351                 include_once 'classes/class.ilGroupXMLWriter.php';
01352 
01353                 $xml_writer = new ilGroupXMLWriter($this);
01354                 $xml_writer->start();
01355 
01356                 $xml = $xml_writer->getXML();
01357 
01358                 $name = time().'__'.$this->ilias->getSetting('inst_id').'__grp_'.$this->getId();
01359 
01360                 $this->__initFileObject();
01361 
01362                 $this->file_obj->addGroupDirectory();
01363                 $this->file_obj->addDirectory($name);
01364                 $this->file_obj->writeToFile($xml,$name.'/'.$name.'.xml');
01365                 $this->file_obj->zipFile($name,$name.'.zip');
01366                 $this->file_obj->deleteDirectory($name);
01367 
01368                 return true;
01369         }
01370 
01371         function deleteExportFiles($a_files)
01372         {
01373                 $this->__initFileObject();
01374 
01375                 foreach($a_files as $file)
01376                 {
01377                         $this->file_obj->deleteFile($file);
01378                 }
01379                 return true;
01380         }
01381 
01382         function downloadExportFile($file)
01383         {
01384                 $this->__initFileObject();
01385 
01386                 if($abs_name = $this->file_obj->getExportFile($file))
01387                 {
01388                         ilUtil::deliverFile($abs_name,$file);
01389                         // Not reached
01390                 }
01391                 return false;
01392         }
01393 
01402         function _importFromXMLString($xml,$parent_id)
01403         {
01404                 include_once 'classes/class.ilGroupImportParser.php';
01405 
01406                 $import_parser = new ilGroupImportParser($xml,$parent_id);
01407 
01408                 return $import_parser->startParsing();
01409         }
01410 
01418         function _importFromFile($file,$parent_id)
01419         {
01420                 global $lng;
01421 
01422                 include_once 'classes/class.ilFileDataGroup.php';
01423 
01424                 $file_obj = new ilFileDataGroup(null);
01425                 $file_obj->addImportDirectory();
01426                 $file_obj->createImportFile($_FILES["xmldoc"]["tmp_name"],$_FILES['xmldoc']['name']);
01427                 $file_obj->unpackImportFile();
01428 
01429                 if(!$file_obj->validateImportFile())
01430                 {
01431                         return false;
01432                 }
01433                 return ilObjGroup::_importFromXMLString(file_get_contents($file_obj->getImportFile()),$parent_id);
01434         }
01435 
01444         function _search(&$a_search_obj)
01445         {
01446                 global $ilBench;
01447 
01448                 // NO CLASS VARIABLES IN STATIC METHODS
01449 
01450                 $where_condition = $a_search_obj->getWhereCondition("like",array("title","description"));
01451                 $in = $a_search_obj->getInStatement("ore.ref_id");
01452 
01453                 $query = "SELECT ore.ref_id AS ref_id FROM object_data AS od, object_reference AS ore ".
01454                         $where_condition." ".
01455                         $in." ".
01456                         "AND od.obj_id = ore.obj_id ".
01457                         "AND od.type = 'grp' ";
01458 
01459                 $ilBench->start("Search", "ilObjGroup_search");
01460                 $res = $a_search_obj->ilias->db->query($query);
01461                 $ilBench->stop("Search", "ilObjGroup_search");
01462 
01463                 $counter = 0;
01464 
01465                 while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
01466                 {
01467                         $result_data[$counter++]["id"]                          =  $row->ref_id;
01468                         #$result_data[$counter]["link"]                         =  "group.php?cmd=view&ref_id=".$row->ref_id;
01469                         #$result_data[$counter++]["target"]                     =  "";
01470                 }
01471 
01472                 return $result_data ? $result_data : array();
01473         }
01474 
01483         function _getLinkToObject($a_id)
01484         {
01485                 return array("repository.php?ref_id=".$a_id."&set_mode=flat&cmdClass=ilobjgroupgui","");
01486         }
01487 
01488         function _lookupIdByTitle($a_title)
01489         {
01490                 global $ilDB;
01491 
01492                 $query = "SELECT * FROM object_data WHERE title = ".
01493                         $ilDB->quote($a_title)." AND type = 'grp'";
01494                 $res = $ilDB->query($query);
01495                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
01496                 {
01497                         return $row->obj_id;
01498                 }
01499                 return 0;
01500         }
01501 
01502 
01503         function isUserRegistered($a_user_id = 0)
01504         {
01505                 global $rbacsystem;
01506 
01507 
01508                 if (!$this->isMember() or !$rbacsystem->checkAccess("join", $this->ref_id))
01509                 {
01510                         return false;
01511                 }
01512 
01513                 return true;
01514         }
01515 
01516         function _isMember($a_user_id,$a_ref_id,$a_field = '')
01517         {
01518                 global $rbacreview,$ilObjDataCache,$ilDB;
01519 
01520                 $rolf = $rbacreview->getRoleFolderOfObject($a_ref_id);
01521                 $local_roles = $rbacreview->getRolesOfRoleFolder($rolf["ref_id"],false);
01522                 $user_roles = $rbacreview->assignedRoles($a_user_id);
01523 
01524                 // Used for membership limitations -> check membership by given field
01525                 if($a_field)
01526                 {
01527                         include_once './Services/User/classes/class.ilObjUser.php';
01528 
01529                         $tmp_user =& ilObjectFactory::getInstanceByObjId($a_user_id);
01530                         switch($a_field)
01531                         {
01532                                 case 'login':
01533                                         $and = "AND login = '".$tmp_user->getLogin()."' ";
01534                                         break;
01535                                 case 'email':
01536                                         $and = "AND email = '".$tmp_user->getEmail()."' ";
01537                                         break;
01538                                 case 'matriculation':
01539                                         $and = "AND matriculation = '".$tmp_user->getMatriculation()."' ";
01540                                         break;
01541 
01542                                 default:
01543                                         $and = "AND usr_id = '".$a_user_id."'";
01544                                         break;
01545                         }
01546                         if(!$members = ilObjGroup::_getMembers($ilObjDataCache->lookupObjId($a_ref_id)))
01547                         {
01548                                 return false;
01549                         }
01550                         $query = "SELECT * FROM usr_data as ud ".
01551                                 "WHERE usr_id IN (".implode(",",ilUtil::quoteArray($members)).") ".
01552                                 $and;
01553                         $res = $ilDB->query($query);
01554 
01555                         return $res->numRows() ? true : false;
01556                 }
01557 
01558 
01559 
01560 
01561 
01562                 if (!array_intersect($local_roles,$user_roles))
01563                 {
01564                         return false;
01565                 }
01566 
01567                 return true;
01568         }
01569 
01570         function _getMembers($a_obj_id)
01571         {
01572                 global $rbacreview;
01573 
01574                 // get reference
01575                 $ref_ids = ilObject::_getAllReferences($a_obj_id);
01576                 $ref_id = current($ref_ids);
01577 
01578                 $rolf = $rbacreview->getRoleFolderOfObject($ref_id);
01579                 $local_roles = $rbacreview->getRolesOfRoleFolder($rolf['ref_id'],false);
01580 
01581                 $users = array();
01582                 foreach($local_roles as $role_id)
01583                 {
01584                         $users = array_merge($users,$rbacreview->assignedUsers($role_id));
01585                 }
01586 
01587                 return array_unique($users);
01588         }
01589 
01590 
01591 
01592         // Private / Protected
01593         function __initFileObject()
01594         {
01595                 if($this->file_obj)
01596                 {
01597                         return $this->file_obj;
01598                 }
01599                 else
01600                 {
01601                         include_once 'classes/class.ilFileDataGroup.php';
01602 
01603                         return $this->file_obj = new ilFileDataGroup($this);
01604                 }
01605         }
01606 
01607         function getMessage()
01608         {
01609                 return $this->message;
01610         }
01611         function setMessage($a_message)
01612         {
01613                 $this->message = $a_message;
01614         }
01615         function appendMessage($a_message)
01616         {
01617                 if($this->getMessage())
01618                 {
01619                         $this->message .= "<br /> ";
01620                 }
01621                 $this->message .= $a_message;
01622         }
01623 
01624 
01625 } //END class.ilObjGroup
01626 ?>

Generated on Fri Dec 13 2013 17:56:48 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1