Returning username of approver in on_page_version_approve event?
Permalink
Hi, folks.
I'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.
I'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.
what about cvAuthorID? also, not the most elegant solution but when passed the pag id you could do a direct db call to collection versions something like
Hey, Jack.
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.
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.
Okay, so $approver is the user ID in that code, right? It will pass back a number. How do I then get the uName associated with that uID? I'm not a coder (all I know I've found in the forums or in a "for dummies" book). I managed to replicate your inelegant db call to pull from the Users table, but I don't know how to pass the $approver result in there.
this will give you the name of the user as $name so you can use it with jordans how to ( i think thats where you're coming from)
http://www.concrete5.org/documentation/developers/permissions/users... can give more info about manipulating the user object.
$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.
Right... I ended up with a fair number of posts in the thread that led to that how-to (lol).
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:
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.
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.
thats strange. Maybe instead of the last two lines I gave you do
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)
$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)
Hmm, editing the code to the new two lines here gave this:
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.
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.
Okay, so I'm still wrestling with this issue.
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?
I have also noticed the getVersionApproverUserName function in the API reference. Could I use this function here?
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?
Update: It took a little more tweaking, but I finally found the solution with Jack's help. That event doesn't have two arguments, as it turns out. Here's how I managed it:
Maybe not an elegant solution, but if it works, that's all I need.
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.
yeah, I;m not sure how to do this with the api, sso it might not be future
compatible- but that should be the only issue. (though its not great mvc)
compatible- but that should be the only issue. (though its not great mvc)