ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilServicesUserTasks.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2016 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
12 {
13  const ANON_FIRSTNAME = 'Anonymous';
14  const ANON_LASTNAME = 'Exam-User';
15  const ANON_LOGIN_PREFIX = 'EX-';
16  const ANON_GENDER = 'm';
17  const PASSWORD_CHARACTERSET = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
18 
25  public static function createAnonymousUsers($context, $params)
26  {
27  $input_params = $params[0];
28  $output_params =$params[1];
29 
30  // IN: useridlist
31  // OUT: anonaccountlist, userIdList
32 
33  $pseudonymousUserMap = array();
34  $discloseMap = array();
35  $usrIdList = array();
36 
37  foreach($input_params['usrIdList'] as $user_id)
38  {
39  $source_user = new ilObjUser($user_id, false);
40  $anon_login = self::getValidLogin();
41  $anon_password = self::generatePassword();
42  $new_id = self::createUser(
43  $anon_login,
44  $anon_password,
45  $source_user->getEmail()
46  );
47 
48  $pseudonymousUserMap[] = array(
49  'Original User' => $user_id,
50  'Anonymous User' => $new_id
51  );
52 
53  $discloseMap[] = array(
54  'Original User' => $user_id,
55  'Original Login' => $source_user->getLogin(),
56  'Original Firstname' => $source_user->getFirstname(),
57  'Original Lastname' => $source_user->getLastname(),
58  'Original Matriculation' => $source_user->getMatriculation(),
59  'Original Gender' => $source_user->getGender(),
60  'Original EMail' => $source_user->getEmail(),
61  'Anon User' => $new_id,
62  'Anon Login' => $anon_login,
63  'Anon Password' => $anon_password
64  );
65 
66  $usrIdList[] = $new_id;
67  }
68 
69  return array($output_params[0] => $discloseMap);
70  }
71 
75  protected static function getValidLogin()
76  {
77  do
78  {
79  $login = self::ANON_LOGIN_PREFIX.str_pad(rand(0,9999999),7,STR_PAD_LEFT);
80  } while ( ilObjUser::_loginExists($login) );
81 
82  return $login;
83  }
84 
90  protected static function generatePassword($length = 8)
91  {
92  $password = array();
93  $setLength = strlen(self::PASSWORD_CHARACTERSET) - 1;
94 
95  for ($i = 0; $i < $length; $i++)
96  {
97  $index = rand(0, $setLength);
98  $password[] = self::PASSWORD_CHARACTERSET[$index];
99  }
100 
101  return implode($password);
102  }
103 
111  protected static function createUser($login, $password, $email)
112  {
113  global $DIC;
114  $rbacadmin = $DIC['rbacadmin'];
115 
116  $user = new ilObjUser();
117  $user->setTimeLimitUnlimited(TRUE);
118  $user->setFirstname(self::ANON_FIRSTNAME);
119  $user->setLastname(self::ANON_LASTNAME);
120  $user->setEmail($email);
121  $user->setGender(self::ANON_GENDER);
122  $user->setPasswd($password, IL_PASSWD_PLAIN);
123  $user->setLogin($login);
124  $user->setActive(true, 6);
125  $user->create();
126 
127  $user->setLastPasswordChangeTS(0);
128  $user->saveAsNew();
129 
130  $user->setPref('send_info_mails', 'n');
131  $user->writePrefs();
132 
133  $rbacadmin->assignUser(4, $user->getId(), true);
134 
135  return $user->getId();
136  }
137 
142  public static function repersonalizeUsers($context, $params)
143  {
144  // IN: discloseMap
145  $input_params = $params[0];
146  $output_params =$params[1];
147 
148  foreach($input_params['discloseMap'] as $disclose_entry)
149  {
150  $anon_user = new ilObjUser($disclose_entry['Anon User'], false);
151  $anon_user->setFirstname($disclose_entry['Original Firstname']);
152  $anon_user->setLastname($disclose_entry['Original Lastname']);
153  $anon_user->setMatriculation($disclose_entry['Original Matriculation']);
154  $anon_user->setGender($disclose_entry['Original Gender']);
155  $anon_user->update();
156  }
157 
158  // OUT: void
159  }
160 }
const IL_PASSWD_PLAIN
static generatePassword($length=8)
static createAnonymousUsers($context, $params)
static repersonalizeUsers($context, $params)
static createUser($login, $password, $email)
static _loginExists($a_login, $a_user_id=0)
check if a login name already exists You may exclude a user from the check by giving his user id as 2...
Class ilServicesUserTasks.
Create styles array
The data for the language used.
global $DIC
$params
Definition: example_049.php:96