OJS OCS OMP OHS

You are viewing the PKP Support Forum | PKP Home Wiki



Chronological display of articles possible?

Are you responsible for making OJS work -- installing, upgrading, migrating or troubleshooting? Do you think you've found a bug? Post in this forum.

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

Forum rules
What to do if you have a technical problem with OJS:

1. Search the forum. You can do this from the Advanced Search Page or from our Google Custom Search, which will search the entire PKP site. If you are encountering an error, we especially recommend searching the forum for said error.

2. Check the FAQ to see if your question or error has already been resolved.

3. Post a question, but please, only after trying the above two solutions. If it's a workflow or usability question you should probably post to the OJS Editorial Support and Discussion subforum; if you have a development question, try the OJS Development subforum.

Chronological display of articles possible?

Postby meinbrodt » Sun Oct 21, 2012 2:47 am

Dear OJS-Team,

we have been presented with the following feature request that - at least from my understanding - doesn't seem possible out-of-the-box.

Besides the normal issue-based display of all articles, our clients requests also a chronological display of all articles (subdivided by sections) to be shown on the front-page of the journal.

Is it principally possible to achieve this behaviour by editing the necessary template files or would that require some more work?

Best regards, Matthias Einbrodt
meinbrodt
 
Posts: 14
Joined: Sun Oct 21, 2012 2:37 am

Re: Chronological display of articles possible?

Postby springday » Sun Oct 21, 2012 4:47 am

Hi Matthias,

chronological means: sorting the articles by the date of publishing? (Articles also have several dates stored in the database; besides publishing date there's also "date_submitted", "last_modified", "date_status_modified" and a date when the files belonging to an article have been uploaded or modified.)

Actually, there is an internal function in OJS that retrieves all published articles of a journal in chronological order, using the publication date. The function can sort in ascending and descending order. It is located in /classes/article/PublishedArticleDAO.inc.php - the function's called "getPublishedArticlesByJournalId".

If you want to display the chronological list of articles on the home page of a journal, you could call this function from /pages/index/IndexHandler.inc.php, in the part starting in line 41 with "if($journal)".

Code: Select all
$publishedArticleDao =& DAORegistry::getDAO('PublishedArticleDAO');
$publishedArticles =& $publishedArticleDao->getPublishedArticlesByJournalId($journal->getId());
$templateMgr->assign_by_ref('publishedArticles', $publishedArticles);


With those lines, your template /templates/index/journal.tpl will know about the articles in chronological order. You can use the variable $publishedArticles to iterate over them and prepare them for display.

I haven't tested this suggestion though, so there might be some caveats that I haven't thought through. You might also want to prepare the $publishedArticles with a VirtualArrayIterator or use some other way to limit the output, if the article list would get too long. However, maybe with those ideas you'll find a way towards the solution you're looking for.

Best wishes,
Kai Weber
springday
 
Posts: 111
Joined: Wed Jul 25, 2012 2:56 pm
Location: Munich, Germany

Re: Chronological display of articles possible?

Postby meinbrodt » Sun Oct 21, 2012 6:30 am

Dear Kai,

thank you very much. That helps a lot.

I will try it and let you know if it worked or not.

Regards, Matthias
meinbrodt
 
Posts: 14
Joined: Sun Oct 21, 2012 2:37 am

Re: Chronological display of articles possible?

Postby meinbrodt » Fri Feb 01, 2013 7:43 am

Dear Kai,

some time has passed. I only was able to implemented your proposed solution today.

I got to the point of retrieving a DaoResultFactoryObject, however I have no idea how to parse it or iterate over it.

Do you have some hints here?

Best regards and thank you, Matthias
meinbrodt
 
Posts: 14
Joined: Sun Oct 21, 2012 2:37 am

Re: Chronological display of articles possible?

Postby springday » Fri Feb 01, 2013 12:09 pm

Hi Matthias,

if I remember correctly, then an easy way to iterate over a DAOResultFactory object is

Code: Select all
while ($article =& $publishedArticles->next()) {

... do something with $article here ...

}


If you feel easier to work with a standard array, you can also call the method toArray() on $publishedArticles, like this:

Code: Select all
$articleArray =& $publishedArticles->toArray()


Hope that helps,

Kai
springday
 
Posts: 111
Joined: Wed Jul 25, 2012 2:56 pm
Location: Munich, Germany

Re: Chronological display of articles possible?

Postby meinbrodt » Tue Feb 05, 2013 9:13 am

Hello Kai,

thank you very much for your help. Based upon your suggestions I miraculously was able to make everything work. :-)

Here the code for the file /pages/index/IndexHandler.inc.php

Code: Select all
// get all published articles, put them into $publishedArticles array and assign it to template responsible for homepage rendering         
$publishedArticleDao =& DAORegistry::getDAO('PublishedArticleDAO');
$publishedArticles =& $publishedArticleDao->getPublishedArticlesByJournalId($journal->getId());
$publishedArticles =& $publishedArticles->toArray();
$templateMgr->assign('publishedArticles', $publishedArticles);


As far as I understand it, this code gives me an array with n PublishedArticle objects representing all articles ever published in the indicated journal which is furthermore assigned to the journal homepage template file for further processing there.

Here the code for the template file of the journal homepage /templates/index/journal.tpl

Code: Select all
{if $publishedArticles}
   {* Displays all articles ever published in journal *}
   <h3>Recently Published Articles</h3>
   {foreach from=$publishedArticles item=article}
      
      {assign var=articlePath value=$article->getBestArticleId($currentJournal)}
         
      <ul>
         <li>
            <span>
               <a href="{url page="article" op="view" path=$articlePath}" name="{$article->getLocalizedTitle()|strip_unsafe_html}" title="{$article->getLocalizedTitle()|strip_unsafe_html}">
                  {$article->getLocalizedTitle()|strip_unsafe_html}
               </a>
            </span>
            <br/>
            <span>
               {if (!$section.hideAuthor && $article->getHideAuthor() == $smarty.const.AUTHOR_TOC_DEFAULT) || $article->getHideAuthor() == $smarty.const.AUTHOR_TOC_SHOW}
                  {foreach from=$article->getAuthors() item=author name=authorList}
                     {$author->getFullName()|escape}{if !$smarty.foreach.authorList.last},{/if}
                  {/foreach}
               {else}
                  &nbsp;
               {/if}   
            </span>
         </li>
      </ul>   
   {/foreach}         
{/if}


Best regards and thanks again, Matthias
meinbrodt
 
Posts: 14
Joined: Sun Oct 21, 2012 2:37 am


Return to OJS Technical Support

Who is online

Users browsing this forum: No registered users and 6 guests