OJS OCS OMP OHS

You are viewing the PKP Support Forum | PKP Home Wiki



Building Author Gallery

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.

Building Author Gallery

Postby censored » Thu Jun 17, 2010 6:57 am

Hi there,

i was looking for a way to build a author gallery. Therefore i created a custom function within the AuthorHandler.inc.php

Code: Select all
   
function faculty() {
    $templateMgr = &TemplateManager::getManager();
    $authorDao =& DAORegistry::getDAO('AuthorDAO');
    $authors =& $authorDao->getAuthorsAlphabetizedByJournal();
    $templateMgr->assign('authors', $authors);
    $templateMgr->display('author/faculty.tpl');
}


Afterwards i created a template (faculty.tpl) where i wanted to display data belonging to the authors

Code: Select all
{iterate from=authors item=author}
    {assign var=fullName value=$author->getFullName()}
    {assign var=firstName value=$author->getFirstName()}
    {assign var=middleName value=$author->getMiddleName()}
    {assign var=lastName value=$author->getLastName()}
    {assign var=authorId value=$author->getAuthorId()}
    {assign var=imageUrl value=$author->getUrl()}
    <div class="authorGalleryItem">
         <a href="{url page="search" op="authors" path="view" firstName=$firstName middleName=$middleName lastName=$lastName affiliation=$authorAffiliation country=$authorCountry}">
            <img src="{$baseUrl}/public/site/profileImage-6.jpg" />
        </a>
        <div class="subline">&nbsp</div>
        <div class="authorGalleryName">{$fullName}</div>
        <div class="subline">{$authorId}{$imageUrl}</div>
    </div>
{/iterate}


Unfortunatelly, just the retrieval of the authors names is working correctly (getFullName(), getFirstName(), getMiddleName(), getLastName()).
Whereas getAuthorId() is retruning a "0" for all of my authors an getUrl() isn't returning any value at all. I checked that the url is present in the article_autors table within the database. I'm claerly missing some detail, but i can't figure out what it is...

thanks for your help in advance
Thomas
censored
 
Posts: 2
Joined: Thu Jun 17, 2010 4:23 am

Re: Building Author Gallery

Postby mcrider » Mon Jun 21, 2010 12:33 pm

Hi Thomas,

Your code looks good, but i'd suggest using $templateMgr->assign_by_ref('authors', $authors); instead of $templateMgr->assign('authors', $authors);. Also, in recent versions of OJS, the function getAuthorId() is deprecated--use getId() instead--Using getAuthorId() might not be returning correct values for you (though it should be backwards-compatible). Other than that, are you getting any messages in your PHP error log that have to do with this?

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

Re: Building Author Gallery

Postby censored » Tue Jun 22, 2010 4:31 am

Hi Matt,

thanks for your reply. I'm getting no error messages regarding the usage of this functions. While trying to understand the structure of the underlying data developed some questions.

For my understanding the data for getAuthorsAlphabetizedByJournal() comes from the article_authors table. By design the authors are incremented per article. So there is no unique id for the author. Same goes for the url within this table. So i had a look on the source of function getAuthorsAlphabetizedByJournal(). It turns out that this function is doing a distinct of all authors identified by firstname, middlename. lastname, affiliation and country. The values for authorid and url are hard coded as 0 and "".

Code: Select all
$result = &$this->retrieveRange(
SELECT DISTINCT
00138             CAST(\'\' AS CHAR) AS url,
00139             0 AS author_id,
00140             0 AS article_id,
00141             CAST(\'\' AS CHAR) AS email,
00142             0 AS primary_contact,
00143             0 AS seq,
00144             aa.first_name AS first_name,
00145             aa.middle_name AS middle_name,
00146             aa.last_name AS last_name,
00147             aa.affiliation AS affiliation,
00148             aa.country


Looking at the structure of the article_authors table this now makes sense to me. So i think i should somehow get all author-objects with equal first/middle/last names, affiliation and country and get one of the urls from a conrete $author.

Via $authors =& $authorDao->getAuthorsAlphabetizedByJournal(); i receive an AuthorDAO object which i can use via the custom smarty function {iterate}. But how can i work with these iterable objects outside of a template? Is there a php function sililar to {iterate}? Or maybe i'am running totally in the wrong direction.

Thanks for making me smarter :)
Thomas
censored
 
Posts: 2
Joined: Thu Jun 17, 2010 4:23 am

Re: Building Author Gallery

Postby mcrider » Tue Jun 22, 2010 9:59 am

Hi Thomas,

You can iterate through those objects (called DAOResultFactories) with a while loop like this
Code: Select all
while($author =& $authors->next()) {
  ...Do stuff with $author...
    unset($author);
}
There should be examples abound in the code of this type of iteration. Also, IIRC you can also call $authors->toArray() on a DAOResultFactory object to convert it to an array (and use a foreach loop to iterate over it).

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


Return to OJS Development

Who is online

Users browsing this forum: No registered users and 3 guests