OJS OCS OMP OHS

You are viewing the PKP Support Forum | PKP Home Wiki



Retreiving a list of Journal Manager(s) and DAO use.

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.

Retreiving a list of Journal Manager(s) and DAO use.

Postby rmichael » Fri Aug 01, 2008 10:15 am

Hello,

I'm starting to work on a plugin and would like to retrieve the e-mail address of the Journal Manager account(s). Examining some of the other code which deals with roles, I've tried to do this as follows:

Code: Select all
$roleDao = &DAORegistry::getDAO('RoleDAO');
$roleId = &$roleDao->getRoleIdFromPath('manager');

/* Log the retreived roleId, this works; I get "16". */
error_log("NotificationPlugin: " . $roleId);

$userDaos = &$roleDao->getUsersByRoleId($roleId, $journalId);


Looking at the API, I expected getUsersByRoleId to return an array (well, ItemIterator) of User objects, but they appear to be UserDAO objects (only based on my trying to print them and PHP telling me it can't convert object of class UserDAO to string). This doesn't seem correct, is there one UserDAO object per User object?

Just trying to iterate over those to understand what's happening, I know I have an account named "admin", so I tried to retrieve it. (I can't do this in general, because I only know the roleId, and UserDAO doesn't seem to have a method to getUserByRoleId.)

Code: Select all
foreach ($userDaos as $userDao) {
  $user = $userDao->getUserByUsername('admin');
  error_log("NotificationPlugin: user " . $user->getUsername() . " has " . $user->getEmail());
}


Then I receive an error message about "a call to member function getUserByUsername on a non-object". I could probably sort that out, but I'm more confused about the use of the UserDAO and User objects.

I don't understand the return value of RoleDAO::getUsersByRoleId in the API at http://pkp.sfu.ca/ojs/doxygen/html/classRoleDAO.html#a24b3e3f9a4958638a4b8364f2095612. What does "array matching Users" mean? An array of User objects, or something else?

I've read the Technical Reference, but it's a simpler example with ArticleDAO. It doesn't help that I'm learning PHP as I go. :-)

Any help would be appreciated, thanks!
rmichael
 
Posts: 113
Joined: Fri Mar 30, 2007 3:32 pm

Re: Retreiving a list of Journal Manager(s) and DAO use.

Postby asmecher » Fri Aug 01, 2008 10:31 am

Hi Richard,

I suspect you're trying to do a regular "foreach" loop on an ItemIterator object. The RoleDAO::getUsersByRoleId function should indeed return an ItemIterator; if you're trying to loop through the results in PHP, use a pattern like:
Code: Select all
$result =& $roleDao->getUsersByRoleId( ... );
while ($user =& $result->next()) {
    echo "Username: " . $user->getUsername() . "<br/>\n";
    unset($user);
}
If you're trying to loop through the results in a Smarty template, assign the result to the template manager and use something like:
Code: Select all
{iterate from=result item=user}
    Username: {$user->getUsername()}<br/>
{/iterate}
Regards,
Alec Smecher
Public Knowledge Project Team
asmecher
 
Posts: 8902
Joined: Wed Aug 10, 2005 12:56 pm

Re: Retreiving a list of Journal Manager(s) and DAO use.

Postby rmichael » Fri Aug 01, 2008 2:03 pm

That's a big help, I've got it working now. Thanks Alec.
rmichael
 
Posts: 113
Joined: Fri Mar 30, 2007 3:32 pm


Return to OJS Development

Who is online

Users browsing this forum: No registered users and 1 guest