mirror of
https://github.com/moodle/moodle.git
synced 2025-04-20 07:56:06 +02:00
Merge branch 'MDL-65553-master' of git://github.com/aanabit/moodle
This commit is contained in:
commit
d688af7edd
@ -178,6 +178,33 @@ class prediction {
|
||||
\core\event\prediction_action_started::create($eventdata)->trigger();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the executed actions.
|
||||
*
|
||||
* Actions could be filtered by actionname.
|
||||
*
|
||||
* @param array $actionnamefilter Limit the results obtained to this list of action names.
|
||||
* @param int $userid the user id. Current user by default.
|
||||
* @return array of actions.
|
||||
*/
|
||||
public function get_executed_actions(array $actionnamefilter = null, int $userid = 0): array {
|
||||
global $USER, $DB;
|
||||
|
||||
$conditions[] = "predictionid = :predictionid";
|
||||
$params['predictionid'] = $this->get_prediction_data()->id;
|
||||
if (!$userid) {
|
||||
$userid = $USER->id;
|
||||
}
|
||||
$conditions[] = "userid = :userid";
|
||||
$params['userid'] = $userid;
|
||||
if ($actionnamefilter) {
|
||||
list($actionsql, $actionparams) = $DB->get_in_or_equal($actionnamefilter, SQL_PARAMS_NAMED);
|
||||
$conditions[] = "actionname $actionsql";
|
||||
$params = $params + $actionparams;
|
||||
}
|
||||
return $DB->get_records_select('analytics_prediction_actions', implode(' AND ', $conditions), $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* format_calculations
|
||||
*
|
||||
|
@ -112,6 +112,86 @@ class analytics_prediction_actions_testcase extends advanced_testcase {
|
||||
$this->assertEquals(2, $DB->count_records('analytics_prediction_actions'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for test_get_executed_actions.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function execute_actions_provider(): array {
|
||||
return [
|
||||
'Empty actions with no filter' => [
|
||||
[],
|
||||
[],
|
||||
0
|
||||
],
|
||||
'Empty actions with filter' => [
|
||||
[],
|
||||
[\core_analytics\prediction::ACTION_FIXED],
|
||||
0
|
||||
],
|
||||
'Multiple actions with no filter' => [
|
||||
[
|
||||
\core_analytics\prediction::ACTION_FIXED,
|
||||
\core_analytics\prediction::ACTION_FIXED,
|
||||
\core_analytics\prediction::ACTION_INCORRECTLY_FLAGGED
|
||||
],
|
||||
[],
|
||||
3
|
||||
],
|
||||
'Multiple actions applying filter' => [
|
||||
[
|
||||
\core_analytics\prediction::ACTION_FIXED,
|
||||
\core_analytics\prediction::ACTION_FIXED,
|
||||
\core_analytics\prediction::ACTION_INCORRECTLY_FLAGGED
|
||||
],
|
||||
[\core_analytics\prediction::ACTION_FIXED],
|
||||
2
|
||||
],
|
||||
'Multiple actions not applying filter' => [
|
||||
[
|
||||
\core_analytics\prediction::ACTION_FIXED,
|
||||
\core_analytics\prediction::ACTION_FIXED,
|
||||
\core_analytics\prediction::ACTION_INCORRECTLY_FLAGGED
|
||||
],
|
||||
[\core_analytics\prediction::ACTION_NOT_APPLICABLE],
|
||||
0
|
||||
],
|
||||
'Multiple actions with multiple filter' => [
|
||||
[
|
||||
\core_analytics\prediction::ACTION_FIXED,
|
||||
\core_analytics\prediction::ACTION_FIXED,
|
||||
\core_analytics\prediction::ACTION_INCORRECTLY_FLAGGED
|
||||
],
|
||||
[\core_analytics\prediction::ACTION_FIXED, \core_analytics\prediction::ACTION_INCORRECTLY_FLAGGED],
|
||||
3
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for get_executed_actions() function.
|
||||
*
|
||||
* @dataProvider execute_actions_provider
|
||||
* @param array $actionstoexecute An array of actions to execute
|
||||
* @param array $actionnamefilter Actions to filter
|
||||
* @param int $returned Number of actions returned
|
||||
*
|
||||
* @covers \core_analytics\prediction::get_executed_actions
|
||||
*/
|
||||
public function test_get_executed_actions(array $actionstoexecute, array $actionnamefilter, int $returned) {
|
||||
|
||||
$this->setUser($this->teacher2);
|
||||
list($ignored, $predictions) = $this->model->get_predictions($this->context, true);
|
||||
$prediction = reset($predictions);
|
||||
$target = $this->model->get_target();
|
||||
foreach($actionstoexecute as $action) {
|
||||
$prediction->action_executed($action, $target);
|
||||
}
|
||||
|
||||
$filteredactions = $prediction->get_executed_actions($actionnamefilter);
|
||||
$this->assertCount($returned, $filteredactions);
|
||||
}
|
||||
|
||||
/**
|
||||
* test_get_predictions
|
||||
*/
|
||||
|
@ -11,6 +11,8 @@ information provided here is intended especially for developers.
|
||||
by updating the lib/db/analytics.php file and bumping the core version.
|
||||
* Final deprecation - get_analysables(). Please see get_analysables_interator() instead.
|
||||
get_analysables_iterator() needs to be overridden by the child class.
|
||||
* A new function get_executed_actions() has been added to \core_analytics\prediction class
|
||||
to get all (or filtered by action name) executed actions of a prediction
|
||||
|
||||
=== 3.8 ===
|
||||
|
||||
|
@ -24,6 +24,8 @@
|
||||
|
||||
namespace report_insights\output;
|
||||
|
||||
use core_analytics\prediction;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
@ -173,25 +175,34 @@ class insight implements \renderable, \templatable {
|
||||
);
|
||||
}
|
||||
|
||||
// This is only rendered in report_insights/insight_details template. We need it to automatically enable
|
||||
// the bulk action buttons in report/insights/prediction.php.
|
||||
$toggleall = new \core\output\checkbox_toggleall('insight-bulk-action-' . $predictedvalue, true, [
|
||||
'id' => 'id-toggle-all-' . $predictedvalue,
|
||||
'name' => 'toggle-all-' . $predictedvalue,
|
||||
'classes' => 'hidden',
|
||||
'label' => get_string('selectall'),
|
||||
'labelclasses' => 'sr-only',
|
||||
'checked' => false
|
||||
]);
|
||||
$data->hiddencheckboxtoggleall = $output->render($toggleall);
|
||||
// This is only rendered in report_insights/insight_details template for predictions with no action.
|
||||
// We need it to automatically enable the bulk action buttons in report/insights/prediction.php.
|
||||
$filtered = [
|
||||
\core_analytics\prediction::ACTION_FIXED,
|
||||
\core_analytics\prediction::ACTION_NOT_USEFUL,
|
||||
\core_analytics\prediction::ACTION_USEFUL,
|
||||
\core_analytics\prediction::ACTION_NOT_APPLICABLE,
|
||||
\core_analytics\prediction::ACTION_INCORRECTLY_FLAGGED,
|
||||
];
|
||||
if (!$this->prediction->get_executed_actions($filtered)) {
|
||||
$toggleall = new \core\output\checkbox_toggleall('insight-bulk-action-' . $predictedvalue, true, [
|
||||
'id' => 'id-toggle-all-' . $predictedvalue,
|
||||
'name' => 'toggle-all-' . $predictedvalue,
|
||||
'classes' => 'hidden',
|
||||
'label' => get_string('selectall'),
|
||||
'labelclasses' => 'sr-only',
|
||||
'checked' => false,
|
||||
]);
|
||||
$data->hiddencheckboxtoggleall = $output->render($toggleall);
|
||||
|
||||
$toggle = new \core\output\checkbox_toggleall('insight-bulk-action-' . $predictedvalue, false, [
|
||||
'id' => 'id-select-' . $data->predictionid,
|
||||
'name' => 'select-' . $data->predictionid,
|
||||
'label' => get_string('selectprediction', 'report_insights', $data->sampledescription),
|
||||
'labelclasses' => 'accesshide',
|
||||
]);
|
||||
$data->toggleslave = $output->render($toggle);
|
||||
$toggle = new \core\output\checkbox_toggleall('insight-bulk-action-' . $predictedvalue, false, [
|
||||
'id' => 'id-select-' . $data->predictionid,
|
||||
'name' => 'select-' . $data->predictionid,
|
||||
'label' => get_string('selectprediction', 'report_insights', $data->sampledescription),
|
||||
'labelclasses' => 'accesshide',
|
||||
]);
|
||||
$data->toggleslave = $output->render($toggle);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user