display user info in page list

Permalink Browser Info Environment
Hi Willem,

I still love this add-on. The site i'm using it on is now a multi-lingual website, also the translated attributes are displaying right through the user info block.

My problem is when using the user info code in a page list. I know, that's not exactly related to your user info block, but i thought you could maybe help me getting this right.

I'm using this code to display user attributes in my pagelist block to display some author information in the list:
<?php
$c = Page::getCurrentPage(); //get the current page to work with it's information
$uID = $c->getCollectionUserID(); //gets the User ID of the Page Owner
$ui = UserInfo::getByID($uID); //with the User ID, load a UserInfo object   
echo $bioFunction
?>


This works great and displays the value of the user attribute. But i want it to display the translated value. So i tried this:
<?php
$c = Page::getCurrentPage(); //get the current page to work with it's information
$uID = $c->getCollectionUserID(); //gets the User ID of the Page Owner
$ui = UserInfo::getByID($uID); //with the User ID, load a UserInfo object   
   if (!$c->isMasterCollection()) {
      $bioFunction = $ui->getCollectionAttributeValue('bio_function'); //Custom select attribute
      echo tc('SelectAttributeValue', $ui->getCollectionAttributeValue('bio_function'));
   }
?>


Als tried the above with the last line changed to
echo tc('SelectAttributeValue', $bioFunction = $ui->getCollectionAttributeValue('bio_function'));


But this displays empty. Do you have a clue on what code i should use to display the translated values? Your help is very much appreciated!

Type: Pre-Sale
Status: Resolved
buurvrouw
View Replies:
buurvrouw replied on at Permalink Reply
buurvrouw
Oh i forgot to mention that i have this in the foreach section of the pagelist view:

<?php  foreach ($controller->pages as $page):
$uID = $page->getCollectionUserID(); //gets the User ID of the Page Owner
$ui = UserInfo::getByID($uID); //with the User ID, load a UserInfo object
   if (!$page->isMasterCollection()) {
      // Some standard values here and then the user info part
      $ownerName = $ui->getUserName(); //get the username of the page owner
      $fullName = $ui->getAttribute('full_name'); //Custom Text attribute
      $bioFunction = $ui->getAttribute('bio_function'); //Custom Select attribute
      $Vestiging = $ui->getAttribute('vestiging'); //Custom Text attribute
      $Phone = $ui->getAttribute('phone'); //Custom Text attribute
      $MobilePhone = $ui->getAttribute('mobile_phone'); //Custom Text attribute
      $profilePic = $ui->getAttribute('portret_foto'); //Custom Image Attribute
   }
?>


I need to get the bio_function. This is a user select attribute with 3 values.
WillemAnchor replied on at Permalink Reply
WillemAnchor
Hi Buurvrouw,

I didn't test this on your specific issue, but:
$value = $ui->getAttributeValueObject($ua);
if (is_object($value)) {
$attval = $value->getValue('displaySanitized', 'display');
}

may do the trick.
You can check how I used it In my getUserAttributes() function

-----

On a different note: I've been working on a new version for UserInfo.

Some of the changes will be:
- added translation, including dutch language
- fixed redactor dropdownmenu problem when switching tabs
- faster code (rewritten cascade calls)
- cleaned up and restructured a lot of the code (config, editors, content, save)
- save config in application file instead of database
specific 8.0 changes:
- attributes compatible with 8.0
- ckeditor plugin (redactor plugin still available for 5.7 installs)
- replaced deprecated UserInfo::getByID

I'm not sure yet when it will be released, but I'll try to have it available before v8 launches.
buurvrouw replied on at Permalink Reply
buurvrouw
Ah thanks for the quick reply and pointing out the direction for a solution, i'm gonna try to get this working.

And this update sounds great!
buurvrouw replied on at Permalink Reply
buurvrouw
Managed to do this with your directions:

Put this in the 'foreach' function in the page list template:
$uID = $page->getCollectionUserID(); //gets the User ID of the Page Owner
$ui = UserInfo::getByID($uID); //with the User ID, load a UserInfo object
   if (!$page->isMasterCollection()) {
      $yourVariable = $ui->getAttributeValueObject('your_attribute'); //Custom Select attribute
         if (is_object($yourVariable)) { 
            $attval = $yourVariable->getValue('displaySanitized', 'display'); 
         }
   }


And then echo $attval somewhere you want to display the value.

Thanks for your help Willem!
WillemAnchor replied on at Permalink Reply
WillemAnchor
Yes, that looks nice. Glad you got it working.

concrete5 Environment Information

.

Browser User-Agent String

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/601.7.7 (KHTML, like Gecko) Version/9.1.2 Safari/601.7.7

Hide Post Content

This will replace the post content with the message: "Content has been removed by an Administrator"

Hide Content

Request Refund

You may not request a refund that is not currently owned by you.