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.

How to show the view times to the visitors?

Postby mer » Mon Feb 18, 2013 1:56 am

The editor can see the view times in the editing section. But how to show the view times to any
visitors?
mer
 
Posts: 3
Joined: Thu Jan 31, 2013 5:03 am

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

Postby alirezaaa » Sun Mar 31, 2013 10:49 pm

Hello mer,
I managed to do this by making these changes in the article class files. This function displays how many times the PDF galley file is downloaded.
If you need to find out the abstract views, you should change the SQL query a little.
First create a backup from each file, then make these necessary changes. You can change the function names as you wish.

1- add this function to /classes/article/PublishedArticleDAO.inc.php
Code: Select all
function getGalleysCountNum($Id)
         {
      $result =& $this->retrieve(
         'SELECT views
         FROM article_galleys
         WHERE label= "PDF" AND article_id = ?',$Id
      );
               return $result;
        }


2- add this function to /classes/article/PublishedArticle.inc.php
Code: Select all
function findGalleyVisitCount($Id)
       {
              $publishedArticleDao =& DAORegistry::getDAO('PublishedArticleDAO');
              $count = $publishedArticleDao->getGalleysCountNum($Id);
              return $count;
       }


3- now you can call this function in /templates/article/article.tpl
Code: Select all
{$article->findGalleyVisitCount($article->getId())}


I Hope it helps.
Best,
Ali
Last edited by alirezaaa on Mon Apr 01, 2013 2:34 am, edited 1 time in total.
alirezaaa
 
Posts: 29
Joined: Sat Jul 09, 2011 9:54 am

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

Postby Garant » Mon Apr 01, 2013 2:06 am

Hi, alirezaaa!
It works :)
Thank you!
Garant
 
Posts: 228
Joined: Wed May 30, 2012 8:53 am

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

Postby marchitelli » Sat Jul 06, 2013 11:11 am

Hi alirezaaa,
using your code I get the word "views" and the number of views in my article template.

Do you think that is a way to show the number only, so that I can use a translation string for different languages?

Thanks,
Andrea
marchitelli
 
Posts: 121
Joined: Tue May 22, 2007 12:44 am

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

Postby Garant » Sat Jul 06, 2013 11:17 am

marchitelli wrote:Hi alirezaaa,
using your code I get the word "views" and the number of views in my article template.

Do you think that is a way to show the number only, so that I can use a translation string for different languages?

Thanks,
Andrea

Code: Select all
<strong>{$article->findGalleyVisitCount($article->getId())} {translate key="your.key.translation.views"}</strong><br />
Garant
 
Posts: 228
Joined: Wed May 30, 2012 8:53 am

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

Postby marchitelli » Sat Jul 06, 2013 12:39 pm

Dear Garant,
I explained myself bad.
If I use
Code: Select all
{$article->findGalleyVisitCount($article->getId())}

I get something like "views 1800", even if I didn't add anything for displaying the word "views".
So, if I would use
Code: Select all
<strong>{$article->findGalleyVisitCount($article->getId())} {translate key="your.key.translation.views"}</strong><br />

I will get "views 1800 your.key.translation.views"

Summing up, my problem is the word "views" (I think it is related to the table column name in database) and not how to add a translation string.

Thanks!
Andrea
marchitelli
 
Posts: 121
Joined: Tue May 22, 2007 12:44 am

[SOLVED] How to show the view times to the visitors?

Postby marchitelli » Sun Jul 07, 2013 2:28 am

solved using SELECT AS statement instead SELECT in this way

Code: Select all
   function getGalleysCountNum($Id)
         {
      $result =& $this->retrieve(
         'SELECT views as " " FROM published_articles WHERE article_id = ?',$Id
      );
               return $result;
        }
marchitelli
 
Posts: 121
Joined: Tue May 22, 2007 12:44 am

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

Postby Garant » Sun Jul 07, 2013 2:37 am

solved using SELECT AS statement instead SELECT in this way

I also think that it's right solution.
Thank you!
Garant
 
Posts: 228
Joined: Wed May 30, 2012 8:53 am

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

