• 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 
00197         function setParent($a_parent_ref)
00198         {
00199                 $this->parent = $a_parent_ref;
00200         }
00201         
00208         function getParent()
00209         {
00210                 return $this->parent;
00211         }
00212 
00219         function ilClone($a_parent_ref)
00220         {               
00221                 // DISABLED
00222                 return false;
00223 
00224                 global $rbacadmin;
00225 
00226                 // always call parent ilClone function first!!
00227                 $new_ref_id = parent::ilClone($a_parent_ref);
00228                 
00229                 // put here role specific stuff
00230 
00231                 // ... and finally always return new reference ID!!
00232                 return $new_ref_id;
00233         }
00234 
00241         function delete()
00242         {               
00243                 global $rbacadmin, $rbacreview;
00244                 
00245                 $role_folders = $rbacreview->getFoldersAssignedToRole($this->getId());
00246                 
00247                 if ($rbacreview->isAssignable($this->getId(),$this->getParent()))
00248                 {
00249                         // do not delete role if this role is the last role a user is assigned to
00250                         
00251                         // first fetch all users assigned to role
00252                         $user_ids = $rbacreview->assignedUsers($this->getId());
00253                         
00254                         $last_role_user_ids = array();
00255 
00256                         foreach ($user_ids as $user_id)
00257                         {
00258                                 // get all roles each user has
00259                                 $role_ids = $rbacreview->assignedRoles($user_id);
00260                                 
00261                                 // is last role?
00262                                 if (count($role_ids) == 1)
00263                                 {
00264                                         $last_role_user_ids[] = $user_id;
00265                                 }                       
00266                         }
00267                         
00268                         // users with last role found?
00269                         if (count($last_role_user_ids) > 0)
00270                         {
00271                                 foreach ($last_role_user_ids as $user_id)
00272                                 {
00273                                         // GET OBJECT TITLE
00274                                         $tmp_obj = $this->ilias->obj_factory->getInstanceByObjId($user_id);
00275                                         $user_names[] = $tmp_obj->getFullname();
00276                                         unset($tmp_obj);
00277                                 }
00278                                 
00279                                 // TODO: This check must be done in rolefolder object because if multiple
00280                                 // roles were selected the other roles are still deleted and the system does not
00281                                 // give any feedback about this.
00282                                 $users = implode(', ',$user_names);
00283                                 $this->ilias->raiseError($this->lng->txt("msg_user_last_role1")." ".
00284                                                                          $users."<br/>".$this->lng->txt("msg_user_last_role2"),$this->ilias->error_obj->WARNING);                               
00285                         }
00286                         else
00287                         {
00288                                 // IT'S A BASE ROLE
00289                                 $rbacadmin->deleteRole($this->getId(),$this->getParent());
00290 
00291                                 // delete object_data entry
00292                                 parent::delete();
00293                                         
00294                                 // delete role_data entry
00295                                 $q = "DELETE FROM role_data WHERE role_id = '".$this->getId()."'";
00296                                 $this->ilias->db->query($q);
00297                         }
00298                 }
00299                 else
00300                 {
00301                         // linked local role: INHERITANCE WAS STOPPED, SO DELETE ONLY THIS LOCAL ROLE
00302                         $rbacadmin->deleteLocalRole($this->getId(),$this->getParent());
00303                 }
00304 
00305                 //  purge empty rolefolders
00306                 foreach ($role_folders as $rolf)
00307                 {
00308                         if (ilObject::_exists($rolf,true))
00309                         {
00310                                 $rolfObj = $this->ilias->obj_factory->getInstanceByRefId($rolf);
00311                                 $rolfObj->purge();
00312                                 unset($roleObj);
00313                         }
00314                 }
00315                 
00316                 return true;
00317         }
00318         
00319         function getCountMembers()
00320         {
00321                 global $rbacreview;
00322                 
00323                 return count($rbacreview->assignedUsers($this->getId()));
00324         }
00325 
00334         function _search(&$a_search_obj)
00335         {
00336                 global $ilBench;
00337 
00338                 // NO CLASS VARIABLES IN STATIC METHODS
00339 
00340                 $where_condition = $a_search_obj->getWhereCondition("like",array("title","description"));
00341                 //$in = $a_search_obj->getInStatement("ore.ref_id");
00342 
00343                 $query = "SELECT obj_id FROM object_data AS od ".
00344                         $where_condition." ".
00345                         "AND od.type = 'role' ";
00346 
00347                 $ilBench->start("Search", "ilObjRole_search");
00348                 $res = $a_search_obj->ilias->db->query($query);
00349                 $ilBench->stop("Search", "ilObjRole_search");
00350 
00351                 $counter = 0;
00352 
00353                 while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00354                 {
00355                         $result_data[$counter++]["id"]                          =  $row->obj_id;
00356                 }
00357 
00358                 return $result_data ? $result_data : array();
00359         }
00360         
00361         // updates role assignments in sessions of users that are online
00362     function _updateSessionRoles($a_selected_users)
00363         {
00364         global $ilDB, $rbacreview;
00365         
00366                 $online_users_all = ilUtil::getUsersOnline();
00367                 
00368         // users online to alter their role assignment
00369         $affected_users = array_intersect(array_keys($online_users_all),$a_selected_users);
00370         
00371             foreach ($affected_users as $user)
00372                 {
00373                         $role_arr = $rbacreview->assignedRoles($user);
00374 
00375                         // current user assigned himself?
00376             if ($user == $_SESSION["AccountId"])
00377                         {
00378                                 $_SESSION["RoleId"] = $role_arr;
00379                         }
00380                         else
00381                         {
00382                                 $roles = "RoleId|".serialize($role_arr);
00383                                 $modified_data = preg_replace("/RoleId.*?;\}/",$roles,$online_users_all[$user]["data"]);
00384 
00385                                 $q = "UPDATE usr_session SET data='".$modified_data."' WHERE user_id = '".$user."'";
00386                                 $ilDB->query($q);
00387                         }
00388                 }
00389         }
00390 } // END class.ilObjRole
00391 ?>

Generated on Fri Dec 13 2013 08:00:14 for ILIAS Release_3_3_x_branch .rev 46803 by  doxygen 1.7.1