Version 4.7.13
This commit is contained in:
1 parent
fd22d99e69
commit
7124a02564
954 files changed
+29277
-59308
No files matched your search
+256
-172
@@ -539,202 +539,240 @@ class _Club extends \IPS\Patterns\ActiveRecord implements \IPS\Content\Embeddabl
|
||||
{
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'club_rules_reacknowledge', FALSE, FALSE, [], NULL, NULL, NULL, 'club_rules_reacknowledge' ) );
|
||||
}
|
||||
|
||||
if ( $values = $form->values() )
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process Club Form
|
||||
*
|
||||
* @param $values
|
||||
* @param bool $acp TRUE if editing in the ACP
|
||||
* @param bool $new TRUE if creating new
|
||||
* @param array|null $availableTypes If creating new, the available types
|
||||
* @return \IPS\Helpers\Form|NULL
|
||||
*/
|
||||
public function processForm($values, bool $acp, bool $new = FALSE, array $availableTypes = NULL): ?\IPS\Helpers\Form
|
||||
{
|
||||
$this->name = $values['club_name'];
|
||||
|
||||
/* If there is only one type available, set it. */
|
||||
if( \is_array( $availableTypes ) AND \count( $availableTypes ) == 1 )
|
||||
{
|
||||
$this->name = $values['club_name'];
|
||||
$values['club_type'] = key( $availableTypes );
|
||||
}
|
||||
|
||||
/* If there is only one type available, set it. */
|
||||
if( \is_array( $availableTypes ) AND \count( $availableTypes ) == 1 )
|
||||
{
|
||||
$values['club_type'] = key( $availableTypes );
|
||||
}
|
||||
|
||||
$needToUpdatePermissions = FALSE;
|
||||
if ( $acp )
|
||||
{
|
||||
if ( $this->type != $values['club_type'] )
|
||||
{
|
||||
$this->type = $values['club_type'];
|
||||
$needToUpdatePermissions = TRUE;
|
||||
}
|
||||
if ( $this->owner != $values['club_owner'] )
|
||||
{
|
||||
$this->owner = $values['club_owner'];
|
||||
$this->addMember( $values['club_owner'], \IPS\Member\Club::STATUS_LEADER, TRUE );
|
||||
}
|
||||
}
|
||||
elseif ( $new )
|
||||
$needToUpdatePermissions = FALSE;
|
||||
if ( $acp )
|
||||
{
|
||||
if ( $this->type != $values['club_type'] )
|
||||
{
|
||||
$this->type = $values['club_type'];
|
||||
$this->owner = \IPS\Member::loggedIn();
|
||||
$needToUpdatePermissions = TRUE;
|
||||
}
|
||||
|
||||
$this->about = $values['club_about'];
|
||||
$this->profile_photo = (string) $values['club_profile_photo'];
|
||||
|
||||
if( $values['club_profile_photo'] )
|
||||
if ( $this->owner != $values['club_owner'] )
|
||||
{
|
||||
$this->profile_photo_uncropped = (string) $values['club_profile_photo'];
|
||||
$this->owner = $values['club_owner'];
|
||||
$this->addMember( $values['club_owner'], Club::STATUS_LEADER, TRUE );
|
||||
|
||||
/* Update purchases for commission */
|
||||
if( \IPS\Application::appIsEnabled( 'nexus' ) and \IPS\Settings::i()->clubs_paid_on )
|
||||
{
|
||||
\IPS\Db::i()->update( 'nexus_purchases', array( 'ps_pay_to' => $this->owner ), array( "ps_pay_to IS NOT NULL and ps_app=? and ps_type=? and ps_item_id=?", 'core', 'club', $this->id ) );
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( $values['club_location'] ) )
|
||||
}
|
||||
elseif ( $new )
|
||||
{
|
||||
$this->type = $values['club_type'];
|
||||
$this->owner = \IPS\Member::loggedIn();
|
||||
}
|
||||
|
||||
$this->about = $values['club_about'];
|
||||
$this->profile_photo = (string) $values['club_profile_photo'];
|
||||
|
||||
if( $values['club_profile_photo'] )
|
||||
{
|
||||
$this->profile_photo_uncropped = (string) $values['club_profile_photo'];
|
||||
}
|
||||
|
||||
if ( isset( $values['club_location'] ) )
|
||||
{
|
||||
$this->location_json = json_encode( $values['club_location'] );
|
||||
if ( $values['club_location']->lat and $values['club_location']->long )
|
||||
{
|
||||
$this->location_json = json_encode( $values['club_location'] );
|
||||
if ( $values['club_location']->lat and $values['club_location']->long )
|
||||
{
|
||||
$this->location_lat = $values['club_location']->lat;
|
||||
$this->location_long = $values['club_location']->long;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->location_lat = NULL;
|
||||
$this->location_long = NULL;
|
||||
}
|
||||
$this->location_lat = $values['club_location']->lat;
|
||||
$this->location_long = $values['club_location']->long;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->location_json = NULL;
|
||||
$this->location_lat = NULL;
|
||||
$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;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->location_json = NULL;
|
||||
$this->location_lat = NULL;
|
||||
$this->location_long = NULL;
|
||||
}
|
||||
|
||||
if ( array_key_exists( 'club_show_membertab', $values ) )
|
||||
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'] )
|
||||
{
|
||||
$this->show_membertab = $values['club_show_membertab'];
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Default is "Everybody" */
|
||||
$this->show_membertab = "nonmember";
|
||||
}
|
||||
case 'free':
|
||||
$this->fee = NULL;
|
||||
$this->renewal_term = 0;
|
||||
$this->renewal_units = NULL;
|
||||
$this->renewal_price = NULL;
|
||||
break;
|
||||
|
||||
$this->save();
|
||||
|
||||
if ( $values['show_rules'] )
|
||||
{
|
||||
$this->rules = $values['club_rules'];
|
||||
\IPS\File::claimAttachments( ( $new ) ? "club-rules-new" : "club-rules-{$this->id}", $this->id, NULL, 'rules' );
|
||||
$this->rules_required = (bool) $values['club_rules_required'];
|
||||
|
||||
/* Do we need to reset the acknowledge flags? */
|
||||
if ( !$new AND \array_key_exists( 'club_rules_reacknowledge', $values ) )
|
||||
{
|
||||
if ( $values['club_rules_reacknowledge'] )
|
||||
case 'paid':
|
||||
$this->fee = json_encode( $values['club_fee'] );
|
||||
|
||||
if ( $values['club_renewals'] and $values['club_renewal_term'] )
|
||||
{
|
||||
\IPS\Db::i()->update( 'core_clubs_memberships', array( "rules_acknowledged" => FALSE ), array( "club_id=?", $this->id ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->rules = NULL;
|
||||
$this->rules_required = FALSE;
|
||||
|
||||
if ( !$new )
|
||||
{
|
||||
/* If this isn't a new club, update all memberships in case they decide to re-add rules later on */
|
||||
\IPS\Db::i()->update( "core_clubs_memberships", array( 'rules_acknowledged' => FALSE ), array( "club_id=?", $this->id ) );
|
||||
}
|
||||
}
|
||||
|
||||
if ( $new )
|
||||
{
|
||||
$this->addMember( \IPS\Member::loggedIn(), \IPS\Member\Club::STATUS_LEADER );
|
||||
$this->acknowledgeRules( \IPS\Member::loggedIn() );
|
||||
}
|
||||
$this->recountMembers();
|
||||
|
||||
$customFieldValues = array();
|
||||
foreach ( \IPS\Member\Club\CustomField::roots() as $field )
|
||||
{
|
||||
if ( isset( $values["core_clubfield_{$field->id}"] ) )
|
||||
{
|
||||
$helper = $field->buildHelper();
|
||||
|
||||
if ( $helper instanceof \IPS\Helpers\Form\Upload )
|
||||
{
|
||||
$customFieldValues[ "field_{$field->id}" ] = (string) $values["core_clubfield_{$field->id}"];
|
||||
$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
|
||||
{
|
||||
$customFieldValues[ "field_{$field->id}" ] = $helper::stringValue( $values["core_clubfield_{$field->id}"] );
|
||||
$this->renewal_term = 0;
|
||||
$this->renewal_units = NULL;
|
||||
$this->renewal_price = NULL;
|
||||
}
|
||||
|
||||
if ( $field->type === 'Editor' )
|
||||
{
|
||||
$field->claimAttachments( $this->id );
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
if ( \count( $customFieldValues ) )
|
||||
{
|
||||
$customFieldValues['club_id'] = $this->id;
|
||||
\IPS\Db::i()->insert( 'core_clubs_fieldvalues', $customFieldValues, TRUE );
|
||||
}
|
||||
|
||||
if ( $needToUpdatePermissions )
|
||||
{
|
||||
foreach ( $this->nodes() as $node )
|
||||
{
|
||||
try
|
||||
{
|
||||
$nodeClass = $node['node_class'];
|
||||
$node = $nodeClass::load( $node['node_id'] );
|
||||
$node->setPermissionsToClub( $this );
|
||||
}
|
||||
catch ( \Exception $e ) { }
|
||||
}
|
||||
}
|
||||
|
||||
if( $new and \IPS\Settings::i()->clubs_require_approval and !$this->approved )
|
||||
{
|
||||
$this->sendModeratorApprovalNotification();
|
||||
}
|
||||
|
||||
if( $new and $this->approved )
|
||||
{
|
||||
\IPS\Api\Webhook::fire( 'club_created', $this );
|
||||
}
|
||||
else if( !$new AND isset( $this->changed['approved'] ) )
|
||||
{
|
||||
$this->onApprove();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return $form;
|
||||
|
||||
if ( array_key_exists( 'club_show_membertab', $values ) )
|
||||
{
|
||||
$this->show_membertab = $values['club_show_membertab'];
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Default is "Everybody" */
|
||||
$this->show_membertab = "nonmember";
|
||||
}
|
||||
|
||||
$this->save();
|
||||
|
||||
if ( $values['show_rules'] )
|
||||
{
|
||||
$this->rules = $values['club_rules'];
|
||||
\IPS\File::claimAttachments( ( $new ) ? "club-rules-new" : "club-rules-{$this->id}", $this->id, NULL, 'rules' );
|
||||
$this->rules_required = (bool) $values['club_rules_required'];
|
||||
|
||||
/* Do we need to reset the acknowledge flags? */
|
||||
if ( !$new AND \array_key_exists( 'club_rules_reacknowledge', $values ) )
|
||||
{
|
||||
if ( $values['club_rules_reacknowledge'] )
|
||||
{
|
||||
\IPS\Db::i()->update( 'core_clubs_memberships', array( "rules_acknowledged" => FALSE ), array( "club_id=?", $this->id ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->rules = NULL;
|
||||
$this->rules_required = FALSE;
|
||||
|
||||
if ( !$new )
|
||||
{
|
||||
/* If this isn't a new club, update all memberships in case they decide to re-add rules later on */
|
||||
\IPS\Db::i()->update( "core_clubs_memberships", array( 'rules_acknowledged' => FALSE ), array( "club_id=?", $this->id ) );
|
||||
}
|
||||
}
|
||||
|
||||
if ( $new )
|
||||
{
|
||||
$this->addMember( \IPS\Member::loggedIn(), Club::STATUS_LEADER );
|
||||
$this->acknowledgeRules( \IPS\Member::loggedIn() );
|
||||
}
|
||||
$this->recountMembers();
|
||||
|
||||
$customFieldValues = array();
|
||||
foreach ( \IPS\Member\Club\CustomField::roots() as $field )
|
||||
{
|
||||
if ( isset( $values["core_clubfield_{$field->id}"] ) )
|
||||
{
|
||||
$helper = $field->buildHelper();
|
||||
|
||||
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' )
|
||||
{
|
||||
$field->claimAttachments( $this->id );
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( \count( $customFieldValues ) )
|
||||
{
|
||||
$customFieldValues['club_id'] = $this->id;
|
||||
\IPS\Db::i()->insert( 'core_clubs_fieldvalues', $customFieldValues, TRUE );
|
||||
}
|
||||
|
||||
if ( $needToUpdatePermissions )
|
||||
{
|
||||
foreach ( $this->nodes() as $node )
|
||||
{
|
||||
try
|
||||
{
|
||||
$nodeClass = $node['node_class'];
|
||||
$node = $nodeClass::load( $node['node_id'] );
|
||||
$node->setPermissionsToClub( $this );
|
||||
}
|
||||
catch ( \Exception $e ) { }
|
||||
}
|
||||
}
|
||||
|
||||
if( $new and \IPS\Settings::i()->clubs_require_approval and !$this->approved )
|
||||
{
|
||||
$this->sendModeratorApprovalNotification();
|
||||
}
|
||||
|
||||
if( $new and $this->approved )
|
||||
{
|
||||
\IPS\Api\Webhook::fire( 'club_created', $this );
|
||||
}
|
||||
else if( !$new AND isset( $this->changed['approved'] ) )
|
||||
{
|
||||
$this->onApprove();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect after save
|
||||
*
|
||||
* @param \IPS\Member\Club $old A clone of the club as it was before
|
||||
* @param \IPS\Member\Club\ $new The club now
|
||||
* @return array
|
||||
*/
|
||||
public static function renewalChanges(Club $old, Club $new)
|
||||
{
|
||||
$changes = array();
|
||||
|
||||
foreach ( array( 'renewal_term', 'renewal_units', 'renewal_price' ) as $k )
|
||||
{
|
||||
if ( $old->$k != $new->$k )
|
||||
{
|
||||
$changes[ $k ] = $old->$k;
|
||||
}
|
||||
}
|
||||
|
||||
return $changes;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2191,4 +2229,50 @@ class _Club extends \IPS\Patterns\ActiveRecord implements \IPS\Content\Embeddabl
|
||||
\IPS\Api\Webhook::fire( 'club_created', $this );
|
||||
$this->owner->achievementAction( 'core', 'NewClub', $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Update existing purchases
|
||||
*
|
||||
* @param \IPS\nexus\Purchase $purchase The purchase
|
||||
* @param array $changes The old values
|
||||
* @param bool $cancelBillingAgreementIfNecessary If making changes to renewal terms, TRUE will cancel associated billing agreements. FALSE will skip that change
|
||||
* @return void
|
||||
*/
|
||||
public function updatePurchase( \IPS\nexus\Purchase $purchase, $changes=array(), $cancelBillingAgreementIfNecessary=FALSE )
|
||||
{
|
||||
$tax = NULL;
|
||||
if ( $purchase->tax )
|
||||
{
|
||||
try
|
||||
{
|
||||
$tax = \IPS\nexus\Tax::load( $purchase->tax );
|
||||
}
|
||||
catch ( \OutOfRangeException $e ) { }
|
||||
}
|
||||
|
||||
$currency = $purchase->renewal_currency ?: $purchase->member->defaultCurrency( );
|
||||
|
||||
$price = json_decode( $this->renewal_price, TRUE );
|
||||
|
||||
$purchase->renewals = new \IPS\nexus\Purchase\RenewalTerm(
|
||||
new \IPS\nexus\Money( $price[$currency]['amount'], $currency ),
|
||||
new \DateInterval( 'P' . $this->renewal_term . mb_strtoupper( $this->renewal_units ) ),
|
||||
$tax
|
||||
);
|
||||
|
||||
if ( $cancelBillingAgreementIfNecessary and $billingAgreement = $purchase->billing_agreement )
|
||||
{
|
||||
if ( array_key_exists( 'renewal_price', $changes ) and !empty( $changes['renewal_price'] ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
$billingAgreement->cancel();
|
||||
$billingAgreement->save();
|
||||
}
|
||||
catch ( \Exception $e ) { }
|
||||
}
|
||||
}
|
||||
|
||||
$purchase->save();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user