Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

Commit

Permalink
Auto Announcements and Activity Log Expansion (#513)
Browse files Browse the repository at this point in the history
* Dynamically generate activity log and store in the database. Activity log table stores the object type and identifier, so the log is up to date even if some portion of the object has changed (i.e., name).

* Optionally, allow for game related activites to be automatically announced through the announcements area.

* Added table "activity_log" to database.

* Added column "auto_announce" into database configuration table.

* Added auto announcement toggle in admin panel.

* Added auto announcement and activity logging for:
  * Game Start, Pause, Resume, and End
  * Levels being Added, Updated, Enabled, Disabled

* Added activity logging for levels being captured.

* Added ActivityLog class:
  * genCaptureLog() - Stores level capture event in activity log
  * genCreateGameActionLog() - Stores a change to the game state
  * genAdminLog() - Stores administrative action
  * genCreateGenericLog() - Stores generic messages
  * genCreate() - Manually create activity log entry

* Invalidated memcached for relevant level actions.

* Cleanly exit the ActivityLog class if a user session doesn't exist.

* Fixed a variable name mismatch in the Level class.

* The Auto Announcement feature, now call from numerous administrative methods, requires the "game" and "auto_announce" configuration values.  Both configuration values have been added to the seed data.

* The configuration test asserts have been updated to match the new record counts.

* The testSetStatus() test case to use the second (undeleted) level.
  • Loading branch information
justinwray authored and gsingh93 committed Jun 6, 2017
1 parent b9f031e commit 323ba05
Show file tree
Hide file tree
Showing 14 changed files with 596 additions and 60 deletions.
20 changes: 20 additions & 0 deletions database/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ INSERT INTO `configuration` (field, value, description) VALUES("pause_ts", "0",
INSERT INTO `configuration` (field, value, description) VALUES("timer", "0", "(Boolean) Timer is enabled");
INSERT INTO `configuration` (field, value, description) VALUES("scoring", "0", "(Boolean) Ability score levels");
INSERT INTO `configuration` (field, value, description) VALUES("gameboard", "1", "(Boolean) Refresh all data in the gameboard");
INSERT INTO `configuration` (field, value, description) VALUES("auto_announce", "0", "(Boolean) Auto game announcements");
INSERT INTO `configuration` (field, value, description) VALUES("progressive_cycle", "300", "(Integer) Frequency to take progressive scoreboard in seconds");
INSERT INTO `configuration` (field, value, description) VALUES("bases_cycle", "5", "(Integer) Frequency to score base levels in seconds");
INSERT INTO `configuration` (field, value, description) VALUES("autorun_cycle", "30", "(Integer) Frequency to cycle autorun in seconds");
Expand Down Expand Up @@ -417,3 +418,22 @@ CREATE TABLE `announcements_log` (
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `activity_log`
--

DROP TABLE IF EXISTS `activity_log`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `activity_log` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`subject` text NOT NULL,
`action` text NOT NULL,
`entity` text NOT NULL,
`message` text NOT NULL,
`arguments` text NOT NULL,
`ts` timestamp NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;
20 changes: 20 additions & 0 deletions database/test_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ INSERT INTO `configuration` (field, value, description) VALUES("pause_ts", "0",
INSERT INTO `configuration` (field, value, description) VALUES("timer", "0", "(Boolean) Timer is enabled");
INSERT INTO `configuration` (field, value, description) VALUES("scoring", "0", "(Boolean) Ability score levels");
INSERT INTO `configuration` (field, value, description) VALUES("gameboard", "1", "(Boolean) Refresh all data in the gameboard");
INSERT INTO `configuration` (field, value, description) VALUES("auto_announce", "0", "(Boolean) Auto game announcements");
INSERT INTO `configuration` (field, value, description) VALUES("progressive_cycle", "300", "(Integer) Frequency to take progressive scoreboard in seconds");
INSERT INTO `configuration` (field, value, description) VALUES("bases_cycle", "5", "(Integer) Frequency to score base levels in seconds");
INSERT INTO `configuration` (field, value, description) VALUES("autorun_cycle", "30", "(Integer) Frequency to cycle autorun in seconds");
Expand Down Expand Up @@ -414,3 +415,22 @@ CREATE TABLE `announcements_log` (
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `activity_log`
--

DROP TABLE IF EXISTS `activity_log`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `activity_log` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`subject` text NOT NULL,
`action` text NOT NULL,
`entity` text NOT NULL,
`message` text NOT NULL,
`arguments` text NOT NULL,
`ts` timestamp NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;
27 changes: 27 additions & 0 deletions src/controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ class="fb-cta cta--yellow"
'ldap_domain_suffix' => Configuration::gen('ldap_domain_suffix'),
'scoring' => Configuration::gen('scoring'),
'gameboard' => Configuration::gen('gameboard'),
'auto_announce' => Configuration::gen('auto_announce'),
'timer' => Configuration::gen('timer'),
'progressive_cycle' => Configuration::gen('progressive_cycle'),
'default_bonus' => Configuration::gen('default_bonus'),
Expand Down Expand Up @@ -334,6 +335,7 @@ class="fb-cta cta--yellow"
$ldap_domain_suffix = $results['ldap_domain_suffix'];
$scoring = $results['scoring'];
$gameboard = $results['gameboard'];
$auto_announce = $results['auto_announce'];
$timer = $results['timer'];
$progressive_cycle = $results['progressive_cycle'];
$default_bonus = $results['default_bonus'];
Expand Down Expand Up @@ -364,6 +366,8 @@ class="fb-cta cta--yellow"
$scoring_off = $scoring->getValue() === '0';
$gameboard_on = $gameboard->getValue() === '1';
$gameboard_off = $gameboard->getValue() === '0';
$auto_announce_on = $auto_announce->getValue() === '1';
$auto_announce_off = $auto_announce->getValue() === '0';
$timer_on = $timer->getValue() === '1';
$timer_off = $timer->getValue() === '0';
$livesync_on = $livesync->getValue() === '1';
Expand Down Expand Up @@ -799,6 +803,29 @@ class="icon--badge"
name="fb--conf--autorun_cycle"
/>
</div>
<div class="form-el el--block-label">
<label>{tr('Auto Announcements')}</label>
<div class="admin-section-toggle radio-inline">
<input
type="radio"
name="fb--conf--auto_announce"
id="fb--conf--auto_announce--on"
checked={$auto_announce_on}
/>
<label for="fb--conf--auto_announce--on">
{tr('On')}
</label>
<input
type="radio"
name="fb--conf--auto_announce"
id="fb--conf--auto_announce--off"
checked={$auto_announce_off}
/>
<label for="fb--conf--auto_announce--off">
{tr('Off')}
</label>
</div>
</div>
<div class="form-el el--block-label"></div>
</div>
</div>
Expand Down
61 changes: 45 additions & 16 deletions src/inc/gameboard/modules/activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,55 @@ class ActivityModuleController {
await tr_start();
$activity_ul = <ul class="activity-stream"></ul>;

$all_activity = await Control::genAllActivity();
$all_activity = await ActivityLog::genAllActivity();
$config = await Configuration::gen('language');
$language = $config->getValue();
foreach ($all_activity as $score) {
if (intval($score['team_id']) === SessionUtils::sessionTeam()) {
$class_li = 'your-team';
$class_span = 'your-name';
foreach ($all_activity as $activity) {
$subject = $activity->getSubject();
$entity = $activity->getEntity();
$ts = $activity->getTs();
if (($subject !== '') && ($entity !== '')) {
$class_li = '';
$class_span = '';
list($subject_type, $subject_id) =
explode(':', $activity->getSubject());
list($entity_type, $entity_id) = explode(':', $activity->getEntity());
if ($subject_type === 'Team') {
if (intval($subject_id) === SessionUtils::sessionTeam()) {
$class_li = 'your-team';
$class_span = 'your-name';
} else {
$class_li = 'opponent-team';
$class_span = 'opponent-name';
}
}
if ($entity_type === 'Country') {
$formatted_entity = locale_get_display_region(
'-'.$activity->getFormattedEntity(),
$language,
);
} else {
$formatted_entity = $activity->getFormattedEntity();
}
$activity_ul->appendChild(
<li class={$class_li}>
[ {time_ago($ts)} ]
<span class={$class_span}>
{$activity->getFormattedSubject()}
</span>&nbsp;{tr($activity->getAction())}&nbsp;
{$formatted_entity}
</li>
);
} else {
$class_li = 'opponent-team';
$class_span = 'opponent-name';
$activity_ul->appendChild(
<li class={'opponent-team'}>
[ {time_ago($ts)} ]
<span class={'opponent-name'}>
{$activity->getFormattedMessage()}
</span>
</li>
);
}
$translated_country =
locale_get_display_region('-'.$score['country'], $language);
$activity_ul->appendChild(
<li class={$class_li}>
[ {time_ago($score['time'])} ]
<span class={$class_span}>{$score['team']}</span>&nbsp;
{tr('captured')}&nbsp;{$translated_country}
</li>
);
}

return
Expand Down
Loading

0 comments on commit 323ba05

Please sign in to comment.