Version 5.0.0 beta 1
This commit is contained in:
1 parent
25ddeb65d6
commit
15c7beabc5
6736 files changed
+627902
-497943
No files matched your search
@@ -11,16 +11,32 @@
|
||||
namespace IPS\nexus\extensions\core\AchievementAction;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\core\Achievements\Actions\AchievementActionAbstract;
|
||||
use IPS\core\Achievements\Rule;
|
||||
use IPS\Helpers\Form\Node;
|
||||
use IPS\Helpers\Form\YesNo;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Member;
|
||||
use IPS\nexus\Subscription as NexusSubscription;
|
||||
use IPS\nexus\Subscription\Package;
|
||||
use IPS\Settings;
|
||||
use IPS\Theme;
|
||||
use OutOfRangeException;
|
||||
use function count;
|
||||
use function defined;
|
||||
use function in_array;
|
||||
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_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
|
||||
class Subscription extends AchievementActionAbstract // NOTE: Other classes exist to provided bases for common situations, like where node-based filters will be required
|
||||
{
|
||||
/**
|
||||
* Can use this rule?
|
||||
@@ -29,32 +45,32 @@ class _Subscription extends \IPS\core\Achievements\Actions\AbstractAchievementAc
|
||||
*/
|
||||
public function canUse(): bool
|
||||
{
|
||||
return (bool) parent::canUse() and \IPS\Settings::i()->nexus_subs_enabled;
|
||||
return parent::canUse() and 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
|
||||
* @param Url $url The URL the form is being shown on
|
||||
* @return array
|
||||
*/
|
||||
public function filters( ?array $filters, \IPS\Http\Url $url ): array
|
||||
public function filters( ?array $filters, 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, [
|
||||
$return['subscriptions'] = new 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 ] )
|
||||
], NULL, Member::loggedIn()->language()->addToStack( 'achievement_filter_Subscriptions_node_prefix', FALSE, [ 'sprintf' => [
|
||||
Member::loggedIn()->language()->addToStack( 'nexus_sub_package_id', FALSE ),
|
||||
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['subscriptions_active'] = new YesNo( 'achievement_filter_Subscriptions_active', $filters and isset( $filters['subscriptions_active'] ) and $filters['subscriptions_active'], FALSE, [],NULL,
|
||||
Member::loggedIn()->language()->addToStack( 'nexus_sub_active', FALSE )
|
||||
);
|
||||
|
||||
return $return;
|
||||
@@ -87,16 +103,16 @@ class _Subscription extends \IPS\core\Achievements\Actions\AbstractAchievementAc
|
||||
* 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 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
|
||||
public function filtersMatch( Member $subject, array $filters, mixed $extra = NULL ): bool
|
||||
{
|
||||
if ( isset( $filters['subscriptions'] ) )
|
||||
{
|
||||
if ( !\in_array( $extra->package_id, $filters['subscriptions'] ) )
|
||||
if ( !in_array( $extra->package_id, $filters['subscriptions'] ) )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
@@ -108,12 +124,12 @@ class _Subscription extends \IPS\core\Achievements\Actions\AbstractAchievementAc
|
||||
{
|
||||
try
|
||||
{
|
||||
\IPS\nexus\Subscription::loadByMemberAndPackage( $subject, \IPS\nexus\Subscription\Package::load( $id ), TRUE );
|
||||
NexusSubscription::loadByMemberAndPackage( $subject, Package::load( $id ), TRUE );
|
||||
|
||||
/* Still here? */
|
||||
return TRUE;
|
||||
}
|
||||
catch ( \OutOfRangeException $e ) { }
|
||||
catch ( OutOfRangeException ) { }
|
||||
}
|
||||
|
||||
/* No active matches */
|
||||
@@ -127,11 +143,11 @@ class _Subscription extends \IPS\core\Achievements\Actions\AbstractAchievementAc
|
||||
* 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 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
|
||||
public function identifier( Member $subject, mixed $extra = NULL ): string
|
||||
{
|
||||
return (string) $extra->id;
|
||||
}
|
||||
@@ -151,20 +167,20 @@ class _Subscription extends \IPS\core\Achievements\Actions\AbstractAchievementAc
|
||||
/**
|
||||
* Get "description" for rule
|
||||
*
|
||||
* @param \IPS\core\Achievements\Rule $rule The rule
|
||||
* @param Rule $rule The rule
|
||||
* @return string|NULL
|
||||
*/
|
||||
public function ruleDescription( \IPS\core\Achievements\Rule $rule ): ?string
|
||||
public function ruleDescription( 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');
|
||||
$conditions[] = Member::loggedIn()->language()->addToStack( 'achievement_filter_Subscriptions_active');
|
||||
}
|
||||
else
|
||||
{
|
||||
$conditions[] = \IPS\Member::loggedIn()->language()->addToStack( 'achievement_filter_Subscriptions_node_prefix');
|
||||
$conditions[] = Member::loggedIn()->language()->addToStack( 'achievement_filter_Subscriptions_node_prefix');
|
||||
}
|
||||
|
||||
if ( $nodeCondition = $this->_nodeFilterDescription( $rule ) )
|
||||
@@ -172,8 +188,8 @@ class _Subscription extends \IPS\core\Achievements\Actions\AbstractAchievementAc
|
||||
$conditions[] = $nodeCondition;
|
||||
}
|
||||
|
||||
return \IPS\Theme::i()->getTemplate( 'achievements' )->ruleDescription(
|
||||
\IPS\Member::loggedIn()->language()->addToStack( 'AchievementAction__Subscription_title' ),
|
||||
return Theme::i()->getTemplate( 'achievements' )->ruleDescription(
|
||||
Member::loggedIn()->language()->addToStack( 'AchievementAction__Subscription_title' ),
|
||||
$conditions
|
||||
);
|
||||
}
|
||||
@@ -181,10 +197,10 @@ class _Subscription extends \IPS\core\Achievements\Actions\AbstractAchievementAc
|
||||
/**
|
||||
* Get "description" for rule (usually a description of the rule's filters)
|
||||
*
|
||||
* @param \IPS\core\Achievements\Rule $rule The rule
|
||||
* @param Rule $rule The rule
|
||||
* @return string|NULL
|
||||
*/
|
||||
protected function _nodeFilterDescription( \IPS\core\Achievements\Rule $rule ): ?string
|
||||
protected function _nodeFilterDescription( Rule $rule ): ?string
|
||||
{
|
||||
if ( isset( $rule->filters['subscriptions'] ) )
|
||||
{
|
||||
@@ -193,21 +209,21 @@ class _Subscription extends \IPS\core\Achievements\Actions\AbstractAchievementAc
|
||||
{
|
||||
try
|
||||
{
|
||||
$nodeNames[] = \IPS\nexus\Subscription\Package::load( $id )->_title;
|
||||
$nodeNames[] = Package::load( $id )->_title;
|
||||
}
|
||||
catch ( \OutOfRangeException $e ) {}
|
||||
catch ( OutOfRangeException ) {}
|
||||
}
|
||||
|
||||
if ( $nodeNames )
|
||||
{
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'achievements_filter_Subscription_type', FALSE, [
|
||||
return 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 ] )
|
||||
Theme::i()->getTemplate( 'achievements' )->ruleDescriptionBadge( 'achievements_filter_Subscription_type',
|
||||
count( $nodeNames ) === 1 ? $nodeNames[0] : Member::loggedIn()->language()->addToStack( 'achievements_filter_Subscription_pl', FALSE, [ 'sprintf' => [
|
||||
count( $nodeNames ),
|
||||
Member::loggedIn()->language()->addToStack( 'nexus_sub_package_id', FALSE, [ 'strtolower' => TRUE ] )
|
||||
] ] ),
|
||||
\count( $nodeNames ) === 1 ? NULL : $nodeNames
|
||||
count( $nodeNames ) === 1 ? NULL : $nodeNames
|
||||
)
|
||||
],
|
||||
] );
|
||||
@@ -222,7 +238,7 @@ class _Subscription extends \IPS\core\Achievements\Actions\AbstractAchievementAc
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static public function rebuildData()
|
||||
static public function rebuildData(): array
|
||||
{
|
||||
return [ [
|
||||
'table' => 'nexus_member_subscriptions',
|
||||
@@ -239,9 +255,9 @@ class _Subscription extends \IPS\core\Achievements\Actions\AbstractAchievementAc
|
||||
* @param array $data Data collected when starting rebuild [table, pkey...]
|
||||
* @return void
|
||||
*/
|
||||
public static function rebuildRow( $row, $data )
|
||||
public static function rebuildRow( array $row, array $data ) : void
|
||||
{
|
||||
\IPS\Member::load( $row['sub_member_id'] )->achievementAction( 'nexus', 'Subscription', \IPS\nexus\Subscription::load( $row['sub_id'] ) );
|
||||
Member::load( $row['sub_member_id'] )->achievementAction( 'nexus', 'Subscription', NexusSubscription::load( $row['sub_id'] ) );
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user