Public Member Functions | Data Fields | Static Public Attributes

ilGroupImportParser Class Reference

Group Import Parser. More...

Inheritance diagram for ilGroupImportParser:
Collaboration diagram for ilGroupImportParser:

Public Member Functions

 ilGroupImportParser ($a_xml, $a_parent_id)
 Constructor.
 __pushParentId ($a_id)
 __popParentId ()
 __getParentId ()
 setHandlers ($a_xml_parser)
 set event handler should be overwritten by inherited class private
 startParsing ()
 start the parser
 handlerBeginTag ($a_xml_parser, $a_name, $a_attribs)
 handler for begin of element
 handlerEndTag ($a_xml_parser, $a_name)
 handlerCharacterData ($a_xml_parser, $a_data)
 handler for character data
 __save ()
 __saveFolder ()
 __saveFile ()
 __assignMembers ()
 __initGroupObject ()
 __initFolderObject ()
 __initImportFileObject ()
 __initFileObject ()
 __destroyFolderObject ()
 __parseId ($a_id)
 setMode ($mode)
 setGroup (&$grp)

Data Fields

 $group_data
 $group_obj
 $parent
 $counter
 $mode
 $grp

Static Public Attributes

static $CREATE = 1
static $UPDATE = 2

Detailed Description

Group Import Parser.

Author:
Stefan Meyer <smeyer@databay.de>
Version:
Id:
class.ilGroupImportParser.php 16330 2008-04-08 12:08:18Z rkuester

Definition at line 37 of file class.ilGroupImportParser.php.


Member Function Documentation

ilGroupImportParser::__assignMembers (  ) 

Definition at line 405 of file class.ilGroupImportParser.php.

References ilSaxParser::$ilias, $user, and __parseId().

Referenced by __save().

        {
                global $ilias,$ilUser;


                $this->group_obj->addMember($ilUser->getId(),$this->group_obj->getDefaultAdminRole());
#print_r($this->group_data["admin"]["attach"]);
                // attach ADMINs
                if (count($this->group_data["admin"]["attach"]))
                {

                        foreach($this->group_data["admin"]["attach"] as $user)
                        {
                                if($id_data = $this->__parseId($user))
                                {
                                        if($id_data['local'] or $id_data['imported'])
                                        {
//                                              if (!$this->group_obj->isMember($id_data['usr_id']))
                                                {
                                                        $this->group_obj->addMember($id_data['usr_id'], $this->group_obj->getDefaultAdminRole());
                                                }
                                                /*else
                                                {
                                                        $this->group_obj->setMemberStatus ($id_data['user_id'],$this->group_obj->getDefaultAdminRole());
                                                }*/
                                        }
                                }
                        }
                }
#print_r($this->group_data["admin"]["detach"]);
                // detach ADMINs
                if (count($this->group_data["admin"]["detach"]))
                {

                        foreach($this->group_data["admin"]["detach"] as $user)
                        {
                                if($id_data = $this->__parseId($user))
                                {
                                        if($id_data['local'] or $id_data['imported'])
                                        {
                                                if ($this->group_obj->isMember($id_data['usr_id']))
                                                {
                                                        $this->group_obj->removeMember($id_data['usr_id']);
                                                }

                                        }
                                }
                        }
                }
#print_r($this->group_data["member"]["attach"]);

                // MEMBER
                if (count($this->group_data["member"]["attach"]))
                {

                        foreach($this->group_data["member"]["attach"] as $user)
                        {
                                if($id_data = $this->__parseId($user))
                                {
                                        if($id_data['local'] or $id_data['imported'])
                                        {
                                                //if (!$this->group_obj->isMember($id_data['usr_id']))
                                                {
                                                        $this->group_obj->addMember($id_data['usr_id'],$this->group_obj->getDefaultMemberRole());
                                                }
/*                                              else
                                                {
                                                        $this->group_obj->setMemberStatus ($id_data['user_id'],$this->group_obj->getDefaultMemberRole());
                                                }
*/
                                        }
                                }
                        }
                }

#print_r($this->group_data["member"]["detach"]);

                if (count($this->group_data["member"]["detach"]))
                {
                        foreach($this->group_data["member"]["detach"] as $user)
                        {
                                if($id_data = $this->__parseId($user))
                                {
                                        if($id_data['local'] or $id_data['imported'])
                                        {
                                                if ($this->group_obj->isMember($id_data['usr_id']))
                                                {
                                                        $this->group_obj->removeMember($id_data['usr_id']);
                                                }
                                        }
                                }
                        }
                }
                return true;
        }

Here is the call graph for this function:

Here is the caller graph for this function:

ilGroupImportParser::__destroyFolderObject (  ) 

Definition at line 542 of file class.ilGroupImportParser.php.

Referenced by __saveFolder().

        {
                unset($this->folder_obj);
        }

