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

classes/class.ilObjRole.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 
00024 
00035 require_once "class.ilObject.php";
00036 
00037 class ilObjRole extends ilObject
00038 {
00046         var $parent;
00047         
00048         var $allow_register;
00049         var $assign_users;
00050 
00057         function ilObjRole($a_id = 0,$a_call_by_reference = false)
00058         {
00059                 $this->type = "role";
00060                 $this->ilObject($a_id,$a_call_by_reference);
00061         }
00062 
00063         function toggleAssignUsersStatus($a_assign_users)
00064         {
00065                 $this->assign_users = (int) $a_assign_users;
00066         }
00067         function getAssignUsersStatus()
00068         {
00069                 return $this->assign_users;
00070         }
00071         // Same method (static)
00072         function _getAssignUsersStatus($a_role_id)
00073         {
00074                 global $ilDB;
00075 
00076                 $query = "SELECT assign_users FROM role_data WHERE role_id = '".$a_role_id."'";
00077 
00078                 $res = $ilDB->query($query);
00079                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00080                 {
00081                         return $row->assign_users ? true : false;
00082                 }
00083                 return false;
00084         }
00085 
00090         function read ()
00091         {
00092                 $q = "SELECT * FROM role_data WHERE role_id='".$this->id."'";
00093                 $r = $this->ilias->db->query($q);
00094 
00095                 if ($r->numRows() > 0)
00096                 {
00097                         $data = $r->fetchRow(DB_FETCHMODE_ASSOC);
00098 
00099                         // fill member vars in one shot
00100                         $this->assignData($data);
00101                 }
00102                 else
00103                 {
00104                          $this->ilias->raiseError("<b>Error: There is no dataset with id ".$this->id."!</b><br />class: ".get_class($this)."<br />Script: ".__FILE__."<br />Line: ".__LINE__, $this->ilias->FATAL);
00105                 }
00106 
00107                 parent::read();
00108         }
00109 
00115         function assignData($a_data)
00116         {
00117                 $this->setTitle(ilUtil::stripSlashes($a_data["title"]));
00118                 $this->setDescription(ilUtil::stripslashes($a_data["desc"]));
00119                 $this->setAllowRegister($a_data["allow_register"]);
00120                 $this->toggleAssignUsersStatus($a_data['assign_users']);
00121         }
00122 
00127         function update ()
00128         {
00129                 $q = "UPDATE role_data SET ".
00130                         "allow_register='".$this->allow_register."', ".
00131                         "assign_users = '".$this->getAssignUsersStatus()."' ".
00132                         "WHERE role_id='".$this->id."'";
00133 
00134                 $this->ilias->db->query($q);
00135 
00136                 parent::update();
00137 
00138                 $this->read();
00139 
00140                 return true;
00141         }
00142         
00150         function create()
00151         {
00152                 $this->id = parent::create();
00153 
00154                 $q = "INSERT INTO role_data ".
00155                         "(role_id,allow_register,assign_users) ".
00156                         "VALUES ".
00157                         "('".$this->id."','".$this->getAllowRegister()."','".$this->getAssignUsersStatus()."')";
00158                 $this->ilias->db->query($q);
00159 
00160                 return $this->id;
00161         }
00162 
00169         function setAllowRegister($a_allow_register)
00170         {
00171                 if (empty($a_allow_register))
00172                 {
00173                         $a_allow_register == 0;
00174                 }
00175                 
00176                 $this->allow_register = (int) $a_allow_register;
00177         }
00178         
00185         function getAllowRegister()
00186         {
00187                 return $this->allow_register;
00188         }
00189 
00196         function _lookupRegisterAllowed()
00197         {
00198                 global $ilDB;
00199                 
00200                 $q = "SELECT * FROM role_data ".
00201                         "LEFT JOIN object_data ON object_data.obj_id = role_data.role_id ".
00202                         "WHERE allow_register = 1";
00203                         
00204                 $r = $ilDB->query($q);
00205         
00206                 $roles = array();
00207                 while ($role = $r->fetchRow(DB_FETCHMODE_ASSOC))
00208                 {
00209                         $roles[] = array("id" => $role["obj_id"],
00210                                 "title" => $role["title"]);
00211                 }
00212                 
00213                 return $roles;
00214         }
00215 
00222         function _lookupAllowRegister($a_role_id)
00223         {
00224                 global $ilDB;
00225                 
00226                 $q = "SELECT * FROM role_data ".
00227                         " WHERE role_id =".$ilDB->quote($a_role_id);
00228                         
00229                 $role_set = $ilDB->query($q);
00230                 
00231                 if ($role_rec = $role_set->fetchRow(DB_FETCHMODE_ASSOC))
00232                 {
00233                         if ($role_rec["allow_register"])
00234                         {
00235                                 return true;
00236                         }
00237                 }
00238                 return false;
00239         }
00240 
00248         function setParent($a_parent_ref)
00249         {
00250                 $this->parent = $a_parent_ref;
00251         }
00252         
00259         function getParent()
00260         {
00261                 return $this->parent;
00262         }
00263 
00270         function ilClone($a_parent_ref)
00271         {               
00272                 // DISABLED
00273                 return false;
00274 
00275                 global $rbacadmin;
00276 
00277                 // always call parent ilClone function first!!
00278                 $new_ref_id = parent::ilClone($a_parent_ref);
00279                 
00280                 // put here role specific stuff
00281 
00282                 // ... and finally always return new reference ID!!
00283                 return $new_ref_id;
00284         }
00285 
00292         function delete()
00293         {               
00294                 global $rbacadmin, $rbacreview;
00295                 
00296                 $role_folders = $rbacreview->getFoldersAssignedToRole($this->getId());
00297                 
00298                 if ($rbacreview->isAssignable($this->getId(),$this->getParent()))
00299                 {
00300                         // do not delete role if this role is the last role a user is assigned to
00301                         
00302                         // first fetch all users assigned to role
00303                         $user_ids = $rbacreview->assignedUsers($this->getId());
00304                         
00305                         $last_role_user_ids = array();
00306 
00307                         foreach ($user_ids as $user_id)
00308                         {
00309                                 // get all roles each user has
00310                                 $role_ids = $rbacreview->assignedRoles($user_id);
00311                                 
00312                                 // is last role?
00313                                 if (count($role_ids) == 1)
00314                                 {
00315                                         $last_role_user_ids[] = $user_id;
00316                                 }                       
00317                         }
00318                         
00319                         // users with last role found?
00320                         if (count($last_role_user_ids) > 0)
00321                         {
00322                                 foreach ($last_role_user_ids as $user_id)
00323                                 {
00324                                         // GET OBJECT TITLE
00325                                         $tmp_obj = $this->ilias->obj_factory->getInstanceByObjId($user_id);
00326                                         $user_names[] = $tmp_obj->getFullname();
00327                                         unset($tmp_obj);
00328                                 }
00329                                 
00330                                 // TODO: This check must be done in rolefolder object because if multiple
00331                                 // roles were selected the other roles are still deleted and the system does not
00332                                 // give any feedback about this.
00333                                 $users = implode(', ',$user_names);
00334                                 $this->ilias->raiseError($this->lng->txt("msg_user_last_role1")." ".
00335                                                                          $users."<br/>".$this->lng->txt("msg_user_last_role2"),$this->ilias->error_obj->WARNING);                               
00336                         }
00337                         else
00338                         {
00339                                 // IT'S A BASE ROLE
00340                                 $rbacadmin->deleteRole($this->getId(),$this->getParent());
00341 
00342                                 // delete object_data entry
00343                                 parent::delete();
00344                                         
00345                                 // delete role_data entry
00346                                 $q = "DELETE FROM role_data WHERE role_id = '".$this->getId()."'";
00347                                 $this->ilias->db->query($q);
00348 
00349                                 include_once './classes/class.ilRoleDesktopItem.php';
00350                                 
00351                                 $role_desk_item_obj =& new ilRoleDesktopItem($this->getId());
00352                                 $role_desk_item_obj->deleteAll();
00353 
00354                         }
00355                 }
00356                 else
00357                 {
00358                         // linked local role: INHERITANCE WAS STOPPED, SO DELETE ONLY THIS LOCAL ROLE
00359                         $rbacadmin->deleteLocalRole($this->getId(),$this->getParent());
00360                 }
00361 
00362                 //  purge empty rolefolders
00363                 foreach ($role_folders as $rolf)
00364                 {
00365                         if (ilObject::_exists($rolf,true))
00366                         {
00367                                 $rolfObj = $this->ilias->obj_factory->getInstanceByRefId($rolf);
00368                                 $rolfObj->purge();
00369                                 unset($roleObj);
00370                         }
00371                 }
00372                 
00373                 return true;
00374         }
00375         
00376         function getCountMembers()
00377         {
00378                 global $rbacreview;
00379                 
00380                 return count($rbacreview->assignedUsers($this->getId()));
00381         }
00382 
00391         function _search(&$a_search_obj)
00392         {
00393                 global $ilBench;
00394 
00395                 // NO CLASS VARIABLES IN STATIC METHODS
00396 
00397                 $where_condition = $a_search_obj->getWhereCondition("like",array("title","description"));
00398                 //$in = $a_search_obj->getInStatement("ore.ref_id");
00399 
00400                 $query = "SELECT obj_id FROM object_data AS od ".
00401                         $where_condition." ".
00402                         "AND od.type = 'role' ";
00403 
00404                 $ilBench->start("Search", "ilObjRole_search");
00405                 $res = $a_search_obj->ilias->db->query($query);
00406                 $ilBench->stop("Search", "ilObjRole_search");
00407 
00408                 $counter = 0;
00409 
00410                 while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00411                 {
00412                         $result_data[$counter++]["id"]                          =  $row->obj_id;
00413                 }
00414 
00415                 return $result_data ? $result_data : array();
00416         }
00417         
00418         // updates role assignments in sessions of users that are online
00419     function _updateSessionRoles($a_selected_users)
00420         {
00421         global $ilDB, $rbacreview;
00422         
00423                 $online_users_all = ilUtil::getUsersOnline();
00424                 
00425         // users online to alter their role assignment
00426         $affected_users = array_intersect(array_keys($online_users_all),$a_selected_users);
00427         
00428             foreach ($affected_users as $user)
00429                 {
00430                         $role_arr = $rbacreview->assignedRoles($user);
00431 
00432                         // current user assigned himself?
00433             if ($user == $_SESSION["AccountId"])
00434                         {
00435                                 $_SESSION["RoleId"] = $role_arr;
00436                         }
00437                         else
00438                         {
00439                                 $roles = "RoleId|".serialize($role_arr);
00440                                 $modified_data = preg_replace("/RoleId.*?;\}/",$roles,$online_users_all[$user]["data"]);
00441 
00442                                 $q = "UPDATE usr_session SET data='".$modified_data."' WHERE user_id = '".$user."'";
00443                                 $ilDB->query($q);
00444                         }
00445                 }
00446         }
00447 } // END class.ilObjRole
00448 ?>

Generated on Fri Dec 13 2013 09:06:34 for ILIAS Release_3_4_x_branch .rev 46804 by  doxygen 1.7.1