plugins/importexport/users/UserExportDom.inc.php

Go to the documentation of this file.
00001 <?php
00002 
00015 //$Id$
00016 
00017 import('xml.XMLCustomWriter');
00018 
00019 define('USERS_DTD_URL', 'http://pkp.sfu.ca/ocs/dtds/users.dtd');
00020 define('USERS_DTD_ID', '-//PKP/OCS Users XML//EN');
00021 
00022 class UserExportDom {
00023    function &exportUsers(&$schedConf, &$users, $allowedRoles = null) {
00024       $roleDao =& DAORegistry::getDAO('RoleDAO');
00025 
00026       $doc =& XMLCustomWriter::createDocument('users', USERS_DTD_ID, USERS_DTD_URL);
00027       $root =& XMLCustomWriter::createElement($doc, 'users');
00028 
00029       foreach ($users as $user) {
00030          $userNode =& XMLCustomWriter::createElement($doc, 'user');
00031 
00032          XMLCustomWriter::createChildWithText($doc, $userNode, 'username', $user->getUserName(), false);
00033          $passwordNode =& XMLCustomWriter::createChildWithText($doc, $userNode, 'password', $user->getPassword());
00034          XMLCustomWriter::setAttribute($passwordNode, 'encrypted', Config::getVar('security', 'encryption'));
00035          XMLCustomWriter::createChildWithText($doc, $userNode, 'salutation', $user->getSalutation(), false);
00036          XMLCustomWriter::createChildWithText($doc, $userNode, 'first_name', $user->getFirstName());
00037          XMLCustomWriter::createChildWithText($doc, $userNode, 'middle_name', $user->getMiddleName(), false);
00038          XMLCustomWriter::createChildWithText($doc, $userNode, 'last_name', $user->getLastName());
00039          XMLCustomWriter::createChildWithText($doc, $userNode, 'initials', $user->getInitials(), false);
00040          XMLCustomWriter::createChildWithText($doc, $userNode, 'gender', $user->getGender(), false);
00041          XMLCustomWriter::createChildWithText($doc, $userNode, 'affiliation', $user->getAffiliation(), false);
00042          XMLCustomWriter::createChildWithText($doc, $userNode, 'email', $user->getEmail());
00043          XMLCustomWriter::createChildWithText($doc, $userNode, 'url', $user->getUrl(), false);
00044          XMLCustomWriter::createChildWithText($doc, $userNode, 'phone', $user->getPhone(), false);
00045          XMLCustomWriter::createChildWithText($doc, $userNode, 'fax', $user->getFax(), false);
00046          XMLCustomWriter::createChildWithText($doc, $userNode, 'mailing_address', $user->getMailingAddress(), false);
00047          XMLCustomWriter::createChildWithText($doc, $userNode, 'country', $user->getCountry(), false);
00048          if (is_array($user->getSignature(null))) {
00049             foreach($user->getSignature(null) as $locale => $value) {
00050                $signatureNode =& XMLCustomWriter::createChildWithText($doc, $userNode, 'signature', $value, false);
00051                if ($signatureNode) {
00052                   XMLCustomWriter::setAttribute($signatureNode, 'locale', $locale);
00053                }
00054                unset($signatureNode);
00055             }
00056          }
00057          if (is_array($user->getInterests(null))) {
00058             foreach($user->getInterests(null) as $locale => $value) {
00059                $interestsNode =& XMLCustomWriter::createChildWithText($doc, $userNode, 'interests', $value, false);
00060                if ($interestsNode) {
00061                   XMLCustomWriter::setAttribute($interestsNode, 'locale', $locale);
00062                }
00063                unset($interestsNode);
00064             }
00065          }
00066          if (is_array($user->getGossip(null))) {
00067             foreach($user->getGossip(null) as $locale => $value) {
00068                $gossipNode =& XMLCustomWriter::createChildWithText($doc, $userNode, 'gossip', $value, false);
00069                if ($interestsNode) {
00070                   XMLCustomWriter::setAttribute($gossipNode, 'locale', $locale);
00071                }
00072                unset($gossipNode);
00073             }
00074          }
00075          if (is_array($user->getBiography(null))) {
00076             foreach($user->getBiography(null) as $locale => $value) {
00077                $biographyNode =& XMLCustomWriter::createChildWithText($doc, $userNode, 'biography', $value, false);
00078                if ($biographyNode) {
00079                   XMLCustomWriter::setAttribute($biographyNode, 'locale', $locale);
00080                }
00081                unset($biographyNode);
00082             }
00083          }
00084          XMLCustomWriter::createChildWithText($doc, $userNode, 'locales', join(':', $user->getLocales()), false);
00085          $roles =& $roleDao->getRolesByUserId($user->getId(), $schedConf->getId());
00086          foreach ($roles as $role) {
00087             $rolePath = $role->getRolePath();
00088             if ($allowedRoles !== null && !in_array($rolePath, $allowedRoles)) {
00089                continue;
00090             }
00091             $roleNode =& XMLCustomWriter::createElement($doc, 'role');
00092             XMLCustomWriter::setAttribute($roleNode, 'type', $rolePath);
00093             XMLCustomWriter::appendChild($userNode, $roleNode);
00094             unset($roleNode);
00095          }
00096 
00097          XMLCustomWriter::appendChild($root, $userNode);
00098       }
00099 
00100       XMLCustomWriter::appendChild($doc, $root);
00101 
00102       return $doc;
00103    }
00104 }
00105 
00106 ?>

Generated on 25 Jul 2013 for Open Conference Systems by  doxygen 1.4.7