Public Member Functions | Data Fields

ilUserImportParser Class Reference

Inheritance diagram for ilUserImportParser:
Collaboration diagram for ilUserImportParser:

Public Member Functions

 ilUserImportParser ($a_xml_file, $a_mode=IL_USER_IMPORT, $a_conflict_rule=IL_FAIL_ON_CONFLICT)
 Constructor.
 setFolderId ($a_folder_id)
 assign users to this folder (normally the usr_folder) But if called from local admin => the ref_id of the category public
 getFolderId ()
 setHandlers ($a_xml_parser)
 set event handler should be overwritten by inherited class private
 startParsing ()
 start the parser
 setRoleAssignment ($a_assign)
 set import to local role assignemt
 buildTag ($type, $name, $attr="")
 generate a tag with given name and attributes
 handlerBeginTag ($a_xml_parser, $a_name, $a_attribs)
 handler for begin of element
 extractRolesBeginTag ($a_xml_parser, $a_name, $a_attribs)
 handler for begin of element in extract roles mode
 importBeginTag ($a_xml_parser, $a_name, $a_attribs)
 handler for begin of element in user import mode
 verifyBeginTag ($a_xml_parser, $a_name, $a_attribs)
 handler for begin of element
 handlerEndTag ($a_xml_parser, $a_name)
 handler for end of element
 extractRolesEndTag ($a_xml_parser, $a_name)
 handler for end of element when in extract roles mode.
 getRoleObject ($a_role_id)
 Returns the parent object of the role folder object which contains the specified role.
 getCourseMembersObjectForRole ($a_role_id)
 Returns the parent object of the role folder object which contains the specified role.
 assignToRole ($a_user_obj, $a_role_id)
 Assigns a user to a role.
 detachFromRole ($a_user_obj, $a_role_id)
 Detachs a user from a role.
 importEndTag ($a_xml_parser, $a_name)
 handler for end of element when in import user mode.
 verifyEndTag ($a_xml_parser, $a_name)
 handler for end of element when in verify mode.
 handlerCharacterData ($a_xml_parser, $a_data)
 handler for character data
 getCollectedRoles ()
 get collected roles
 getUserCount ()
 get count of User elements
 logWarning ($aLogin, $aMessage)
 Writes a warning log message to the protocol.
 logFailure ($aLogin, $aMessage)
 Writes a failure log message to the protocol.
 getProtocol ()
 Returns the protocol.
 getProtocolAsHTML ($a_log_title)
 Returns the protocol as a HTML table.
 isSuccess ()
 Returns true, if the import was successful.
 getErrorLevel ()
 Returns the error level.

Data Fields

 $folder_id
 $roles
 $action
 The Action attribute determines what to do for the current User element.
 $protocol
 The variable holds the protocol of the import.
 $logins
 This variable is used to collect each login that we encounter in the import data.
 $conflict_rule
 Conflict handling rule.
 $error_level
 This variable is used to report the error level of the validation process or the importing process.
 $currPasswordType
 The password type of the current user.
 $currPassword
 The password of the current user.
 $currActive
 The active state of the current user.
 $userCount
 The count of user elements in the XML file.
 $localRoleCache
 Cached local roles.

Detailed Description

Definition at line 47 of file class.ilUserImportParser.php.


Member Function Documentation

ilUserImportParser::assignToRole ( a_user_obj,
a_role_id 
)

Assigns a user to a role.

Definition at line 471 of file class.ilUserImportParser.php.

References $rbacadmin, $rbacreview, $tree, getCourseMembersObjectForRole(), and getRoleObject().

Referenced by importEndTag().

        {
                require_once "classes/class.ilObjRole.php";
                require_once "course/classes/class.ilObjCourse.php";
                require_once "course/classes/class.ilCourseMembers.php";

                global $rbacreview, $rbacadmin, $tree;

                // If it is a course role, use the ilCourseMember object to assign
                // the user to the role
                $role_obj = $this->getRoleObject($a_role_id);
                if (substr($role_obj->getTitle(),0,6) == 'il_crs')
                {
                        $crsmembers_obj = $this->getCourseMembersObjectForRole($a_role_id);

                        switch (substr($role_obj->getTitle(),0,12))
                        {
                                case 'il_crs_admin' :
                                        $crs_role = $crsmembers_obj->ROLE_ADMIN;
                                        $crs_status = $crsmembers_obj->STATUS_NO_NOTIFY;
                                        break;
                                case 'il_crs_tutor' :
                                        $crs_role = $crsmembers_obj->ROLE_TUTOR;
                                        $crs_status = $crsmembers_obj->STATUS_NO_NOTIFY;
                                        break;
                                case 'il_crs_membe' :
                                default :
                                        $crs_role = $crsmembers_obj->ROLE_MEMBER;
                                        $crs_status = $crsmembers_obj->STATUS_UNBLOCKED;
                                        break;
                        }

                        if ($crsmembers_obj->isAssigned($a_user_obj->getID()))
                        {
                                $crsmembers_obj->update($a_user_obj->getID(), $crs_role, $crs_status, false);
                        }
                        else
                        {
                                $crsmembers_obj->add($a_user_obj, $crs_role);
                        }
                }
                // If it is not a course role, use RBAC to assign the user to the role
                else
                {
                        $rbacadmin->assignUser($a_role_id, $a_user_obj->getId(), true);
                }
        }

Here is the call graph for this function:

Here is the caller graph for this function:

ilUserImportParser::buildTag ( type,
name,
attr = "" 
)

generate a tag with given name and attributes

