By Philippe on Monday, 20 August 2018
Likes 0
Views 22.4K
Votes 0
Hello,

I integrated a button to join a specific Group, outside the Group.

This is what I pasted into the file /modules/mod_easysocial_quickpost/tmpl/default.php :

<a class="btn btn-es-default-o btn-sm" href="javascript:void(0);" data-es-groups-join data-id="2" data-page-reload="1">
<div class="o-loader o-loader--sm"></div>
<?php echo JText::_('COM_EASYSOCIAL_GROUPS_JOIN_GROUP');?>
</a>
The button works. By clicking on it, the user automatically joins the Group

However, I would like this button to appear only if the user is not yet a member of the specified group.

Would you have any idea of the php code that I can use to check this, and decide whether or not to display this button ?

A code like for example :

<?php if ($this->my->getAccess()->get('groups.allow.join') && !$group->isInviteOnly() && !$group->isMember() && !$group->isPendingMember() && !$group->isInvited()) { ?>
<a class="btn btn-es-default-o btn-sm" href="javascript:void(0);" data-es-groups-join data-id="2" data-page-reload="1">
<div class="o-loader o-loader--sm"></div>
<?php echo JText::_('COM_EASYSOCIAL_GROUPS_JOIN_GROUP');?>
</a>
<?php } ?>
But it would be necessary to specify the Group id concerned in the PHP code...

Thank your for your help
Philippe
Hi Phillipe,

You almost get it right, where you need to alter it a bit where you need to add another condition if the group with that id only show the button eg:
[gist type="php"]
<?php if ($this->my->getAccess()->get('groups.allow.join') && !$group->isInviteOnly() && !$group->isMember() && !$group->isPendingMember() && !$group->isInvited() && ($group->id == 2)) { ?>
[/gist]

and if the user if already a member you can do the condition as:
[gist type="php"]
<?php if ($group->isMember()) { ?>
<?php } ?>
[/gist]
so that the user will not see the button anymore.
·
Tuesday, 21 August 2018 11:02
·
0 Likes
·
0 Votes
·
0 Comments
·
Thanks for your return Fadhli.
Ah, I see, it's the magic formula I missed : ($group->id == 2)

Only I get an error :
#0 Using $this when not in object context

Because in my opinion it is because we are in a module, and not in the Group.
And we must probably specify the context.
Something is missing...

An idea Fadhli ?
Thank you,
Philippe

PS.
Here is the complete content of my file : /modules/mod_easysocial_quickpost/tmpl/default.php
Display in Dashboard and Profile.


<?php
/**
* @package EasySocial
* @copyright Copyright (C) 2010 - 2016 Stack Ideas Sdn Bhd. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* EasySocial is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/
defined('_JEXEC') or die('Unauthorized Access');
?>
<div id="es" class="mod-es mod-es-quickpost <?php echo $lib->getSuffix();?>" data-quickpost-module>

<?php if ($this->my->getAccess()->get('groups.allow.join') && !$group->isInviteOnly() && !$group->isMember() && !$group->isPendingMember() && !$group->isInvited() && ($group->id == 2)) { ?>
<a class="btn btn-es-default-o btn-sm" href="javascript:void(0);" data-es-groups-join data-id="2" data-page-reload="1">
<div class="o-loader o-loader--sm"></div>
<?php echo JText::_('COM_EASYSOCIAL_GROUPS_JOIN_GROUP');?>
</a>
<?php } ?>

<?php echo $story->html(true);?>
</div>
·
Tuesday, 21 August 2018 17:03
·
0 Likes
·
0 Votes
·
0 Comments
·
Basically the
[gist type="php"]
$this->my
[/gist]
is
[gist type="php"]
ES::user();
[/gist]

Perhaps, can you try change it to
[gist type="php"]
ES::user()->getAccess()->get('groups.allow.join')
[/gist]
and see how it goes?
·
Tuesday, 21 August 2018 17:41
·
0 Likes
·
0 Votes
·
0 Comments
·
Thanks. There is progress but it does not work

I get this error message :
#0 Call to a member function isInviteOnly() on null
With this code :

<?php if (ES::user()->getAccess()->get('groups.allow.join') && !$group->isInviteOnly() && !$group->isMember() && !$group->isPendingMember() && !$group->isInvited() && ($group->id == 2)) { ?>
<a class="btn btn-es-default-o btn-sm" href="javascript:void(0);" data-es-groups-join data-id="2" data-page-reload="1">
<div class="o-loader o-loader--sm"></div>
<?php echo JText::_('COM_EASYSOCIAL_GROUPS_JOIN_GROUP');?>
</a>
<?php } ?>


Philippe
·
Tuesday, 21 August 2018 18:08
·
0 Likes
·
0 Votes
·
0 Comments
·
You need to called the group library for the $group
as example:
[gist type="php"]
$group = ES::group($groupId);
[/gist]
·
Tuesday, 21 August 2018 19:03
·
0 Likes
·
0 Votes
·
0 Comments
·
It was the piece that was missing from my puzzle !
It works as I want now.

Thank you very much Fadhli.
Philippe
·
Tuesday, 21 August 2018 23:15
·
0 Likes
·
0 Votes
·
0 Comments
·
Great Phiippe

Just for your information, I have locked and marked this thread as resolved to avoid confusions in the future. Please start a new thread if you have any other issue in the future so it will be easier for us to manage your inquiries.

Thanks for understanding and have a nice day ahead
·
Thursday, 23 August 2018 10:17
·
0 Likes
·
0 Votes
·
0 Comments
·
View Full Post