-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1312 from proditis/master
Limit the amount of queries performed for a single target/view of non guests
- Loading branch information
Showing
16 changed files
with
184 additions
and
69 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace app\components; | ||
|
||
|
||
use Yii; | ||
use yii\base\Component; | ||
use yii\base\InvalidConfigException; | ||
|
||
class ProfileVisibility extends Component | ||
{ | ||
|
||
public static function visible(int $player_id, $visibility): bool | ||
{ | ||
if ($visibility === 'public') return true; | ||
if (self::visibilityAllowed($player_id)) return true; | ||
if (self::visibilityDenied($visibility)) return false; | ||
return true; | ||
} | ||
|
||
public static function visibilityAllowed(int $player_id): bool | ||
{ | ||
if (!\Yii::$app->user->isGuest) { | ||
if (intval(\Yii::$app->user->id) === intval($player_id)) return true; | ||
if (\Yii::$app->user->identity->isAdmin) return true; | ||
} | ||
return false; | ||
} | ||
|
||
public static function visibilityDenied($visibility): bool | ||
{ | ||
if (\Yii::$app->sys->player_profile === false) return true; | ||
|
||
if ($visibility === 'private') return true; | ||
|
||
return false; | ||
} | ||
} |
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
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
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
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
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
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
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
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
28 changes: 7 additions & 21 deletions
28
frontend/themes/material/modules/target/views/default/_headshots_card.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 |
---|---|---|
@@ -1,27 +1,13 @@ | ||
<?php | ||
use yii\helpers\Html; | ||
use app\widgets\target\HeadshotsWidget; | ||
?> | ||
<div class="card bg-dark headshots"> | ||
<div class="card-header"> | ||
<h4><i class="fas fa-skull"></i> <?=\Yii::t('app','{headshots,plural,=0{No headshots yet} =1{# Headshot} other{# Headshots (newer first)}}',['headshots'=>count($target->headshots)])?> | ||
<h4><i class="fas fa-skull"></i> <?= \Yii::t('app', '{headshots,plural,=0{No headshots yet} =1{# Headshot} other{# Headshots (newer first)}}', ['headshots' => count($target->headshots)]) ?> | ||
</h4> | ||
</div> | ||
<div class="card-body table-responsive"> | ||
<?php | ||
$headshots=[]; | ||
foreach($target->lastHeadshots as $hs) | ||
{ | ||
if((int) $hs->player->active === 1) | ||
$headshots[]=$hs->player->profile->link; | ||
} | ||
if(!empty($headshots)) | ||
{ | ||
echo "<code>",implode(", ", array_slice($headshots, 0,19)),"</code>"; | ||
if(count($headshots)>19){ | ||
echo "<details class=\"headshotters\">"; | ||
echo "<summary data-open=\"Hide more\" data-close=\"Show more\"></summary>"; | ||
echo "<code>",implode(", ", array_slice($headshots, 19)),"</code>"; | ||
echo "</details>"; | ||
} | ||
} | ||
else | ||
echo '<code>'.\Yii::t('app','no one yet...').'</code>';?> | ||
<?php echo HeadshotsWidget::widget(['target_id'=>$target->id]);?> | ||
</div> | ||
</div> | ||
</div> |
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
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
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
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
Oops, something went wrong.