Skip to content

Commit

Permalink
MDL-57791 analytics: Always absolute full class names
Browse files Browse the repository at this point in the history
Some extra tiny changes as well.
  • Loading branch information
David Monllao committed Jul 24, 2017
1 parent 1cc2b4b commit 3a39628
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 12 deletions.
2 changes: 1 addition & 1 deletion admin/settings/analytics.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@

$timesplittingoptions = array();
$timesplittingdefaults = array('\\core_analytics\\local\\time_splitting\\quarters_accum',
'\\core_analytics\\local\\time_splitting\\quarters');
'\\core_analytics\\local\\time_splitting\\quarters', '\\core_analytics\\local\\time_splitting\\no_splitting');
foreach ($alltimesplittings as $key => $timesplitting) {
$timesplittingoptions[$key] = $timesplitting->get_name();
}
Expand Down
6 changes: 3 additions & 3 deletions admin/tool/models/classes/output/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ class renderer extends plugin_renderer_base {
/**
* Defer to template.
*
* @param templatable $templatable
* @param \tool_models\output\models_list $templatable
* @return string HTML
*/
protected function render_models_list(templatable $templatable) {
$data = $templatable->export_for_template($this);
protected function render_models_list(\tool_models\output\models_list $modelslist) {
$data = $modelslist->export_for_template($this);
return parent::render_from_template('tool_models/models_list', $data);
}

Expand Down
2 changes: 1 addition & 1 deletion analytics/classes/calculable.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ abstract class calculable {
* @return string
*/
public static function get_name() {
return get_called_class();
return '\\' . get_called_class();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion analytics/classes/local/indicator/binary.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function get_calculation_outcome($value, $subtype = false) {
*/
public static function get_feature_headers() {
// Just 1 single feature obtained from the calculated value.
return array(get_called_class());
return array('\\' . get_called_class());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ protected function cognitive_calculate_sample($sampleid, $tablename, $starttime

switch ($potentiallevel) {
case 5:
// Cognitive level 4 is to comment on feedback.
// Cognitive level 5 is to submit after feedback.
if ($this->any_feedback('submitted', $cm, $contextid, $user)) {
$score += $scoreperlevel * 5;
break;
Expand Down
2 changes: 1 addition & 1 deletion analytics/classes/local/indicator/discrete.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected static function get_classes() {
* @return string[]
*/
public static function get_feature_headers() {
$fullclassname = get_called_class();
$fullclassname = '\\' . get_called_class();

$headers = array($fullclassname);
foreach (self::get_classes() as $class) {
Expand Down
2 changes: 1 addition & 1 deletion analytics/classes/local/indicator/linear.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected static function include_averages() {
*/
public static function get_feature_headers() {

$fullclassname = get_called_class();
$fullclassname = '\\' . get_called_class();

if (static::include_averages()) {
// The calculated value + context indicators.
Expand Down
2 changes: 1 addition & 1 deletion analytics/classes/local/time_splitting/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ protected function get_headers($indicators, $target = false) {

// The target as well.
if ($target) {
$headers[] = get_class($target);
$headers[] = $target->get_id();
}

return $headers;
Expand Down
5 changes: 4 additions & 1 deletion analytics/classes/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ public static function get_all_models($enabled = false, $trained = false, $predi

$models = array();
foreach ($modelobjs as $modelobj) {
$models[$modelobj->id] = new \core_analytics\model($modelobj);
$model = new \core_analytics\model($modelobj);
if ($model->is_available()) {
$models[$modelobj->id] = $model;
}
}
return $models;
}
Expand Down
22 changes: 21 additions & 1 deletion analytics/classes/model.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,26 @@ public function __construct($model) {
$this->model = $model;
}

/**
* Quick safety check to discard site models which required components are not available anymore.
*
* @return bool
*/
public function is_available() {
$target = $this->get_target();
if (!$target) {
return false;
}
$analyser = $this->get_target();

$classname = $target->get_analyser_class();
if (!class_exists($classname)) {
return false;
}

return true;
}

/**
* Returns the model id.
*
Expand Down Expand Up @@ -1217,7 +1237,7 @@ private static function indicator_classes($indicators) {
if (!is_object($indicator) && !is_scalar($indicator)) {
$indicator = strval($indicator);
} else if (is_object($indicator)) {
$indicator = get_class($indicator);
$indicator = '\\' . get_class($indicator);
}
throw new \moodle_exception('errorinvalidindicator', 'analytics', '', $indicator);
}
Expand Down

0 comments on commit 3a39628

Please sign in to comment.