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!