Parameters:
string "start" | "end" for starting or ending tag
string element/tag name
array array of attributes

Definition at line 249 of file class.ilUserImportParser.php.

References $type.

        {
                $tag = "<";

                if ($type == "end")
                        $tag.= "/";

                $tag.= $name;

                if (is_array($attr))
                {
                        while (list($k,$v) = each($attr))
                                $tag.= " ".$k."=\"$v\"";
                }

                $tag.= ">";

                return $tag;
        }

ilUserImportParser::detachFromRole ( a_user_obj,
a_role_id 
)

Detachs a user from a role.

Definition at line 521 of file class.ilUserImportParser.php.

References $rbacadmin, $rbacreview, $role_id, $tree, getCourseMembersObjectForRole(), and getRoleObject().

Referenced by importEndTag().

        {
                require_once "classes/class.ilObjRole.php";
                require_once "course/classes/class.ilObjCourse.php";
                require_once "course/classes/class.ilCourseMembers.php";

                global $rbacreview, $rbacadmin, $tree;

                // If it is a course role, use the ilCourseMember object to assign
                // the user to the role
                $role_obj = $this->getRoleObject($a_role_id);
                if (substr($role_obj->getTitle(),0,6) == 'il_crs')
                {
                        $crsmembers_obj = $this->getCourseMembersObjectForRole($role_id);
                        switch (substr($role_obj->getTitle(),0,12)) 
                        {
                                case 'il_crs_membe' :
                                        if ($crsmembers_obj->isMember($a_user_obj->getId()))
                                        {
                                                $crsmembers_obj->delete($a_user_obj->getId());
                                        }
                                        break;
                                case 'il_crs_admin' :
                                        if ($crsmembers_obj->isAdmin($a_user_obj->getId()))
                                        {
                                                $crsmembers_obj->delete($a_user_obj->getId());
                                        }
                                        break;
                                case 'il_crs_tutor' :
                                        if ($crsmembers_obj->isTutor($a_user_obj->getId()))
                                        {
                                                $crsmembers_obj->delete($a_user_obj->getId());
                                        }
                                        break;
                        }
                }
                // If it is not a course role, use RBAC to assign the user to the role
                else
                {
                        $rbacadmin->deassignUser($a_role_id, $a_user_obj->getId());
                }
        }

Here is the call graph for this function:

Here is the caller graph for this function:

ilUserImportParser::extractRolesBeginTag ( a_xml_parser,
a_name,
a_attribs 
)

handler for begin of element in extract roles mode

Definition at line 293 of file class.ilUserImportParser.php.

Referenced by handlerBeginTag().

        {
                switch($a_name)
                {
                        case "Role":
                                $this->current_role_id = $a_attribs["Id"];
                                $this->current_role_type = $a_attribs["Type"];
                                break;
                }
        }

Here is the caller graph for this function:

ilUserImportParser::extractRolesEndTag ( a_xml_parser,
a_name 
)

handler for end of element when in extract roles mode.

Definition at line 415 of file class.ilUserImportParser.php.

Referenced by handlerEndTag().

        {
                switch($a_name)
                {
                        case "Role":
                                $this->roles[$this->current_role_id]["name"] = $this->cdata;
                                $this->roles[$this->current_role_id]["type"] =
                                        $this->current_role_type;
                                break;
                }
        }

Here is the caller graph for this function:

ilUserImportParser::getCollectedRoles (  ) 

get collected roles

Definition at line 1094 of file class.ilUserImportParser.php.

        {
                return $this->roles;
        }

ilUserImportParser::getCourseMembersObjectForRole ( a_role_id  ) 

Returns the parent object of the role folder object which contains the specified role.

Definition at line 448 of file class.ilUserImportParser.php.

References $rbacadmin, $rbacreview, and $tree.

Referenced by assignToRole(), and detachFromRole().

        {
                global $rbacreview, $rbacadmin, $tree;
                
                if (array_key_exists($a_role_id.'_courseMembersoObject', $this->localRoleCache)) 
                {
                        return $this->localRoleCache[$a_role_id];
                }
                else
                {
                        $rolf_refs = $rbacreview->getFoldersAssignedToRole($a_role_id,true);
                        $course_ref = $tree->getParentId($rolf_refs[0]);
                        $course_obj = new ilObjCourse($course_ref, true);
                        $crsmembers_obj = new ilCourseMembers($course_obj);
                        $this->localRoleCache[$a_role_id.'_courseMembersObject'] = $crsmembers_obj;
                        return $crsmembers_obj;
                }
                
        }

Here is the caller graph for this function:

ilUserImportParser::getErrorLevel (  ) 

Returns the error level.

Returns:
IL_IMPORT_SUCCESS | IL_IMPORT_WARNING | IL_IMPORT_FAILURE

Definition at line 1204 of file class.ilUserImportParser.php.

        {
                return $this->error_level;
        }

ilUserImportParser::getFolderId (  ) 

Definition at line 207 of file class.ilUserImportParser.php.

Referenced by importEndTag().

        {
                return $this->folder_id;
        }

Here is the caller graph for this function:

ilUserImportParser::getProtocol (  ) 

Returns the protocol.

The protocol is an associative array. Keys are login names. Values are non-associative arrays. Each array element contains an error message.

Definition at line 1155 of file class.ilUserImportParser.php.

Referenced by getProtocolAsHTML().

        {
                return $this->protocol;
        }

Here is the caller graph for this function:

ilUserImportParser::getProtocolAsHTML ( a_log_title  ) 

Returns the protocol as a HTML table.

