PubIdPlugin::getPubId PHP Method

getPubId() public method

public getPubId ( $pubObject )
    function getPubId($pubObject)
    {
        // Get the pub id type
        $pubIdType = $this->getPubIdType();
        // If we already have an assigned pub id, use it.
        $storedPubId = $pubObject->getStoredPubId($pubIdType);
        if ($storedPubId) {
            return $storedPubId;
        }
        // Determine the type of the publishing object.
        $pubObjectType = $this->getPubObjectType($pubObject);
        // Initialize variables for publication objects.
        $issue = $pubObjectType == 'Issue' ? $pubObject : null;
        $submission = $pubObjectType == 'Submission' ? $pubObject : null;
        $representation = $pubObjectType == 'Representation' ? $pubObject : null;
        $submissionFile = $pubObjectType == 'SubmissionFile' ? $pubObject : null;
        // Get the context id.
        if (in_array($pubObjectType, array('Issue', 'Submission'))) {
            $contextId = $pubObject->getJournalId();
        } else {
            // Retrieve the submission.
            assert(is_a($pubObject, 'Representation') || is_a($pubObject, 'SubmissionFile'));
            $submissionDao = Application::getSubmissionDAO();
            $submission = $submissionDao->getById($pubObject->getSubmissionId(), null, true);
            if (!$submission) {
                return null;
            }
            // Now we can identify the context.
            $contextId = $submission->getJournalId();
        }
        // Check the context
        $context = $this->getContext($contextId);
        if (!$context) {
            return null;
        }
        $contextId = $context->getId();
        // Check whether pub ids are enabled for the given object type.
        $objectTypeEnabled = $this->isObjectTypeEnabled($pubObjectType, $contextId);
        if (!$objectTypeEnabled) {
            return null;
        }
        // Retrieve the issue.
        if (!is_a($pubObject, 'Issue')) {
            assert(!is_null($submission));
            $issueDao = DAORegistry::getDAO('IssueDAO');
            /* @var $issueDao IssueDAO */
            $issue = $issueDao->getIssueByArticleId($submission->getId(), $contextId);
        }
        if ($issue && $contextId != $issue->getJournalId()) {
            return null;
        }
        // Retrieve the pub id prefix.
        $pubIdPrefix = $this->getSetting($contextId, $this->getPrefixFieldName());
        if (empty($pubIdPrefix)) {
            return null;
        }
        // Generate the pub id suffix.
        $suffixFieldName = $this->getSuffixFieldName();
        $suffixGenerationStrategy = $this->getSetting($contextId, $suffixFieldName);
        switch ($suffixGenerationStrategy) {
            case 'customId':
                $pubIdSuffix = $pubObject->getData($suffixFieldName);
                break;
            case 'pattern':
                $suffixPatternsFieldNames = $this->getSuffixPatternsFieldNames();
                $pubIdSuffix = $this->getSetting($contextId, $suffixPatternsFieldNames[$pubObjectType]);
                // %j - journal initials
                $pubIdSuffix = PKPString::regexp_replace('/%j/', PKPString::strtolower($context->getAcronym($context->getPrimaryLocale())), $pubIdSuffix);
                // %x - custom identifier
                if ($pubObject->getStoredPubId('publisher-id')) {
                    $pubIdSuffix = PKPString::regexp_replace('/%x/', $pubObject->getStoredPubId('publisher-id'), $pubIdSuffix);
                }
                if ($issue) {
                    // %v - volume number
                    $pubIdSuffix = PKPString::regexp_replace('/%v/', $issue->getVolume(), $pubIdSuffix);
                    // %i - issue number
                    $pubIdSuffix = PKPString::regexp_replace('/%i/', $issue->getNumber(), $pubIdSuffix);
                    // %Y - year
                    $pubIdSuffix = PKPString::regexp_replace('/%Y/', $issue->getYear(), $pubIdSuffix);
                }
                if ($submission) {
                    // %a - article id
                    $pubIdSuffix = PKPString::regexp_replace('/%a/', $submission->getId(), $pubIdSuffix);
                    // %p - page number
                    if ($submission->getPages()) {
                        $pubIdSuffix = PKPString::regexp_replace('/%p/', $submission->getPages(), $pubIdSuffix);
                    }
                }
                if ($representation) {
                    // %g - galley id
                    $pubIdSuffix = PKPString::regexp_replace('/%g/', $representation->getId(), $pubIdSuffix);
                }
                if ($submissionFile) {
                    // %f - file id
                    $pubIdSuffix = PKPString::regexp_replace('/%f/', $submissionFile->getFileId(), $pubIdSuffix);
                }
                break;
            default:
                $pubIdSuffix = PKPString::strtolower($context->getAcronym($context->getPrimaryLocale()));
                if ($issue) {
                    $pubIdSuffix .= '.v' . $issue->getVolume() . 'i' . $issue->getNumber();
                } else {
                    $pubIdSuffix .= '.v%vi%i';
                }
                if ($submission) {
                    $pubIdSuffix .= '.' . $submission->getId();
                }
                if ($representation) {
                    $pubIdSuffix .= '.g' . $representation->getId();
                }
                if ($submissionFile) {
                    $pubIdSuffix .= '.f' . $submissionFile->getFileId();
                }
        }
        if (empty($pubIdSuffix)) {
            return null;
        }
        // Costruct the pub id from prefix and suffix.
        $pubId = $this->constructPubId($pubIdPrefix, $pubIdSuffix, $contextId);
        return $pubId;
    }