Skip to content

Commit

Permalink
improved virtual events
Browse files Browse the repository at this point in the history
  • Loading branch information
sfraysse committed Oct 12, 2020
1 parent fc015df commit f14b655
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 8 deletions.
5 changes: 5 additions & 0 deletions classes/src/services/statements.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ public function get_from_event(\stdClass $event) {
// No error, but refused to process the event. Log as unsupported.
$this->logs->log_unsupported($event);
return;

} elseif ($statement == -1) {

// This event should not be logged.
return;
}

// We got it, but we want to be sure to have a log for this event,
Expand Down
37 changes: 34 additions & 3 deletions classes/src/statements/logstore_trax/cohort_defined.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,42 @@ class cohort_defined extends base_statement {
* @return array
*/
protected function statement() {
global $DB;

// Build the xAPI cohort.
$cohort = $this->actors->get_cohort($this->eventother->id, true);

// Check if it has changed.
$last = $DB->get_record('logstore_trax_status', [
'event' => 'cohort_defined',
'objecttable' => 'cohort',
'objectid' => $this->eventother->id
]);
$encoded = json_encode($cohort);
if ($last && $last->data == $encoded) {
// Return -1 which is a specific code to say "don't log this!"
return -1;
}

// Record the current value.
if ($last) {
$last->data = $encoded;
$DB->update_record('logstore_trax_status', $last);
} else {
$last = (object)[
'event' => 'cohort_defined',
'objecttable' => 'cohort',
'objectid' => $this->eventother->id,
'data' => $encoded
];
$DB->insert_record('logstore_trax_status', $last);
}

// Return the statement.
return array_replace($this->base('system'), [
'actor' => $this->actors->get_system(),
'actor' => $this->actors->get_system(),
'verb' => $this->verbs->get('defined'),
'object' => $this->actors->get_cohort($this->eventother->id, true),
'object' => $cohort,
]);
}

}
33 changes: 30 additions & 3 deletions classes/src/statements/logstore_trax/course_defined.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,41 @@ class course_defined extends base_statement {
* @return array
*/
protected function statement() {
global $DB;

// Build the xAPI course.
$course = $this->activities->get('course', $this->eventother->id);
$this->add_course_structure($course, $this->eventother);

// Check if it has changed.
$last = $DB->get_record('logstore_trax_status', [
'event' => 'course_defined',
'objecttable' => 'course',
'objectid' => $this->eventother->id
]);
$encoded = json_encode($course);
if ($last && $last->data == $encoded) {
// Return -1 which is a specific code to say "don't log this!"
return -1;
}

// Add the course structure.
$this->add_course_structure($course, $this->eventother);
// Record the current value.
if ($last) {
$last->data = $encoded;
$DB->update_record('logstore_trax_status', $last);
} else {
$last = (object)[
'event' => 'course_defined',
'objecttable' => 'course',
'objectid' => $this->eventother->id,
'data' => $encoded
];
$DB->insert_record('logstore_trax_status', $last);
}

// Build statement only when the course structure is not empty.
return array_replace($this->base('course'), [
'actor' => $this->actors->get_system(),
'actor' => $this->actors->get_system(),
'verb' => $this->verbs->get('defined'),
'object' => $course,
]);
Expand Down
13 changes: 13 additions & 0 deletions db/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@
</INDEXES>
</TABLE>

<TABLE NAME="logstore_trax_status" COMMENT="Logs status">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" UNSIGNED="true" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="event" TYPE="char" LENGTH="50" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="objecttable" TYPE="char" LENGTH="50" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="objectid" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="data" TYPE="text" LENGTH="big" NOTNULL="true" SEQUENCE="false"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
</KEYS>
</TABLE>

</TABLES>

</XMLDB>
23 changes: 23 additions & 0 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,5 +223,28 @@ function xmldb_logstore_trax_upgrade($oldversion) {
upgrade_plugin_savepoint(true, 2018050812, 'logstore', 'trax');
}

// Add status table.
if ($oldversion < 2018050818) {

// Define the table.
$table = new xmldb_table('logstore_trax_status');

// Add fields.
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE);
$table->add_field('event', XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL);
$table->add_field('objecttable', XMLDB_TYPE_CHAR, '50');
$table->add_field('objectid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED);
$table->add_field('data', XMLDB_TYPE_TEXT, 'big', null, XMLDB_NOTNULL);

// Adding keys to table.
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));

// Create the table.
$dbman->create_table($table);

// Savepoint.
upgrade_plugin_savepoint(true, 2018050818, 'logstore', 'trax');
}

return true;
}
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2018050817;
$plugin->version = 2018050818;
$plugin->requires = 2018050800;
$plugin->component = 'logstore_trax';

$plugin->release = 'v0.16';
$plugin->release = 'v0.18';
$plugin->maturity = MATURITY_ALPHA;

0 comments on commit f14b655

Please sign in to comment.