Definition at line 1162 of file class.ilUserImportParser.php.

References ilSaxParser::$lng, and getProtocol().

        {
                global $lng;

                $block = new ilTemplate("tpl.usr_import_log_block.html", true, true);
                $block->setVariable("TXT_LOG_TITLE", $a_log_title);
                $block->setVariable("TXT_MESSAGE_ID", $lng->txt("login"));
                $block->setVariable("TXT_MESSAGE_TEXT", $lng->txt("message"));
                foreach ($this->getProtocol() as $login => $messages)
                {
                        $block->setCurrentBlock("log_row");
                        $reason = "";
                        foreach ($messages as $message)
                        {
                                if ($reason == "")
                                {
                                        $reason = $message;
                                }
                                else
                                {
                                        $reason = $reason."<br>".$message;
                                }
                        }
                        $block->setVariable("MESSAGE_ID", $login);
                        $block->setVariable("MESSAGE_TEXT", $reason);
                        $block->parseCurrentBlock();
                }
                return $block->get();
        }

Here is the call graph for this function:

ilUserImportParser::getRoleObject ( a_role_id  ) 

Returns the parent object of the role folder object which contains the specified role.

Definition at line 430 of file class.ilUserImportParser.php.

Referenced by assignToRole(), and detachFromRole().

        {
                if (array_key_exists($a_role_id, $this->localRoleCache)) 
                {
                        return $this->localRoleCache[$a_role_id];
                }
                else
                {
                        $role_obj = new ilObjRole($a_role_id, false);
                        $role_obj->read();
                        $this->localRoleCache[$a_role_id] = $role_obj;
                        return $role_obj;
                }
                
        }

Here is the caller graph for this function:

ilUserImportParser::getUserCount (  ) 

get count of User elements

Definition at line 1101 of file class.ilUserImportParser.php.

        {
                return $this->userCount;
        }

ilUserImportParser::handlerBeginTag ( a_xml_parser,
a_name,
a_attribs 
)

handler for begin of element

Definition at line 272 of file class.ilUserImportParser.php.

References extractRolesBeginTag(), importBeginTag(), and verifyBeginTag().

        {
                switch ($this->mode) 
                {
                        case IL_EXTRACT_ROLES :
                                $this->extractRolesBeginTag($a_xml_parser, $a_name, $a_attribs);
                                break;
                        case IL_USER_IMPORT :
                                $this->importBeginTag($a_xml_parser, $a_name, $a_attribs);
                                break;
                        case IL_VERIFY :
                                $this->verifyBeginTag($a_xml_parser, $a_name, $a_attribs);
                                break;
                }

                $this->cdata = "";
        }

Here is the call graph for this function:

ilUserImportParser::handlerCharacterData ( a_xml_parser,
a_data 
)

handler for character data

Definition at line 1073 of file class.ilUserImportParser.php.

        {
                // i don't know why this is necessary, but
                // the parser seems to convert "&gt;" to ">" and "&lt;" to "<"
                // in character data, but we don't want that, because it's the
                // way we mask user html in our content, so we convert back...
                $a_data = str_replace("<","&lt;",$a_data);
                $a_data = str_replace(">","&gt;",$a_data);

                // DELETE WHITESPACES AND NEWLINES OF CHARACTER DATA
                $a_data = preg_replace("/\n/","",$a_data);
                $a_data = preg_replace("/\t+/","",$a_data);
                if(!empty($a_data))
                {
                        $this->cdata .= $a_data;
                }
        }

ilUserImportParser::handlerEndTag ( a_xml_parser,
a_name 
)

handler for end of element

Definition at line 396 of file class.ilUserImportParser.php.

References extractRolesEndTag(), importEndTag(), and verifyEndTag().

        {
                switch ($this->mode) 
                {
                        case IL_EXTRACT_ROLES :
                                $this->extractRolesEndTag($a_xml_parser, $a_name);
                                break;
                        case IL_USER_IMPORT :
                                $this->importEndTag($a_xml_parser, $a_name);
                                break;
                        case IL_VERIFY :
                                $this->verifyEndTag($a_xml_parser, $a_name);
                                break;
                }
        }

Here is the call graph for this function:

ilUserImportParser::ilUserImportParser ( a_xml_file,
a_mode = IL_USER_IMPORT,
a_conflict_rule = IL_FAIL_ON_CONFLICT 
)

Constructor.

Parameters:
string $a_xml_file xml file
int $a_mode IL_EXTRACT_ROLES | IL_USER_IMPORT | IL_VERIFY
int $a_conflict_rue IL_FAIL_ON_CONFLICT | IL_UPDATE_ON_CONFLICT | IL_IGNORE_ON_CONFLICT

public

Definition at line 183 of file class.ilUserImportParser.php.

References ilSaxParser::$lng, $tree, and ilSaxParser::ilSaxParser().

        {
                global $lng, $tree;

                $this->roles = array();
                $this->mode = $a_mode;
                $this->conflict_rule = $a_conflict_rule;
                $this->error_level = IL_IMPORT_SUCCESS;
                $this->protocol = array();
                $this->logins = array();
                $this->userCount = 0;
                $this->localRoleCache = array();
                parent::ilSaxParser($a_xml_file);
        }

Here is the call graph for this function:

ilUserImportParser::importBeginTag ( a_xml_parser,
a_name,
a_attribs 
)

handler for begin of element in user import mode

Definition at line 306 of file class.ilUserImportParser.php.

Referenced by handlerBeginTag().

        {
                switch($a_name)
                {
                        case "Role":
                                $this->current_role_id = $a_attribs["Id"];
                                $this->current_role_type = $a_attribs["Type"];
                                $this->current_role_action = (is_null($a_attribs["Action"])) ? "Assign" : $a_attribs["Action"];
                                break;

                        case "User":
                                $this->userCount++;
                                $this->userObj = new ilObjUser();
                                $this->userObj->setLanguage($a_attribs["Language"]);
                                $this->userObj->setImportId($a_attribs["Id"]);
                                $this->action = (is_null($a_attribs["Action"])) ? "Insert" : $a_attribs["Action"];
                                $this->currPassword = null;
                                $this->currPasswordType = null;
                                $this->currActive = null;
                                break;

                        case "Password":
                                $this->currPasswordType = $a_attribs["Type"];
                                break;
                }
        }

Here is the caller graph for this function:

ilUserImportParser::importEndTag ( a_xml_parser,
a_name 
)

handler for end of element when in import user mode.

Definition at line 567 of file class.ilUserImportParser.php.

References ilSaxParser::$ilias, $ilUser, ilSaxParser::$lng, $rbacadmin, $rbacreview, $role_id, $user_id, assignToRole(), detachFromRole(), getFolderId(), ilObjUser::getUserIdByLogin(), logFailure(), and logWarning().

Referenced by handlerEndTag().

        {
                global $ilias, $rbacadmin, $rbacreview, $ilUser, $lng;

                switch($a_name)
                {
                        case "Role":
                                $this->roles[$this->current_role_id]["name"] = $this->cdata;
                                $this->roles[$this->current_role_id]["type"] = $this->current_role_type;
                                $this->roles[$this->current_role_id]["action"] = $this->current_role_action;
                                break;

                        case "User":
                                // Fetch the user_id from the database
                                $user_id = ilObjUser::getUserIdByLogin($this->userObj->getLogin());

                                // Handle conflicts
                                switch ($this->conflict_rule)
                                {
                                        case IL_FAIL_ON_CONFLICT :
                                                // do not change action
                                                break;
                                        case IL_UPDATE_ON_CONFLICT :
                                                switch ($this->action)
                                                {
                                                        case "Insert" :
                                                                if ($user_id) 
                                                                {
                                                                        $this->logWarning($this->userObj->getLogin(),sprintf($lng->txt("usrimport_action_replaced"),"Insert","Update"));
                                                                        $this->action = "Update";
                                                                }
                                                                break;
                                                        case "Update" :
                                                                if (! $user_id) 
                                                                {
                                                                        $this->logWarning($this->userObj->getLogin(),sprintf($lng->txt("usrimport_action_replaced"),"Update","Insert"));
                                                                        $this->action = "Insert";
                                                                }
                                                                break;
                                                        case "Delete" :
                                                                if (! $user_id) 
                                                                {
                                                                        $this->logWarning($this->userObj->getLogin(),sprintf($lng->txt("usrimport_action_ignored"),"Delete"));
                                                                        $this->action = "Ignore";
                                                                }
                                                                break;
                                                }
                                                break;
                                        case IL_IGNORE_ON_CONFLICT :
                                                switch ($this->action)
                                                {
                                                        case "Insert" :
                                                                if ($user_id) 
                                                                {
                                                                        $this->logWarning($this->userObj->getLogin(),sprintf($lng->txt("usrimport_action_ignored"),"Insert"));
                                                                        $this->action = "Ignore";
                                                                }
                                                                break;
                                                        case "Update" :
                                                                if (! $user_id) 
                                                                {
                                                                        $this->logWarning($this->userObj->getLogin(),sprintf($lng->txt("usrimport_action_ignored"),"Update"));
                                                                        $this->action = "Ignore";
                                                                }
                                                                break;
                                                        case "Delete" :
                                                                if (! $user_id) 
                                                                {
                                                                        $this->logWarning($this->userObj->getLogin(),sprintf($lng->txt("usrimport_action_ignored"),"Delete"));
                                                                        $this->action = "Ignore";
                                                                }
                                                                break;
                                                }
                                                break;
                                }

                                // Perform the action
                                switch ($this->action)
                                {
                                        case "Insert" :
                                                if ($user_id) 
                                                {
                                                        $this->logFailure($this->userObj->getLogin(),$lng->txt("usrimport_cant_insert"));
                                                }
                                                else
                                                {
                                                        switch ($this->currPasswordType)
                                                        {
                                                                case "ILIAS2":
                                                                        $this->userObj->setPasswd($this->currPassword, IL_PASSWD_CRYPT);
                                                                        break;

                                                                case "ILIAS3":
                                                                        $this->userObj->setPasswd($this->currPassword, IL_PASSWD_MD5);
                                                                        break;
                                                        }

                                                        $this->userObj->setTitle($this->userObj->getFullname());
                                                        $this->userObj->setDescription($this->userObj->getEmail());

                                                        // default time limit settings

                                                        $this->userObj->setTimeLimitOwner($this->getFolderId());
                                                        $this->userObj->setTimeLimitUnlimited($ilias->account->getTimeLimitUnlimited());
                                                        $this->userObj->setTimeLimitFrom($ilias->account->getTimeLimitFrom());
                                                        $this->userObj->setTimeLimitUntil($ilias->account->getTimeLimitUntil());
                                                        $this->userObj->setActive($this->currActive == 'true' || is_null($this->currActive), $ilUser->getId());

                                                        $this->userObj->create();

                                                        //insert user data in table user_data
                                                        $this->userObj->saveAsNew(false);

                                                        // set user preferences
                                                        $this->userObj->setPref("skin",
                                                                $ilias->ini->readVariable("layout","skin"));
                                                        $this->userObj->setPref("style",
                                                                $ilias->ini->readVariable("layout","style"));
                                                        $this->userObj->writePrefs();

                                                        //set role entries
                                                        foreach($this->roles as $role_id => $role)
                                                        {
                                                                if ($this->role_assign[$role_id])
                                                                {
                                                                        $this->assignToRole($this->userObj, $this->role_assign[$role_id]);
                                                                }
                                                        }
                                                }
                                                break;

                                        case "Update" :
                                                if (! $user_id) 
                                                {
                                                        $this->logFailure($this->userObj->getLogin(),$lng->txt("usrimport_cant_update"));
                                                }
                                                else
                                                {
                                                        $updateUser = new ilObjUser($user_id);
                                                        $updateUser->read();
                                                        $updateUser->readPrefs();
                                                        if ($this->currPassword != null)
                                                        {
                                                                switch ($this->currPasswordType)
                                                                {
                                                                        case "ILIAS2":
                                                                                $updateUser->setPasswd($this->currPassword, IL_PASSWD_CRYPT);
                                                                                break;

                                                                        case "ILIAS3":
                                                                                $updateUser->setPasswd($this->currPassword, IL_PASSWD_MD5);
                                                                                break;
                                                                }
                                                        }
                                                        if (! is_null($this->userObj->getFirstname())) $updateUser->setFirstname($this->userObj->getFirstname());
                                                        if (! is_null($this->userObj->getLastname())) $updateUser->setLastname($this->userObj->getLastname());
                                                        if (! is_null($this->userObj->getUTitle())) $updateUser->setUTitle($this->userObj->getUTitle());
                                                        if (! is_null($this->userObj->getGender())) $updateUser->setGender($this->userObj->getGender());
                                                        if (! is_null($this->userObj->getEmail())) $updateUser->setEmail($this->userObj->getEmail());
                                                        if (! is_null($this->userObj->getInstitution())) $updateUser->setInstitution($this->userObj->getInstitution());
                                                        if (! is_null($this->userObj->getStreet())) $updateUser->setStreet($this->userObj->getStreet());
                                                        if (! is_null($this->userObj->getCity())) $updateUser->setCity($this->userObj->getCity());
                                                        if (! is_null($this->userObj->getZipCode())) $updateUser->setZipCode($this->userObj->getZipCode());
                                                        if (! is_null($this->userObj->getCountry())) $updateUser->setCountry($this->userObj->getCountry());
                                                        if (! is_null($this->userObj->getPhoneOffice())) $updateUser->setPhoneOffice($this->userObj->getPhoneOffice());
                                                        if (! is_null($this->userObj->getPhoneHome())) $updateUser->setPhoneHome($this->userObj->getPhoneHome());
                                                        if (! is_null($this->userObj->getPhoneMobile())) $updateUser->setPhoneMobile($this->userObj->getPhoneMobile());
                                                        if (! is_null($this->userObj->getFax())) $updateUser->setFax($this->userObj->getFax());
                                                        if (! is_null($this->userObj->getHobby())) $updateUser->setHobby($this->userObj->getHobby());
                                                        if (! is_null($this->userObj->getComment())) $updateUser->setComment($this->userObj->getComment());
                                                        if (! is_null($this->userObj->getDepartment())) $updateUser->setDepartment($this->userObj->getDepartment());
                                                        if (! is_null($this->userObj->getMatriculation())) $updateUser->setMatriculation($this->userObj->getMatriculation());
                                                        if (! is_null($this->currActive)) $updateUser->setActive($this->currActive == "true", $ilUser->getId());
                                                        if (! is_null($this->userObj->getClientIP())) $updateUser->setClientIP($this->userObj->getClientIP());

                                                        $updateUser->update();

                                                        //update role entries
                                                        //-------------------
                                                        foreach ($this->roles as $role_id => $role)
                                                        {
                                                                if ($this->role_assign[$role_id])
                                                                {
                                                                        switch ($role["action"])
                                                                        {
                                                                                case "Assign" :
                                                                                        $this->assignToRole($updateUser, $this->role_assign[$role_id]);
                                                                                        break;
                                                                                case "Detach" :
                                                                                        $this->detachFromRole($updateUser, $this->role_assign[$role_id]);
                                                                                        break;
                                                                        }
                                                                }
                                                        }
                                                }
                                                break;
                                        case "Delete" :
                                                if (! $user_id) 
                                                {
                                                        $this->logFailure($this->userObj->getLogin(),$lng->txt("usrimport_cant_delete"));
                                                }
                                                else
                                                {
                                                        $deleteUser = new ilObjUser($user_id);
                                                        $deleteUser->delete();
                                                }
                                                break;
                                }

                                // init role array for next user
                                $this->roles = array();
                                break;

                        case "Login":
                                $this->userObj->setLogin($this->cdata);
                                break;

                        case "Password":
                                $this->currPassword = $this->cdata;
                                break;

                        case "Firstname":
                                $this->userObj->setFirstname($this->cdata);
                                break;

                        case "Lastname":
                                $this->userObj->setLastname($this->cdata);
                                $this->userObj->setFullname();
                                break;

                        case "Title":
                                $this->userObj->setUTitle($this->cdata);
                                break;

                        case "Gender":
                                $this->userObj->setGender($this->cdata);
                                break;

                        case "Email":
                                $this->userObj->setEmail($this->cdata);
                                break;

                        case "Institution":
                                $this->userObj->setInstitution($this->cdata);
                                break;

                        case "Street":
                                $this->userObj->setStreet($this->cdata);
                                break;

                        case "City":
                                $this->userObj->setCity($this->cdata);
                                break;

                        case "PostalCode":
                                $this->userObj->setZipCode($this->cdata);
                                break;

                        case "Country":
                                $this->userObj->setCountry($this->cdata);
                                break;

                        case "PhoneOffice":
                                $this->userObj->setPhoneOffice($this->cdata);
                                break;

                        case "PhoneHome":
                                $this->userObj->setPhoneHome($this->cdata);
                                break;

                        case "PhoneMobile":
                                $this->userObj->setPhoneMobile($this->cdata);
                                break;

                        case "Fax":
                                $this->userObj->setFax($this->cdata);
                                break;

                        case "Hobby":
                                $this->userObj->setHobby($this->cdata);
                                break;

                        case "Comment":
                                $this->userObj->setComment($this->cdata);
                                break;

                        case "Department":
                                $this->userObj->setDepartment($this->cdata);
                                break;

                        case "Matriculation":
                                $this->userObj->setMatriculation($this->cdata);
                                break;

                        case "Active":
                                $this->currActive = $this->cdata;
                                break;

                        case "ClientIP":
                                $this->userObj->setClientIP($this->cdata);
                                break;
                }
        }

Here is the call graph for this function:

Here is the caller graph for this function:

ilUserImportParser::isSuccess (  ) 

Returns true, if the import was successful.

Definition at line 1195 of file class.ilUserImportParser.php.

        {
                return $this->error_level == IL_IMPORT_SUCCESS;
        }

ilUserImportParser::logFailure ( aLogin,
aMessage 
)

Writes a failure log message to the protocol.

Parameters:
string login
string message

Definition at line 1133 of file class.ilUserImportParser.php.

Referenced by importEndTag(), verifyBeginTag(), and verifyEndTag().

        {
                if (! array_key_exists($aLogin, $this->protocol))
                {
                        $this->protocol[$aLogin] = array();
                }
                if ($aMessage)
                {
                        $this->protocol[$aLogin][] = $aMessage;
                }
                $this->error_level = IL_IMPORT_FAILURE;
        }

Here is the caller graph for this function:

ilUserImportParser::logWarning ( aLogin,
aMessage 
)

Writes a warning log message to the protocol.

Parameters:
string login
string message

Definition at line 1112 of file class.ilUserImportParser.php.

Referenced by importEndTag(), and verifyEndTag().

        {
                if (! array_key_exists($aLogin, $this->protocol))
                {
                        $this->protocol[$aLogin] = array();
                }
                if ($aMessage)
                {
                        $this->protocol[$aLogin][] = $aMessage;
                }
                if ($this->error_level == IL_IMPORT_SUCCESS)
                {
                        $this->error_level = IL_IMPORT_WARNING;
                }
        }

Here is the caller graph for this function:

ilUserImportParser::setFolderId ( a_folder_id  ) 

assign users to this folder (normally the usr_folder) But if called from local admin => the ref_id of the category public

Definition at line 203 of file class.ilUserImportParser.php.

        {
                $this->folder_id = $a_folder_id;
        }

ilUserImportParser::setHandlers ( a_xml_parser  ) 

set event handler should be overwritten by inherited class private

Reimplemented from ilSaxParser.

Definition at line 217 of file class.ilUserImportParser.php.

        {
                xml_set_object($a_xml_parser,$this);
                xml_set_element_handler($a_xml_parser,'handlerBeginTag','handlerEndTag');
                xml_set_character_data_handler($a_xml_parser,'handlerCharacterData');
        }

ilUserImportParser::setRoleAssignment ( a_assign  ) 

set import to local role assignemt

Parameters:
array role assignment (key: import id; value: local role id)

Definition at line 237 of file class.ilUserImportParser.php.

        {
                $this->role_assign = $a_assign;
        }

ilUserImportParser::startParsing (  ) 

start the parser

Reimplemented from ilSaxParser.

Definition at line 227 of file class.ilUserImportParser.php.

ilUserImportParser::verifyBeginTag ( a_xml_parser,
a_name,
a_attribs 
)

handler for begin of element

Definition at line 335 of file class.ilUserImportParser.php.

References ilSaxParser::$lng, and logFailure().

Referenced by handlerBeginTag().

        {
                global $lng;

                switch($a_name)
                {
                        case "Role":
                                if (is_null($a_attribs['Id'])
                                || $a_attribs['Id'] == "")
                                {
                                        $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_attribute_missing"),"Role","Id"));
                                }
                                $this->current_role_id = $a_attribs["Id"];
                                $this->current_role_type = $a_attribs["Type"];
                                if ($this->current_role_type != 'Global'
                                && $this->current_role_type != 'Local')
                                {
                                        $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_attribute_missing"),"Role","Type"));
                                }
                                $this->current_role_action = (is_null($a_attribs["Action"])) ? "Assign" : $a_attribs["Action"];
                                if ($this->current_role_action != "Assign"
                                && $this->current_role_action != "Detach")
                                {
                                        $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_attribute_value_illegal"),"Role","Action",$a_attribs["Action"]));
                                }
                                if ($this->action == "Insert"
                                && $this->current_role_action == "Detach")
                                {
                                        $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_attribute_value_inapplicable"),"Role","Action",$this->current_role_action,$this->action));
                                }
                                if ($this->action == "Delete")
                                {
                                        $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_element_inapplicable"),"Role","Delete"));
                                }
                                break;

                        case "User":
                                $this->userCount++;
                                $this->userObj = new ilObjUser();
                                $this->userObj->setLanguage($a_attribs["Language"]);
                                $this->userObj->setImportId($a_attribs["Id"]);
                                $this->action = (is_null($a_attribs["Action"])) ? "Insert" : $a_attribs["Action"];
                                if ($this->action != "Insert"
                                && $this->action != "Update"
                                && $this->action != "Delete")
                                {
                                        $this->logFailure($this->userObj->getImportId(), sprintf($lng->txt("usrimport_xml_attribute_value_illegal"),"User","Action",$a_attribs["Action"]));
                                }
                                $this->currPassword = null;
                                $this->currPasswordType = null;
                                break;

                        case "Password":
                                $this->currPasswordType = $a_attribs["Type"];
                                break;
                }
        }

