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

Services/Registration/classes/class.ilRegistrationEmailRoleAssignments.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 
00033 define('IL_REG_MISSING_DOMAIN',1);
00034 define('IL_REG_MISSING_ROLE',2);
00035 
00036 class ilRegistrationRoleAssignments
00037 {
00038         var $assignments = array();
00039         var $default_role = 0;
00040 
00041         function ilRegistrationRoleAssignments()
00042         {
00043                 global $ilDB;
00044 
00045                 $this->db =& $ilDB;
00046                 $this->__read();
00047         }
00048 
00049         function getRoleByEmail($a_email)
00050         {
00051                 global $ilObjDataCache;
00052 
00053                 foreach($this->assignments as $assignment)
00054                 {
00055                         if(!$assignment['domain'] or !$assignment['role'])
00056                         {
00057                                 continue;
00058                         }
00059                         if(stristr($a_email,$assignment['domain']))
00060                         {
00061                                 // check if role exists
00062                                 if(!$ilObjDataCache->lookupType($assignment['role']))
00063                                 {
00064                                         continue;
00065                                 }
00066                                 return $assignment['role'];
00067                         }
00068                 }
00069                 // return default
00070                 return $this->getDefaultRole();
00071         }
00072         
00073         function getAssignments()
00074         {
00075                 return $this->assignments ? $this->assignments : array();
00076         }
00077 
00078         function setDomain($a_id,$a_domain)
00079         {
00080                 $this->assignments[$a_id]['domain'] = $a_domain;
00081         }
00082         function setRole($a_id,$a_role)
00083         {
00084                 $this->assignments[$a_id]['role'] = $a_role;
00085         }
00086 
00087         function getDefaultRole()
00088         {
00089                 return $this->default_role;
00090         }
00091         function setDefaultRole($a_role_id)
00092         {
00093                 $this->default_role = $a_role_id;
00094         }
00095 
00096         function delete($a_id)
00097         {
00098                 global $ilDB;
00099                 
00100                 $query = "DELETE FROM reg_email_role_assignments ".
00101                         "WHERE assignment_id = ".$ilDB->quote($a_id);
00102 
00103                 $this->db->query($query);
00104 
00105                 $this->__read();
00106                 return true;
00107         }
00108 
00109         function add()
00110         {
00111                 $query = "INSERT INTO reg_email_role_assignments ".
00112                         "SET domain = '', ".
00113                         "role = ''";
00114 
00115                 $this->db->query($query);
00116 
00117                 $this->__read();
00118                 return true;
00119         }
00120 
00121         function save()
00122         {
00123                 global $ilias, $ilDB;
00124 
00125                 // Save default role
00126                 $ilias->setSetting('reg_default_role',$this->getDefaultRole());
00127 
00128                 foreach($this->assignments as $assignment)
00129                 {
00130                         $query = "UPDATE reg_email_role_assignments ".
00131                                 "SET domain = ".$ilDB->quote($assignment['domain']).", ".
00132                                 "role = ".$ilDB->quote($assignment['role'])." ".
00133                                 "WHERE assignment_id = ".$ilDB->quote($assignment['id']);
00134 
00135                         $this->db->query($query);
00136                 }
00137                 return true;
00138         }
00139 
00140         function validate()
00141         {
00142                 foreach($this->assignments as $assignment)
00143                 {
00144                         if(!strlen($assignment['domain']))
00145                         {
00146                                 return IL_REG_MISSING_DOMAIN;
00147                         }
00148                         if(!$assignment['role'])
00149                         {
00150                                 return IL_REG_MISSING_ROLE;
00151                         }
00152                 }
00153                 if(!$this->getDefaultRole())
00154                 {
00155                         return IL_REG_MISSING_ROLE;
00156                 }
00157                 return 0;
00158         }
00159                         
00160         
00161 
00162 
00163         // Private
00164         function __read()
00165         {
00166                 global $ilias, $ilDB;
00167 
00168                 $query = "SELECT * FROM reg_email_role_assignments ";
00169                 $res = $this->db->query($query);
00170 
00171                 $this->assignments = array();
00172                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00173                 {
00174                         $this->assignments[$row->assignment_id]['id'] =  $row->assignment_id;
00175                         $this->assignments[$row->assignment_id]['role'] = $row->role;
00176                         $this->assignments[$row->assignment_id]['domain'] = $row->domain;
00177                 }
00178 
00179                 $this->default_role = $ilias->getSetting('reg_default_role');
00180 
00181                 return true;
00182         }
00183 }
00184 ?>

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