NativeXmlPKPAuthorFilter::handleElement PHP Method

handleElement() public method

Handle a submission element
public handleElement ( $node ) : array
$node DOMElement
return array Array of PKPAuthor objects
    function handleElement($node)
    {
        $deployment = $this->getDeployment();
        $context = $deployment->getContext();
        $submission = $deployment->getSubmission();
        assert(is_a($submission, 'Submission'));
        // Create the data object
        $authorDao = DAORegistry::getDAO('AuthorDAO');
        $author = $authorDao->newDataObject();
        $author->setSubmissionId($submission->getId());
        if ($node->getAttribute('primary_contact')) {
            $author->setPrimaryContact(true);
        }
        if ($node->getAttribute('include_in_browse')) {
            $author->setIncludeInBrowse(true);
        }
        // Identify the user group by name
        $userGroupName = $node->getAttribute('user_group_ref');
        $userGroupDao = DAORegistry::getDAO('UserGroupDAO');
        $userGroups = $userGroupDao->getByContextId($context->getId());
        while ($userGroup = $userGroups->next()) {
            if (in_array($userGroupName, $userGroup->getName(null))) {
                // Found a candidate; stash it.
                $author->setUserGroupId($userGroup->getId());
                break;
            }
        }
        if (!$author->getUserGroupId()) {
            $deployment->addError(ASSOC_TYPE_SUBMISSION, $submission->getId(), __('plugins.importexport.common.error.unknownUserGroup', array('param' => $userGroupName)));
        }
        // Handle metadata in subelements
        for ($n = $node->firstChild; $n !== null; $n = $n->nextSibling) {
            if (is_a($n, 'DOMElement')) {
                switch ($n->tagName) {
                    case 'firstname':
                        $author->setFirstName($n->textContent);
                        break;
                    case 'middlename':
                        $author->setMiddleName($n->textContent);
                        break;
                    case 'lastname':
                        $author->setLastName($n->textContent);
                        break;
                    case 'affiliation':
                        $locale = $n->getAttribute('locale');
                        if (empty($locale)) {
                            $locale = $submission->getLocale();
                        }
                        $author->setAffiliation($n->textContent, $locale);
                        break;
                    case 'country':
                        $author->setCountry($n->textContent);
                        break;
                    case 'email':
                        $author->setEmail($n->textContent);
                        break;
                    case 'url':
                        $author->setUrl($n->textContent);
                        break;
                    case 'biography':
                        $locale = $n->getAttribute('locale');
                        if (empty($locale)) {
                            $locale = $submission->getLocale();
                        }
                        $author->setBiography($n->textContent, $locale);
                        break;
                }
            }
        }
        $authorDao->insertObject($author);
        return $author;
    }