Here is the call graph for this function:

Here is the caller graph for this function:

ilUserImportParser::verifyEndTag ( a_xml_parser,
a_name 
)

handler for end of element when in verify mode.

Definition at line 874 of file class.ilUserImportParser.php.

References ilSaxParser::$lng, ilObjUser::getUserIdByLogin(), logFailure(), and logWarning().

Referenced by handlerEndTag().

        {
                global $lng;

                switch($a_name)
                {
                        case "Role":
                                $this->roles[$this->current_role_id]["name"] = $this->cdata;
                                $this->roles[$this->current_role_id]["type"] = $this->current_role_type;
                                $this->roles[$this->current_role_id]["action"] = $this->current_role_action;
                                break;

                        case "User":
                                $user_exists = ilObjUser::getUserIdByLogin($this->userObj->getLogin()) != 0;

                                if (is_null($this->userObj->getLogin()))
                                {       
                                        $this->logFailure("---",sprintf($lng->txt("usrimport_xml_element_for_action_required"),"Login", "Insert"));
                                }

                                switch ($this->action)
                                {
                                        case "Insert" :
                                                if ($user_exists) 
                                                {
                                                        $this->logWarning($this->userObj->getLogin(),$lng->txt("usrimport_cant_insert"));
                                                }
                                                if (is_null($this->userObj->getGender()))
                                                {       
                                                        $this->logFailure($this->userObj->getLogin(),sprintf($lng->txt("usrimport_xml_element_for_action_required"),"Gender", "Insert"));
                                                }
                                                if (is_null($this->userObj->getFirstname()))
                                                {       
                                                        $this->logFailure($this->userObj->getLogin(),sprintf($lng->txt("usrimport_xml_element_for_action_required"),"Firstname", "Insert"));
                                                }
                                                if (is_null($this->userObj->getLastname()))
                                                {       
                                                        $this->logFailure($this->userObj->getLogin(),sprintf($lng->txt("usrimport_xml_element_for_action_required"),"Lastname", "Insert"));
                                                }
                                                if (count($this->roles) == 0)
                                                {       
                                                        $this->logFailure($this->userObj->getLogin(),sprintf($lng->txt("usrimport_xml_element_for_action_required"),"Role", "Insert"));
                                                } 
                                                else 
                                                {
                                                        $has_global_role = false;
                                                        foreach ($this->roles as $role)
                                                        {
                                                                if ($role['type'] == 'Global')
                                                                {
                                                                        $has_global_role = true;
                                                                        break;
                                                                }
                                                        }
                                                        if (! $has_global_role)
                                                        {
                                                                $this->logFailure($this->userObj->getLogin(),sprintf($lng->txt("usrimport_global_role_for_action_required"),"Insert"));
                                                        }
                                                }
                                                break;
                                        case "Update" :
                                                if (! $user_exists) 
                                                {
                                                        $this->logWarning($this->userObj->getLogin(),$lng->txt("usrimport_cant_update"));
                                                }
                                                break;
                                        case "Delete" :
                                                if (! $user_exists) 
                                                {
                                                        $this->logWarning($this->userObj->getLogin(),$lng->txt("usrimport_cant_delete"));
                                                }
                                                break;
                                }

                                // init role array for next user
                                $this->roles = array();
                                break;

                        case "Login":
                                if (array_key_exists($this->cdata, $this->logins))
                                {
                                        $this->logFailure($this->cdata, $lng->txt("usrimport_login_is_not_unique"));
                                } 
                                else
                                {
                                        $this->logins[$this->cdata] = $this->cdata;
                                }
                                $this->userObj->setLogin($this->cdata);
                                break;

                        case "Password":
                                switch ($this->currPasswordType)
                                {
                                        case "ILIAS2":
                                                $this->userObj->setPasswd($this->cdata, IL_PASSWD_CRYPT);
                                                break;

                                        case "ILIAS3":
                                                $this->userObj->setPasswd($this->cdata, IL_PASSWD_MD5);
                                                break;

                                        default :
                                                $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_attribute_value_illegal"),"Type","Password",$this->currPasswordType));
                                                break;
                                }
                                break;

                        case "Firstname":
                                $this->userObj->setFirstname($this->cdata);
                                break;

                        case "Lastname":
                                $this->userObj->setLastname($this->cdata);
                                $this->userObj->setFullname();
                                break;

                        case "Title":
                                $this->userObj->setUTitle($this->cdata);
                                break;

                        case "Gender":
                                if ($this->cdata != "m"
                                && $this->cdata != "f")
                                {
                                        $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_attribute_value_illegal"),"Gender",$this->cdata));
                                }
                                $this->userObj->setGender($this->cdata);
                                break;

                        case "Email":
                                $this->userObj->setEmail($this->cdata);
                                break;

                        case "Institution":
                                $this->userObj->setInstitution($this->cdata);
                                break;

                        case "Street":
                                $this->userObj->setStreet($this->cdata);
                                break;

                        case "City":
                                $this->userObj->setCity($this->cdata);
                                break;

                        case "PostalCode":
                                $this->userObj->setZipCode($this->cdata);
                                break;

                        case "Country":
                                $this->userObj->setCountry($this->cdata);
                                break;

                        case "PhoneOffice":
                                $this->userObj->setPhoneOffice($this->cdata);
                                break;

                        case "PhoneHome":
                                $this->userObj->setPhoneHome($this->cdata);
                                break;

                        case "PhoneMobile":
                                $this->userObj->setPhoneMobile($this->cdata);
                                break;

                        case "Fax":
                                $this->userObj->setFax($this->cdata);
                                break;

                        case "Hobby":
                                $this->userObj->setHobby($this->cdata);
                                break;

                        case "Comment":
                                $this->userObj->setComment($this->cdata);
                                break;

                        case "Department":
                                $this->userObj->setDepartment($this->cdata);
                                break;

                        case "Matriculation":
                                $this->userObj->setMatriculation($this->cdata);
                                break;

                        case "Active":
                                if ($this->cdata != "true"
                                && $this->cdata != "false")
                                {
                                        $this->logFailure($this->userObj->getLogin(), sprintf($lng->txt("usrimport_xml_attribute_value_illegal"),"Active",$this->cdata));
                                }
                                $this->currActive = $this->cdata;
                                break;
                }
        }

