OJS OCS OMP OHS

You are viewing the PKP Support Forum | PKP Home Wiki



{iterate/} - Custom PKP Smarty Block Function?

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.

{iterate/} - Custom PKP Smarty Block Function?

Postby petienne » Mon Jul 27, 2009 10:54 am

PKP Devs/Users -

I'm working on building a way to reliably reference the "second most recently published issue" of a journal. Put another way, the issue immediately preceding issue flagged as "current". I've found something that seems to be related, namely the archive() function of the pages/issue/IssueHandler.inc.php and the archive.tpl. It seems the logic for calculating the order of the current issues is built into an array here. I was going to borrow this already established code, but have been unable to find any documentation for the {iterate/} block function. There doesn't seem to be any record of it within Smarty, so I'd assume it's a custom PKP Smarty block function, but I've not been able to find the "source code" for it in the PKP ojs distribution. The only thing I've been able to find is lib/adodb-iterator.inc.php and I'm not sure that it's related.

I'm primarily concerned with documentation on the available uses/properties of the {iterate/} function, but any hints, tips, or advice in the arena would certainly be appreciated.

Thanks!

- Patrick E.
petienne
 
Posts: 15
Joined: Thu Feb 05, 2009 2:23 pm
Location: Atlanta, GA

Re: {iterate/} - Custom PKP Smarty Block Function?

Postby mcrider » Tue Jul 28, 2009 11:52 am

Hi Patrick,

Yes, this is a custom function (smartyIterate) defined in classes/template/TemplateManager.inc.php, where all custom smarty functions are defined and associated with smarty in the constructor function. I think the primary purpose for it is to behave like Smarty's foreach function, but take the ItemIterator class we use extensively in the code. A grep of the code for the term '{iterate' should provide plenty of use cases for you to look at.

Cheers,
Matt
mcrider
 
Posts: 952
Joined: Mon May 05, 2008 10:29 am
Location: Vancouver, BC

Re: {iterate/} - Custom PKP Smarty Block Function?

Postby petienne » Wed Jul 29, 2009 7:05 am

Thanks Matt! I did try to grep '{iterate' before posting and only saw the lib/adodb-iterator.inc.php. I probably did something silly like looking from the wrong directory (or scope thereof). I'll remember classes/template/TemplateManager.inc.php for custom smarty functions as well. Many thanks for your response!

- Patrick
petienne
 
Posts: 15
Joined: Thu Feb 05, 2009 2:23 pm
Location: Atlanta, GA

{iterate/} - No Access to "Key" param?

Postby petienne » Mon Aug 03, 2009 8:58 am

PKP Devs, Users -

Working with the custom block function {iterate/} again. I'm using the variable $issues which originates from the pages/issue/IssueHandler.inc.php within the archive() function. Using that variable I create a basic {iterate/} block function within the templates/issue/archive.tpl.

Code: Select all
{iterate from=issues key=index item=issue}
     <a href="{url op="view" path=$issue->getBestIssueId($currentJournal)}">
          {$issue->getIssueIdentification()|escape}
     </a>
     <span>{$index}</span>
     <br />
{/iterate}

No matter what, using the iterate block function I can't seem to get the "key" parameter to work at all. It's always empty. I've looked at the source for the smartyIterate function and while I understand some of it, I don't understand it all. Are "key" params supposed be accessible like they are from {foreach/} functions for {iterate/} functions? Or is there something unique about the $issues variable that precludes this as an option?

Code: Select all
$publishedIssuesIterator =
     $issueDao->getPublishedIssues($journal->getJournalId(), $rangeInfo);
$templateMgr->assign_by_ref('issues', $publishedIssuesIterator);


Any help would greatly be appreciated

- Patrick E.
petienne
 
Posts: 15
Joined: Thu Feb 05, 2009 2:23 pm
Location: Atlanta, GA

Re: {iterate/} - Custom PKP Smarty Block Function?

Postby mcrider » Tue Aug 04, 2009 10:51 am

Hi Patrick,

What are you trying to use this parameter for? I don't think you'd get any useful information by using the 'key' parameter with issue objects -- All of the information is encapsulated by the issue object itself. If you want to find out what the keys are for the array you're iterating, I'd suggest using a print_r($array) in the PHP file that assigns the array to the template.

Cheers,
Matt
mcrider
 
Posts: 952
Joined: Mon May 05, 2008 10:29 am
Location: Vancouver, BC

Re: {iterate/} - Custom PKP Smarty Block Function?

Postby petienne » Wed Aug 05, 2009 1:04 pm

Hello Matt,

Thanks for your response. I've spent a while double-checking over my goal and how I had thought to reach it. Concerning the key, you're right that I wouldn't get any useful information, in that I wouldn't be able to use the key for any flow control after the fact anyway (since it's already in smarty by that time). The other hand is much more interesting. The important piece of information I was looking for was not the contents of the issue itself, but the order of the particular issues within the Issues object.

Here's my conundrum:
Code: Select all
$publishedIssuesIterator =
     $issueDao->getPublishedIssues($journal->getJournalId(), $rangeInfo);
$templateMgr->assign_by_ref('issues', $publishedIssuesIterator);

The archives.tpl uses the "issues" object to iterate through and print links to all of the published issues, which happen to be in the order of publication (otherwise they would return on the page in an indeterminate order). The unexpected thing I found was that using {debug} or "print_r($issues)", the $Issues object only seemed to contain one issue. That's perplexing to me.

Context / Purpose:
My client wanted to customize their OJS instance to add the "second most recent issue" of the journal to the home page. It's clear that the HCID benefit is dubious at best, but I wanted to try to fulfill their request. The "current" issue of the journal is flagged in the database. In order to determine the "second most recent issue" some calculations based on database values would be necessary. Rather than making this calculation, I'd thought to borrow the $Issues object used in creating the archives listing (since in that list, the database calculations have already been made). If (to make a simple analogy) the $Issues object were an array, the current issue would be index "0" and the second most recent would be index "1". I'd thought that there would be a way to access the "second most recent issue" from the archive's $Issues object in a similar way.

But again, it seems that even though the $Issues object is used to display a listing for the issues on the archives page, any snapshot of the contents of the $Issues object seems only to show one issue.

My questions would be:
1) Does the $Issues object actually contain all (or all published?) issues in the journal?
2) If so, why do {debug} and print_r($Issues) only show one issue?
3) If not, I don't understand at all how the archives page is getting it's link listings.

