Version 4.6.0
This commit is contained in:
1 parent
f79dcf067a
commit
517a5e1f70
2036 files changed
+110041
-26162
No files matched your search
@@ -0,0 +1,270 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Achievement Action Extension
|
||||
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) Invision Power Services, Inc.
|
||||
* @license https://www.invisioncommunity.com/legal/standards/
|
||||
* @subpackage Commerce
|
||||
* @since 25 Mar 2021
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\extensions\core\AchievementAction;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Achievement Action Extension
|
||||
*/
|
||||
class _Subscription extends \IPS\core\Achievements\Actions\AbstractAchievementAction // NOTE: Other classes exist to provided bases for common situations, like where node-based filters will be required
|
||||
{
|
||||
/**
|
||||
* Can use this rule?
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function canUse(): bool
|
||||
{
|
||||
return (bool) parent::canUse() and \IPS\Settings::i()->nexus_subs_enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get filter form elements
|
||||
*
|
||||
* @param array|NULL $filters Current filter values (if editing)
|
||||
* @param \IPS\Http\Url $url The URL the form is being shown on
|
||||
* @return array
|
||||
*/
|
||||
public function filters( ?array $filters, \IPS\Http\Url $url ): array
|
||||
{
|
||||
$return = array();
|
||||
|
||||
$return['subscriptions'] = new \IPS\Helpers\Form\Node( 'achievement_filter_Subscriptions', ( $filters and isset( $filters['subscriptions'] ) and $filters['subscriptions'] ) ? $filters['subscriptions'] : 0, FALSE, [
|
||||
'url' => $url,
|
||||
'class' => 'IPS\nexus\Subscription\Package',
|
||||
'showAllNodes' => TRUE,
|
||||
'multiple' => TRUE,
|
||||
], NULL, \IPS\Member::loggedIn()->language()->addToStack( 'achievement_filter_Subscriptions_node_prefix', FALSE, [ 'sprintf' => [
|
||||
\IPS\Member::loggedIn()->language()->addToStack( 'nexus_sub_package_id', FALSE ),
|
||||
\IPS\Member::loggedIn()->language()->addToStack( 'calendars_sg', FALSE, [ 'strtolower' => TRUE ] )
|
||||
] ] ) );
|
||||
|
||||
$return['subscriptions_active'] = new \IPS\Helpers\Form\YesNo( 'achievement_filter_Subscriptions_active', $filters and isset( $filters['subscriptions_active'] ) and $filters['subscriptions_active'], FALSE, [],NULL,
|
||||
\IPS\Member::loggedIn()->language()->addToStack( 'nexus_sub_active', FALSE )
|
||||
);
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format filter form values
|
||||
*
|
||||
* @param array $values The values from the form
|
||||
* @return array
|
||||
*/
|
||||
public function formatFilterValues( array $values ): array
|
||||
{
|
||||
$return = [];
|
||||
if ( isset( $values['achievement_filter_Subscriptions'] ) )
|
||||
{
|
||||
$return['subscriptions'] = array_keys( $values['achievement_filter_Subscriptions'] );
|
||||
}
|
||||
if ( isset( $values['achievement_filter_Subscriptions_active'] ) )
|
||||
{
|
||||
$return['subscriptions_active'] = $values['achievement_filter_Subscriptions_active'];
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Work out if the filters applies for a given action
|
||||
*
|
||||
* Important note for milestones: consider the context. This method is called by \IPS\Member::achievementAction(). If your code
|
||||
* calls that BEFORE making its change in the database (or there is read/write separation), you will need to add
|
||||
* 1 to the value being considered for milestones
|
||||
*
|
||||
* @param \IPS\Member $subject The subject member
|
||||
* @param array $filters The value returned by formatFilterValues()
|
||||
* @param mixed $extra Any additional information about what is happening (e.g. if a post is being made: the post object)
|
||||
* @return bool
|
||||
*/
|
||||
public function filtersMatch( \IPS\Member $subject, array $filters, $extra = NULL ): bool
|
||||
{
|
||||
if ( isset( $filters['subscriptions'] ) )
|
||||
{
|
||||
if ( !\in_array( $extra->_id, $filters['subscriptions'] ) )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( $filters['subscriptions_active'] ) )
|
||||
{
|
||||
foreach ( $filters['subscriptions'] as $id )
|
||||
{
|
||||
try
|
||||
{
|
||||
$package = \IPS\nexus\Subscription\Package::load( $id );
|
||||
\IPS\nexus\Subscription::loadByMemberAndPackage( $subject, $package, TRUE );
|
||||
}
|
||||
catch ( \OutOfRangeException $e ) {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the labels for the people this action might give awards to
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
// You don't need to implement this if your action only gives points to the subject
|
||||
// public function awardOptions(): array
|
||||
// {
|
||||
// return [
|
||||
// 'subject' => 'achievement_filter_Subscription_receiver',
|
||||
// 'other' => 'achievement_filter_Subscription_giver'
|
||||
// ];
|
||||
// }
|
||||
|
||||
/**
|
||||
* Get the "other" people we need to award =stuff to
|
||||
*
|
||||
* @param mixed $extra Any additional information about what is happening (e.g. if a post is being made: the post object)
|
||||
* @return array
|
||||
*/
|
||||
// You don't need to implement this if your action only gives points to the subject
|
||||
// public function awardOther( $extra = NULL ): array
|
||||
// {
|
||||
// return [ \IPS\Member::loggedIn() ];
|
||||
// }
|
||||
|
||||
/**
|
||||
* Get identifier to prevent the member being awarded points for the same action twice
|
||||
* Must be unique within within of this domain, must not exceed 32 chars.
|
||||
*
|
||||
* @param \IPS\Member $subject The subject member
|
||||
* @param mixed $extra Any additional information about what is happening (e.g. if a post is being made: the post object)
|
||||
* @return string
|
||||
*/
|
||||
public function identifier( \IPS\Member $subject, $extra = NULL ): string
|
||||
{
|
||||
return (string) $extra->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a description for this action to show in the log
|
||||
*
|
||||
* @param string $identifier The identifier as returned by identifier()
|
||||
* @param array $actor If the member was the "subject", "other", or both
|
||||
* @return string
|
||||
*/
|
||||
public function logRow( string $identifier, array $actor ): string
|
||||
{
|
||||
return "Subscription";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get "description" for rule
|
||||
*
|
||||
* @param \IPS\core\Achievements\Rule $rule The rule
|
||||
* @return string|NULL
|
||||
*/
|
||||
public function ruleDescription( \IPS\core\Achievements\Rule $rule ): ?string
|
||||
{
|
||||
$conditions = [];
|
||||
|
||||
if ( isset( $rule->filters['subscriptions_active'] ) AND $rule->filters['subscriptions_active'] )
|
||||
{
|
||||
$conditions[] = \IPS\Member::loggedIn()->language()->addToStack( 'achievement_filter_Subscriptions_active');
|
||||
}
|
||||
else
|
||||
{
|
||||
$conditions[] = \IPS\Member::loggedIn()->language()->addToStack( 'achievement_filter_Subscriptions_node_prefix');
|
||||
}
|
||||
|
||||
if ( $nodeCondition = $this->_nodeFilterDescription( $rule ) )
|
||||
{
|
||||
$conditions[] = $nodeCondition;
|
||||
}
|
||||
|
||||
return \IPS\Theme::i()->getTemplate( 'achievements' )->ruleDescription(
|
||||
\IPS\Member::loggedIn()->language()->addToStack( 'AchievementAction__Subscription_title' ),
|
||||
$conditions
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get "description" for rule (usually a description of the rule's filters)
|
||||
*
|
||||
* @param \IPS\core\Achievements\Rule $rule The rule
|
||||
* @return string|NULL
|
||||
*/
|
||||
protected function _nodeFilterDescription( \IPS\core\Achievements\Rule $rule ): ?string
|
||||
{
|
||||
if ( isset( $rule->filters['subscriptions'] ) )
|
||||
{
|
||||
$nodeNames = [];
|
||||
foreach ( $rule->filters['subscriptions'] as $id )
|
||||
{
|
||||
try
|
||||
{
|
||||
$nodeNames[] = \IPS\nexus\Subscription\Package::load( $id )->_title;
|
||||
}
|
||||
catch ( \OutOfRangeException $e ) {}
|
||||
}
|
||||
|
||||
if ( $nodeNames )
|
||||
{
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'achievements_filter_Subscription_type', FALSE, [
|
||||
'htmlsprintf' => [
|
||||
\IPS\Theme::i()->getTemplate( 'achievements' )->ruleDescriptionBadge( 'achievements_filter_Subscription_type',
|
||||
\count( $nodeNames ) === 1 ? $nodeNames[0] : \IPS\Member::loggedIn()->language()->addToStack( 'achievements_filter_Subscription_pl', FALSE, [ 'sprintf' => [
|
||||
\count( $nodeNames ),
|
||||
\IPS\Member::loggedIn()->language()->addToStack( 'nexus_sub_package_id', FALSE, [ 'strtolower' => TRUE ] )
|
||||
] ] ),
|
||||
\count( $nodeNames ) === 1 ? NULL : $nodeNames
|
||||
)
|
||||
],
|
||||
] );
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get rebuild data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static public function rebuildData()
|
||||
{
|
||||
return [ [
|
||||
'table' => 'nexus_member_subscriptions',
|
||||
'pkey' => 'sub_id',
|
||||
'date' => 'sub_start',
|
||||
'where' => [ ['sub_active=?', 1 ] ],
|
||||
] ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the rebuild row
|
||||
*
|
||||
* @param array $row Row from database
|
||||
* @param array $data Data collected when starting rebuild [table, pkey...]
|
||||
* @return void
|
||||
*/
|
||||
public static function rebuildRow( $row, $data )
|
||||
{
|
||||
\IPS\Member::load( $row['member_id'] )->achievementAction( 'nexus', 'Subscription', \IPS\nexus\Subscription::load( $row['sub_id'] ) );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -504,6 +504,10 @@ class _Support
|
||||
if ( !$file->isImage() )
|
||||
{
|
||||
$replacements["<fileStore.core_Attachment>/{$file}"] = \IPS\Settings::i()->base_url . "applications/core/interface/file/attachment.php?id={$attachment['attach_id']}";
|
||||
if ( $attachment['attach_security_key'] )
|
||||
{
|
||||
$replacements["<fileStore.core_Attachment>/{$file}"] .= "&key={$attachment['attach_security_key']}";
|
||||
}
|
||||
}
|
||||
|
||||
\IPS\Db::i()->insert( 'core_attachments_map', array(
|
||||
|
||||
@@ -89,7 +89,7 @@ class _Notes extends \IPS\core\MemberACPProfile\Block
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'customers', 'customer_notes_delete' ) )
|
||||
{
|
||||
$return['delete'] = array(
|
||||
'link' => \IPS\Http\Url::internal("app=nexus&module=customers&controller=view&id={$this->member->member_id}")->setQueryString( array( 'do' => 'deleteNote', 'note_id' => $row['note_id'], 'support' => isset( \IPS\Request::i()->support ) ? \IPS\Request::i()->support : 0 ) ),
|
||||
'link' => \IPS\Http\Url::internal("app=nexus&module=customers&controller=view&id={$this->member->member_id}")->setQueryString( array( 'do' => 'deleteNote', 'note_id' => $row['note_id'], 'support' => isset( \IPS\Request::i()->support ) ? \IPS\Request::i()->support : 0 ) )->csrf(),
|
||||
'title' => 'delete',
|
||||
'icon' => 'times-circle',
|
||||
'data' => array( 'confirm' => '' )
|
||||
|
||||
@@ -57,8 +57,8 @@ class _Purchases
|
||||
{
|
||||
return !( $node instanceof \IPS\nexus\Package\Group );
|
||||
} ) ),
|
||||
new \IPS\Helpers\Form\CheckboxSet( 'nexus_bm_filters_type', isset( $criteria['nexus_bm_filters_type'] ) ? explode( ',', $criteria['nexus_bm_filters_type'] ) : array( 'active' ), FALSE, array( 'toggles' => array( 'expired' => array( 'nexus_bm_filters_pkg_expired' ) ), 'options' => array( 'active' => 'nexus_bm_filters_type_active', 'expired' => 'nexus_bm_filters_type_expired', 'canceled' => 'nexus_bm_filters_type_canceled' ) ), NULL, NULL, NULL, 'nexus_bm_filters_types' ),
|
||||
new \IPS\Helpers\Form\Custom( 'nexus_bm_filters_pkg_expired', array( 0 => isset( $criteria['nexus_bm_filters_pkg_expired']['range'] ) ? $criteria['nexus_bm_filters_pkg_expired']['range'] : '', 1 => isset( $criteria['nexus_bm_filters_pkg_expired']['days'] ) ? $criteria['nexus_bm_filters_pkg_expired']['days'] : NULL ), FALSE, array(
|
||||
new \IPS\Helpers\Form\CheckboxSet( 'nexus_bm_filters_type', isset( $criteria['nexus_bm_filters_type'] ) ? $criteria['nexus_bm_filters_type'] : array( 'active' ), FALSE, array( 'toggles' => array( 'expired' => array( 'nexus_bm_filters_pkg_expired' ) ), 'options' => array( 'active' => 'nexus_bm_filters_type_active', 'expired' => 'nexus_bm_filters_type_expired', 'canceled' => 'nexus_bm_filters_type_canceled' ) ), NULL, NULL, NULL, 'nexus_bm_filters_types' ),
|
||||
new \IPS\Helpers\Form\Custom( 'nexus_bm_filters_pkg_expired', array( 0 => isset( $criteria['nexus_bm_filters_pkg_expired']['range'] ) ? $criteria['nexus_bm_filters_pkg_expired']['range'] : '', 1 => isset( $criteria['nexus_bm_filters_pkg_expired']['days'] ) ? $criteria['nexus_bm_filters_pkg_expired']['days'] : NULL, 3 => isset( $criteria['nexus_bm_filters_pkg_expired']['days_lt'] ) ? $criteria['nexus_bm_filters_pkg_expired']['days_lt'] : NULL ), FALSE, array(
|
||||
'getHtml' => function( $element )
|
||||
{
|
||||
$dateRange = new \IPS\Helpers\Form\DateRange( "{$element->name}[0]", $element->value[0], FALSE );
|
||||
@@ -78,6 +78,8 @@ class _Purchases
|
||||
*/
|
||||
public function save( $post )
|
||||
{
|
||||
$return = array();
|
||||
|
||||
if ( \is_array( $post['nexus_bm_filters_packages'] ) )
|
||||
{
|
||||
$ids = array();
|
||||
@@ -86,28 +88,35 @@ class _Purchases
|
||||
$ids[] = $package->id;
|
||||
}
|
||||
|
||||
$return = array(
|
||||
'nexus_bm_filters_packages' => implode( ',', $ids ),
|
||||
'nexus_bm_filters_pkg_active' => (bool) ( \in_array( "active", $post['nexus_bm_filters_type'] ) ),
|
||||
'nexus_bm_filters_pkg_canceled' => (bool) ( \in_array( "canceled", $post['nexus_bm_filters_type'] ) ),
|
||||
'nexus_bm_filters_pkg_expired' => NULL
|
||||
);
|
||||
$return['nexus_bm_filters_packages'] = implode( ',', $ids );
|
||||
}
|
||||
|
||||
if( isset( $post['nexus_bm_filters_type'] ) )
|
||||
{
|
||||
$return['nexus_bm_filters_type'] = $post['nexus_bm_filters_type'];
|
||||
$return['nexus_bm_filters_pkg_active'] = (bool) ( \in_array( "active", $post['nexus_bm_filters_type'] ) );
|
||||
$return['nexus_bm_filters_pkg_canceled'] = (bool) ( \in_array( "canceled", $post['nexus_bm_filters_type'] ) );
|
||||
$return['nexus_bm_filters_pkg_expired'] = NULL;
|
||||
|
||||
if( isset( $post['nexus_bm_filters_pkg_expired'][2] ) AND $post['nexus_bm_filters_pkg_expired'][2] == 'days' )
|
||||
{
|
||||
$return['nexus_bm_filters_pkg_expired'] = $post['nexus_bm_filters_pkg_expired'][1] ? array( 'days' => \intval( $post['nexus_bm_filters_pkg_expired'][1] ) ) : FALSE;
|
||||
}
|
||||
elseif( isset( $post['nexus_bm_filters_pkg_expired'][2] ) AND $post['nexus_bm_filters_pkg_expired'][2] == 'days_lt' )
|
||||
{
|
||||
$return['nexus_bm_filters_pkg_expired'] = $post['nexus_bm_filters_pkg_expired'][3] ? array( 'days_lt' => \intval( $post['nexus_bm_filters_pkg_expired'][3] ) ) : FALSE;
|
||||
}
|
||||
elseif( isset( $post['nexus_bm_filters_pkg_expired'][2] ) AND $post['nexus_bm_filters_pkg_expired'][2] == 'range' )
|
||||
{
|
||||
$return['nexus_bm_filters_pkg_expired'] = array( 'range' => json_decode( json_encode( $post['nexus_bm_filters_pkg_expired'][0] ), TRUE ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Normalize objects to their array form. Bulk mailer stores options as a json array where as member export does not, so $data['range']['start'] is a DateTime object */
|
||||
$return['nexus_bm_filters_pkg_expired'] = ( empty($post['nexus_bm_filters_pkg_expired'][0]) ) ? FALSE : array( 'range' => json_decode( json_encode( $post['nexus_bm_filters_pkg_expired'][0] ), TRUE ) );
|
||||
$return['nexus_bm_filters_pkg_expired'] = FALSE;
|
||||
}
|
||||
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
return \count( $return ) ? $return : FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -120,7 +129,7 @@ class _Purchases
|
||||
{
|
||||
if ( isset( $data['nexus_bm_filters_packages'] ) and $data['nexus_bm_filters_packages'] )
|
||||
{
|
||||
return array( 'nexus_purchases.ps_id IS NOT NULL' );
|
||||
return array( 'purchase.ps_id IS NOT NULL' );
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@@ -141,12 +150,12 @@ class _Purchases
|
||||
|
||||
if ( isset($data[ 'nexus_bm_filters_pkg_active' ]) and $data[ 'nexus_bm_filters_pkg_active' ] )
|
||||
{
|
||||
$types[] = 'nexus_purchases.ps_active=1';
|
||||
$types[] = 'purchase.ps_active=1';
|
||||
}
|
||||
|
||||
if ( isset( $data[ 'nexus_bm_filters_pkg_canceled' ] ) and $data[ 'nexus_bm_filters_pkg_canceled' ] )
|
||||
{
|
||||
$types[] = 'nexus_purchases.ps_cancelled=1';
|
||||
$types[] = 'purchase.ps_cancelled=1';
|
||||
}
|
||||
|
||||
if ( !empty( $data[ 'nexus_bm_filters_pkg_expired' ][ 'range' ] ) AND !empty( $data[ 'nexus_bm_filters_pkg_expired' ][ 'range' ][ 'end' ] ) )
|
||||
@@ -156,20 +165,31 @@ class _Purchases
|
||||
|
||||
if ( $start and $end )
|
||||
{
|
||||
$types[] = "( nexus_purchases.ps_active=0 AND nexus_purchases.ps_cancelled=0 AND nexus_purchases.ps_expire BETWEEN {$start->getTimestamp()} AND {$end->getTimestamp()})";
|
||||
$types[] = "( purchase.ps_active=0 AND purchase.ps_cancelled=0 AND purchase.ps_expire BETWEEN {$start->getTimestamp()} AND {$end->getTimestamp()})";
|
||||
}
|
||||
}
|
||||
elseif ( !empty( $data[ 'nexus_bm_filters_pkg_expired' ][ 'days' ] ) )
|
||||
{
|
||||
$date = \IPS\DateTime::create()->sub( new \DateInterval( 'P' . $data[ 'nexus_bm_filters_pkg_expired' ][ 'days' ] . 'D' ) );
|
||||
$types[] = "( nexus_purchases.ps_active=0 AND nexus_purchases.ps_cancelled=0 AND nexus_purchases.ps_expire < {$date->getTimestamp()})";
|
||||
$types[] = "( purchase.ps_active=0 AND purchase.ps_cancelled=0 AND purchase.ps_expire < {$date->getTimestamp()})";
|
||||
}
|
||||
elseif( !empty( $data[ 'nexus_bm_filters_pkg_expired' ][ 'days_lt' ] ) AND (int) $data[ 'nexus_bm_filters_pkg_expired' ][ 'days_lt' ] )
|
||||
{
|
||||
$date = \IPS\DateTime::create()->sub( new \DateInterval( 'P' . (int) $data[ 'nexus_bm_filters_pkg_expired' ][ 'days_lt' ] . 'D' ) );
|
||||
|
||||
$types[] = "( purchase.ps_active=0 AND purchase.ps_cancelled=0 AND purchase.ps_expire > {$date->getTimestamp()})";
|
||||
}
|
||||
elseif( isset( $data['nexus_bm_filters_type'] ) AND \in_array( 'expired', $data['nexus_bm_filters_type'] ) )
|
||||
{
|
||||
$types[] = "(purchase.ps_expire < " . time() . ")";
|
||||
}
|
||||
|
||||
if ( !empty( $types ) )
|
||||
{
|
||||
$types = implode( ' OR ', $types );
|
||||
$query->join( 'nexus_purchases', "nexus_purchases.ps_app='nexus' AND nexus_purchases.ps_type='package' AND nexus_purchases.ps_member=core_members.member_id AND " . \IPS\Db::i()->in( 'nexus_purchases.ps_item_id', explode( ',', $data['nexus_bm_filters_packages'] ) ) . " AND ( {$types} )" );
|
||||
}
|
||||
|
||||
$query->join( ['nexus_purchases', 'purchase'], "purchase.ps_app='nexus' AND purchase.ps_type='package' AND purchase.ps_member=core_members.member_id AND " . \IPS\Db::i()->in( 'purchase.ps_item_id', explode( ',', $data['nexus_bm_filters_packages'] ) ) . ( $types ? " AND ( {$types} )" : '' ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -98,6 +98,8 @@ class _Nexus
|
||||
\IPS\Db::i()->update( 'nexus_support_ratings', array( 'rating_staff' => $member->member_id ), array( 'rating_staff=?', $member2->member_id ) );
|
||||
|
||||
\IPS\Db::i()->delete( 'nexus_customer_spend', array( 'spend_member_id=?', $member2->member_id ) );
|
||||
|
||||
\IPS\Db::i()->delete( 'nexus_alternate_contacts', array( 'main_id = alt_id' ) );
|
||||
|
||||
/* Account Credit */
|
||||
$customerToKeep = \IPS\nexus\Customer::load( $member->member_id );
|
||||
|
||||
@@ -48,18 +48,6 @@ class _DisablePOP
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Code to execute when other applications are uninstalled
|
||||
*
|
||||
* @param string $application Application directory
|
||||
* @return void
|
||||
* @deprecated This is here for backwards-compatibility - all new code should go in onOtherUninstall
|
||||
*/
|
||||
public function onOtherAppUninstall( $application )
|
||||
{
|
||||
return $this->onOtherUninstall( $application );
|
||||
}
|
||||
|
||||
/**
|
||||
* Code to execute when other applications or plugins are uninstalled
|
||||
*
|
||||
|
||||
@@ -189,7 +189,7 @@ class _CustomPackage extends \IPS\nexus\extensions\nexus\Item\Package
|
||||
{
|
||||
if( $values['p_tax'] )
|
||||
{
|
||||
$tax = \IPS\nexus\Tax::load( $values['p_tax'] );
|
||||
$tax = $values['p_tax'];
|
||||
}
|
||||
}
|
||||
catch( \OutOfRangeException $e ){}
|
||||
|
||||
@@ -68,7 +68,7 @@ class _MiscellaneousCharge extends \IPS\nexus\Invoice\Item\Charge
|
||||
{
|
||||
$availableShippingMethods['easypost'] = 'enhancements__nexus_EasyPost';
|
||||
}
|
||||
$form->add( new \IPS\Helpers\Form\Select( 'item_shipmethods', '*', FALSE, array( 'options' => $availableShippingMethods, 'multiple' => TRUE, 'unlimited' => '*' ), NULL, NULL, NULL, 'item_shipmethods' ) );
|
||||
$form->add( new \IPS\Helpers\Form\CheckboxSet( 'item_shipmethods', '*', FALSE, array( 'options' => $availableShippingMethods, 'multiple' => TRUE, 'unlimited' => '*', 'impliedUnlimited' => TRUE ), NULL, NULL, NULL, 'item_shipmethods' ) );
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'item_pay_other', FALSE, FALSE, array( 'togglesOn' => array( 'item_pay_to', 'item_commission', 'item_fee' ) ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Member( 'item_pay_to', FALSE, FALSE, array(), NULL, NULL, NULL, 'item_pay_to' ) );
|
||||
|
||||
@@ -503,10 +503,7 @@ class _Package extends \IPS\nexus\Invoice\Item\Purchase
|
||||
/* Is this the same as any of the other items? */
|
||||
foreach ( $itemsToAdd as $_item )
|
||||
{
|
||||
$cloned = clone $_item;
|
||||
$cloned->quantity = 1;
|
||||
|
||||
if ( $cloned == $item )
|
||||
if ( $_item->isSameAsOtherItem( $item ) )
|
||||
{
|
||||
$_item->quantity++;
|
||||
continue 2;
|
||||
@@ -516,10 +513,7 @@ class _Package extends \IPS\nexus\Invoice\Item\Purchase
|
||||
/* Or anything on the invoice? */
|
||||
foreach ( $invoice->items as $k => $_item )
|
||||
{
|
||||
$cloned = clone $_item;
|
||||
$cloned->quantity = 1;
|
||||
|
||||
if ( $cloned == $item )
|
||||
if ( $_item->isSameAsOtherItem( $item ) )
|
||||
{
|
||||
$invoice->changeItem( $k, array( 'quantity' => $_item->quantity + 1 ) );
|
||||
continue 2;
|
||||
|
||||
@@ -43,6 +43,51 @@ class _Subscription extends \IPS\nexus\Invoice\Item\Purchase
|
||||
*/
|
||||
public static $title = 'nexus_member_subscription';
|
||||
|
||||
/**
|
||||
* Purchase can be reactivated in the ACP?
|
||||
*
|
||||
* @param \IPS\nexus\Purchase $purchase The purchase
|
||||
* @param NULL $error Error to show, passed by reference
|
||||
* @return bool
|
||||
*/
|
||||
public static function canAcpReactivate( \IPS\nexus\Purchase $purchase, &$error=NULL )
|
||||
{
|
||||
/* If the user has a different subscription that is active -or- can be reactivated, then we cannot reactivate this one */
|
||||
if ( $subscription = \IPS\nexus\Subscription::loadByMember( $purchase->member, FALSE ) AND ( $subscription->purchase->active OR ( $subscription->purchase->cancelled AND $subscription->purchase->can_reactivate ) ) )
|
||||
{
|
||||
if ( $subscription->purchase == $purchase )
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
$error = 'not_with_existing_subscription';
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Otherwise, we're good */
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* ACP Edit Save
|
||||
*
|
||||
* @param \IPS\nexus\Purchase $purchase The purchase
|
||||
* @param array $values Values from form
|
||||
* @return string
|
||||
*/
|
||||
public static function acpEditSave( \IPS\nexus\Purchase $purchase, array $values )
|
||||
{
|
||||
parent::acpEditSave( $purchase, $values );
|
||||
|
||||
try
|
||||
{
|
||||
$subscription = \IPS\nexus\Subscription::loadByMemberAndPurchase( $purchase->member, $purchase );
|
||||
$subscription->expire = \is_object( $purchase->expire ) ? $purchase->expire->getTimestamp() : ( $purchase->expire ?: 0 );
|
||||
$subscription->save();
|
||||
}
|
||||
catch( \UnderflowException $e) { }
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Title
|
||||
*
|
||||
@@ -201,6 +246,9 @@ class _Subscription extends \IPS\nexus\Invoice\Item\Purchase
|
||||
$subscription->purchase_id = $purchase->id;
|
||||
$subscription->invoice_id = $invoice->id;
|
||||
$subscription->save();
|
||||
|
||||
/* Achievements */
|
||||
$purchase->member->achievementAction( 'nexus', 'Subscription', $subscription );
|
||||
}
|
||||
catch ( \Exception $e ) {}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user