Keyword

Hiding Attachments or Extra Fields based on User L

  • Jim Grove
  • Jim Grove's Avatar Topic Author
  • Offline
  • New Member
More
10 years 6 months ago #120296 by Jim Grove
Is there an easy way to display the Extra Fields or Attachments to registered users only? Could another variable/criteria be added to the <?php if...> statement in the item.php template that determines whether or not to display the Extra Fields or Attachments?

I am looking to create a White Paper/Presentation Directory. I want to use the Content Tab for the Abstract and The image Tab for the Speaker. Both of these should be seen by the public for Search/browsing capability. However, a user must be registered or part of a certain ACL group to see and download the actual paper or presentation under Extra Fields or Attachments.

Any advice would be appreciated.

Thanks,

Jim

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
10 years 6 months ago #120297 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: Hiding Attachments or Extra Fields based on User L
You can Joomla!'s API to hide or show elements in a K2 template

eg. forum.joomla.org/viewtopic.php?p=2725146

Just make sure $user is not initialy defined in the K2 template as well.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

  • Jim Grove
  • Jim Grove's Avatar Topic Author
  • Offline
  • New Member
More
10 years 6 months ago - 10 years 6 months ago #120298 by Jim Grove
A PHP knowledgeable friend of mine suggested this.

So the following line of:

<?php if($this->item->params->get('itemAttachments') && count($this->item->attachments)): ?>

Would become:

<?php
$user = JFactory::getUser();
$groupID = 2; // Replace "2" with the group ID
if ($user && ($userId = $user->get('id'))) {
$groups = JAccess::getGroupsByUser($userId, false);
if (in_array($groupID, $groups) && $this->item->params->get('itemAttachments') && count($this->item->attachments)): ?>

Then at the end of that section where it has this:

<?php endif; ?>

Replace it with this:

<?php endif; } ?>

Do you see any issues with this line of thinking?

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
10 years 6 months ago #120299 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: Hiding Attachments or Extra Fields based on User L
I think that would work as well but it kind of an overkill if you only want to check if a user is logged in. You can use this solution if you want your user to belong to a specific user group.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

  • Jim Grove
  • Jim Grove's Avatar Topic Author
  • Offline
  • New Member
More
10 years 6 months ago #120300 by Jim Grove
Thanks Krikor! However, we do need the specific group. We have different Member Levels. The only thing he didn't show me was how to name Multiple groups. I wish I knew php...

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
10 years 6 months ago #120301 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: Hiding Attachments or Extra Fields based on User L
the
$groupID = 2; // Replace "2" with the group ID

part shoudl do the trick. You can see the ID from the backend.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum