Keyword

Hiding specific extra fields from public

  • robb rich
  • robb rich's Avatar Topic Author
  • Offline
  • New Member
More
12 years 9 months ago #101838 by robb rich
Hiding specific extra fields from public was created by robb rich
Hello,
I followed a couple of great posts that showed how to break the Extra Fields into individual items, and then call to them by ID to easily customize how they are displayed. The only thing I have run into is I need about 20 of those to be viewable only to registered (administrator) users.

I have some plugins that will hide text from public view, but that only works within the editor. So I am hoping someone knows of a php script I can insert in my K2 item.php to hide the Extra Fields based on the status of the visitor.

Thank you in advance,
Robb

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

More
12 years 9 months ago #101839 by william white
Replied by william white on topic Re: Hiding specific extra fields from public
a combination of

?php $user =& JFactory::getUser()

and

if ($user->guest) {
echo "Please log in.";
} else {
echo "Welcome!";
}

can be used to wrap the dispaly code with the appropriate changes

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

  • robb rich
  • robb rich's Avatar Topic Author
  • Offline
  • New Member
More
12 years 9 months ago #101840 by robb rich
Replied by robb rich on topic Re: Hiding specific extra fields from public
william
thank you for the reply!

so to see if I understand correctly, in my K2 item.php page I would do something like this?
<?php $user =& JFactory::getUser()>
if ($user->guest) { 
echo "Please log in."; 
} else { 
echo 
<ul>
<li>
	<?php if($extrafieldsid[31]) {?>
	<span class="itemExtraFieldsLabel"><?php echo $extrafieldslabels[31];?>: </span><span class="itemExtraFieldsValue"><?php echo $extrafieldsid[31];?></span><br>
	<?php }?>
</li>

</ul>
; 
} 

would that code also hide these items from the search feature for a guest?

I am really close to having this issue resolved...

thanks again
robb

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

More
12 years 9 months ago #101841 by william white
Replied by william white on topic Re: Hiding specific extra fields from public
I dont know, but i wouldnt think so, as the search routine is different. Just have to test it when you get it hidden

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

  • robb rich
  • robb rich's Avatar Topic Author
  • Offline
  • New Member
More
12 years 9 months ago #101842 by robb rich
Replied by robb rich on topic Re: Hiding specific extra fields from public
Thanks! That really helped.

I found the correct combination for the code to hide my entire string of extra fields - now I just need to find a way to get my search to not look at the extra fields. I may have to use a different search component, but thanks to you I am that much closer.

here's what I ended up doing:
<?php $user =& JFactory::getUser(); ?>
<?php if ($user->guest): ?>
<?php else: ?> 

<ul>
<li>
        <?php if($extrafieldsid[31]) {?>
       <span class="itemExtraFieldsLabel"><?php echo $extrafieldslabels[31];?>: </span><span class="itemExtraFieldsValue"><?php echo $extrafieldsid[31];?></span><br>
  <?php }?>
</li>
 
</ul>

<?php endif; ?>

thanks for your help!
robb

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

More
12 years 7 months ago #101843 by Steven Johnson
Replied by Steven Johnson on topic Re: Hiding specific extra fields from public
Thanks for this thread, I think it was exactly what I needed.

I was hoping to display a content item to any visitor but if that visitor is a logged member they they would see the content item plus some extra fields.

I was thinking this could be my plan

1. Create the content item
2. Add extrafields to the the content item
3. Use this code to only show the extra field to registered users
Log in  or Create an account to join the conversation.

  • robb rich
  • robb rich's Avatar Topic Author
  • Offline
  • New Member
More
12 years 7 months ago #101844 by robb rich
Replied by robb rich on topic Re: Hiding specific extra fields from public
steven
I would think it's possible. you'd just have to create the two separate groups, and then find the right phrasing to get the group.