Postby ausmt » Thu Sep 12, 2013 10:52 pm

Hi alirezaaa,
using your code I get the word "views" and the number of views in my article template.
But the number always shows "0", is that normal? or I did something wrong?

Thanks,
Monica
ausmt
 
Posts: 6
Joined: Thu Sep 12, 2013 10:46 pm

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

Postby ausmt » Sun Sep 15, 2013 6:44 pm

Hi alirezaaa,
using your code I get the word "views" and the number of views in my article template.
But the number always shows "0", is that normal? or I did something wrong?

Thanks,
Monica

alirezaaa wrote:Hello mer,
I managed to do this by making these changes in the article class files. This function displays how many times the PDF galley file is downloaded.
If you need to find out the abstract views, you should change the SQL query a little.
First create a backup from each file, then make these necessary changes. You can change the function names as you wish.

1- add this function to /classes/article/PublishedArticleDAO.inc.php
Code: Select all
function getGalleysCountNum($Id)
         {
      $result =& $this->retrieve(
         'SELECT views
         FROM article_galleys
         WHERE label= "PDF" AND article_id = ?',$Id
      );
               return $result;
        }


2- add this function to /classes/article/PublishedArticle.inc.php
Code: Select all
function findGalleyVisitCount($Id)
       {
              $publishedArticleDao =& DAORegistry::getDAO('PublishedArticleDAO');
              $count = $publishedArticleDao->getGalleysCountNum($Id);
              return $count;
       }


3- now you can call this function in /templates/article/article.tpl
Code: Select all
{$article->findGalleyVisitCount($article->getId())}


I Hope it helps.
Best,
Ali
ausmt
 
Posts: 6
Joined: Thu Sep 12, 2013 10:46 pm

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

Postby asmecher » Mon Sep 16, 2013 7:20 am

Hi Monica,

Please don't post the same thing multiple times; it clutters the forum. See http://pkp.sfu.ca/support/forum/viewtopic.php?f=2&t=10576.

Regards,
Alec Smecher
Public Knowledge Project Team
asmecher
 
Posts: 9214
Joined: Wed Aug 10, 2005 12:56 pm

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

Postby alirezaaa » Sun Sep 22, 2013 10:12 am

Hi Monica,
1- Andrea has a post in this page that describes how to delete the 'view' word. I've used Regular Expressions in my solution, but her version is simpler.
2- As I've mentioned, the current function displays how many times the PDF galley file is downloaded and it seems that your articles don't have such file. So again, as Andrea has modified the function, use this one instead of what I had used and both your problems are solved!
Code: Select all
function getGalleysCountNum($Id)
         {
      $result =& $this->retrieve(
         'SELECT views as " " FROM published_articles WHERE article_id = ?',$Id);
               return $result;
        }
alirezaaa
 
Posts: 29
Joined: Sat Jul 09, 2011 9:54 am

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

Postby Garant » Wed Jan 15, 2014 8:19 am

Hi!
After upgrade to 2.4.3 it doesn't work.
Code: Select all
DB Error: Unknown column 'views' in 'field list'

Any thoughts how to fix it?
Garant
 
Posts: 228
Joined: Wed May 30, 2012 8:53 am

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

Postby asmecher » Wed Jan 15, 2014 8:38 am

Hi Garant,

The statistics data storage has been overhauled in OJS 2.4.3, including the "views" column, which is no longer used. See http://pkp.sfu.ca/wiki/index.php?title=PKP_Statistics_Framework for an overview.

Regards,
Alec Smecher
Public Knowledge Project Team
asmecher
 
Posts: 9214
Joined: Wed Aug 10, 2005 12:56 pm

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

Postby Garant » Wed Jan 15, 2014 8:54 am

HI Alec!
Yes, I understand that the statistics were rebuilt.
Does someone has a new working solution to show the article's view times inside the template?
As I understood from the documentation no code change is needed. Only correct function's call inside the template is needed?
Garant
 
Posts: 228
Joined: Wed May 30, 2012 8:53 am

Next

Return to OJS Development

Who is online

Users browsing this forum: No registered users and 0 guests