Here is the caller graph for this function:

ilGroupImportParser::__getParentId (  ) 

Definition at line 86 of file class.ilGroupImportParser.php.

Referenced by __save(), __saveFile(), and __saveFolder().

        {
                return $this->parent[count($this->parent) - 1];
        }

Here is the caller graph for this function:

ilGroupImportParser::__initFileObject (  ) 

Definition at line 533 of file class.ilGroupImportParser.php.

Referenced by __saveFile().

        {
                include_once "./Modules/File/classes/class.ilObjFile.php";

                $this->file_obj =& new ilObjFile();

                return true;
        }

Here is the caller graph for this function:

ilGroupImportParser::__initFolderObject (  ) 

Definition at line 515 of file class.ilGroupImportParser.php.

Referenced by __saveFolder().

        {
                include_once "classes/class.ilObjFolder.php";

                $this->folder_obj =& new ilObjFolder();

                return true;
        }

Here is the caller graph for this function:

ilGroupImportParser::__initGroupObject (  ) 

Definition at line 501 of file class.ilGroupImportParser.php.

References $CREATE, and $UPDATE.

Referenced by __save().

        {
                include_once "classes/class.ilObjGroup.php";

                if ($this->mode == ilGroupImportParser::$CREATE)
                {
                        $this->group_obj =& new ilObjGroup();
                } elseif ($this->mode == ilGroupImportParser::$UPDATE) {
                        $this->group_obj = $this->grp;
                }

                return true;
        }

Here is the caller graph for this function:

ilGroupImportParser::__initImportFileObject (  ) 

Definition at line 524 of file class.ilGroupImportParser.php.

Referenced by __saveFile().

        {
                include_once "classes/class.ilFileDataImportGroup.php";

                $this->import_file_obj =& new ilFileDataImportGroup();

                return true;
        }

Here is the caller graph for this function:

ilGroupImportParser::__parseId ( a_id  ) 

Definition at line 547 of file class.ilGroupImportParser.php.

References ilSaxParser::$ilias, ilObjUser::_getImportedUserId(), and ilObjUser::_lookupName().

Referenced by __assignMembers().

        {
                global $ilias;

                $fields = explode('_',$a_id);

                if(!is_array($fields) or
                   $fields[0] != 'il' or
                   !is_numeric($fields[1]) or
                   $fields[2] != 'usr' or
                   !is_numeric($fields[3]))
                {
                        return false;
                }
                if($id = ilObjUser::_getImportedUserId($a_id))
                {
                        return array('imported' => true,
                                                 'local' => false,
                                                 'usr_id' => $id);
                }
                if(($fields[1] == $ilias->getSetting('inst_id',0)) and strlen(ilObjUser::_lookupName($fields[3])))
                {
                        return array('imported' => false,
                                                 'local' => true,
                                                 'usr_id' => $fields[3]);
                }
                return false;
        }

Here is the call graph for this function:

Here is the caller graph for this function:

ilGroupImportParser::__popParentId (  ) 

Definition at line 80 of file class.ilGroupImportParser.php.

Referenced by handlerEndTag().

        {
                array_pop($this->parent);

                return true;
        }

Here is the caller graph for this function:

ilGroupImportParser::__pushParentId ( a_id  ) 

Definition at line 76 of file class.ilGroupImportParser.php.

Referenced by __save(), __saveFolder(), and ilGroupImportParser().

        {
                $this->parent[] = $a_id;
        }

Here is the caller graph for this function:

ilGroupImportParser::__save (  ) 

mode can be create or update

Definition at line 254 of file class.ilGroupImportParser.php.

References $CREATE, __assignMembers(), ilUtil::__extractId(), __getParentId(), __initGroupObject(), and __pushParentId().

Referenced by handlerBeginTag(), and handlerEndTag().

        {
                if($this->group_imported)
                {
                        return true;
                }

                $this->__initGroupObject();

                $this->group_obj->setImportId($this->group_data["id"]);
                $this->group_obj->setTitle($this->group_data["title"]);
                $this->group_obj->setDescription($this->group_data["description"]);
                
                $ownerChanged = false;
                if (isset($this->group_data["owner"])) 
                {
                        $owner = $this->group_data["owner"];
                        if (!is_numeric($owner)) 
                        {
                                $owner = ilUtil::__extractId ($owner, IL_INST_ID);
                        }
                        if (is_numeric($owner) && $owner > 0) 
                        {
                                $this->group_obj->setOwner($owner);
                                $ownerChanged = true;
                        }
                }

                switch($this->group_data['registration_type'])
                {
                        case 'disabled':
                                $flag = 0;
                                break;

                        case 'enabled':
                                $flag = 1;
                                break;

                        case 'password':
                                $flag = 2;
                                break;

                        default:
                                $flag = 0;
                }
                $this->group_obj->setRegistrationFlag($flag);
                // CREATE IT

                if ($this->mode == ilGroupImportParser::$CREATE)
                {
                        $this->group_obj->create();
                        $this->group_obj->createReference();
                        $this->group_obj->putInTree($this->__getParentId());
                        $this->group_obj->setPermissions($this->__getParentId());                       
                        $this->group_obj->initDefaultRoles();
                        $this->group_obj->initGroupStatus($this->group_data["type"] == "open" ? 0 : 1);
                } elseif ($ownerChanged) 
                {
                        $this->group_obj->updateOwner();
                }

                // SET GROUP SPECIFIC DATA
                switch($this->group_data['registration_type'])
                {
                        case 'disabled':
                                $flag = 0;
                                break;

                        case 'enabled':
                                $flag = 1;
                                break;

                        case 'password':
                                $flag = 2;
                                break;

                        default:
                                $flag = 0;
                }
                $this->group_obj->setRegistrationFlag($flag);
                if($this->group_data['expiration'])
                {
                        #$this->group_obj->setExpirationDateTime(date('Y-m-d H:i:s',$this->group_data['expiration']));
                        $this->group_obj->updateExpiration(date('YmdHis',$this->group_data['expiration']));
                }
                $this->group_obj->setPassword($this->group_data['password']);

                if ($this->mode == ilGroupImportParser::$CREATE)
                {
                        $this->group_obj->initGroupStatus($this->group_data["type"] == "open" ? 0 : 1);
                }

                // ASSIGN ADMINS/MEMBERS
                $this->__assignMembers();

                $this->__pushParentId($this->group_obj->getRefId());


                $this->group_imported = true;

                return true;
        }

Here is the call graph for this function:

Here is the caller graph for this function:

ilGroupImportParser::__saveFile (  ) 

Definition at line 377 of file class.ilGroupImportParser.php.

References __getParentId(), __initFileObject(), and __initImportFileObject().

Referenced by handlerBeginTag().

        {
                $this->__initFileObject();

                $this->file_obj->setType("file");
                $this->file_obj->setTitle($this->file["fileName"]);
                $this->file_obj->setFileName($this->file["fileName"]);
                $this->file_obj->create();
                $this->file_obj->createReference();
                $this->file_obj->putInTree($this->__getParentId());
                $this->file_obj->setPermissions($this->__getParentId());

                // COPY FILE
                $this->file_obj->createDirectory();

                $this->__initImportFileObject();

                if($this->import_file_obj->findObjectFile($this->file["id"]))
                {
                        $this->file_obj->copy($this->import_file_obj->getObjectFile(),$this->file["fileName"]);
                }

                unset($this->file_obj);
                unset($this->import_file_obj);

                return true;
        }

Here is the call graph for this function:

Here is the caller graph for this function:

ilGroupImportParser::__saveFolder (  ) 

Definition at line 360 of file class.ilGroupImportParser.php.

References __destroyFolderObject(), __getParentId(), __initFolderObject(), and __pushParentId().

Referenced by handlerEndTag().

        {
                $this->__initFolderObject();

                $this->folder_obj->setTitle($this->folder);
                $this->folder_obj->create();
                $this->folder_obj->createReference();
                $this->folder_obj->putInTree($this->__getParentId());
                $this->folder_obj->initDefaultRoles();

                $this->__pushParentId($this->folder_obj->getRefId());

                $this->__destroyFolderObject();

                return true;
        }

Here is the call graph for this function:

Here is the caller graph for this function:

ilGroupImportParser::handlerBeginTag ( a_xml_parser,
a_name,
a_attribs 
)

handler for begin of element

Definition at line 124 of file class.ilGroupImportParser.php.

References $ilErr, __save(), and __saveFile().

        {
                global $ilErr;

                switch($a_name)
                {
                        // GROUP DATA
                        case "group":
                                #if($a_attribs["exportVersion"] < EXPORT_VERSION)
                                #{
                                #       $ilErr->raiseError("!!! This export Version isn't supported, update your ILIAS 2 installation"
                                #                                          ,$ilErr->WARNING);
                                #}
                                // DEFAULT
                                $this->group_data["admin"] = array();
                                $this->group_data["member"] = array();

                                $this->group_data["type"] = $a_attribs["type"];
                                $this->group_data["id"] = $a_attribs["id"];

                                break;

                        case 'title':
                                break;

                        case "owner":
                                $this->group_data["owner"] = $a_attribs["id"];
                                break;

                        case 'registration':
                                $this->group_data['registration_type'] = $a_attribs['type'];
                                break;

                        case "admin":
                                if (!isset($a_attribs['action']) || $a_attribs['action'] == "Attach")
                                {
                                        $this->group_data["admin"]["attach"][] = $a_attribs["id"];
                                } elseif (isset($a_attribs['action']) || $a_attribs['action'] == "Detach")
                                {
                                        $this->group_data["admin"]["detach"][] = $a_attribs["id"];
                                }
                                break;

                        case "member":
                                if (!isset($a_attribs['action']) || $a_attribs['action'] == "Attach")
                                {
                                        $this->group_data["member"]["attach"][] = $a_attribs["id"];
                                } elseif (isset($a_attribs['action']) || $a_attribs['action'] == "Detach")
                                {
                                        $this->group_data["member"]["detach"][] = $a_attribs["id"];
                                }

                                break;

                        case "folder":
                                // NOW SAVE THE NEW OBJECT (if it hasn't been imported)
                                $this->__save();
                                break;

                        case "file":
                                // NOW SAVE THE NEW OBJECT (if it hasn't been imported)
                                $this->__save();

                                $this->file["fileName"] = $a_attribs["fileName"];
                                $this->file["id"] = $a_attribs["id"];

                                // SAVE IT
                                $this->__saveFile();
                                break;
                }
        }