probably something similar to this:
if ( $userGroupName == $myGroupName && $myGroupName == 'Group1' )
{
// administrators can't change each other
$lists = '<input type="hidden" name="gid" value="'. $user->get('gid') .'" /><strong>'. JText::_( 'Group1' ) .'</strong>';
}
else
{
$gtree = $acl->get_group_children_tree( null, 'USERS', true);

I'm not 100% certain of the call to make, but I'm pretty sure it can be done with some variation on the code above.

good luck!
rob

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

More
12 years 7 months ago #101845 by william white
Replied by william white on topic Re: Hiding specific extra fields from public
Could I change php to show a video to group1 and a different video to group2?

if you are relying on using the built in k2 media (video) there is only one per item

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

More
12 years 7 months ago #101846 by szecska
Replied by szecska on topic Re: Hiding specific extra fields from public
Hi!

I can't find this text. :(

K2 v.2.6.1

Should I find it here?
components\com_k2\templates\default\item.php

Should I edit this?
<ul>
			<?php foreach ($this->item->extra_fields as $key=>$extraField): ?>
			<?php if($extraField->value): ?>
			<li class="<?php echo ($key%2) ? "odd" : "even"; ?> type<?php echo ucfirst($extraField->type); ?> group<?php echo $extraField->group; ?>">
				<span class="itemExtraFieldsLabel"><?php echo $extraField->name; ?>:</span>
				<span class="itemExtraFieldsValue"><?php echo $extraField->value; ?></span>
			</li>
			<?php endif; ?>
			<?php endforeach; ?>
			</ul>

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

More
12 years 7 months ago #101847 by william white
Replied by william white on topic Re: Hiding specific extra fields from public
If you want to hide an extra field in the item view then use item.php in your k2 template folder of edit item.php in yoru k2 custom override folder(best solution)

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

More
12 years 7 months ago #101848 by szecska
Replied by szecska on topic Re: Hiding specific extra fields from public
Thanks for your quick reply.
I would like to make visible the extra fields only for the registered users.

Would you write down to me what should I change in the item.php file exactly?

Thanks.

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

More
12 years 6 months ago - 12 years 6 months ago #101849 by william white
Replied by william white on topic Re: Hiding specific extra fields from public
The k2 2.5.7 changes would be something like this
<?php if($this->item->params->get('itemExtraFields') && count($this->item->extra_fields)): ?>
<!-- Allow Retistared Users Only -->
<?php $user =& JFactory::getUser(); ?>
<?php if ($user->guest): ?>
guest user cannot see them
<?php else: ?>      
          <!-- Item extra fields -->
          <div class="itemExtraFields">
                <h3><?php echo JText::_('K2_ADDITIONAL_INFO'); ?></h3>
                <ul>
                        <?php foreach ($this->item->extra_fields as $key=>$extraField): ?>
                        <?php if($extraField->value): ?>
                        <li class="<?php echo ($key%2) ? "odd" : "even"; ?> type<?php echo ucfirst($extraField->type); ?> group<?php echo $extraField->group; ?>">
                                <span class="itemExtraFieldsLabel"><?php echo $extraField->name; ?>:</span>
                                <span class="itemExtraFieldsValue"><?php echo $extraField->value; ?></span>
                        </li>
                        <?php endif; ?>
                        <?php endforeach; ?>
                        </ul>
            <div class="clr"></div>
          </div>
<?php endif; ?>
          <?php endif; ?>

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

More
12 years 6 months ago #101850 by szecska
Replied by szecska on topic Re: Hiding specific extra fields from public
Thank you William!

It' s working.... :)

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

More
12 years 6 months ago #101851 by william white
Replied by william white on topic Re: Hiding specific extra fields from public
welcome

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

More
10 years 10 months ago #101852 by Pablo Benitez
Replied by Pablo Benitez on topic Re: Hiding specific extra fields from public
I'm trying to filter one group of extra field, but the condition is not working. Any idea?

Here is the problem:
((int)($extrafield->group)) == 12

If i put <> the condition is met, and in the echo $extraField->group a 12 is print. This doesn't make sense to me but I'm not a php expert. It should be something silly that I'm missing. Please help!

<?php foreach ($this->item->extra_fields as $key=>$extraField): ?>

			<?php if($extraField->value): ?>
				<!-- Allow Retistared Users Only -->
		    	<?php $user =& JFactory::getUser(); ?>
				<?php if ($user->guest): ?>
					<?php if(((int)($extrafield->group)) == 12): ?>
						<li class="<?php echo ($key%2) ? "odd" : "even"; ?> type<?php echo ucfirst($extraField->type); ?> group<?php echo $extraField->group; ?>">
							<span class="itemExtraFieldsLabel">TEST<?php echo $extraField->group; ?>TEST</span>
							<span class="itemExtraFieldsValue"><?php echo $extraField->value; ?></span>
						</li>
					<?php else: ?>	
						<li class="<?php echo ($key%2) ? "odd" : "even"; ?> type<?php echo ucfirst($extraField->type); ?> group<?php echo $extraField->group; ?>">
							<span class="itemExtraFieldsLabel"><?php echo $extrafield->id  ?><?php echo $extraField->name; ?>:</span>
							<span class="itemExtraFieldsValue"><?php echo $extraField->value; ?></span>
						</li>
					<?php endif; ?>
				<?php else: ?>
					<li class="<?php echo ($key%2) ? "odd" : "even"; ?> type<?php echo ucfirst($extraField->type); ?> group<?php echo $extraField->group; ?>">
						<span class="itemExtraFieldsLabel"><?php echo "86" ?><?php echo $extraField->name; ?>:</span>
						<span class="itemExtraFieldsValue"><?php echo $extraField->value; ?></span>
					</li>
				<?php endif; ?>
			<?php endif; ?>

			<?php endforeach; ?>

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
10 years 10 months ago #101853 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: Hiding specific extra fields from public
What does echo $extrafield->group; return.

Have you tried using var_dump() to see all the possible values you can use?

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