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

classes/class.ilRoleDesktopItem.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 
00038 class ilRoleDesktopItem
00039 {
00040         var $db;
00041         var $role_id;
00042  
00047         function ilRoleDesktopItem($a_role_id)
00048         {
00049                 global $ilDB;
00050 
00051                 $this->db =& $ilDB;
00052                 $this->role_id = $a_role_id;
00053         }
00054 
00055         function getRoleId()
00056         {
00057                 return $this->role_id;
00058         }
00059         function setRoleId($a_role_id)
00060         {
00061                 $this->role_id = $a_role_id;
00062         }
00063 
00064         function add($a_item_id,$a_item_type)
00065         {
00066                 if($a_item_type and $a_item_id)
00067                 {
00068                         $query = "INSERT INTO role_desktop_items ".
00069                                 "SET role_id = '".$this->getRoleId()."', ".
00070                                 "item_id = '".$a_item_id."', ".
00071                                 "item_type = '".$a_item_type."'";
00072                         
00073                         $this->db->query($query);
00074 
00075                         $this->__assign($a_item_id,$a_item_type);
00076                         
00077                         return true;
00078                 }
00079                 return false;
00080         }
00081         function delete($a_role_item_id)
00082         {
00083                 $query = "DELETE FROM role_desktop_items ".
00084                         "WHERE role_item_id = '".$a_role_item_id."'";
00085 
00086                 $this->db->query($query);
00087 
00088                 return true;
00089         }
00090 
00091         function deleteAll()
00092         {
00093                 $query = "DELETE FROM role_desktop_items ".
00094                         "WHERE role_id = '".$this->getRoleId()."'";
00095 
00096                 $this->db->query($query);
00097 
00098                 return true;
00099         }
00100 
00101         function isAssigned($a_item_ref_id)
00102         {
00103                 $query = "SELECT * FROM role_desktop_items ".
00104                         "WHERE role_id = '".$this->getRoleId()."' ".
00105                         "AND item_id = '".$a_item_ref_id."'";
00106 
00107                 $res = $this->db->query($query);
00108 
00109                 return $res->numRows() ? true : false;
00110         }
00111 
00112         function getItem($a_role_item_id)
00113         {
00114                 $query = "SELECT * FROM role_desktop_items ".
00115                         "WHERE role_id = '".$this->getRoleId()."' ".
00116                         "AND role_item_id = '".$a_role_item_id."'";
00117 
00118                 $res = $this->db->query($query);
00119                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00120                 {
00121                         $item['item_id'] = $row->item_id;
00122                         $item['item_type'] = $row->item_type;
00123                 }
00124 
00125                 return $item ? $item : array();
00126         }
00127 
00128 
00129 
00130         function getAll()
00131         {
00132                 global $tree;
00133 
00134                 $query = "SELECT * FROM role_desktop_items ".
00135                         "WHERE role_id = '".$this->getRoleId()."'";
00136 
00137                 $res = $this->db->query($query);
00138                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00139                 {
00140                         // TODO this check must be modified for non tree objects
00141                         if(!$tree->isInTree($row->item_id))
00142                         {
00143                                 $this->delete($row->role_item_id);
00144                                 continue;
00145                         }
00146                         $items[$row->role_item_id]['item_id'] = $row->item_id;
00147                         $items[$row->role_item_id]['item_type'] = $row->item_type;
00148                 }
00149                 return $items ? $items : array();
00150         }
00151 
00152         // PRIVATE
00153         function __assign($a_item_id,$a_item_type)
00154         {
00155                 global $rbacreview;
00156 
00157                 foreach($rbacreview->assignedUsers($this->getRoleId()) as $user_id)
00158                 {
00159                         if(is_object($tmp_user = ilObjectFactory::getInstanceByObjId($user_id,false)))
00160                         {
00161                                 if(!$tmp_user->isDesktopItem($a_item_id,$a_item_type))
00162                                 {
00163                                         $tmp_user->addDesktopItem($a_item_id,$a_item_type);
00164                                 }
00165                         }
00166                 }
00167                 return true;
00168         }
00169 }
00170 ?>

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