-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GH-230 Move noob protection infobox & effects into own component
- Loading branch information
Showing
10 changed files
with
209 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...iew/screens/Overview/components/NoobProtectionInfoBox/NoobProtectionInfoBox.component.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
namespace UniEngine\Engine\Modules\Overview\Screens\Overview\Components\NoobProtectionInfoBox; | ||
|
||
use UniEngine\Engine\Modules\Overview\Screens\Overview\Components\NoobProtectionInfoBox; | ||
|
||
/** | ||
* @param array $params | ||
* @param arrayRef $params['input'] | ||
* @param arrayRef $params['user'] | ||
* @param number $params['currentTimestamp'] | ||
*/ | ||
function render($props) { | ||
global $_Lang; | ||
|
||
$input = &$props['input']; | ||
$user = &$props['user']; | ||
$currentTimestamp = $props['currentTimestamp']; | ||
|
||
$isProtectedByNoobProtection = NoobProtectionInfoBox\Utils\isProtectedByNoobProtection([ | ||
'user' => &$user, | ||
'currentTimestamp' => $currentTimestamp, | ||
]); | ||
|
||
if (!$isProtectedByNoobProtection) { | ||
return [ | ||
'componentHTML' => '', | ||
'globalJS' => '', | ||
]; | ||
} | ||
|
||
$effectsResult = NoobProtectionInfoBox\runEffects([ | ||
'input' => &$input, | ||
'user' => &$user, | ||
'currentTimestamp' => $currentTimestamp, | ||
]); | ||
|
||
$localTemplateLoader = createLocalTemplateLoader(__DIR__); | ||
|
||
if ( | ||
$effectsResult['isSuccess'] && | ||
$effectsResult['payload']['protectionTurnedOff'] | ||
) { | ||
$componentHTML = parsetemplate( | ||
$localTemplateLoader('turnOffMessage'), | ||
$_Lang | ||
); | ||
|
||
return [ | ||
'componentHTML' => $componentHTML, | ||
'globalJS' => '', | ||
]; | ||
} | ||
|
||
$protectionTimeLeft = $user['NoobProtection_EndTime'] - $currentTimestamp; | ||
|
||
$componentHTML = parsetemplate( | ||
$localTemplateLoader('body'), | ||
[ | ||
'data_ProtectionCounterMessage' => sprintf( | ||
$_Lang['NewUserProtection_Text'], | ||
pretty_time($protectionTimeLeft, true, 'dhms') | ||
) | ||
] | ||
); | ||
|
||
$protectionCountdownJS = InsertJavaScriptChronoApplet('newprotect', '', $protectionTimeLeft); | ||
|
||
return [ | ||
'componentHTML' => $componentHTML, | ||
'globalJS' => $protectionCountdownJS, | ||
]; | ||
} | ||
|
||
?> |
50 changes: 50 additions & 0 deletions
50
...verview/screens/Overview/components/NoobProtectionInfoBox/NoobProtectionInfoBox.utils.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace UniEngine\Engine\Modules\Overview\Screens\Overview\Components\NoobProtectionInfoBox; | ||
|
||
use UniEngine\Engine\Modules\Overview\Screens\Overview\Components\NoobProtectionInfoBox; | ||
|
||
/** | ||
* @param array $params | ||
* @param arrayRef $params['input'] | ||
* @param arrayRef $params['user'] | ||
* @param number $params['currentTimestamp'] | ||
*/ | ||
function runEffects($props) { | ||
$input = &$props['input']; | ||
$user = &$props['user']; | ||
$currentTimestamp = $props['currentTimestamp']; | ||
|
||
$isProtectedByNoobProtection = NoobProtectionInfoBox\Utils\isProtectedByNoobProtection([ | ||
'user' => &$user, | ||
'currentTimestamp' => $currentTimestamp, | ||
]); | ||
|
||
if (!$isProtectedByNoobProtection) { | ||
return [ | ||
'isSuccess' => null, | ||
]; | ||
} | ||
if ( | ||
!isset($input['cancelprotection']) || | ||
$input['cancelprotection'] != '1' | ||
) { | ||
return [ | ||
'isSuccess' => null, | ||
]; | ||
} | ||
|
||
NoobProtectionInfoBox\Utils\Effects\turnOffProtection([ | ||
'user' => &$user, | ||
'currentTimestamp' => $currentTimestamp, | ||
]); | ||
|
||
return [ | ||
'isSuccess' => true, | ||
'payload' => [ | ||
'protectionTurnedOff' => true, | ||
], | ||
]; | ||
} | ||
|
||
?> |
8 changes: 8 additions & 0 deletions
8
modules/overview/screens/Overview/components/NoobProtectionInfoBox/body.tpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<tr> | ||
<th class="c pad5 lime" colspan="3"> | ||
{data_ProtectionCounterMessage} | ||
</th> | ||
</tr> | ||
<tr> | ||
<th style="visibility: hidden;"> </th> | ||
</tr> |
5 changes: 5 additions & 0 deletions
5
modules/overview/screens/Overview/components/NoobProtectionInfoBox/index.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
header("Location: ../index.php"); | ||
|
||
?> |
8 changes: 8 additions & 0 deletions
8
modules/overview/screens/Overview/components/NoobProtectionInfoBox/turnOffMessage.tpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<tr> | ||
<th class="c pad5 lime" colspan="3"> | ||
{NewUserProtection_Canceled} | ||
</th> | ||
</tr> | ||
<tr> | ||
<th style="visibility: hidden;"> </th> | ||
</tr> |
31 changes: 31 additions & 0 deletions
31
...eens/Overview/components/NoobProtectionInfoBox/utils/effects/turnOffProtection.effect.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace UniEngine\Engine\Modules\Overview\Screens\Overview\Components\NoobProtectionInfoBox\Utils\Effects; | ||
|
||
/** | ||
* @param array $params | ||
* @param arrayRef $params['user'] | ||
* @param number $params['currentTimestamp'] | ||
*/ | ||
function turnOffProtection($props) { | ||
$user = &$props['user']; | ||
$currentTimestamp = $props['currentTimestamp']; | ||
|
||
$protectionPropKey = 'NoobProtection_EndTime'; | ||
|
||
$user[$protectionPropKey] = $currentTimestamp; | ||
|
||
$updateQuery = ( | ||
"UPDATE {{table}} " . | ||
"SET " . | ||
"`{$protectionPropKey}` = {$currentTimestamp} " . | ||
"WHERE " . | ||
"`id` = {$user['id']} " . | ||
"LIMIT 1 " . | ||
";" | ||
); | ||
|
||
doquery($updateQuery, 'users'); | ||
} | ||
|
||
?> |
14 changes: 14 additions & 0 deletions
14
modules/overview/screens/Overview/components/NoobProtectionInfoBox/utils/helpers.utils.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace UniEngine\Engine\Modules\Overview\Screens\Overview\Components\NoobProtectionInfoBox\Utils; | ||
|
||
/** | ||
* @param array $params | ||
* @param arrayRef $params['user'] | ||
* @param number $params['currentTimestamp'] | ||
*/ | ||
function isProtectedByNoobProtection($props) { | ||
return ($props['user']['NoobProtection_EndTime'] > $props['currentTimestamp']); | ||
} | ||
|
||
?> |
5 changes: 5 additions & 0 deletions
5
modules/overview/screens/Overview/components/NoobProtectionInfoBox/utils/index.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
header("Location: ../index.php"); | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters