.

CreateUsersBaseCommand Class Reference
[Usermanagement]

Create a user command to be overloaded. More...

Inheritance diagram for CreateUsersBaseCommand:
CommandChain CommandBase ICommand IAction ISerializable CreateUsersCommand

List of all members.

Protected Member Functions

  do_execute ()
  Execute this command.
  link_roles ($user, $params)
  Link Roles.
  postprocess ($user, $params)
  Postprocess.
  preprocess_check_roles (&$params)
  Check if at least one role is assigned.
  preprocess_hash_password (&$params)
  Hash the password.
  preprocess_params ($params)
  Preprocess param array.

Detailed Description

Create a user command to be overloaded.

Author:
Gerd Riesselmann

Definition at line 8 of file createusers.cmd.php.


Member Function Documentation

CreateUsersBaseCommand::do_execute (  )  [protected]

Execute this command.

Reimplemented from CommandChain.

Definition at line 12 of file createusers.cmd.php.

00012                                         {
00013                 $ret = new Status();
00014                 
00015                 $params = $this->preprocess_params($this->get_params());
00016                 
00017                 // Validate
00018                 $cmd_validate = CommandsFactory::create_command('users', 'validate', $params);
00019                 $ret->merge($cmd_validate->execute()); 
00020                 
00021                 // Insert
00022                 if ($ret->is_ok()) {
00023                         Load::commands('generics/create');
00024                         $cmd = new CreateCommand('users', $params);
00025                         $ret->merge($cmd->execute());
00026                         $this->set_result($cmd->get_result());
00027                 }
00028 
00029                 // Link Role
00030                 if ($ret->is_ok()) {
00031                         $user = $this->get_result();
00032                         $ret->merge($this->link_roles($user, $params));
00033                 }
00034                 // Allow overloads to do stuff 
00035                 if ($ret->is_ok()) {
00036                         $user = $this->get_result();
00037                         $ret->merge($this->postprocess($user, $params));
00038                 }
00039                 
00040                 return $ret;
00041         }
CreateUsersBaseCommand::link_roles ( user,
params  
) [protected]

Link Roles.

Parameters:
DAOUsers  $user
array  $params
Returns:
Status

Definition at line 50 of file createusers.cmd.php.

00050                                                       {
00051                 $ret = new Status();
00052                 
00053                 $roles = Arr::force(Arr::get_item($params, 'roles', array()));
00054                 // Append link creation commands
00055                 foreach($roles as $role) {
00056                         $params_link = array(
00057                                 'id_user' => $user->id,
00058                                 'id_role' => $role 
00059                         );
00060                         $this->append(CommandsFactory::create_command('users2userroles', 'create', $params_link));
00061                 }
00062                 
00063                 return $ret;
00064         }
CreateUsersBaseCommand::postprocess ( user,
params  
) [protected]

Postprocess.

Parameters:
DAOUsers  $user
array  $params
Returns:
Status

Definition at line 73 of file createusers.cmd.php.

00073                                                        {
00074                 return new Status();
00075         }
CreateUsersBaseCommand::preprocess_check_roles ( &$  params  )  [protected]

Check if at least one role is assigned.

Since:
0.5.1

Definition at line 114 of file createusers.cmd.php.

00114                                                             {
00115                 // Check roles
00116                 $roles = Arr::force(Arr::get_item($params, 'roles', array()));
00117                 if (count($roles) == 0) {
00118                         // Assign at least default role
00119                         $role = UserRoles::get_by_name(Config::get_value(ConfigUsermanagement::DEFAULT_ROLE));
00120                         if ($role) {
00121                                 $roles[] = $role->id;
00122                                 $params['roles'] = $roles;
00123                         }       
00124                 }                       
00125         }
CreateUsersBaseCommand::preprocess_hash_password ( &$  params  )  [protected]

Hash the password.

Since:
0.5.1

Definition at line 97 of file createusers.cmd.php.

00097                                                               {
00098                 $params['hash_type'] = Arr::get_item($params, 'hash_type', Config::get_value(ConfigUsermanagement::HASH_TYPE, 'md5'));
00099                 
00100                 $pwd = Arr::get_item($params, 'password', '');
00101                 if (!empty($pwd)) {
00102                         $params['password'] = Users::create_hash($pwd, $params['hash_type']);
00103                 }
00104                 else {
00105                         unset($params['password']);
00106                 }                       
00107         }
CreateUsersBaseCommand::preprocess_params ( params  )  [protected]

Preprocess param array.

Parameters:
array  $params
Returns:
array

Definition at line 83 of file createusers.cmd.php.

00083                                                       {
00084                 $params['tos_version'] = Config::get_value(ConfigUsermanagement::TOS_VERSION);
00085                 // Encrypt password
00086                 $params['hash_type'] = Config::get_value(ConfigUsermanagement::HASH_TYPE, 'md5');
00087                 $this->preprocess_hash_password($params);
00088                 $this->preprocess_check_roles($params);
00089                 return $params;
00090         }

The documentation for this class was generated from the following file: