OJS OCS OMP OHS

You are viewing the PKP Support Forum | PKP Home Wiki



How to show the view times to the visitors?

OJS development discussion, enhancement requests, third-party patches and plug-ins.

Moderators: jmacgreg, btbell, michael, bdgregg, barbarah, asmecher

Forum rules
Developer Resources:

Documentation: The OJS Technical Reference and the OJS API Reference are both available from the OJS Documentation page.

Git: You can access our public Git Repository here. Comprehensive Git usage instructions are available on the wiki.

Bugzilla: You can access our Bugzilla report tracker here.

Search: You can use our Google Custom Search to search across our main website, the support forum, and Bugzilla.

Questions and discussion are welcome, but if you have a workflow or usability question you should probably post to the OJS Editorial Support and Discussion subforum; if you have a technical support question, try the OJS Technical Support subforum.

Re: How to show the view times to the visitors?

Postby bbeghelli » Mon Jan 27, 2014 3:32 am

Garant,

That's not the way you get data from an object. You have to instantiate the object and then call the method. In your case I don't think you need that, just use the code I've sent you and replace the $submissionId for $articleId. The $articleId variable is defined at the top of the method, so it should work.

Remember that this solution is quicker now, but expensive in the long run. You are modifying core code, so any update you do will force you to change the code again to insert this modification.

The best way to do this is writing a plugin. You have a couple of options on how to do this, but they depends on some more advanced programming skills.

Regards,
Bruno
bbeghelli
 
Posts: 123
Joined: Tue Jun 25, 2013 2:22 pm

Re: How to show the view times to the visitors?

Postby Garant » Mon Jan 27, 2014 5:38 am

