Invision Community 4: SEO, prepare for v5 and dormant account notifications By Matt Monday at 02:04 PM
Skeptical Posted November 11, 2017 Posted November 11, 2017 Does anyone know or know where I can find the code to check if a member is a member of a specific club?
Ilya Hoilik Posted November 11, 2017 Posted November 11, 2017 Didn't test, but probably something like this /* Load a club and a member */ $club = \IPS\Member\Club::load( CLUB_ID ); $member = \IPS\Member::load( MEMBER_ID ); /* We want to do something only if member status is listed below */ $expectedStatuses = array( \IPS\Member\Club::STATUS_MEMBER, \IPS\Member\Club::STATUS_INVITED, \IPS\Member\Club::STATUS_REQUESTED, \IPS\Member\Club::STATUS_DECLINED, \IPS\Member\Club::STATUS_BANNED, \IPS\Member\Club::STATUS_MODERATOR, \IPS\Member\Club::STATUS_LEADER, ); /* Check whether member status is in the $expectedStatuses array */ if ( in_array( $club->memberStatus( $member ), $expectedStatuses ) ) { // Yes, do something } You can also check only for \IPS\Member\Club::STATUS_MEMBER status: /* Load a club and a member */ $club = \IPS\Member\Club::load( CLUB_ID ); $member = \IPS\Member::load( MEMBER_ID ); /* Is $member located in list of $club members as regular member (not moderator, leader, etc.)? */ if ( $club->memberStatus( $member ) == \IPS\Member\Club::STATUS_MEMBER ) { // Yes, do something } And even shorter: if ( \IPS\Member\Club::load( CLUB_ID )->memberStatus( \IPS\Member::load( MEMBER_ID ) ) == \IPS\Member\Club::STATUS_MEMBER ) { // Do something }
Skeptical Posted November 11, 2017 Author Posted November 11, 2017 15 minutes ago, Ilya Hoilik said: Didn't test, but probably something like this /* Load a club and a member */ $club = \IPS\Member\Club::load( CLUB_ID ); $member = \IPS\Member::load( MEMBER_ID ); /* We want to do something only if member status is listed below */ $expectedStatuses = array( \IPS\Member\Club::STATUS_MEMBER, \IPS\Member\Club::STATUS_INVITED, \IPS\Member\Club::STATUS_REQUESTED, \IPS\Member\Club::STATUS_DECLINED, \IPS\Member\Club::STATUS_BANNED, \IPS\Member\Club::STATUS_MODERATOR, \IPS\Member\Club::STATUS_LEADER, ); /* Check whether member status is in the $expectedStatuses array */ if ( in_array( $club->memberStatus( $member ), $expectedStatuses ) ) { // Yes, do something } You can also check only for \IPS\Member\Club::STATUS_MEMBER status: /* Load a club and a member */ $club = \IPS\Member\Club::load( CLUB_ID ); $member = \IPS\Member::load( MEMBER_ID ); /* Is $member located in list of $club members as regular member (not moderator, leader, etc.)? */ if ( $club->memberStatus( $member ) == \IPS\Member\Club::STATUS_MEMBER ) { // Yes, do something } And even shorter: if ( \IPS\Member\Club::load( CLUB_ID )->memberStatus( \IPS\Member::load( MEMBER_ID ) ) == \IPS\Member\Club::STATUS_MEMBER ) { // Do something } Awesome! So, if I wanted to check on the forum index page if a member was a member of club_id == 7, what would that last line look like? 1 minute ago, Skeptical said: if ( \IPS\Member\Club::load( CLUB_ID )->memberStatus( \IPS\Member::load( MEMBER_ID ) ) == \IPS\Member\Club::STATUS_MEMBER ) this? if ( \IPS\Member\Club::load( 7 )->memberStatus( \IPS\Member::load( MEMBER_ID ) ) == \IPS\Member\Club::STATUS_MEMBER )
Ilya Hoilik Posted November 11, 2017 Posted November 11, 2017 Do you want to check this in HTML templates? If so, there is your code: {{if \IPS\Member\Club::load( 7 )->memberStatus( \IPS\Member::loggedIn() ) == \IPS\Member\Club::STATUS_MEMBER}} show something {{endif}} Otherwise, use normal PHP: if ( \IPS\Member\Club::load( 7 )->memberStatus( \IPS\Member::loggedIn() ) == \IPS\Member\Club::STATUS_MEMBER ) { // do something }
Skeptical Posted November 11, 2017 Author Posted November 11, 2017 Hmmm.... I can't seem to get this right. Here is my full function: public function render() { /* Show this only to members of chatbox member group */ /* if ( \IPS\Member::loggedIn()->mgroup_others == "14" || member_group_id == "4" ) */ if ( \IPS\Member\Club::load( 6 )->memberStatus( \IPS\Member::loggedIn() ) == \IPS\Member\Club::STATUS_MEMBER ) { if ( \IPS\Settings::i()->chatbox_conf_on == 1 && \IPS\Application::load('bimchatbox')->can_View() ) { \IPS\Application::load('bimchatbox')->loadChatbox(); return $this->output(); } } else { return ''; } } We are using the BIMCHATBOX application and users want it located above the forum index page below the header. I would like to hide it from the majority of posters who don't use it. My thought would the the Chatbox users would join a club and that would be their "permission" to see the chatbpx below the header. If you don't want to see it - don't join the club. This way I don't have to try and figure out how to add permissions to the bimchatbox script. I hesitate to use templates, because I don't want them overwritten. This chatbox script will be updated less frequently. Make sense?
Ilya Hoilik Posted November 11, 2017 Posted November 11, 2017 /** * Render a widget * * @return string */ public function render() { $club = \IPS\Member\Club::load( 6 ); $status = $club->memberStatus( \IPS\Member::loggedIn() ); if ( \IPS\Settings::i()->chatbox_conf_on == 1 && \IPS\Application::load('bimchatbox')->can_View() && $status ) { \IPS\Application::load('bimchatbox')->loadChatbox(); return $this->output(); } return ""; }
Skeptical Posted November 11, 2017 Author Posted November 11, 2017 Do you have a paypal account you want to share so I can send you a tip? PM me if you do.... You made a lot of chatbox users very happy!
Recommended Posts
Archived
This topic is now archived and is closed to further replies.