Hook on createdByUserNumHTML

By Djulia - February 24, 2012 - edited: February 24, 2012

Hi,

Is it possible to apply a hook to createdByUserNumHTML with a plugin?

I would like to obtain only to the list the editors and authors who have access to the section for example.

Thanks for your suggestions!

Djulia

Re: [Djulia] Hook on createdByUserNumHTML

By Dave - February 29, 2012

Hi Djulia,

Sorry for the delay, this question required some digging into the code. :)

Can you provide some more details on what you're looking for?
- Are you wanting to update the <select user> pulldown so it only shows users who can access a section
- Are you wanted to get a list of users who can access a section for another purpose?

Would it make sense to have a plugin filter that would allow you to modify an array of users in /lib/common.php ajaxGetUsersAsPulldown() ?

Let me know some more details and I'll try to help or update the code for you. Thanks!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Hook on createdByUserNumHTML

By Djulia - February 29, 2012

Hi Dave,

>Sorry for the delay
Your availability is already very large ! :)

> Are you wanting to update the <select user> pulldown
Yes, I have 150 users in the pulldown, but there are only 2 editors and 1 authors for each section. If the list were less important and limited to the authorized accounts (editors, authors), the use would be more ergonomic. Currently, we must check directly in the Accounts section if the editor (or the author) has an access to the section.

>Would it make sense to have a plugin filter
I do not think that there are many scenarios but a plugin would give certainly other possibilities.

Do you think that it is possible?

Thanks again! :)

Djulia

Re: [Djulia] Hook on createdByUserNumHTML

By Dave - February 29, 2012

Hi Djulia,

I've written up some code for that for the next version. Can you help me test it?

Replace this function in /lib/menus/default/common.php

// show pulldown when editor clicks "change" beside "Created By" on edit page in CMS
function ajaxGetUsersAsPulldown() {
global $TABLE_PREFIX, $hasEditorAccess, $tableName;
if (!$hasEditorAccess) { return ''; } // must have section admin access

// get users with access to this section
$query = "SELECT u.num, u.username
FROM {$TABLE_PREFIX}accounts u
JOIN {$TABLE_PREFIX}_accesslist a ON u.num = a.userNum
WHERE a.accessLevel > 1 AND a.tableName IN ('all','$tableName')";
$users = mysql_fetch($query);

// get option values
$userNums = array_pluck($users, 'num');
$userNames = array_pluck($users, 'username');
$optionsHTML = getSelectOptions(null, $userNums, $userNames);

// show pulldown
$selectHTML = "<select name='createdByUserNum'>\n";
$selectHTML .= "<option value=''>" .htmlspecialchars(t("<select user>")). "</option>\n";
$selectHTML .= $optionsHTML;
$selectHTML .= "</select>\n";

//
print $selectHTML;
exit;
}


Hope that helps, can you let me know if that does what you need? Thanks!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Hook on createdByUserNumHTML

By Djulia - March 1, 2012

Hi Dave,

It is perfect for me! :)

Thanks to have taken into account this request.

Djulia

Re: [gkornbluth] Hook on createdByUserNumHTML

By Djulia - March 15, 2012

Hi Jerry,

In fact, my request was really directed on the <select user> pulldown.

Nevertheless, thanks for your effort.

Djulia