Keyword

Making K2 Userblock Options Conditional

  • MW Rajiv
  • MW Rajiv's Avatar Topic Author
  • Offline
  • New Member
More
8 years 10 months ago - 8 years 10 months ago #145170 by MW Rajiv
Making K2 Userblock Options Conditional was created by MW Rajiv
Hello everyone, i'm intending to create a multi user blog with joomla & k2. I've usergroup: "Author" ID: "3" in joomla usergroup with "Viewing Access Levels" set & usergroup: "Author" ID: "2" in K2 usergroup. I want users in "Author" usergroup will be blogger & "Registered" usergroup will be just commenter. I've enabled front-end editing in K2 so registered people can see their options in userblock after login. There are 3 common options in the userblock for users:
1. My Page
2. My Account
3. Moderate Items to my Published Items

Now i need to make "My Page" & "Moderate Items to my Published Items" conditional so that users without authoring privilege can't see these options, Because they don't need to access these options as they don't supposed to have their page or any published item.

I tried to describe my problem here in detail & i expect somebody may help me out in detail also. Thanks.
Image Link: i.imgur.com/Gtm1H3I.jpg
Last edit: 8 years 10 months ago by MW Rajiv.

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
8 years 10 months ago #145199 by Krikor Boghossian
Replied by Krikor Boghossian on topic Making K2 Userblock Options Conditional
Hello,

With this function you can check the current user's groups.
docs.joomla.org/Accessing_the_current_user_object

Depending on the user's groups you can show/ hide elements in the K2 User module.

Do not forget to override the module.
docs.joomla.org/How_to_override_the_output_from_the_Joomla!_core

Use the same method as described for the mod_k2_user module.

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

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

  • MW Rajiv
  • MW Rajiv's Avatar Topic Author
  • Offline
  • New Member
More
8 years 10 months ago #145251 by MW Rajiv
Replied by MW Rajiv on topic Making K2 Userblock Options Conditional
Thank you www.joomlaworks.net/forum/profile/990-krikor for your kind reply, but as i am inexpert in coding i couldn't figure it out yet. But still i'm trying. Thank you again.

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

  • MW Rajiv
  • MW Rajiv's Avatar Topic Author
  • Offline
  • New Member
More
8 years 10 months ago - 8 years 10 months ago #145253 by MW Rajiv
Replied by MW Rajiv on topic Making K2 Userblock Options Conditional
Dear Mr. Krikor, though i'm inexpert in coding i tried it but no results returned. What i've tried as i couldn't attach with this reply i'm pasting it here. Would you please checkout what i've mistaken? it would be kind enough if you give me the fixes.. .
	<?php
	  $user = JFactory::getUser();

	  if (in_array("2" /*(K2 Author Group ID is 2)*/, $user->groups)) {
		  <div class="k2UserBlockDetails">
			  <?php if($params->get('userAvatar')): ?>
			  <a class="k2Avatar ubAvatar" href="<?php echo JRoute::_(K2HelperRoute::getUserRoute($user->id)); ?>" title="<?php echo JText::_('K2_MY_PAGE'); ?>">
				<img src="<?php echo K2HelperUtilities::getAvatar($user->id, $user->email); ?>" alt="<?php echo K2HelperUtilities::cleanHtml($user->name); ?>" style="width:<?php echo $avatarWidth; ?>px;height:auto;" />
			  </a>
			  <?php endif; ?>
			  <span class="ubName"><?php echo $user->name; ?></span>
				<span class="ubCommentsCount"><?php echo JText::_('K2_YOU_HAVE'); ?> <b><?php echo $user->numOfComments; ?></b> <?php if($user->numOfComments==1) echo JText::_('K2_PUBLISHED_COMMENT'); else echo JText::_('K2_PUBLISHED_COMMENTS'); ?></span>
			  <div class="clr"></div>
		  </div>
	  } else {
		  <div class="k2UserBlockDetails">
			  <?php if($params->get('userAvatar')): ?>
			  <a class="k2Avatar ubAvatar" href="<?php echo JRoute::_(K2HelperRoute::getUserRoute($user->id)); ?>" title="">
				<img src="<?php echo K2HelperUtilities::getAvatar($user->id, $user->email); ?>" alt="<?php echo K2HelperUtilities::cleanHtml($user->name); ?>" style="width:<?php echo $avatarWidth; ?>px;height:auto;" />
			  </a>
			  <?php endif; ?>
			  <span class="ubName"><?php echo $user->name; ?></span>
			  <div class="clr"></div>
		  </div>
	  }
	?>
Last edit: 8 years 10 months ago by MW Rajiv.

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
8 years 10 months ago #145268 by Krikor Boghossian
Replied by Krikor Boghossian on topic Making K2 Userblock Options Conditional
First of all kudos for getting your hands dirty.
Good for you.

in_array("2", -> should be in_array(2,

Also you need to watch for unclosed php tags.
All php code should be enclosed inside <?php ?>
eg: , $user->groups)) { should be: , $user->groups)) { ?>

} else { should be :
<?php } else { ?>

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