MDL-59057 analytics: Standarize indicators and targets ids

Part of MDL-57791 epic.
This commit is contained in:
David Monllao 2017-06-09 13:29:56 +02:00
parent e499074f39
commit b0c2492906
5 changed files with 14 additions and 6 deletions

View file

@ -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);
}

View file

@ -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);

View file

@ -53,6 +53,15 @@ abstract class calculable {
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
*

View file

@ -206,7 +206,7 @@ class manager {
$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;
}
}

View file

@ -268,7 +268,7 @@ class model {
$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;
@ -1057,7 +1057,7 @@ class model {
}
throw new \moodle_exception('errorinvalidindicator', 'analytics', '', $indicator);
}
$indicatorclasses[] = '\\' . get_class($indicator);
$indicatorclasses[] = $indicator->get_id();
}
return $indicatorclasses;