Custom Attributes - List of Users

Permalink
I'm working on a site where I've created registered user accounts. Those users can publish content. I would like to associate content to the related user's profile page. For instance, if you look at a certain user's profile, I'd like the details to include a list of and links to articles that person has written.

What I was wondering is: is there a way to create a custom select attribute where the options are a list of all registered users?

Thanks

 
mkly replied on at Permalink Reply
mkly
I'm not totally sure what you are looking for but some of this might be of help


You can do a page list to get a list of pages
If you override the profile view.php single page you ca do
Loader::model('page_list');
$pl = new PageList();
//$profile is provided to profile page view from its controller
$pl->filterByUserID($profile->getUserID());
$user_articles = $pl->get();

That will get you a list of all the Pages created by that user. If that is how they are creating content. I'm not sure if that's what you mean.

You can definitely make a select box of all the registered users.
In a controller of a block or something you can do
Loader::model('user_list');
$ul = new UserList();
//returns a list of users
$users = $ul->get();
$select_users_options = array();
//create an array to be used in the form
foreach($users as $user) {
  $select_user[$user->getUserID()] = $user->getUserName();
}


Then you can use that in a select form element
<?php $form = Loader::helper('form'); ?>
<?php echo $form->label('user_select', 'Select a User'); ?>
<?php echo $form->select('user_select', $select_users_options); ?>


Hope that is of some help.
Metaglyphics replied on at Permalink Reply
Thanks. This is great info. But what I was thinking was, that when creating a page, you would have a custom attribute that listed all the users. You could then select the name or names to be associated with that page.

For instance, if I were publishing a news item that relates to a couple of people, I would like to be able to select those names and cross-reference this item with those profile pages.

And those custom attributes would ideally list all of the users that have been added to the system. Rather than a hard-coded list of names...
Metaglyphics replied on at Permalink Reply
In other words, if I create a Page Attribute called AllUsers, make it a Select type, allowing multiple selections, I would normally have to create several values for the dropdown list.

What would be ideal is if there were a way to automatically populate that dropdown with a list of all the users in the database.

Then when I create a page, in its properties, I can select one or more users to be associated with this page.

Then when I look at one of those user's profiles, I can have the profile details include a link to that page.
mkly replied on at Permalink Reply
mkly
Well if you were really motivated you could use the user select list code from about and create a new page type.
http://www.concrete5.org/documentation/developers/attributes/types/...

Probably wouldn't be too terribly difficult.