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,31 +11,60 @@
|
||||
namespace IPS\core\Achievements;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use DomainException;
|
||||
use IPS\Application;
|
||||
use IPS\core\Achievements\Actions\AchievementActionAbstract;
|
||||
use IPS\Data\Store;
|
||||
use IPS\DateTime;
|
||||
use IPS\Db;
|
||||
use IPS\Dispatcher;
|
||||
use IPS\File;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\Custom;
|
||||
use IPS\Helpers\Form\Select;
|
||||
use IPS\Helpers\Form\Translatable;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Lang;
|
||||
use IPS\Member;
|
||||
use IPS\Node\Model;
|
||||
use IPS\Request;
|
||||
use IPS\Task;
|
||||
use IPS\Theme;
|
||||
use OutOfRangeException;
|
||||
use XMLReader;
|
||||
use function count;
|
||||
use function defined;
|
||||
use function get_class;
|
||||
use function intval;
|
||||
use function is_array;
|
||||
use function is_numeric;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Achievements Rule Model
|
||||
*/
|
||||
class _Rule extends \IPS\Node\Model
|
||||
class Rule extends Model
|
||||
{
|
||||
/**
|
||||
* @brief Database Table
|
||||
*/
|
||||
public static $databaseTable = 'core_achievements_rules';
|
||||
public static ?string $databaseTable = 'core_achievements_rules';
|
||||
|
||||
/**
|
||||
* @brief Multiton Store
|
||||
*/
|
||||
protected static $multitons;
|
||||
protected static array $multitons;
|
||||
|
||||
/**
|
||||
* @brief [Node] Node Title
|
||||
*/
|
||||
public static $nodeTitle = 'achievements_rules';
|
||||
public static string $nodeTitle = 'achievements_rules';
|
||||
|
||||
/**
|
||||
* @brief [Node] ACP Restrictions
|
||||
@@ -53,7 +82,7 @@ class _Rule extends \IPS\Node\Model
|
||||
'prefix' => 'foo_', // [Optional] Rather than specifying each key in the map, you can specify a prefix, and it will automatically look for restrictions with the key "[prefix]_add/edit/permissions/delete"
|
||||
* @endcode
|
||||
*/
|
||||
protected static $restrictions = array(
|
||||
protected static ?array $restrictions = array(
|
||||
'app' => 'core',
|
||||
'module' => 'achievements',
|
||||
'prefix' => 'rules_',
|
||||
@@ -63,7 +92,7 @@ class _Rule extends \IPS\Node\Model
|
||||
* @brief [ActiveRecord] Caches
|
||||
* @note Defined cache keys will be cleared automatically as needed
|
||||
*/
|
||||
protected $caches = ['achievementRules'];
|
||||
protected array $caches = ['achievementRules'];
|
||||
|
||||
/**
|
||||
* [ActiveRecord] Get cached rules
|
||||
@@ -72,7 +101,7 @@ class _Rule extends \IPS\Node\Model
|
||||
*/
|
||||
public static function getStore(): array
|
||||
{
|
||||
if ( !isset( \IPS\Data\Store::i()->achievementRules ) )
|
||||
if ( !isset( Store::i()->achievementRules ) )
|
||||
{
|
||||
$v = [];
|
||||
foreach ( static::roots() as $rule )
|
||||
@@ -90,21 +119,21 @@ class _Rule extends \IPS\Node\Model
|
||||
'enabled' => $rule->enabled
|
||||
];
|
||||
}
|
||||
\IPS\Data\Store::i()->achievementRules = $v;
|
||||
Store::i()->achievementRules = $v;
|
||||
}
|
||||
|
||||
return \IPS\Data\Store::i()->achievementRules;
|
||||
return Store::i()->achievementRules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the extension
|
||||
*
|
||||
* @return \IPS\core\Achievements\Actions\AbstractAchievementAction
|
||||
* @return AchievementActionAbstract
|
||||
*/
|
||||
public function extension(): \IPS\core\Achievements\Actions\AbstractAchievementAction
|
||||
public function extension(): AchievementActionAbstract
|
||||
{
|
||||
$exploded = explode( '_', $this->action );
|
||||
return \IPS\Application::load( $exploded[0] )->extensions( 'core', 'AchievementAction' )[ $exploded[1] ];
|
||||
return Application::load( $exploded[0] )->extensions( 'core', 'AchievementAction' )[ $exploded[1] ];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -112,9 +141,9 @@ class _Rule extends \IPS\Node\Model
|
||||
*
|
||||
* @return array|NULL
|
||||
*/
|
||||
protected function get_filters()
|
||||
protected function get_filters() : ?array
|
||||
{
|
||||
if ( isset( $this->_data['filters'] ) and \is_array( $this->_data['filters'] ) )
|
||||
if ( isset( $this->_data['filters'] ) and is_array( $this->_data['filters'] ) )
|
||||
{
|
||||
return $this->_data['filters'];
|
||||
}
|
||||
@@ -125,31 +154,29 @@ class _Rule extends \IPS\Node\Model
|
||||
/**
|
||||
* [Node] Add/Edit Form
|
||||
*
|
||||
* @param \IPS\Helpers\Form $form The form
|
||||
* @param Form $form The form
|
||||
* @return void
|
||||
*/
|
||||
public function form( &$form )
|
||||
public function form( Form &$form ) : void
|
||||
{
|
||||
$form->_activeFilters = [];
|
||||
|
||||
$options = [];
|
||||
$toggles = [];
|
||||
$extraElements = [];
|
||||
foreach ( \IPS\Application::allExtensions( 'core', 'AchievementAction' ) as $achievementAction )
|
||||
foreach ( Application::allExtensions( 'core', 'AchievementAction' ) as $achievementAction )
|
||||
{
|
||||
if ( ! $achievementAction->canUse() )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$exploded = explode( '\\', \get_class( $achievementAction ) );
|
||||
$exploded = explode( '\\', get_class( $achievementAction ) );
|
||||
$options[ "{$exploded[1]}_{$exploded[5]}" ] = "AchievementAction__{$exploded[5]}";
|
||||
|
||||
$toggles[ "{$exploded[1]}_{$exploded[5]}" ] = [ "{$exploded[1]}_{$exploded[5]}_award_subject" ];
|
||||
$toggles[ "{$exploded[1]}_{$exploded[5]}" ][] = "{$exploded[1]}_{$exploded[5]}_award_subject_badge";
|
||||
foreach ( $achievementAction->filters( $this->filters, \IPS\Http\Url::internal( $this->id ? "app=core&module=achievements&controller=rules&do=form&id={$this->id}" : 'app=core&module=achievements&controller=rules&do=form' ) ) as $filterKey => $filterElement )
|
||||
foreach ($achievementAction->filters( $this->filters, Url::internal( $this->id ? "app=core&module=achievements&controller=rules&do=form&id={$this->id}" : 'app=core&module=achievements&controller=rules&do=form' ) ) as $filterKey => $filterElement )
|
||||
{
|
||||
if ( $this->filters and array_key_exists( $filterKey, $this->filters ) )
|
||||
if ( is_array( $this->filters ) and array_key_exists( $filterKey, $this->filters ) )
|
||||
{
|
||||
$form->_activeFilters[] = $filterElement->name;
|
||||
}
|
||||
@@ -162,34 +189,34 @@ class _Rule extends \IPS\Node\Model
|
||||
}
|
||||
|
||||
$awardTo = $achievementAction->awardOptions( $this->filters );
|
||||
$awardSubjectField = new \IPS\Helpers\Form\Custom( "{$exploded[1]}_{$exploded[5]}_award_subject", [ 'points' => $this->points_subject, 'badge' => $this->badge_subject ], FALSE, [
|
||||
$awardSubjectField = new Custom( "{$exploded[1]}_{$exploded[5]}_award_subject", [ 'points' => $this->points_subject, 'badge' => $this->badge_subject ], FALSE, [
|
||||
'getHtml' => function( $field ) {
|
||||
return \IPS\Theme::i()->getTemplate('achievements')->awardField( $field->name, $field->value );
|
||||
return Theme::i()->getTemplate('achievements')->awardField( $field->name, $field->value );
|
||||
}
|
||||
], NULL, NULL, NULL, "{$exploded[1]}_{$exploded[5]}_award_subject" );
|
||||
if ( isset( $awardTo['subject'] ) )
|
||||
{
|
||||
$awardSubjectField->label = \IPS\Member::loggedIn()->language()->addToStack( $awardTo['subject'] );
|
||||
$awardSubjectField->label = Member::loggedIn()->language()->addToStack( $awardTo['subject'] );
|
||||
}
|
||||
$extraElements[] = $awardSubjectField;
|
||||
$extraElements[] = new \IPS\Helpers\Form\Translatable( "{$exploded[1]}_{$exploded[5]}_award_subject_badge", NULL, NULL, [ 'app' => 'core', 'key' => ( $this->id ) ? "core_award_subject_badge_" . $this->id : NULL ], NULL, NULL, NULL, "{$exploded[1]}_{$exploded[5]}_award_subject_badge" );
|
||||
$extraElements[] = new Translatable( "{$exploded[1]}_{$exploded[5]}_award_subject_badge", NULL, NULL, [ 'app' => 'core', 'key' => ( $this->id ) ? "core_award_subject_badge_" . $this->id : NULL ], NULL, NULL, NULL, "{$exploded[1]}_{$exploded[5]}_award_subject_badge" );
|
||||
|
||||
if ( isset( $awardTo['other'] ) )
|
||||
{
|
||||
$awardOtherField = new \IPS\Helpers\Form\Custom( "{$exploded[1]}_{$exploded[5]}_award_other", [ 'points' => $this->points_other, 'badge' => $this->badge_other ], FALSE, [
|
||||
$awardOtherField = new Custom( "{$exploded[1]}_{$exploded[5]}_award_other", [ 'points' => $this->points_other, 'badge' => $this->badge_other ], FALSE, [
|
||||
'getHtml' => function( $field ) {
|
||||
return \IPS\Theme::i()->getTemplate('achievements')->awardField( $field->name, $field->value );
|
||||
return Theme::i()->getTemplate('achievements')->awardField( $field->name, $field->value );
|
||||
}
|
||||
], NULL, NULL, NULL, "{$exploded[1]}_{$exploded[5]}_award_other" );
|
||||
$awardOtherField->label = \IPS\Member::loggedIn()->language()->addToStack( $awardTo['other'] );
|
||||
$awardOtherField->label = Member::loggedIn()->language()->addToStack( $awardTo['other'] );
|
||||
$extraElements[] = $awardOtherField;
|
||||
$extraElements[] = new \IPS\Helpers\Form\Translatable( "{$exploded[1]}_{$exploded[5]}_award_other_badge", NULL, NULL, [ 'app' => 'core', 'key' => ( $this->id ) ? "core_award_other_badge_" . $this->id : NULL ], NULL, NULL, NULL, "{$exploded[1]}_{$exploded[5]}_award_other_badge" );
|
||||
$extraElements[] = new Translatable( "{$exploded[1]}_{$exploded[5]}_award_other_badge", NULL, NULL, [ 'app' => 'core', 'key' => ( $this->id ) ? "core_award_other_badge_" . $this->id : NULL ], NULL, NULL, NULL, "{$exploded[1]}_{$exploded[5]}_award_other_badge" );
|
||||
$toggles[ "{$exploded[1]}_{$exploded[5]}" ][] = "{$exploded[1]}_{$exploded[5]}_award_other";
|
||||
$toggles[ "{$exploded[1]}_{$exploded[5]}" ][] = "{$exploded[1]}_{$exploded[5]}_award_other_badge";
|
||||
}
|
||||
}
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Select( 'achievement_rule_action', $this->action, TRUE, [ 'options' => $options, 'toggles' => $toggles, 'sort' => TRUE ] ) );
|
||||
$form->add( new Select( 'achievement_rule_action', $this->action, TRUE, [ 'options' => $options, 'toggles' => $toggles, 'sort' => TRUE ] ) );
|
||||
|
||||
foreach ( $extraElements as $element )
|
||||
{
|
||||
@@ -203,22 +230,22 @@ class _Rule extends \IPS\Node\Model
|
||||
* @param array $values Values from the form
|
||||
* @return array
|
||||
*/
|
||||
public function formatFormValues( $values )
|
||||
public function formatFormValues( array $values ): array
|
||||
{
|
||||
if ( !$this->id )
|
||||
{
|
||||
$this->action = '';
|
||||
$this->filters = NULL;
|
||||
$this->filters = null;
|
||||
$this->points_other = 0;
|
||||
$this->points_subject = 0;
|
||||
$this->save();
|
||||
}
|
||||
|
||||
$exploded = explode( '_', $values['achievement_rule_action'] );
|
||||
$extension = \IPS\Application::load( $exploded[0] )->extensions( 'core', 'AchievementAction' )[ $exploded[1] ];
|
||||
$extension = Application::load( $exploded[0] )->extensions( 'core', 'AchievementAction' )[ $exploded[1] ];
|
||||
|
||||
$filterValues = [];
|
||||
foreach ( \IPS\Request::i()->activeFilters ?: [] as $k => $v )
|
||||
foreach ( Request::i()->activeFilters ?: [] as $k => $v )
|
||||
{
|
||||
$filterValues[ $k ] = $values[ $k ];
|
||||
}
|
||||
@@ -230,39 +257,37 @@ class _Rule extends \IPS\Node\Model
|
||||
{
|
||||
if ( $values[$values['achievement_rule_action'] . '_award_' . $type]['badge'] )
|
||||
{
|
||||
\IPS\Lang::saveCustom( 'core', "core_award_" . $type . "_badge_{$this->id}", $values[$values['achievement_rule_action'] . '_award_' . $type . '_badge'] );
|
||||
Lang::saveCustom( 'core', "core_award_" . $type . "_badge_{$this->id}", $values[$values['achievement_rule_action'] . '_award_' . $type . '_badge'] );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Lang::deleteCustom( 'core', "core_award_" . $type . "_badge_{$this->id}" );
|
||||
Lang::deleteCustom( 'core', "core_award_" . $type . "_badge_{$this->id}" );
|
||||
}
|
||||
|
||||
unset( $values[$values['achievement_rule_action'] . '_award_' . $type . '_badge'] );
|
||||
}
|
||||
}
|
||||
|
||||
$return = [
|
||||
return [
|
||||
'action' => $values['achievement_rule_action'],
|
||||
'filters' => $filters ? json_encode( $filters ) : NULL,
|
||||
'milestone' => ( isset( $filters['milestone'] ) and \is_numeric( $filters['milestone'] ) ) ? $filters['milestone'] : NULL,
|
||||
'points_subject'=> \intval( $values[ $values['achievement_rule_action'] . '_award_subject' ]['points'] ),
|
||||
'badge_subject' => $values[ $values['achievement_rule_action'] . '_award_subject' ]['badge'] ? \intval( $values[ $values['achievement_rule_action'] . '_award_subject' ]['badge'] ): NULL,
|
||||
'points_other' => \intval( isset( $values[ $values['achievement_rule_action'] . '_award_other' ] ) ? $values[ $values['achievement_rule_action'] . '_award_other' ]['points'] : 0 ),
|
||||
'badge_other' => isset( $values[ $values['achievement_rule_action'] . '_award_other' ] ) ? ( $values[ $values['achievement_rule_action'] . '_award_other' ]['badge'] ? \intval( $values[ $values['achievement_rule_action'] . '_award_other' ]['badge'] ) : NULL ) : NULL,
|
||||
'milestone' => ( isset( $filters['milestone'] ) and is_numeric( $filters['milestone'] ) ) ? $filters['milestone'] : NULL,
|
||||
'points_subject'=> intval( $values[ $values['achievement_rule_action'] . '_award_subject' ]['points'] ),
|
||||
'badge_subject' => $values[ $values['achievement_rule_action'] . '_award_subject' ]['badge'] ? intval( $values[ $values['achievement_rule_action'] . '_award_subject' ]['badge'] ): NULL,
|
||||
'points_other' => intval( isset( $values[ $values['achievement_rule_action'] . '_award_other' ] ) ? $values[ $values['achievement_rule_action'] . '_award_other' ]['points'] : 0 ),
|
||||
'badge_other' => isset( $values[ $values['achievement_rule_action'] . '_award_other' ] ) ? ( $values[ $values['achievement_rule_action'] . '_award_other' ]['badge'] ? intval( $values[ $values['achievement_rule_action'] . '_award_other' ]['badge'] ) : NULL ) : NULL,
|
||||
];
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Get buttons to display in tree
|
||||
* Example code explains return value
|
||||
*
|
||||
* @param string $url Base URL
|
||||
* @param bool $subnode Is this a subnode?
|
||||
* @return array
|
||||
* @param Url $url Base URL
|
||||
* @param bool $subnode Is this a subnode?
|
||||
* @return array
|
||||
*/
|
||||
public function getButtons( $url, $subnode=FALSE )
|
||||
public function getButtons( Url $url, bool $subnode=FALSE ): array
|
||||
{
|
||||
$buttons = parent::getButtons( $url, $subnode );
|
||||
|
||||
@@ -270,7 +295,7 @@ class _Rule extends \IPS\Node\Model
|
||||
$buttons['toggleEnabled'] = array(
|
||||
'icon' => ( $this->enabled ) ? 'pause-circle' : 'play-circle',
|
||||
'title' => ( $this->enabled ) ? 'acp_disable_rule' : 'acp_enable_rule',
|
||||
'link' => \IPS\Http\Url::internal( "app=core&module=achievements&controller=rules&do=toggleEnabled&id={$this->_id}&enable=" . ( $this->enabled ? 0 : 1 ) )->csrf(),
|
||||
'link' => Url::internal( "app=core&module=achievements&controller=rules&do=toggleEnabled&id={$this->_id}&enable=" . ( $this->enabled ? 0 : 1 ) )->csrf(),
|
||||
'data' => [ 'data-confirm' => 'true' ]
|
||||
);
|
||||
|
||||
@@ -280,17 +305,17 @@ class _Rule extends \IPS\Node\Model
|
||||
/**
|
||||
* Get badge for subject
|
||||
*
|
||||
* @return \IPS\core\Achievements\Badge|NULL
|
||||
* @return Badge|NULL
|
||||
*/
|
||||
public function badgeSubject(): ?\IPS\core\Achievements\Badge
|
||||
public function badgeSubject(): ?Badge
|
||||
{
|
||||
if ( $this->badge_subject )
|
||||
{
|
||||
try
|
||||
{
|
||||
return \IPS\core\Achievements\Badge::load( $this->badge_subject );
|
||||
return Badge::load( $this->badge_subject );
|
||||
}
|
||||
catch( \OutOfRangeException $e ) { }
|
||||
catch( OutOfRangeException $e ) { }
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@@ -298,17 +323,17 @@ class _Rule extends \IPS\Node\Model
|
||||
/**
|
||||
* Get badge for others
|
||||
*
|
||||
* @return \IPS\core\Achievements\Badge|NULL
|
||||
* @return Badge|NULL
|
||||
*/
|
||||
public function badgeOther(): ?\IPS\core\Achievements\Badge
|
||||
public function badgeOther(): ?Badge
|
||||
{
|
||||
if ( $this->badge_other )
|
||||
{
|
||||
try
|
||||
{
|
||||
return \IPS\core\Achievements\Badge::load( $this->badge_other );
|
||||
return Badge::load( $this->badge_other );
|
||||
}
|
||||
catch( \OutOfRangeException $e ) { }
|
||||
catch( OutOfRangeException $e ) { }
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@@ -316,16 +341,16 @@ class _Rule extends \IPS\Node\Model
|
||||
/**
|
||||
* Delete Record
|
||||
*
|
||||
* @return void
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
public function delete(): void
|
||||
{
|
||||
parent::delete();
|
||||
|
||||
\IPS\Db::i()->delete( 'core_achievements_log_milestones', array( 'milestone_rule=?', $this->id ) );
|
||||
Db::i()->delete( 'core_achievements_log_milestones', array( 'milestone_rule=?', $this->id ) );
|
||||
|
||||
\IPS\Lang::deleteCustom( 'core', "core_award_subject_badge_{$this->id}" );
|
||||
\IPS\Lang::deleteCustom( 'core', "core_award_other_badge_{$this->id}" );
|
||||
Lang::deleteCustom( 'core', "core_award_subject_badge_{$this->id}" );
|
||||
Lang::deleteCustom( 'core', "core_award_other_badge_{$this->id}" );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -345,7 +370,7 @@ class _Rule extends \IPS\Node\Model
|
||||
|
||||
foreach ( array( 'subject' => "core_award_subject_badge_{$this->id}", 'other' => "core_award_other_badge_{$this->id}") as $fieldKey => $langKey ) {
|
||||
$oldLangKey = str_replace( $this->id, $oldId, $langKey );
|
||||
\IPS\Lang::saveCustom( 'core', $langKey, iterator_to_array(\IPS\Db::i()->select( 'word_custom, lang_id', 'core_sys_lang_words', array('word_key=?', $oldLangKey ) )->setKeyField('lang_id')->setValueField('word_custom' ) ) );
|
||||
Lang::saveCustom( 'core', $langKey, iterator_to_array(Db::i()->select( 'word_custom, lang_id', 'core_sys_lang_words', array('word_key=?', $oldLangKey ) )->setKeyField('lang_id')->setValueField('word_custom' ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -358,7 +383,7 @@ class _Rule extends \IPS\Node\Model
|
||||
{
|
||||
$return = [ 'count' => 0, 'processed' => 0 ];
|
||||
$rebuilding = FALSE;
|
||||
foreach( \IPS\Db::i()->select( '*', 'core_queue', [ [ '`key`=?', 'RebuildAchievements' ] ] ) as $rebuild )
|
||||
foreach( Db::i()->select( '*', 'core_queue', [ [ '`key`=?', 'RebuildAchievements' ] ] ) as $rebuild )
|
||||
{
|
||||
$data = json_decode( $rebuild['data'], TRUE );
|
||||
|
||||
@@ -378,33 +403,30 @@ class _Rule extends \IPS\Node\Model
|
||||
/**
|
||||
* Rebuild all cheeeeeevs
|
||||
*
|
||||
* @param \IPS\DateTime|null $time
|
||||
* @param DateTime|null $time
|
||||
*/
|
||||
public static function rebuildAllAchievements( ?\IPS\DateTime $time )
|
||||
public static function rebuildAllAchievements( ?DateTime $time ) : void
|
||||
{
|
||||
\IPS\Db::i()->delete( 'core_achievements_log' );
|
||||
\IPS\Db::i()->delete( 'core_achievements_log_milestones' );
|
||||
\IPS\Db::i()->delete( 'core_points_log' );
|
||||
\IPS\Db::i()->delete( 'core_member_badges', [ 'rule > 0' ] ); /* 0 is a manually awarded badge. Don't hate the coder, hate the player */
|
||||
\IPS\Db::i()->update( 'core_members', [ 'achievements_points' => 0 ] );
|
||||
Db::i()->delete( 'core_achievements_log' );
|
||||
Db::i()->delete( 'core_achievements_log_milestones' );
|
||||
Db::i()->delete( 'core_points_log' );
|
||||
Db::i()->delete( 'core_member_badges', [ 'rule > 0' ] ); /* 0 is a manually awarded badge. Don't hate the coder, hate the player */
|
||||
Db::i()->update( 'core_members', [ 'achievements_points' => 0 ] );
|
||||
|
||||
/* Remove all previous tasks */
|
||||
\IPS\Db::i()->delete( 'core_queue', [ '`key`=?', 'RebuildAchievements' ] );
|
||||
Db::i()->delete( 'core_queue', [ '`key`=?', 'RebuildAchievements' ] );
|
||||
|
||||
foreach( \IPS\Application::applications() as $app )
|
||||
foreach( Application::applications() as $app )
|
||||
{
|
||||
foreach ( \IPS\Application::load( $app->directory )->extensions( 'core', 'AchievementAction' ) as $extension )
|
||||
foreach ( Application::load( $app->directory )->extensions( 'core', 'AchievementAction' ) as $extension )
|
||||
{
|
||||
if ( method_exists( $extension, 'rebuildData' ) )
|
||||
{
|
||||
$bits = explode( '\\', \get_class( $extension ) );
|
||||
$className = array_pop( $bits );
|
||||
\IPS\Task::queue( 'core', 'RebuildAchievements', [
|
||||
'extension' => $app->directory . '_' . $className,
|
||||
'data' => $extension::rebuildData(),
|
||||
'time' => ( $time ) ? $time->getTimestamp() : NULL,
|
||||
], 4 );
|
||||
}
|
||||
$bits = explode( '\\', get_class( $extension ) );
|
||||
$className = array_pop( $bits );
|
||||
Task::queue( 'core', 'RebuildAchievements', [
|
||||
'extension' => $app->directory . '_' . $className,
|
||||
'data' => $extension::rebuildData(),
|
||||
'time' => ( $time ) ? $time->getTimestamp() : NULL,
|
||||
], 4 );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -417,20 +439,20 @@ class _Rule extends \IPS\Node\Model
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function importXml( $file, $deleteExisting=FALSE )
|
||||
public static function importXml( string $file, bool $deleteExisting=FALSE ) : void
|
||||
{
|
||||
/* Open XML file */
|
||||
$xml = \IPS\Xml\XMLReader::safeOpen( $file );
|
||||
|
||||
if ( ! @$xml->read() )
|
||||
{
|
||||
throw new \DomainException( 'xml_upload_invalid' );
|
||||
throw new DomainException( 'xml_upload_invalid' );
|
||||
}
|
||||
|
||||
/* Did we want to wipe first? */
|
||||
if ( $deleteExisting )
|
||||
{
|
||||
foreach( \IPS\core\Achievements\Rule::getStore() as $action => $rules )
|
||||
foreach(Rule::getStore() as $action => $rules )
|
||||
{
|
||||
foreach( $rules as $ruleId => $rule )
|
||||
{
|
||||
@@ -438,7 +460,7 @@ class _Rule extends \IPS\Node\Model
|
||||
{
|
||||
static::load( $ruleId )->delete();
|
||||
}
|
||||
catch( \OutOfRangeException $e ){}
|
||||
catch( OutOfRangeException $e ){}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -450,7 +472,7 @@ class _Rule extends \IPS\Node\Model
|
||||
/* Rules: Start looping through each row */
|
||||
while ( $xml->read() )
|
||||
{
|
||||
if( $xml->nodeType != \XMLReader::ELEMENT )
|
||||
if( $xml->nodeType != XMLReader::ELEMENT )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -474,7 +496,7 @@ class _Rule extends \IPS\Node\Model
|
||||
|
||||
while ( $xml->read() and $xml->name != 'rule' )
|
||||
{
|
||||
if ( $xml->nodeType != \XMLReader::ELEMENT )
|
||||
if ( $xml->nodeType != XMLReader::ELEMENT )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -510,23 +532,23 @@ class _Rule extends \IPS\Node\Model
|
||||
}
|
||||
}
|
||||
|
||||
$insertId = \IPS\Db::i()->insert( 'core_achievements_rules', $insert );
|
||||
$insertId = Db::i()->insert( 'core_achievements_rules', $insert );
|
||||
$allBadges[ $insertId ] = $badgesToUpdate;
|
||||
|
||||
if ( ! empty( $awardSubject ) )
|
||||
{
|
||||
\IPS\Lang::saveCustom( 'core', "core_award_subject_badge_{$insertId}", $awardSubject );
|
||||
Lang::saveCustom( 'core', "core_award_subject_badge_{$insertId}", $awardSubject );
|
||||
}
|
||||
|
||||
if ( ! empty( $awardOther ) )
|
||||
{
|
||||
\IPS\Lang::saveCustom( 'core', "core_award_other_badge_{$insertId}", $awardOther );
|
||||
Lang::saveCustom( 'core', "core_award_other_badge_{$insertId}", $awardOther );
|
||||
}
|
||||
}
|
||||
/* Badges: Start looping through each row */
|
||||
else if ( $xml->name == 'badge' )
|
||||
{
|
||||
if( $xml->nodeType != \XMLReader::ELEMENT )
|
||||
if( $xml->nodeType != XMLReader::ELEMENT )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -537,7 +559,7 @@ class _Rule extends \IPS\Node\Model
|
||||
|
||||
while ( $xml->read() and $xml->name != 'badge' )
|
||||
{
|
||||
if( $xml->nodeType != \XMLReader::ELEMENT )
|
||||
if( $xml->nodeType != XMLReader::ELEMENT )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -564,22 +586,22 @@ class _Rule extends \IPS\Node\Model
|
||||
|
||||
if ( ! empty( $insert['icon_name'] ) and ! empty( $insert['icon_data'] ) )
|
||||
{
|
||||
$insert['image'] = (string) \IPS\File::create( 'core_Badges', $insert['icon_name'], $insert['icon_data'], NULL, TRUE, NULL, FALSE );
|
||||
$insert['image'] = (string) File::create( 'core_Badges', $insert['icon_name'], $insert['icon_data'], NULL, TRUE, NULL, FALSE );
|
||||
unset( $insert['icon_name'] );
|
||||
unset( $insert['icon_data'] );
|
||||
}
|
||||
|
||||
$insertId = \IPS\Db::i()->insert( 'core_badges', $insert );
|
||||
$insertId = Db::i()->insert( 'core_badges', $insert );
|
||||
$badgeMap[ $id ] = $insertId;
|
||||
|
||||
if ( ! empty( $title ) )
|
||||
{
|
||||
\IPS\Lang::saveCustom( 'core', "core_badges_{$insertId}", $title );
|
||||
Lang::saveCustom( 'core', "core_badges_{$insertId}", $title );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( \count( $allBadges ) )
|
||||
if ( count( $allBadges ) )
|
||||
{
|
||||
foreach( $allBadges as $ruleId => $data )
|
||||
{
|
||||
@@ -592,14 +614,14 @@ class _Rule extends \IPS\Node\Model
|
||||
}
|
||||
}
|
||||
|
||||
if ( \count( $update ) )
|
||||
if ( count( $update ) )
|
||||
{
|
||||
\IPS\Db::i()->update( 'core_achievements_rules', $update, ['`id`=?', $ruleId ] );
|
||||
Db::i()->update( 'core_achievements_rules', $update, ['`id`=?', $ruleId ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unset( \IPS\Data\Store::i()->achievementRules );
|
||||
unset( Store::i()->achievementRules );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -610,8 +632,14 @@ class _Rule extends \IPS\Node\Model
|
||||
*/
|
||||
public static function canImport( string $value ) : bool
|
||||
{
|
||||
/* If we are in the middle of an installation, we can always import */
|
||||
if( Dispatcher::hasInstance() and Dispatcher::i()->controllerLocation == 'setup' )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
$appKey = explode( '_', $value );
|
||||
return \IPS\Application::appIsEnabled( $appKey[0] );
|
||||
return Application::appIsEnabled( $appKey[0] );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -622,7 +650,7 @@ class _Rule extends \IPS\Node\Model
|
||||
*/
|
||||
public static function ruleHasMilestone( ?array $filters ): bool
|
||||
{
|
||||
if ( \is_array( $filters ) and \count( $filters ) )
|
||||
if ( is_array( $filters ) and count( $filters ) )
|
||||
{
|
||||
foreach( $filters as $key => $value )
|
||||
{
|
||||
@@ -641,9 +669,9 @@ class _Rule extends \IPS\Node\Model
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function titleForLog()
|
||||
public function titleForLog(): ?string
|
||||
{
|
||||
$exploded = explode( '_', $this->action );
|
||||
return \IPS\Lang::load( \IPS\Lang::defaultLanguage() )->get( 'AchievementAction__' . $exploded[1] . '_title' ) . " #" . $this->id;
|
||||
return Lang::load( Lang::defaultLanguage() )->get( 'AchievementAction__' . $exploded[1] . '_title' ) . " #" . $this->id;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user