Here is the call graph for this function:

Here is the caller graph for this function:


Field Documentation

ilUserImportParser::$action

The Action attribute determines what to do for the current User element.

This variable supports the following values: "Insert","Update","Delete".

Definition at line 55 of file class.ilUserImportParser.php.

ilUserImportParser::$conflict_rule

Conflict handling rule.

Values: IL_FAIL_ON_CONFLICT IL_UPDATE_ON_CONFLICT IL_IGNORE_ON_CONFLICT

Definition at line 83 of file class.ilUserImportParser.php.

ilUserImportParser::$currActive

The active state of the current user.

Definition at line 159 of file class.ilUserImportParser.php.

ilUserImportParser::$currPassword

The password of the current user.

Definition at line 155 of file class.ilUserImportParser.php.

ilUserImportParser::$currPasswordType

The password type of the current user.

Definition at line 151 of file class.ilUserImportParser.php.

ilUserImportParser::$error_level

This variable is used to report the error level of the validation process or the importing process.

Values: IL_IMPORT_SUCCESS IL_IMPORT_WARNING IL_IMPORT_FAILURE

Meaning of the values when in validation mode: IL_IMPORT_WARNING Some of the entity actions can not be processed as specified in the XML file. One or more of the following conflicts have occurred:

  • An "Insert" action has been specified for a user who is already in the database.
  • An "Update" action has been specified for a user who is not in the database.
  • A "Delete" action has been specified for a user who is not in the database. IL_IMPORT_FAILURE Some of the XML elements are invalid.

Meaning of the values when in import mode: IL_IMPORT_WARNING Some of the entity actions have not beeen processed as specified in the XML file.

In IL_UPDATE_ON_CONFLICT mode, the following may have occured:

  • An "Insert" action has been replaced by a "Update" action for a user who is already in the database.
    • An "Update" action has been replaced by a "Insert" action for a user who is not in the database.
  • A "Delete" action has been replaced by a "Ignore" action for a user who is not in the database.

In IL_IGNORE_ON_CONFLICT mode, the following may have occured:

  • An "Insert" action has been replaced by a "Ignore" action for a user who is already in the database.
  • An "Update" action has been replaced by a "Ignore" action for a user who is not in the database.
    • A "Delete" action has been replaced by a "Ignore" action for a user who is not in the database.

IL_IMPORT_FAILURE The import could not be completed.

In IL_FAIL_ON_CONFLICT mode, the following may have occured:

  • An "Insert" action has failed for a user who is already in the database.
  • An "Update" action has failed for a user who is not in the database.
  • A "Delete" action has failed for a user who is not in the database.

Definition at line 146 of file class.ilUserImportParser.php.

ilUserImportParser::$folder_id

Definition at line 49 of file class.ilUserImportParser.php.

ilUserImportParser::$localRoleCache

Cached local roles.

This is used to speed up access to local roles. This is an associative array. The key is either a role_id or a role_id with the string "_parent" appended. TThe value is a role object or the object for which the role is defined

Definition at line 172 of file class.ilUserImportParser.php.

ilUserImportParser::$logins

This variable is used to collect each login that we encounter in the import data.

This variable is needed to detect duplicate logins in the import data. The variable is an associative array. (I would prefer using a set, but PHP does not appear to support sets.) Keys are logins. Values are logins.

Definition at line 74 of file class.ilUserImportParser.php.

ilUserImportParser::$protocol

The variable holds the protocol of the import.

This variable is an associative array.

  • Keys are login names of users or "missing login", if the login name is missing.
  • Values are an array of error messages associated with the login. If the value array is empty, then the user was imported successfully.

Definition at line 64 of file class.ilUserImportParser.php.

ilUserImportParser::$roles

Definition at line 50 of file class.ilUserImportParser.php.

ilUserImportParser::$userCount

The count of user elements in the XML file.

Definition at line 163 of file class.ilUserImportParser.php.


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