Version 4.3.0
This commit is contained in:
1 parent
96997ddd8e
commit
fe1acf984a
1349 files changed
+116159
-67711
No files matched your search
+461
-39
@@ -26,10 +26,15 @@ class _Club extends \IPS\Patterns\ActiveRecord implements \IPS\Content\Embeddabl
|
||||
const TYPE_OPEN = 'open';
|
||||
const TYPE_CLOSED = 'closed';
|
||||
const TYPE_PRIVATE = 'private';
|
||||
const TYPE_READONLY = 'readonly';
|
||||
|
||||
const STATUS_MEMBER = 'member';
|
||||
const STATUS_INVITED = 'invited';
|
||||
const STATUS_INVITED_BYPASSING_PAYMENT = 'invited_bypassing_payment';
|
||||
const STATUS_REQUESTED = 'requested';
|
||||
const STATUS_WAITING_PAYMENT = 'payment_pending';
|
||||
const STATUS_EXPIRED = 'expired';
|
||||
const STATUS_EXPIRED_MODERATOR = 'expired_moderator';
|
||||
const STATUS_DECLINED = 'declined';
|
||||
const STATUS_BANNED = 'banned';
|
||||
const STATUS_MODERATOR = 'moderator';
|
||||
@@ -45,6 +50,11 @@ class _Club extends \IPS\Patterns\ActiveRecord implements \IPS\Content\Embeddabl
|
||||
*/
|
||||
public static $databaseTable = 'core_clubs';
|
||||
|
||||
/**
|
||||
* @brief Use a default cover photo
|
||||
*/
|
||||
public static $coverPhotoDefault = true;
|
||||
|
||||
/* !Fetch Clubs */
|
||||
|
||||
/**
|
||||
@@ -72,10 +82,10 @@ class _Club extends \IPS\Patterns\ActiveRecord implements \IPS\Content\Embeddabl
|
||||
* @param \IPS\Member $member The member to base permission off or NULL for all clubs
|
||||
* @param int $limit Number to get
|
||||
* @param string $sortOption The sort option ('last_activity', 'members', 'content' or 'created')
|
||||
* @param bool|\IPS\Member $mineOnly Limit to clubs a particular member has joined (TRUE to use the same value as $member)
|
||||
* @param bool|\IPS\Member|array $mineOnly Limit to clubs a particular member has joined (TRUE to use the same value as $member). Can also provide an array as array( 'member' => \IPS\Member, 'statuses' => array( STATUS_MEMBER... ) ) to limit to certain member statuses
|
||||
* @param array $filters Custom field filters
|
||||
* @param mixed $extraWhere Additional WHERE clause
|
||||
* @return \IPS\Patterns\ActiveRecordIterator
|
||||
* @return \IPS\Patterns\ActiveRecordIterator|array
|
||||
*/
|
||||
public static function clubs( \IPS\Member $member = NULL, $limit, $sortOption, $mineOnly=FALSE, $filters=array(), $extraWhere=NULL )
|
||||
{
|
||||
@@ -95,7 +105,7 @@ class _Club extends \IPS\Patterns\ActiveRecord implements \IPS\Content\Embeddabl
|
||||
if ( $member->member_id )
|
||||
{
|
||||
$joins['membership'] = array( array( 'core_clubs_memberships', 'membership' ), array( 'membership.club_id=core_clubs.id AND membership.member_id=?', $member->member_id ) );
|
||||
$where[] = array( "( type<>? OR membership.status IN('" . static::STATUS_MEMBER . "','" . static::STATUS_MODERATOR . "','" . static::STATUS_LEADER . "') )", static::TYPE_PRIVATE );
|
||||
$where[] = array( "( type<>? OR membership.status IN('" . static::STATUS_MEMBER . "','" . static::STATUS_MODERATOR . "','" . static::STATUS_LEADER . "','" . static::STATUS_EXPIRED . "','" . static::STATUS_EXPIRED_MODERATOR . "') )", static::TYPE_PRIVATE );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -106,7 +116,16 @@ class _Club extends \IPS\Patterns\ActiveRecord implements \IPS\Content\Embeddabl
|
||||
/* Restrict to clubs we have joined */
|
||||
if ( $mineOnly )
|
||||
{
|
||||
$mineOnly = ( $mineOnly === TRUE ) ? $member : $mineOnly;
|
||||
if ( is_array( $mineOnly ) )
|
||||
{
|
||||
$statuses = $mineOnly['statuses'];
|
||||
$mineOnly = $mineOnly['member'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$mineOnly = ( $mineOnly === TRUE ) ? $member : $mineOnly;
|
||||
$statuses = array( static::STATUS_MEMBER, static::STATUS_MODERATOR, static::STATUS_LEADER, static::STATUS_EXPIRED, static::STATUS_EXPIRED_MODERATOR );
|
||||
}
|
||||
if ( !$mineOnly->member_id )
|
||||
{
|
||||
return array();
|
||||
@@ -114,12 +133,12 @@ class _Club extends \IPS\Patterns\ActiveRecord implements \IPS\Content\Embeddabl
|
||||
|
||||
if ( $member and $mineOnly->member_id === $member->member_id and isset( $joins['membership'] ) )
|
||||
{
|
||||
$where[] = array( "membership.status IN('" . static::STATUS_MEMBER . "','" . static::STATUS_MODERATOR . "','" . static::STATUS_LEADER . "')" );
|
||||
$where[] = array( "membership.status IN('" . static::STATUS_MEMBER . "','" . static::STATUS_MODERATOR . "','" . static::STATUS_LEADER . "','" . static::STATUS_EXPIRED . "','" . static::STATUS_EXPIRED_MODERATOR . "')" );
|
||||
}
|
||||
else
|
||||
{
|
||||
$joins['others_membership'] = array( array( 'core_clubs_memberships', 'others_membership' ), array( 'others_membership.club_id=core_clubs.id AND others_membership.member_id=?', $mineOnly->member_id ) );
|
||||
$where[] = array( "others_membership.status IN('" . static::STATUS_MEMBER . "','" . static::STATUS_MODERATOR . "','" . static::STATUS_LEADER . "')" );
|
||||
$where[] = array( "others_membership.status IN('" . static::STATUS_MEMBER . "','" . static::STATUS_MODERATOR . "','" . static::STATUS_LEADER . "','" . static::STATUS_EXPIRED . "','" . static::STATUS_EXPIRED_MODERATOR . "')" );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,7 +150,7 @@ class _Club extends \IPS\Patterns\ActiveRecord implements \IPS\Content\Embeddabl
|
||||
{
|
||||
if ( is_array( $v ) )
|
||||
{
|
||||
$where[] = array( \IPS\Db::i()->in( "field_{$k}", $v ) );
|
||||
$where[] = array( \IPS\Db::i()->findInSet( "field_{$k}", $v ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -279,12 +298,21 @@ class _Club extends \IPS\Patterns\ActiveRecord implements \IPS\Content\Embeddabl
|
||||
|
||||
if ( $acp or ( $new and count( $availableTypes ) > 1 ) )
|
||||
{
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'club_type', $this->type, TRUE, array( 'options' => $new ? $availableTypes : array(
|
||||
\IPS\Member\Club::TYPE_PUBLIC => 'club_type_' . \IPS\Member\Club::TYPE_PUBLIC,
|
||||
\IPS\Member\Club::TYPE_OPEN => 'club_type_' . \IPS\Member\Club::TYPE_OPEN,
|
||||
\IPS\Member\Club::TYPE_CLOSED => 'club_type_' . \IPS\Member\Club::TYPE_CLOSED,
|
||||
\IPS\Member\Club::TYPE_PRIVATE => 'club_type_' . \IPS\Member\Club::TYPE_PRIVATE,
|
||||
) ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'club_type', $this->type, TRUE, array(
|
||||
'options' => $new ? $availableTypes : array(
|
||||
\IPS\Member\Club::TYPE_PUBLIC => 'club_type_' . \IPS\Member\Club::TYPE_PUBLIC,
|
||||
\IPS\Member\Club::TYPE_OPEN => 'club_type_' . \IPS\Member\Club::TYPE_OPEN,
|
||||
\IPS\Member\Club::TYPE_CLOSED => 'club_type_' . \IPS\Member\Club::TYPE_CLOSED,
|
||||
\IPS\Member\Club::TYPE_PRIVATE => 'club_type_' . \IPS\Member\Club::TYPE_PRIVATE,
|
||||
\IPS\Member\Club::TYPE_READONLY => 'club_type_' . \IPS\Member\Club::TYPE_READONLY,
|
||||
),
|
||||
'toggles' => array(
|
||||
\IPS\Member\Club::TYPE_OPEN => array( 'club_membership_fee' ),
|
||||
\IPS\Member\Club::TYPE_CLOSED => array( 'club_membership_fee' ),
|
||||
\IPS\Member\Club::TYPE_PRIVATE => array( 'club_membership_fee' ),
|
||||
\IPS\Member\Club::TYPE_READONLY => array( 'club_membership_fee' ),
|
||||
)
|
||||
) ) );
|
||||
|
||||
if ( $acp )
|
||||
{
|
||||
@@ -294,6 +322,63 @@ class _Club extends \IPS\Patterns\ActiveRecord implements \IPS\Content\Embeddabl
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\TextArea( 'club_about', $this->about ) );
|
||||
|
||||
if ( \IPS\Application::appIsEnabled( 'nexus' ) and \IPS\Settings::i()->clubs_paid_on and \IPS\Member::loggedIn()->group['gbw_paid_clubs'] )
|
||||
{
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'club_membership_fee', ( $this->id and $this->fee ) ? 'paid' : 'free', TRUE, array(
|
||||
'options' => array(
|
||||
'free' => 'club_membership_free',
|
||||
'paid' => 'club_membership_paid'
|
||||
),
|
||||
'toggles' => array(
|
||||
'paid' => array( 'club_fee', 'club_renewals' )
|
||||
)
|
||||
), NULL, NULL, NULL, 'club_membership_fee' ) );
|
||||
|
||||
$commissionBlurb = NULL;
|
||||
$fees = NULL;
|
||||
if ( $_fees = \IPS\Settings::i()->clubs_paid_transfee )
|
||||
{
|
||||
$fees = array();
|
||||
foreach ( $_fees as $fee )
|
||||
{
|
||||
$fees[] = (string) ( new \IPS\nexus\Money( $fee['amount'], $fee['currency'] ) );
|
||||
}
|
||||
$fees = \IPS\Member::loggedIn()->language()->formatList( $fees, \IPS\Member::loggedIn()->language()->get('or_list_format') );
|
||||
}
|
||||
if ( \IPS\Settings::i()->clubs_paid_commission and $fees )
|
||||
{
|
||||
$commissionBlurb = \IPS\Member::loggedIn()->language()->addToStack( 'club_fee_desc_both', FALSE, array( 'sprintf' => array( \IPS\Settings::i()->clubs_paid_commission, $fees ) ) );
|
||||
}
|
||||
elseif ( \IPS\Settings::i()->clubs_paid_commission )
|
||||
{
|
||||
$commissionBlurb = \IPS\Member::loggedIn()->language()->addToStack('club_fee_desc_percent', FALSE, array( 'sprintf' => \IPS\Settings::i()->clubs_paid_commission ) );
|
||||
}
|
||||
elseif ( $fees )
|
||||
{
|
||||
$commissionBlurb = \IPS\Member::loggedIn()->language()->addToStack('club_fee_desc_fee', FALSE, array( 'sprintf' => $fees ) );
|
||||
}
|
||||
|
||||
\IPS\Member::loggedIn()->language()->words['club_fee_desc'] = $commissionBlurb;
|
||||
$form->add( new \IPS\nexus\Form\Money( 'club_fee', $this->id ? json_decode( $this->fee, TRUE ) : array(), NULL, array(), NULL, NULL, NULL, 'club_fee' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'club_renewals', $this->id ? ( $this->renewal_term ? 1 : 0 ) : 0, TRUE, array(
|
||||
'options' => array( 0 => 'club_renewals_off', 1 => 'club_renewals_on' ),
|
||||
'toggles' => array( 1 => array( 'club_renewal_term' ) )
|
||||
), NULL, NULL, NULL, 'club_renewals' ) );
|
||||
\IPS\Member::loggedIn()->language()->words['club_renewal_term_desc'] = $commissionBlurb;
|
||||
$renewTermForEdit = NULL;
|
||||
if ( $this->id and $this->renewal_term )
|
||||
{
|
||||
$renewPrices = array();
|
||||
foreach ( json_decode( $this->renewal_price, TRUE ) as $currency => $data )
|
||||
{
|
||||
$renewPrices[ $currency ] = new \IPS\nexus\Money( $data['amount'], $currency );
|
||||
}
|
||||
$renewTermForEdit = new \IPS\nexus\Purchase\RenewalTerm( $renewPrices, new \DateInterval( 'P' . $this->renewal_term . mb_strtoupper( $this->renewal_units ) ) );
|
||||
}
|
||||
$form->add( new \IPS\nexus\Form\RenewalTerm( 'club_renewal_term', $renewTermForEdit, NULL, array( 'allCurrencies' => TRUE ), NULL, NULL, NULL, 'club_renewal_term' ) );
|
||||
|
||||
}
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Upload( 'club_profile_photo', $this->profile_photo ? \IPS\File::get( 'core_Clubs', $this->profile_photo ) : NULL, FALSE, array( 'storageExtension' => 'core_Clubs', 'image' => array( 'maxWidth' => 200, 'maxHeight' => 200 ) ) ) );
|
||||
|
||||
if ( \IPS\Settings::i()->clubs_locations )
|
||||
@@ -310,7 +395,13 @@ class _Club extends \IPS\Patterns\ActiveRecord implements \IPS\Content\Embeddabl
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
$this->name = $values['club_name'];
|
||||
|
||||
|
||||
/* If there is only one type available, set it. */
|
||||
if( count( $availableTypes ) == 1 )
|
||||
{
|
||||
$values['club_type'] = key( $availableTypes );
|
||||
}
|
||||
|
||||
$needToUpdatePermissions = FALSE;
|
||||
if ( $acp )
|
||||
{
|
||||
@@ -355,6 +446,36 @@ class _Club extends \IPS\Patterns\ActiveRecord implements \IPS\Content\Embeddabl
|
||||
$this->location_long = NULL;
|
||||
}
|
||||
|
||||
if ( \IPS\Application::appIsEnabled( 'nexus' ) and \IPS\Settings::i()->clubs_paid_on and \IPS\Member::loggedIn()->group['gbw_paid_clubs'] )
|
||||
{
|
||||
switch ( $values['club_membership_fee'] )
|
||||
{
|
||||
case 'free':
|
||||
$this->fee = NULL;
|
||||
$this->renewal_term = 0;
|
||||
$this->renewal_units = NULL;
|
||||
$this->renewal_price = NULL;
|
||||
break;
|
||||
|
||||
case 'paid':
|
||||
$this->fee = json_encode( $values['club_fee'] );
|
||||
if ( $values['club_renewals'] and $values['club_renewal_term'] )
|
||||
{
|
||||
$term = $values['club_renewal_term']->getTerm();
|
||||
$this->renewal_term = $term['term'];
|
||||
$this->renewal_units = $term['unit'];
|
||||
$this->renewal_price = json_encode( $values['club_renewal_term']->cost );
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->renewal_term = 0;
|
||||
$this->renewal_units = NULL;
|
||||
$this->renewal_price = NULL;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->save();
|
||||
|
||||
if ( $new )
|
||||
@@ -369,7 +490,15 @@ class _Club extends \IPS\Patterns\ActiveRecord implements \IPS\Content\Embeddabl
|
||||
if ( isset( $values["core_clubfield_{$field->id}"] ) )
|
||||
{
|
||||
$helper = $field->buildHelper();
|
||||
$customFieldValues[ "field_{$field->id}" ] = $helper::stringValue( $values["core_clubfield_{$field->id}"] );
|
||||
|
||||
if ( $helper instanceof \IPS\Helpers\Form\Upload )
|
||||
{
|
||||
$customFieldValues[ "field_{$field->id}" ] = (string) $values["core_clubfield_{$field->id}"];
|
||||
}
|
||||
else
|
||||
{
|
||||
$customFieldValues[ "field_{$field->id}" ] = $helper::stringValue( $values["core_clubfield_{$field->id}"] );
|
||||
}
|
||||
|
||||
if ( $field->type === 'Editor' )
|
||||
{
|
||||
@@ -396,7 +525,47 @@ class _Club extends \IPS\Patterns\ActiveRecord implements \IPS\Content\Embeddabl
|
||||
catch ( \Exception $e ) { }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if( $new and \IPS\Settings::i()->clubs_require_approval and !$this->approved )
|
||||
{
|
||||
/* Send notification to mods */
|
||||
$moderators = array( 'm' => array(), 'g' => array() );
|
||||
foreach ( \IPS\Db::i()->select( '*', 'core_moderators' ) as $mod )
|
||||
{
|
||||
$canView = FALSE;
|
||||
if ( $mod['perms'] == '*' )
|
||||
{
|
||||
$canView = TRUE;
|
||||
}
|
||||
if ( $canView === FALSE )
|
||||
{
|
||||
$perms = json_decode( $mod['perms'], TRUE );
|
||||
|
||||
if ( isset( $perms['can_access_all_clubs'] ) AND $perms['can_access_all_clubs'] === TRUE )
|
||||
{
|
||||
$canView = TRUE;
|
||||
}
|
||||
}
|
||||
if ( $canView === TRUE )
|
||||
{
|
||||
$moderators[ $mod['type'] ][] = $mod['id'];
|
||||
}
|
||||
}
|
||||
$notification = new \IPS\Notification( \IPS\Application::load('core'), 'unapproved_club', $this, array( $this ) );
|
||||
foreach ( \IPS\Db::i()->select( '*', 'core_members', ( count( $moderators['m'] ) ? \IPS\Db::i()->in( 'member_id', $moderators['m'] ) . ' OR ' : '' ) . \IPS\Db::i()->in( 'member_group_id', $moderators['g'] ) . ' OR ' . \IPS\Db::i()->findInSet( 'mgroup_others', $moderators['g'] ) ) as $member )
|
||||
{
|
||||
if( $member['member_id'] != \IPS\Member::loggedIn()->member_id )
|
||||
{
|
||||
$notification->recipients->attach( \IPS\Member::constructFromData( $member ) );
|
||||
}
|
||||
}
|
||||
|
||||
if( count( $notification->recipients ) )
|
||||
{
|
||||
$notification->send();
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -440,8 +609,19 @@ class _Club extends \IPS\Patterns\ActiveRecord implements \IPS\Content\Embeddabl
|
||||
}
|
||||
$photo->editable = $this->isLeader();
|
||||
$photo->object = $this;
|
||||
|
||||
return $photo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Produce a random hex color for a background
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function coverPhotoBackgroundColor()
|
||||
{
|
||||
return $this->staticCoverPhotoBackgroundColor( $this->name );
|
||||
}
|
||||
|
||||
/**
|
||||
* Location
|
||||
@@ -456,6 +636,137 @@ class _Club extends \IPS\Patterns\ActiveRecord implements \IPS\Content\Embeddabl
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is paid?
|
||||
*
|
||||
* @return string|NULL
|
||||
*/
|
||||
public function isPaid()
|
||||
{
|
||||
if ( \IPS\Application::appIsEnabled( 'nexus' ) and \IPS\Settings::i()->clubs_paid_on and $this->fee )
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Message to explain paid club joining process
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function memberFeeMessage()
|
||||
{
|
||||
if ( $this->type === static::TYPE_CLOSED )
|
||||
{
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'club_closed_join_fee', FALSE, array( 'sprintf' => array( $this->priceBlurb() ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'club_open_join_fee', FALSE, array( 'sprintf' => array( $this->priceBlurb() ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Joining fee
|
||||
*
|
||||
* @param string|NULL $currency Desired currency, or NULL to choose based on member's chosen currency
|
||||
* @return \IPS\nexus\Money|NULL
|
||||
*/
|
||||
public function joiningFee( $currency = NULL )
|
||||
{
|
||||
if ( $this->isPaid() )
|
||||
{
|
||||
if ( !$currency )
|
||||
{
|
||||
$currency = ( isset( $_SESSION['currency'] ) and in_array( $_SESSION['currency'], \IPS\nexus\Money::currencies() ) ) ? $_SESSION['currency'] : \IPS\nexus\Customer::loggedIn()->defaultCurrency();
|
||||
}
|
||||
|
||||
$costs = json_decode( $this->fee, TRUE );
|
||||
|
||||
if ( is_array( $costs ) and isset( $costs[ $currency ]['amount'] ) and $costs[ $currency ]['amount'] )
|
||||
{
|
||||
return new \IPS\nexus\Money( $costs[ $currency ]['amount'], $currency );
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Joining fee
|
||||
*
|
||||
* @param string|NULL $currency Desired currency, or NULL to choose based on member's chosen currency
|
||||
* @return \IPS\nexus\Money|NULL
|
||||
* @throws \OutOfRangeException
|
||||
*/
|
||||
public function renewalTerm( $currency = NULL )
|
||||
{
|
||||
if ( $this->renewal_price and $renewalPrices = json_decode( $this->renewal_price, TRUE ) )
|
||||
{
|
||||
if ( !$currency )
|
||||
{
|
||||
$currency = ( isset( $_SESSION['currency'] ) and in_array( $_SESSION['currency'], \IPS\nexus\Money::currencies() ) ) ? $_SESSION['currency'] : \IPS\nexus\Customer::loggedIn()->defaultCurrency();
|
||||
}
|
||||
|
||||
if ( isset( $renewalPrices[ $currency ] ) )
|
||||
{
|
||||
return new \IPS\nexus\Purchase\RenewalTerm( new \IPS\nexus\Money( $renewalPrices[ $currency ]['amount'], $currency ), new \DateInterval( 'P' . $this->renewal_term . mb_strtoupper( $this->renewal_units ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Price Blurb
|
||||
*
|
||||
* @return string|NULL
|
||||
*/
|
||||
public function priceBlurb()
|
||||
{
|
||||
if ( \IPS\Application::appIsEnabled( 'nexus' ) and \IPS\Settings::i()->clubs_paid_on )
|
||||
{
|
||||
if ( $this->isPaid() )
|
||||
{
|
||||
if ( $fee = $this->joiningFee() )
|
||||
{
|
||||
try
|
||||
{
|
||||
$renewalTerm = $this->renewalTerm( $fee->currency );
|
||||
if ( $renewalTerm->cost->amount == $fee->amount )
|
||||
{
|
||||
return $renewalTerm;
|
||||
}
|
||||
else
|
||||
{
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'club_fee_plus_renewal', FALSE, array( 'sprintf' => array( $fee, $renewalTerm ) ) );
|
||||
}
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
return \IPS\Member::loggedIn()->language()->addToStack('club_paid_unavailable');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return \IPS\Member::loggedIn()->language()->addToStack('club_paid_unavailable');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return \IPS\Member::loggedIn()->language()->addToStack('club_membership_free');
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/* !Manage Memberships */
|
||||
|
||||
@@ -465,7 +776,7 @@ class _Club extends \IPS\Patterns\ActiveRecord implements \IPS\Content\Embeddabl
|
||||
* @param array $statuses The membership statuses to get
|
||||
* @param int $limit Number to get
|
||||
* @param string $order ORDER BY clause
|
||||
* @param int $returnType 0 = core_clubs_memberships rows, 1 = core_clubs_memberships plus \IPS\Member::columnsForPhoto(), 2 = full core_members rows, 3 = same as 1 but also getting name of adder/invitee, 4 = count only
|
||||
* @param int $returnType 0 = core_clubs_memberships rows, 1 = core_clubs_memberships plus \IPS\Member::columnsForPhoto(), 2 = full core_members rows, 3 = same as 1 but also getting name of adder/invitee, 4 = count only, 5 = same as 3 but also getting expire date
|
||||
* @return \IPS\Db\Select|int
|
||||
*/
|
||||
public function members( $statuses = array( 'member', 'moderator', 'leader' ), $limit = 25, $order = 'core_clubs_memberships.joined ASC', $returnType = 1 )
|
||||
@@ -483,29 +794,39 @@ class _Club extends \IPS\Patterns\ActiveRecord implements \IPS\Content\Embeddabl
|
||||
else
|
||||
{
|
||||
$columns = 'core_clubs_memberships.member_id,core_clubs_memberships.joined,core_clubs_memberships.status,core_clubs_memberships.added_by,core_clubs_memberships.invited_by';
|
||||
if ( $returnType === 1 or $returnType === 3 )
|
||||
if ( $returnType === 1 or $returnType === 3 or $returnType === 5 )
|
||||
{
|
||||
$columns .= ',' . implode( ',', array_map( function( $column ) {
|
||||
return 'core_members.' . $column;
|
||||
}, \IPS\Member::columnsForPhoto() ) );
|
||||
}
|
||||
if ( $returnType === 3 )
|
||||
if ( $returnType === 3 or $returnType === 5 )
|
||||
{
|
||||
$columns .= ',added_by.name,invited_by.name';
|
||||
|
||||
if ( $returnType === 5 and \IPS\Application::appIsEnabled('nexus') and \IPS\Settings::i()->clubs_paid_on and $this->isPaid() and $this->renewal_price )
|
||||
{
|
||||
$columns .= ',nexus_purchases.ps_active,nexus_purchases.ps_expire';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$select = \IPS\Db::i()->select( $columns, 'core_clubs_memberships', array( array( 'club_id=?', $this->id ), array( \IPS\Db::i()->in( 'status', $statuses ) ) ), $order, $limit, NULL, NULL, \IPS\Db::SELECT_SQL_CALC_FOUND_ROWS + \IPS\Db::SELECT_MULTIDIMENSIONAL_JOINS );
|
||||
}
|
||||
|
||||
if ( $returnType === 1 or $returnType === 2 or $returnType === 3 )
|
||||
if ( $returnType === 1 or $returnType === 2 or $returnType === 3 or $returnType === 5 )
|
||||
{
|
||||
$select->join( 'core_members', 'core_members.member_id=core_clubs_memberships.member_id' );
|
||||
}
|
||||
if ( $returnType === 3 )
|
||||
if ( $returnType === 3 or $returnType === 5 )
|
||||
{
|
||||
$select->join( array( 'core_members', 'added_by' ), 'added_by.member_id=core_clubs_memberships.added_by' );
|
||||
$select->join( array( 'core_members', 'invited_by' ), 'invited_by.member_id=core_clubs_memberships.invited_by' );
|
||||
|
||||
if ( $returnType === 5 and \IPS\Application::appIsEnabled('nexus') and \IPS\Settings::i()->clubs_paid_on and $this->isPaid() and $this->renewal_price )
|
||||
{
|
||||
$select->join( 'nexus_purchases', array( 'ps_app=? AND ps_type=? AND ps_member=core_clubs_memberships.member_id AND ps_item_id=? AND ps_cancelled=0', 'core', 'club', $this->id ) );
|
||||
}
|
||||
}
|
||||
|
||||
return $select;
|
||||
@@ -556,6 +877,11 @@ class _Club extends \IPS\Patterns\ActiveRecord implements \IPS\Content\Embeddabl
|
||||
) );
|
||||
|
||||
$member->rebuildPermissionArray();
|
||||
if ( \IPS\Settings::i()->club_nodes_in_apps )
|
||||
{
|
||||
$member->create_menu = NULL;
|
||||
$member->save();
|
||||
}
|
||||
}
|
||||
catch ( \IPS\Db\Exception $e )
|
||||
{
|
||||
@@ -573,10 +899,15 @@ class _Club extends \IPS\Patterns\ActiveRecord implements \IPS\Content\Embeddabl
|
||||
{
|
||||
$save['joined'] = time();
|
||||
}
|
||||
|
||||
|
||||
\IPS\Db::i()->update( 'core_clubs_memberships', $save, array( 'club_id=? AND member_id=?', $this->id, $member->member_id ) );
|
||||
|
||||
$member->rebuildPermissionArray();
|
||||
if ( \IPS\Settings::i()->club_nodes_in_apps )
|
||||
{
|
||||
$member->create_menu = NULL;
|
||||
$member->save();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -599,7 +930,13 @@ class _Club extends \IPS\Patterns\ActiveRecord implements \IPS\Content\Embeddabl
|
||||
public function removeMember( \IPS\Member $member )
|
||||
{
|
||||
\IPS\Db::i()->delete( 'core_clubs_memberships', array( 'club_id=? AND member_id=?', $this->id, $member->member_id ) );
|
||||
|
||||
$member->rebuildPermissionArray();
|
||||
if ( \IPS\Settings::i()->club_nodes_in_apps )
|
||||
{
|
||||
$member->create_menu = NULL;
|
||||
$member->save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -609,7 +946,7 @@ class _Club extends \IPS\Patterns\ActiveRecord implements \IPS\Content\Embeddabl
|
||||
*/
|
||||
public function recountMembers()
|
||||
{
|
||||
$this->members = \IPS\Db::i()->select( 'COUNT(*)', 'core_clubs_memberships', array( 'club_id=? AND ( status=? OR status=? OR status=? )', $this->id, static::STATUS_MEMBER, static::STATUS_MODERATOR, static::STATUS_LEADER ) );
|
||||
$this->members = \IPS\Db::i()->select( 'COUNT(*)', 'core_clubs_memberships', array( 'club_id=? AND ( status=? OR status=? OR status=? OR status=? OR status=? )', $this->id, static::STATUS_MEMBER, static::STATUS_MODERATOR, static::STATUS_LEADER, static::STATUS_EXPIRED, static::STATUS_EXPIRED_MODERATOR ) );
|
||||
$this->save();
|
||||
}
|
||||
|
||||
@@ -641,6 +978,11 @@ class _Club extends \IPS\Patterns\ActiveRecord implements \IPS\Content\Embeddabl
|
||||
|
||||
return array_unique( $return );
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Cached nodes
|
||||
*/
|
||||
protected $cachedNodes = NULL;
|
||||
|
||||
/**
|
||||
* Get Node names and URLs
|
||||
@@ -649,25 +991,53 @@ class _Club extends \IPS\Patterns\ActiveRecord implements \IPS\Content\Embeddabl
|
||||
*/
|
||||
public function nodes()
|
||||
{
|
||||
$return = array();
|
||||
|
||||
foreach ( \IPS\Db::i()->select( '*', 'core_clubs_node_map', array( 'club_id=?', $this->id ) ) as $row )
|
||||
if( $this->cachedNodes === NULL )
|
||||
{
|
||||
$class = $row['node_class'];
|
||||
$this->cachedNodes = array();
|
||||
|
||||
$return[ $row['id'] ] = array(
|
||||
'name' => $row['name'],
|
||||
'url' => \IPS\Http\Url::internal( $class::$urlBase . $row['node_id'], 'front', $class::$urlTemplate, array( \IPS\Http\Url\Friendly::seoTitle( $row['name'] ) ) ),
|
||||
'node_class' => $row['node_class'],
|
||||
'node_id' => $row['node_id'],
|
||||
);
|
||||
foreach ( \IPS\Db::i()->select( '*', 'core_clubs_node_map', array( 'club_id=?', $this->id ) ) as $row )
|
||||
{
|
||||
$class = $row['node_class'];
|
||||
$classBits = explode( '\\', $class );
|
||||
|
||||
if( !\IPS\Application::load( $classBits[1] )->_enabled )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->cachedNodes[ $row['id'] ] = array(
|
||||
'name' => $row['name'],
|
||||
'url' => \IPS\Http\Url::internal( $class::$urlBase . $row['node_id'], 'front', $class::$urlTemplate, array( \IPS\Http\Url\Friendly::seoTitle( $row['name'] ) ) ),
|
||||
'node_class' => $row['node_class'],
|
||||
'node_id' => $row['node_id'],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
return $this->cachedNodes;
|
||||
}
|
||||
|
||||
/* !Permissions */
|
||||
|
||||
/**
|
||||
* Load and check permissions
|
||||
*
|
||||
* @param mixed $id ID
|
||||
* @return static
|
||||
* @throws \OutOfRangeException
|
||||
*/
|
||||
public static function loadAndCheckPerms( $id )
|
||||
{
|
||||
$obj = static::load( $id );
|
||||
|
||||
if ( !$obj->canView() )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can a member see this club and who's in it?
|
||||
*
|
||||
@@ -677,6 +1047,12 @@ class _Club extends \IPS\Patterns\ActiveRecord implements \IPS\Content\Embeddabl
|
||||
public function canView( \IPS\Member $member = NULL )
|
||||
{
|
||||
$member = $member ?: \IPS\Member::loggedIn();
|
||||
|
||||
/* If we can't access the module, stop here */
|
||||
if ( !$member->canAccessModule( \IPS\Application\Module::get( 'core', 'clubs', 'front' ) ) )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* If it's not approved, only moderators and the person who created it can see it */
|
||||
if ( \IPS\Settings::i()->clubs_require_approval and !$this->approved )
|
||||
@@ -697,7 +1073,7 @@ class _Club extends \IPS\Patterns\ActiveRecord implements \IPS\Content\Embeddabl
|
||||
}
|
||||
|
||||
/* Otherwise, only if they're a member or have been invited */
|
||||
return in_array( $this->memberStatus( $member ), array( static::STATUS_MEMBER, static::STATUS_MODERATOR, static::STATUS_LEADER, static::STATUS_INVITED ) );
|
||||
return in_array( $this->memberStatus( $member ), array( static::STATUS_MEMBER, static::STATUS_MODERATOR, static::STATUS_LEADER, static::STATUS_INVITED, static::STATUS_INVITED_BYPASSING_PAYMENT, static::STATUS_EXPIRED, static::STATUS_EXPIRED_MODERATOR ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -729,7 +1105,7 @@ class _Club extends \IPS\Patterns\ActiveRecord implements \IPS\Content\Embeddabl
|
||||
|
||||
/* If they're already a member, or have aleready asked to join, they can't join again */
|
||||
$memberStatus = $this->memberStatus( $member );
|
||||
if ( in_array( $memberStatus, array( static::STATUS_MEMBER, static::STATUS_MODERATOR, static::STATUS_LEADER, static::STATUS_REQUESTED, static::STATUS_DECLINED ) ) )
|
||||
if ( in_array( $memberStatus, array( static::STATUS_MEMBER, static::STATUS_MODERATOR, static::STATUS_LEADER, static::STATUS_REQUESTED, static::STATUS_DECLINED, static::STATUS_EXPIRED, static::STATUS_EXPIRED_MODERATOR ) ) )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
@@ -740,10 +1116,10 @@ class _Club extends \IPS\Patterns\ActiveRecord implements \IPS\Content\Embeddabl
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* If it's private, they have to be invited */
|
||||
if ( $this->type === static::TYPE_PRIVATE )
|
||||
/* If it's private or read-only, they have to be invited */
|
||||
if ( $this->type === static::TYPE_PRIVATE or $this->type === static::TYPE_READONLY )
|
||||
{
|
||||
return $memberStatus === static::STATUS_INVITED;
|
||||
return in_array( $memberStatus, array( static::STATUS_INVITED, static::STATUS_INVITED_BYPASSING_PAYMENT ) );
|
||||
}
|
||||
|
||||
/* Otherwise they can join */
|
||||
@@ -762,6 +1138,7 @@ class _Club extends \IPS\Patterns\ActiveRecord implements \IPS\Content\Embeddabl
|
||||
{
|
||||
case static::TYPE_PUBLIC:
|
||||
case static::TYPE_OPEN:
|
||||
case static::TYPE_READONLY:
|
||||
return TRUE;
|
||||
|
||||
case static::TYPE_CLOSED:
|
||||
@@ -787,6 +1164,7 @@ class _Club extends \IPS\Patterns\ActiveRecord implements \IPS\Content\Embeddabl
|
||||
case static::TYPE_OPEN:
|
||||
case static::TYPE_CLOSED:
|
||||
case static::TYPE_PRIVATE:
|
||||
case static::TYPE_READONLY:
|
||||
$member = $member ?: \IPS\Member::loggedIn();
|
||||
return $member->modPermission('can_access_all_clubs') or in_array( $this->memberStatus( $member ), array( static::STATUS_MEMBER, static::STATUS_MODERATOR, static::STATUS_LEADER ) );
|
||||
}
|
||||
@@ -816,6 +1194,7 @@ class _Club extends \IPS\Patterns\ActiveRecord implements \IPS\Content\Embeddabl
|
||||
|
||||
case static::TYPE_CLOSED:
|
||||
case static::TYPE_PRIVATE:
|
||||
case static::TYPE_READONLY:
|
||||
return $this->isLeader( $member );
|
||||
}
|
||||
}
|
||||
@@ -888,6 +1267,49 @@ class _Club extends \IPS\Patterns\ActiveRecord implements \IPS\Content\Embeddabl
|
||||
return $this->_memberStatuses[ $member->member_id ];
|
||||
}
|
||||
|
||||
/* ! Following */
|
||||
|
||||
const FOLLOW_PUBLIC = 1;
|
||||
const FOLLOW_ANONYMOUS = 2;
|
||||
|
||||
/**
|
||||
* @brief Cache for current follow data, used on "My Followed Content" screen
|
||||
*/
|
||||
public $_followData;
|
||||
|
||||
/**
|
||||
* @brief Application
|
||||
*/
|
||||
public static $application = 'core';
|
||||
|
||||
/**
|
||||
* Container Follower Count
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function followerCount()
|
||||
{
|
||||
return \IPS\Db::i()->select( 'COUNT(*)', 'core_follow', array( 'follow_app=? AND follow_area=? AND follow_rel_id=?', 'core', 'club', $this->id ) )->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* Followers
|
||||
*
|
||||
* @param int $privacy static::FOLLOW_PUBLIC + static::FOLLOW_ANONYMOUS
|
||||
* @param array $frequencyTypes array( 'immediate', 'daily', 'weekly' )
|
||||
* @param \IPS\DateTime|int|NULL $date Only users who started following before this date will be returned. NULL for no restriction
|
||||
* @param int|array $limit LIMIT clause
|
||||
* @param string $order Column to order by
|
||||
* @param int $flags Flags to pass to select (e.g. \IPS\Db::SELECT_SQL_CALC_FOUND_ROWS)
|
||||
* @param int
|
||||
* @return \IPS\Db\Select|NULL
|
||||
* @throws \BadMethodCallException
|
||||
*/
|
||||
public function followers( $privacy=3, $frequencyTypes=array( 'immediate', 'daily', 'weekly' ), $date=NULL, $limit=array( 0, 25 ), $order=NULL, $flags=\IPS\Db::SELECT_SQL_CALC_FOUND_ROWS )
|
||||
{
|
||||
return static::_followers( 'club', $this->id, $privacy, $frequencyTypes, $date, $limit, $order, $flags );
|
||||
}
|
||||
|
||||
/* ! Utility */
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user