Returning username of approver in on_page_version_approve event?
PermalinkI've got change notifications going out via email based on page additions and updates, and it's working well, but I can't figure out how to return the name of the person approving a page in the on_page_version_approve event. The author name is available to be grabbed, but not the user ID of the approving party. I was using the Event Tester add-on to track what information is passed in the on_page_version_approve event, and there is a field for cvApproverUID, but it's blank every time.
Any ideas?
Thanks.

Thanks for the response. Unfortunately, the cvAuthorID won't work because that's almost always going to be someone different than the approver in my system (users will make page edits and submit them to supervisors for approval). As for the db call, that looks promising. I'll give it a shot and let you know how it works.
$db=loader::db(); $approver=$db->getOne("SELECT cvApproverUID from CollectionVersions where cvIsApproved=1 AND cvID=?", array($page->getCollectionID())); $u = User::getByUserID($approver); $name=$u->getUserName();
http://www.concrete5.org/documentation/developers/permissions/users... can give more info about manipulating the user object.
I'm using that code, but now it's leaving me with a blank space where the information should be appearing... here's what I've got:
function on_page_version_approve($page) { $name = $page->getCollectionName(); $db = loader::db(); $approver = $db->getOne("SELECT cvApproverUID from CollectionVersions where cvIsApproved = 1 AND cvID = ?", array($page->getCollectionID())); $u = User::getByUserID($approver); $approvername = $u->getUserName(); $location = View::url($page->getCollectionPath()); ChangeNotifications::send($page, "The $name document has been approved by $approvername and published in the Document Library. You can access this document athttp://localhost$location.\n\nThanks,\nDocument Library Admin", 'example@email.com', 'example2@email.com', "$name Document Published"); }
My result looks like this...
The Test Page document has been approved by and published in the Document Library....
Seems like it's just passing a blank.
$ui = UserInfo::getByID($approver); $ui->getUserName();
but I'm just guessing. Can you check if the $approver variable is a valid uid? go to /dashboard/users/search?uID=$approver if it is, then check that ther is a user name set. If not, then the approver is an invalid user (which is even wierder)
Fatal error: Call to a member function getUserName() on a non-object in C:\wamp\www\concrete\libraries\change_notifications.php on line 54
I don't think the issue is with the users... I have tried with two different users that have approval privileges and received the same blank space result each time.
Let me see if I can just get the email to include the user ID rather than the name and make sure that I can get at least that. If I can get that, maybe we can pinpoint where the blank space is coming from.
Thanks for the help.
-----
EDIT: Okay, when I just try to put the user ID in the email, I still get that blank space. So the db call isn't returning a value for some reason. At least, I think that's what's happening.
According to the documentation for events, the on_page_version_approve event "passes an additional page object containing the approved version."
Does that mean the event has two arguments? Could I reference it like so?
function on_page_version_approve($page, $nv) {
I have also noticed the getVersionApproverUserName function in the API reference. Could I use this function here?
function on_page_version_approve($page) { $name = $page->getCollectionName(); $db = loader::db(); $versionid = $page->getVersionID(); $approver = $db->getOne("SELECT cvApproverUID from CollectionVersions where cvIsApproved = 1 AND cvID = '$versionid'"); $u = User::getByUserID($approver); $approvername = $u->getUserName(); $location = View::url($page->getCollectionPath()); ChangeNotifications::send($page, "The $name document has been approved by $approvername and published...
Maybe not an elegant solution, but if it works, that's all I need.
compatible- but that should be the only issue. (though its not great mvc)