ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.shibUser.php
Go to the documentation of this file.
1 <?php
2 require_once('./Services/AuthShibboleth/classes/Config/class.shibConfig.php');
3 require_once('./Services/User/classes/class.ilObjUser.php');
4 
10 class shibUser extends ilObjUser {
11 
15  protected $shibServerData;
16 
17 
24  public static function getInstance(shibServerData $shibServerData) {
25  return self::buildInstance($shibServerData);
26  }
27 
28 
34  public static function buildInstance(shibServerData $shibServerData) {
35  $shibUser = new self();
36  $shibUser->shibServerData = $shibServerData;
37  $ext_id = $shibUser->shibServerData->getLogin();
38  $shibUser->setExternalAccount($ext_id);
39  $existing_usr_id = self::getUsrIdByExtId($ext_id);
40  if ($existing_usr_id) {
41  $shibUser->setId($existing_usr_id);
42  $shibUser->read();
43  }
44  $shibUser->setAuthMode('shibboleth');
45 
46  return $shibUser;
47  }
48 
49 
50  public function updateFields() {
51  $shibConfig = shibConfig::getInstance();
52  if ($shibConfig->getUpdateFirstname()) {
53  $this->setFirstname($this->shibServerData->getFirstname());
54  }
55  if ($shibConfig->getUpdateLastname()) {
56  $this->setLastname($this->shibServerData->getLastname());
57  }
58  if ($shibConfig->getUpdateGender()) {
59  $this->setGender($this->shibServerData->getGender());
60  }
61  if ($shibConfig->getUpdateTitle()) {
62  $this->setTitle($this->shibServerData->getTitle());
63  }
64  if ($shibConfig->getUpdateInstitution()) {
66  }
67  if ($shibConfig->getUpdateDepartment()) {
68  $this->setDepartment($this->shibServerData->getDepartment());
69  }
70  if ($shibConfig->getUpdateStreet()) {
71  $this->setStreet($this->shibServerData->getStreet());
72  }
73  if ($shibConfig->getUpdateZipcode()) {
74  $this->setZipcode($this->shibServerData->getZipcode());
75  }
76  if ($shibConfig->getUpdateCountry()) {
77  $this->setCountry($this->shibServerData->getCountry());
78  }
79  if ($shibConfig->getUpdatePhoneOffice()) {
81  }
82  if ($shibConfig->getUpdatePhoneHome()) {
83  $this->setPhoneHome($this->shibServerData->getPhoneHome());
84  }
85  if ($shibConfig->getUpdatePhoneMobile()) {
87  }
88  if ($shibConfig->getUpdateFax()) {
89  $this->setFax($this->shibServerData->getFax());
90  }
91  if ($shibConfig->getUpdateMatriculation()) {
93  }
94  if ($shibConfig->getUpdateEmail()) {
95  $this->setEmail($this->shibServerData->getEmail());
96  }
97  if ($shibConfig->getUpdateHobby()) {
98  $this->setHobby($this->shibServerData->getHobby());
99  }
100  if ($shibConfig->getUpdateLanguage()) {
101  $this->setLanguage($this->shibServerData->getLanguage());
102  }
103  $this->setDescription($this->getEmail());
104  }
105 
106 
107  public function createFields() {
108  $this->setFirstname($this->shibServerData->getFirstname());
109  $this->setLastname($this->shibServerData->getLastname());
110  $this->setLogin($this->returnNewLoginName());
112  $this->setGender($this->shibServerData->getGender());
113  $this->setExternalAccount($this->shibServerData->getLogin());
114  $this->setTitle($this->shibServerData->getTitle());
115  $this->setInstitution($this->shibServerData->getInstitution());
116  $this->setDepartment($this->shibServerData->getDepartment());
117  $this->setStreet($this->shibServerData->getStreet());
118  $this->setZipcode($this->shibServerData->getZipcode());
119  $this->setCountry($this->shibServerData->getCountry());
120  $this->setPhoneOffice($this->shibServerData->getPhoneOffice());
121  $this->setPhoneHome($this->shibServerData->getPhoneHome());
122  $this->setPhoneMobile($this->shibServerData->getPhoneMobile());
123  $this->setFax($this->shibServerData->getFax());
125  $this->setEmail($this->shibServerData->getEmail());
126  $this->setHobby($this->shibServerData->getHobby());
127  $this->setTitle($this->getFullname());
128  $this->setDescription($this->getEmail());
129  $this->setLanguage($this->shibServerData->getLanguage());
130  $this->setTimeLimitOwner(7);
131  $this->setTimeLimitUnlimited(1);
132  $this->setTimeLimitFrom(time());
133  $this->setTimeLimitUntil(time());
134  $this->setActive(true);
135  }
136 
137 
138  public function create() {
139  if ($this->getLogin() != '' AND $this->getLogin() != '.') {
140  parent::create();
141  } else {
142  throw new ilUserException('No Login-name created');
143  }
144  }
145 
146 
150  protected function returnNewLoginName() {
151  $login = substr(self::cleanName($this->getFirstname()), 0, 1) . '.' . self::cleanName($this->getLastname());
152  $appendix = NULL;
153  $login_tmp = $login;
154  while (self::loginExists($login, $this->getId())) {
155  $login = $login_tmp . $appendix;
156  $appendix ++;
157  }
158 
159  return $login;
160  }
161 
162 
166  public function isNew() {
167  return (bool)($this->getId() == 0);
168  }
169 
170 
176  protected static function cleanName($name) {
177  $upas = array(
178  'ä' => 'ae',
179  'ü' => 'ue',
180  'ö' => 'oe',
181  'Ä' => 'Ae',
182  'Ü' => 'Ue',
183  'Ö' => 'Oe',
184  'é' => 'e',
185  'è' => 'e',
186  'ê' => 'e',
187  'Á' => 'A',
188  '\'' => '',
189  ' ' => '',
190  '-' => '',
191  '.' => '',
192  );
193 
194  return strtolower(strtr($name, $upas));
195  }
196 
197 
204  private static function loginExists($login, $usr_id) {
205  global $ilDB;
209  $query = 'SELECT usr_id FROM usr_data WHERE login = ' . $ilDB->quote($login, 'text');
210  $query .= ' AND usr_id != ' . $ilDB->quote($usr_id, 'integer');
211 
212  return (bool)($ilDB->numRows($ilDB->query($query)) > 0);
213  }
214 
215 
221  protected static function getUsrIdByExtId($ext_id) {
222  global $ilDB;
226  $query = 'SELECT usr_id FROM usr_data WHERE ext_account = ' . $ilDB->quote($ext_id, 'text');
227  $a_set = $ilDB->query($query);
228  if ($ilDB->numRows($a_set) == 0) {
229  return false;
230  } else {
231  $usr = $ilDB->fetchObject($a_set);
232 
233  return $usr->usr_id;
234  }
235  }
236 }
237 
238 ?>