Skip to content

Commit

Permalink
MDL-59057 analytics: Standarize indicators and targets ids
Browse files Browse the repository at this point in the history
Part of MDL-57791 epic.
  • Loading branch information
David Monllao committed Jul 24, 2017
1 parent e499074 commit b0c2492
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
3 changes: 1 addition & 2 deletions admin/tool/models/db/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,5 @@ function xmldb_tool_models_install() {
$target = \core_analytics\manager::get_target('\tool_models\analytics\target\no_teaching_activity');
$weekbeforestart = '\core_analytics\local\time_splitting\week_before_course_start';
$noteacher = \core_analytics\manager::get_indicator('\core_course\analytics\indicator\no_teacher');
$key = '\\' . get_class($noteacher);
\core_analytics\model::create($target, array($key => $noteacher), $weekbeforestart);
\core_analytics\model::create($target, array($noteacher->get_id() => $noteacher), $weekbeforestart);
}
2 changes: 1 addition & 1 deletion admin/tool/models/db/uninstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function xmldb_tool_models_uninstall() {
$options = array();
foreach ($targets as $classname => $unused) {
$target = \core_analytics\manager::get_target($classname);
$options[] = '\\' . get_class($target);
$options[] = $target->get_id();
}
list($sql, $params) = $DB->get_in_or_equal($options);
$models = $DB->get_records_select('analytics_models', "target $sql", $params);
Expand Down
9 changes: 9 additions & 0 deletions analytics/classes/calculable.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ public static function get_name() {
return get_called_class();
}

/**
* The class id is the calculable class full qualified class name.
*
* @return string
*/
public function get_id() {
return '\\' . get_class($this);
}

/**
* add_sample_data
*
Expand Down
2 changes: 1 addition & 1 deletion analytics/classes/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public static function get_all_indicators() {
$instance = self::get_indicator($fullclassname);
if ($instance) {
// Using get_class as get_component_classes_in_namespace returns double escaped fully qualified class names.
self::$allindicators['\\' . get_class($instance)] = $instance;
self::$allindicators[$instance->get_id()] = $instance;
}
}

Expand Down
4 changes: 2 additions & 2 deletions analytics/classes/model.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public static function create(\core_analytics\local\target\base $target, array $
$now = time();

$modelobj = new \stdClass();
$modelobj->target = '\\' . get_class($target);
$modelobj->target = $target->get_id();
$modelobj->indicators = json_encode($indicatorclasses);
$modelobj->version = $now;
$modelobj->timecreated = $now;
Expand Down Expand Up @@ -1057,7 +1057,7 @@ private static function indicator_classes($indicators) {
}
throw new \moodle_exception('errorinvalidindicator', 'analytics', '', $indicator);
}
$indicatorclasses[] = '\\' . get_class($indicator);
$indicatorclasses[] = $indicator->get_id();
}

return $indicatorclasses;
Expand Down

0 comments on commit b0c2492

Please sign in to comment.