-
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 new surveys counter to a component
- Loading branch information
Showing
5 changed files
with
90 additions
and
16 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
74 changes: 74 additions & 0 deletions
74
modules/overview/screens/Overview/components/NewSurveysInfo/NewSurveysInfo.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,74 @@ | ||
<?php | ||
|
||
namespace UniEngine\Engine\Modules\Overview\Screens\Overview\Components\NewSurveysInfo; | ||
|
||
/** | ||
* @param array $props | ||
* @param number $props['userId'] | ||
*/ | ||
function render($props) { | ||
global $_Lang; | ||
|
||
$userId = $props['userId']; | ||
|
||
$getSurveysDataQuery = ( | ||
"SELECT " . | ||
"`surveys`.`id`, `votes`.`id` AS `vote_id` " . | ||
"FROM {{table}} AS `surveys` " . | ||
"LEFT JOIN {{prefix}}poll_votes AS `votes` " . | ||
"ON " . | ||
"`votes`.`poll_id` = `surveys`.`id` AND " . | ||
"`votes`.`user_id` = {$userId} " . | ||
"WHERE " . | ||
"`surveys`.`open` = 1 " . | ||
"ORDER BY `surveys`.`time` DESC " . | ||
";" | ||
); | ||
$surveysData = doquery($getSurveysDataQuery, 'polls'); | ||
|
||
$surveysWithoutVotes = mapQueryResults($surveysData, function ($surveyEntry) { | ||
$hasUserVoted = ($surveyEntry['vote_id'] > 0); | ||
|
||
return ( | ||
$hasUserVoted ? | ||
0 : | ||
1 | ||
); | ||
}); | ||
$surveysWithoutVotesCount = array_sum($surveysWithoutVotes); | ||
|
||
if ($surveysWithoutVotesCount == 0) { | ||
return [ | ||
'componentHTML' => '', | ||
]; | ||
} | ||
|
||
$localTemplateLoader = createLocalTemplateLoader(__DIR__); | ||
|
||
/** | ||
* TODO: Use a better translation system to support more languages. | ||
*/ | ||
$content = vsprintf( | ||
$_Lang['PollBox_You_can_vote_in_new_polls'], | ||
( | ||
$surveysWithoutVotesCount > 1 ? | ||
$_Lang['PollBox_More'] : | ||
$_Lang['PollBox_One'] | ||
) | ||
); | ||
|
||
$tplBodyParams = [ | ||
'content' => $content, | ||
]; | ||
|
||
$componentHTML = parsetemplate( | ||
$localTemplateLoader('body'), | ||
$tplBodyParams | ||
); | ||
|
||
return [ | ||
'componentHTML' => $componentHTML, | ||
]; | ||
} | ||
|
||
?> |
7 changes: 7 additions & 0 deletions
7
modules/overview/screens/Overview/components/NewSurveysInfo/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,7 @@ | ||
<tr> | ||
<th colspan="3"> | ||
<a style="color: orange;" href="polls.php"> | ||
{content} | ||
</a> | ||
</th> | ||
</tr> |
5 changes: 5 additions & 0 deletions
5
modules/overview/screens/Overview/components/NewSurveysInfo/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