I'm thinking it'll be a simpler solution to just calculate on my own what the "second most recent" issue of the journal is, but I'm still very interested in what is happening with the $Issues object (if for no other reason than to become more familiar with "OO" php, smarty, and OJS.

Any time you or any other PKP devs/users would have to respond would certainly be appreciated :)

- Patrick E.
petienne
 
Posts: 15
Joined: Thu Feb 05, 2009 2:23 pm
Location: Atlanta, GA

Re: {iterate/} - Custom PKP Smarty Block Function?

Postby mcrider » Wed Aug 05, 2009 1:37 pm

Hi Patrick,

The issues object you are getting is not really an array, its an object containing all of the issues in a mingled-up, OO form (though it is ordered by publication date ascending)--Its a child of the 'ItemIterator' class. You could try using this code to turn the issues object into an array, and get the second most-recent issue:
Code: Select all
$issuesIterator = $issueDao->getPublishedIssues($journalId);
$issues = $issuesIterator->toArray();
$secondLastIssue = $issues[1];

Let us know how that works!

Cheers,
Matt
mcrider
 
Posts: 952
Joined: Mon May 05, 2008 10:29 am
Location: Vancouver, BC

Re: {iterate/} - Custom PKP Smarty Block Function?

Postby petienne » Wed Aug 05, 2009 2:18 pm

Very interesting! I'm so used to procedural php, that the new(ish) OO-ness has been throwing me for a loop (ha! no pun intended, but that was a good one :P). Most likely that code will get me where I need to go, but I'm also going to have to look up the details on the ItemIterator class to come full circle on my understanding of the issue.

My sincere thanks Matt, You've been a great help :)

- Patrick E.
petienne
 
Posts: 15
Joined: Thu Feb 05, 2009 2:23 pm
Location: Atlanta, GA

Re: {iterate/} - Custom PKP Smarty Block Function?

Postby MartinD » Fri Sep 21, 2012 7:18 am

Patrick, did you find out how to use {iterate /} to get the second most recent issue?
I am looking for the exact same solution, only my client wants the 4 or 5 most recent issues on the front page of her journal.
So far I have not dug that deep into PKP or smarty functions, so I don't know what to do with {iterate} at all :-/
MartinD
 
Posts: 10
Joined: Tue Aug 16, 2011 3:35 am


Return to OJS Technical Support

Who is online

Users browsing this forum: Google [Bot] and 5 guests