ArticleHandler::userCanViewGalley PHP Метод

userCanViewGalley() публичный Метод

Determines whether a user can view this article galley or not.
public userCanViewGalley ( $request, $articleId, $galleyId = null )
$request Request
$articleId string
$galleyId int or string
    function userCanViewGalley($request, $articleId, $galleyId = null)
    {
        import('classes.issue.IssueAction');
        $issueAction = new IssueAction();
        $journal = $request->getJournal();
        $publishedArticle = $this->article;
        $issue = $this->issue;
        $journalId = $journal->getId();
        $user = $request->getUser();
        $userId = $user ? $user->getId() : 0;
        // If this is an editorial user who can view unpublished/unscheduled
        // articles, bypass further validation. Likewise for its author.
        if ($publishedArticle && $issueAction->allowedPrePublicationAccess($journal, $publishedArticle)) {
            return true;
        }
        // Make sure the reader has rights to view the article/issue.
        if ($issue && $issue->getPublished() && $publishedArticle->getStatus() == STATUS_PUBLISHED) {
            $subscriptionRequired = $issueAction->subscriptionRequired($issue);
            $isSubscribedDomain = $issueAction->subscribedDomain($journal, $issue->getId(), $publishedArticle->getId());
            // Check if login is required for viewing.
            if (!$isSubscribedDomain && !Validation::isLoggedIn() && $journal->getSetting('restrictArticleAccess') && isset($galleyId) && $galleyId) {
                Validation::redirectLogin();
            }
            // bypass all validation if subscription based on domain or ip is valid
            // or if the user is just requesting the abstract
            if (!$isSubscribedDomain && $subscriptionRequired && (isset($galleyId) && $galleyId)) {
                // Subscription Access
                $subscribedUser = $issueAction->subscribedUser($journal, $issue->getId(), $publishedArticle->getId());
                import('classes.payment.ojs.OJSPaymentManager');
                $paymentManager = new OJSPaymentManager($request);
                $purchasedIssue = false;
                if (!$subscribedUser && $paymentManager->purchaseIssueEnabled()) {
                    $completedPaymentDao = DAORegistry::getDAO('OJSCompletedPaymentDAO');
                    $purchasedIssue = $completedPaymentDao->hasPaidPurchaseIssue($userId, $issue->getId());
                }
                if (!(!$subscriptionRequired || $publishedArticle->getAccessStatus() == ARTICLE_ACCESS_OPEN || $subscribedUser || $purchasedIssue)) {
                    if ($paymentManager->purchaseArticleEnabled() || $paymentManager->membershipEnabled()) {
                        /* if only pdf files are being restricted, then approve all non-pdf galleys
                         * and continue checking if it is a pdf galley */
                        if ($paymentManager->onlyPdfEnabled()) {
                            if ($this->galley && !$this->galley->isPdfGalley()) {
                                $this->issue = $issue;
                                $this->article = $publishedArticle;
                                return true;
                            }
                        }
                        if (!Validation::isLoggedIn()) {
                            Validation::redirectLogin("payment.loginRequired.forArticle");
                        }
                        /* if the article has been paid for then forget about everything else
                         * and just let them access the article */
                        $completedPaymentDao = DAORegistry::getDAO('OJSCompletedPaymentDAO');
                        $dateEndMembership = $user->getSetting('dateEndMembership', 0);
                        if ($completedPaymentDao->hasPaidPurchaseArticle($userId, $publishedArticle->getId()) || !is_null($dateEndMembership) && $dateEndMembership > time()) {
                            $this->issue = $issue;
                            $this->article = $publishedArticle;
                            return true;
                        } else {
                            $queuedPayment = $paymentManager->createQueuedPayment($journalId, PAYMENT_TYPE_PURCHASE_ARTICLE, $user->getId(), $publishedArticle->getId(), $journal->getSetting('purchaseArticleFee'));
                            $queuedPaymentId = $paymentManager->queuePayment($queuedPayment);
                            $paymentManager->displayPaymentForm($queuedPaymentId, $queuedPayment);
                            exit;
                        }
                    }
                    if (!isset($galleyId) || $galleyId) {
                        if (!Validation::isLoggedIn()) {
                            Validation::redirectLogin('reader.subscriptionRequiredLoginText');
                        }
                        $request->redirect(null, 'about', 'subscriptions');
                    }
                }
            }
        } else {
            $request->redirect(null, 'search');
        }
        return true;
    }