Here is the call graph for this function:

ilGroupImportParser::handlerCharacterData ( a_xml_parser,
a_data 
)

handler for character data

Definition at line 238 of file class.ilGroupImportParser.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);

                if(!empty($a_data))
                {
                        $this->cdata .= $a_data;
                }
        }

ilGroupImportParser::handlerEndTag ( a_xml_parser,
a_name 
)

Definition at line 197 of file class.ilGroupImportParser.php.

References __popParentId(), __save(), and __saveFolder().

        {
                switch($a_name)
                {
                        case "title":
                                $this->group_data["title"] = trim($this->cdata);
                                break;

                        case "description":
                                $this->group_data["description"] = trim($this->cdata);
                                break;

                        case 'password':
                                $this->group_data['password'] = trim($this->cdata);
                                break;

                        case 'expiration':
                                $this->group_data['expiration'] = trim($this->cdata);
                                break;

                        case "folder":
                                $this->__popParentId();
                                break;

                        case "folderTitle":
                                $this->folder = trim($this->cdata);
                                $this->__saveFolder();
                                break;

                        case "group":
                                // NOW SAVE THE NEW OBJECT (if it hasn't been imported)
                                $this->__save();
                                break;
                }
                $this->cdata = '';
        }

Here is the call graph for this function:

ilGroupImportParser::ilGroupImportParser ( a_xml,
a_parent_id 
)

Constructor.

Parameters:
string $a_xml_file xml file

public

Definition at line 59 of file class.ilGroupImportParser.php.

References $CREATE, __pushParentId(), ilSaxParser::ilSaxParser(), and ilSaxParser::setXMLContent().

        {
                define('EXPORT_VERSION',2);

                parent::ilSaxParser();

                $this->mode =  ilGroupImportParser::$CREATE;
                $this->grp = null;

                $this->setXMLContent($a_xml);

                // SET MEMBER VARIABLES
                $this->__pushParentId($a_parent_id);


        }

Here is the call graph for this function:

ilGroupImportParser::setGroup ( &$  grp  ) 

Definition at line 581 of file class.ilGroupImportParser.php.

References $grp.

                                         {
                $this->grp = $grp;
        }

ilGroupImportParser::setHandlers ( a_xml_parser  ) 

set event handler should be overwritten by inherited class private

Reimplemented from ilSaxParser.

Definition at line 96 of file class.ilGroupImportParser.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');
        }

ilGroupImportParser::setMode ( mode  ) 

Definition at line 577 of file class.ilGroupImportParser.php.

References $mode.

                                       {
                $this->mode = $mode;
        }

ilGroupImportParser::startParsing (  ) 

start the parser

Reimplemented from ilSaxParser.

Definition at line 106 of file class.ilGroupImportParser.php.

References $CREATE.

        {
                parent::startParsing();

                if ($this->mode == ilGroupImportParser::$CREATE)
                {
                        return is_object($this->group_obj) ? $this->group_obj->getRefId() : false;
                }
                else
                {
                        return is_object($this->group_obj) ? $this->group_obj->update() : false;
                }
        }


Field Documentation

ilGroupImportParser::$counter

Definition at line 46 of file class.ilGroupImportParser.php.

ilGroupImportParser::$CREATE = 1 [static]
ilGroupImportParser::$group_data

Definition at line 42 of file class.ilGroupImportParser.php.

ilGroupImportParser::$group_obj

Definition at line 43 of file class.ilGroupImportParser.php.

ilGroupImportParser::$grp

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

Referenced by setGroup().

ilGroupImportParser::$mode

Definition at line 48 of file class.ilGroupImportParser.php.

Referenced by setMode().

ilGroupImportParser::$parent

Definition at line 45 of file class.ilGroupImportParser.php.

ilGroupImportParser::$UPDATE = 2 [static]

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