Hi Bruno!
Thank you for answers!
Yes, I understand that the best technique is to write the plugin. But I'm limited in such information regarding OJS plug-ins.
What's very strange, I've done how you wrote. But the result is null... To get this value I've turned on the smarties debug feature.
Here is the full code now:
Code: Select all
   function view($args, &$request) {
      $router =& $request->getRouter();
      $articleId = isset($args[0]) ? $args[0] : 0;
      $galleyId = isset($args[1]) ? $args[1] : 0;

      $this->validate($request, $articleId, $galleyId);
      $journal =& $this->journal;
      $issue =& $this->issue;
      $article =& $this->article;
      $this->setupTemplate();

      $rtDao =& DAORegistry::getDAO('RTDAO');
      $journalRt = $rtDao->getJournalRTByJournal($journal);

      $sectionDao =& DAORegistry::getDAO('SectionDAO');
      $section =& $sectionDao->getSection($article->getSectionId(), $journal->getId(), true);

      $version = null;
      if ($journalRt->getVersion()!=null && $journalRt->getDefineTerms()) {
         // Determine the "Define Terms" context ID.
         $version = $rtDao->getVersion($journalRt->getVersion(), $journalRt->getJournalId(), true);
         if ($version) foreach ($version->getContexts() as $context) {
            if ($context->getDefineTerms()) {
               $defineTermsContextId = $context->getContextId();
               break;
            }
         }
      }

      $commentDao =& DAORegistry::getDAO('CommentDAO');
      $enableComments = $journal->getSetting('enableComments');

      if (($article->getEnableComments()) && ($enableComments == COMMENTS_AUTHENTICATED || $enableComments == COMMENTS_UNAUTHENTICATED || $enableComments == COMMENTS_ANONYMOUS)) {
         $comments =& $commentDao->getRootCommentsBySubmissionId($article->getId());
      }

      $galleyDao =& DAORegistry::getDAO('ArticleGalleyDAO');
      if ($journal->getSetting('enablePublicGalleyId')) {
         $galley =& $galleyDao->getGalleyByBestGalleyId($galleyId, $article->getId());
      } else {
         $galley =& $galleyDao->getGalley($galleyId, $article->getId());
      }

      if ($galley && !$galley->isHtmlGalley() && !$galley->isPdfGalley()) {
         if ($galley->getRemoteURL()) {
            $request->redirectUrl($galley->getRemoteURL());
         }
         if ($galley->isInlineable()) {
            return $this->viewFile(
               array($galley->getArticleId(), $galley->getId()),
               $request
            );
         } else {
            return $this->download(
               array($galley->getArticleId(), $galley->getId()),
               $request
            );
         }
      }

      $templateMgr =& TemplateManager::getManager($request);
      $templateMgr->addJavaScript('js/relatedItems.js');
      $templateMgr->addJavaScript('js/inlinePdf.js');
      $templateMgr->addJavaScript('js/pdfobject.js');

      if (!$galley) {
         // Get the subscription status if displaying the abstract;
         // if access is open, we can display links to the full text.
         import('classes.issue.IssueAction');

         // The issue may not exist, if this is an editorial user
         // and scheduling hasn't been completed yet for the article.
         if ($issue) {
            $templateMgr->assign('subscriptionRequired', IssueAction::subscriptionRequired($issue));
         }

         $templateMgr->assign('subscribedUser', IssueAction::subscribedUser($journal, isset($issue) ? $issue->getId() : null, isset($article) ? $article->getId() : null));
         $templateMgr->assign('subscribedDomain', IssueAction::subscribedDomain($journal, isset($issue) ? $issue->getId() : null, isset($article) ? $article->getId() : null));

         $templateMgr->assign('showGalleyLinks', $journal->getSetting('showGalleyLinks'));

         import('classes.payment.ojs.OJSPaymentManager');
         $paymentManager = new OJSPaymentManager($request);
         if ( $paymentManager->onlyPdfEnabled() ) {
            $templateMgr->assign('restrictOnlyPdf', true);
         }
         if ( $paymentManager->purchaseArticleEnabled() ) {
            $templateMgr->assign('purchaseArticleEnabled', true);
         }

         // Article cover page.
         $locale = AppLocale::getLocale();
         if (isset($article) && $article->getLocalizedFileName() && $article->getLocalizedShowCoverPage() && !$article->getLocalizedHideCoverPageAbstract()) {
            import('classes.file.PublicFileManager');
            $publicFileManager = new PublicFileManager();
            $coverPagePath = $request->getBaseUrl() . '/';
            $coverPagePath .= $publicFileManager->getJournalFilesPath($journal->getId()) . '/';
            $templateMgr->assign('coverPagePath', $coverPagePath);
            $templateMgr->assign('coverPageFileName', $article->getLocalizedFileName());
            $templateMgr->assign('width', $article->getLocalizedWidth());
            $templateMgr->assign('height', $article->getLocalizedHeight());
            $templateMgr->assign('coverPageAltText', $article->getLocalizedCoverPageAltText());
         }

         // References list.
         // FIXME: We only display the edited raw citations right now. We also want
         // to allow for generated citations to be displayed here (including a way for
         // the reader to choose any of the installed citation styles for output), see #5938.
         $citationDao =& DAORegistry::getDAO('CitationDAO'); /* @var $citationDao CitationDAO */
         $citationFactory =& $citationDao->getObjectsByAssocId(ASSOC_TYPE_ARTICLE, $article->getId());
         $templateMgr->assign('citationFactory', $citationFactory);
      } else {
         // Use the article's CSS file, if set.
         if ($galley->isHTMLGalley() && $styleFile =& $galley->getStyleFile()) {
            $templateMgr->addStyleSheet($router->url($request, null, 'article', 'viewFile', array(
               $article->getId(),
               $galley->getBestGalleyId($journal),
               $styleFile->getFileId()
            )));
         }
      }

      $templateMgr->assign_by_ref('issue', $issue);
      $templateMgr->assign_by_ref('article', $article);
      $templateMgr->assign_by_ref('galley', $galley);
      $templateMgr->assign_by_ref('section', $section);
      $templateMgr->assign_by_ref('journalRt', $journalRt);
      $templateMgr->assign_by_ref('version', $version);
      $templateMgr->assign_by_ref('journal', $journal);
      $templateMgr->assign('articleId', $articleId);
      $templateMgr->assign('postingAllowed', (
         ($article->getEnableComments()) && (
         $enableComments == COMMENTS_UNAUTHENTICATED ||
         (($enableComments == COMMENTS_AUTHENTICATED ||
         $enableComments == COMMENTS_ANONYMOUS) &&
         Validation::isLoggedIn()))
      ));
      $templateMgr->assign('enableComments', $enableComments);
      $templateMgr->assign('postingLoginRequired', ($enableComments != COMMENTS_UNAUTHENTICATED && !Validation::isLoggedIn()));
      $templateMgr->assign('galleyId', $galleyId);
      $templateMgr->assign('defineTermsContextId', isset($defineTermsContextId)?$defineTermsContextId:null);
      $templateMgr->assign('comments', isset($comments)?$comments:null);

      $templateMgr->assign('sharingEnabled', $journalRt->getSharingEnabled());

      if($journalRt->getSharingEnabled()) {
         $templateMgr->assign('sharingRequestURL', $request->getRequestURL());
         $templateMgr->assign('sharingArticleTitle', $article->getArticleTitle());
         $templateMgr->assign_by_ref('sharingUserName', $journalRt->getSharingUserName());
         $templateMgr->assign_by_ref('sharingButtonStyle', $journalRt->getSharingButtonStyle());
         $templateMgr->assign_by_ref('sharingDropDownMenu', $journalRt->getSharingDropDownMenu());
         $templateMgr->assign_by_ref('sharingBrand', $journalRt->getSharingBrand());
         $templateMgr->assign_by_ref('sharingDropDown', $journalRt->getSharingDropDown());
         $templateMgr->assign_by_ref('sharingLanguage', $journalRt->getSharingLanguage());
         $templateMgr->assign_by_ref('sharingLogo', $journalRt->getSharingLogo());
         $templateMgr->assign_by_ref('sharingLogoBackground', $journalRt->getSharingLogoBackground());
         $templateMgr->assign_by_ref('sharingLogoColor', $journalRt->getSharingLogoColor());
         list($btnUrl, $btnWidth, $btnHeight) = SharingRT::sharingButtonImage($journalRt);
         $templateMgr->assign('sharingButtonUrl', $btnUrl);
         $templateMgr->assign('sharingButtonWidth', $btnWidth);
         $templateMgr->assign('sharingButtonHeight', $btnHeight);
      }

      $templateMgr->assign('articleSearchByOptions', array(
         'query' => 'search.allFields',
         'authors' => 'search.author',
         'title' => 'article.title',
         'abstract' => 'search.abstract',
         'indexTerms' => 'search.indexTerms',
         'galleyFullText' => 'search.fullText'
      ));

      /*2014 Statistics*/
      $application =& PKPApplication::getApplication();
      $stats = $application->getMetrics(
          OJS_METRIC_TYPE_COUNTER,
          null,
          array(STATISTICS_DIMENSION_SUBMISSION_ID => $articleId, STATISTICS_DIMENSION_ASSOC_TYPE => ASSOC_TYPE_GALLEY)
      );
      $articleGalleysViewsAndDownloads = $stats[STATISTICS_METRIC];
      $templateMgr->assign('articleGalleysViewsAndDownloads', $articleGalleysViewsAndDownloads);
      /**/

      // consider public identifiers
      $pubIdPlugins =& PluginRegistry::loadCategory('pubIds', true);
      $templateMgr->assign('pubIdPlugins', $pubIdPlugins);
      $templateMgr->display('article/article.tpl');
   }


And the view:
Code: Select all
<strong>{$articleGalleysViewsAndDownloads} {translate key="plugins.block.popularArticles.views"}</strong><br />
Garant
 
Posts: 219
Joined: Wed May 30, 2012 8:53 am

Re: How to show the view times to the visitors?

Postby bbeghelli » Fri Feb 07, 2014 1:34 am

Hi Garant,

Can you double check that the article you are visualizing have statistics? I mean, get the article id and manually execute this sql:

Code: Select all
SELECT * from metrics WHERE submission_id = ?


change the ? for the article id that you are visualizing. You can get the article id looking for it inside the url to access it. It should be something like this:
your-domain/index.php/your-journal/article/view/the-article-id

If you have path info disabled, then you can check for the article_id url parameter value.

Thanks.
bbeghelli
 
Posts: 123
Joined: Tue Jun 25, 2013 2:22 pm

Re: How to show the view times to the visitors?

Postby Garant » Sun Feb 09, 2014 2:59 am

Hi Bruno!
This query displays these rows:
Code: Select all
 load_id    assoc_type    context_id    issue_id    submission_id    assoc_id    day    month    file_type    country_id    region    city    metric_type    metric

with data
Garant
 
Posts: 219
Joined: Wed May 30, 2012 8:53 am

Re: How to show the view times to the visitors?

Postby bbeghelli » Mon Feb 17, 2014 5:17 am

Hi Garant,

So this article has no processed statistics. Can you double check to see if your log files are being processed? Look at your files directory and check the usageStats/archive folder. You should have files there. If not, let me know.

Thanks,
Bruno
bbeghelli
 
Posts: 123
Joined: Tue Jun 25, 2013 2:22 pm

Re: How to show the view times to the visitors?

Postby Garant » Thu Feb 20, 2014 4:06 am

Hi Bruno!
I don't have any usageStats or archive folders in OJS root directory
Garant
 
Posts: 219
Joined: Wed May 30, 2012 8:53 am

Re: How to show the view times to the visitors?

Postby bbeghelli » Thu Feb 20, 2014 11:41 am

Hi Garant,

Not inside root. Inside the files directory, it should not be publicly available. The one that has it's path defined inside config.inc.php file.

Cheers,
Bruno
bbeghelli
 
Posts: 123
Joined: Tue Jun 25, 2013 2:22 pm

Re: How to show the view times to the visitors?

Postby Garant » Thu Feb 20, 2014 11:46 am

Hi Bruno!
Yes, I've found them.
The information regarding that article looks like this:
Code: Select all
xx.xxx.xx.xx - - "2014-01-14 16:03:15" https://www3.mruni.eu/ojs/intellectual-economics/article/view/1648 200 "Mozilla/5.0 (Windows NT 5.1; rv:26.0) Gecko/20100101 Firefox/26.0"
Garant
 
Posts: 219
Joined: Wed May 30, 2012 8:53 am

Re: How to show the view times to the visitors?

Postby bbeghelli » Wed Mar 05, 2014 2:43 pm

Hi Garant,

This event is an article abstract page view, it's not an article file download. If you don't have any other entry, then no file downloads were made for this article. Try to download a file for this article and check the current day log file, it should have an entry with the donwload operation, with the id of both the article and the file into the request url.

Cheers,
Bruno
bbeghelli
 
Posts: 123
Joined: Tue Jun 25, 2013 2:22 pm

Re: How to show the view times to the visitors?

Postby bakerl » Thu Oct 16, 2014 7:09 pm

Did anyone ever write a plugin for this, as was suggested?
bakerl
 
Posts: 4
Joined: Tue Apr 03, 2012 9:43 am

Previous

Return to OJS Development

Who is online

Users browsing this forum: No registered users and 3 guests