first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
+214
View File
@@ -0,0 +1,214 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace report_insights;
use core_external\external_api;
use core_external\external_value;
use core_external\external_single_structure;
use core_external\external_multiple_structure;
use core_external\external_function_parameters;
use core_external\external_warnings;
/**
* This is the external API for this component.
*
* @package report_insights
* @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class external extends external_api {
/**
* set_notuseful_prediction parameters.
*
* @return external_function_parameters
* @since Moodle 3.4
*/
public static function set_notuseful_prediction_parameters() {
return new external_function_parameters(
array(
'predictionid' => new external_value(PARAM_INT, 'The prediction id', VALUE_REQUIRED)
)
);
}
/**
* Flags a prediction as fixed so no need to display it any more.
*
* @param int $predictionid
* @return array an array of warnings and a boolean
* @since Moodle 3.4
*/
public static function set_notuseful_prediction($predictionid) {
$params = self::validate_parameters(self::set_notuseful_prediction_parameters(), array('predictionid' => $predictionid));
list($model, $prediction, $context) = self::validate_prediction($params['predictionid']);
$prediction->action_executed(\core_analytics\prediction::ACTION_NOT_USEFUL, $model->get_target());
$success = true;
return array('success' => $success, 'warnings' => array());
}
/**
* set_notuseful_prediction return
*
* @return \core_external\external_description
* @since Moodle 3.4
*/
public static function set_notuseful_prediction_returns() {
return new external_single_structure(
array(
'success' => new external_value(PARAM_BOOL, 'True if the prediction was successfully flagged as not useful.'),
'warnings' => new external_warnings(),
)
);
}
/**
* Deprecated in favour of action_executed.
*/
public static function set_notuseful_prediction_is_deprecated() {
return true;
}
/**
* set_fixed_prediction parameters.
*
* @return external_function_parameters
* @since Moodle 3.4
*/
public static function set_fixed_prediction_parameters() {
return new external_function_parameters(
array(
'predictionid' => new external_value(PARAM_INT, 'The prediction id', VALUE_REQUIRED)
)
);
}
/**
* Flags a prediction as fixed so no need to display it any more.
*
* @param int $predictionid
* @return array an array of warnings and a boolean
* @since Moodle 3.4
*/
public static function set_fixed_prediction($predictionid) {
$params = self::validate_parameters(self::set_fixed_prediction_parameters(), array('predictionid' => $predictionid));
list($model, $prediction, $context) = self::validate_prediction($params['predictionid']);
$prediction->action_executed(\core_analytics\prediction::ACTION_FIXED, $model->get_target());
$success = true;
return array('success' => $success, 'warnings' => array());
}
/**
* set_fixed_prediction return
*
* @return \core_external\external_description
* @since Moodle 3.4
*/
public static function set_fixed_prediction_returns() {
return new external_single_structure(
array(
'success' => new external_value(PARAM_BOOL, 'True if the prediction was successfully flagged as fixed.'),
'warnings' => new external_warnings(),
)
);
}
/**
* Deprecated in favour of action_executed.
*/
public static function set_fixed_prediction_is_deprecated() {
return true;
}
/**
* action_executed parameters.
*
* @return external_function_parameters
* @since Moodle 3.8
*/
public static function action_executed_parameters() {
return new external_function_parameters (
array(
'actionname' => new external_value(PARAM_ALPHANUMEXT, 'The name of the action', VALUE_REQUIRED),
'predictionids' => new external_multiple_structure(
new external_value(PARAM_INT, 'Prediction id', VALUE_REQUIRED),
'Array of prediction ids'
),
)
);
}
/**
* Stores an action executed over a group of predictions.
*
* @param string $actionname
* @param array $predictionids
* @return array an array of warnings and a boolean
* @since Moodle 3.8
*/
public static function action_executed(string $actionname, array $predictionids) {
$params = self::validate_parameters(self::action_executed_parameters(),
array('actionname' => $actionname, 'predictionids' => $predictionids));
foreach ($params['predictionids'] as $predictionid) {
list($model, $prediction, $context) = self::validate_prediction($predictionid);
// The method action_executed checks that the provided action is valid.
$prediction->action_executed($actionname, $model->get_target());
}
return array('warnings' => array());
}
/**
* action_executed return
*
* @return \core_external\external_description
* @since Moodle 3.8
*/
public static function action_executed_returns() {
return new external_single_structure(
array(
'warnings' => new external_warnings(),
)
);
}
/**
* Validates access to the prediction and returns it.
*
* @param int $predictionid
* @return array array($model, $prediction, $context)
*/
protected static function validate_prediction($predictionid) {
list($model, $prediction, $context) = \core_analytics\manager::get_prediction($predictionid);
self::validate_context($context);
return array($model, $prediction, $context);
}
}
@@ -0,0 +1,120 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Output helper to export actions for rendering.
*
* @package report_insights
* @copyright 2019 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace report_insights\output;
defined('MOODLE_INTERNAL') || die();
/**
* Output helper to export actions for rendering.
*
* @package report_insights
* @copyright 2019 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class actions_exporter {
/**
* Add the prediction actions renderable.
*
* @param \core_analytics\local\target\base $target
* @param \renderer_base $output
* @param \core_analytics\prediction $prediction
* @param bool $includedetailsaction
* @return \stdClass|false
*/
public static function add_prediction_actions(\core_analytics\local\target\base $target, \renderer_base $output,
\core_analytics\prediction $prediction, bool $includedetailsaction = false) {
$actions = $target->prediction_actions($prediction, $includedetailsaction);
if ($actions) {
$actionsmenu = new \action_menu();
// Add all actions defined by the target.
foreach ($actions as $action) {
$actionsmenu->add_primary_action($action->get_action_link());
}
return $actionsmenu->export_for_template($output);
}
return false;
}
/**
* Add bulk actions renderables.
*
* Note that if you are planning to render the bulk actions, the provided predictions must share the same predicted value.
*
* @param \core_analytics\local\target\base $target
* @param \renderer_base $output
* @param \core_analytics\prediction[] $predictions Bulk actions for this set of predictions.
* @param \context $context The context of these predictions.
* @return \stdClass[]|false
*/
public static function add_bulk_actions(\core_analytics\local\target\base $target, \renderer_base $output, array $predictions,
\context $context) {
global $USER;
$bulkactions = $target->bulk_actions($predictions);
if ($context->contextlevel === CONTEXT_USER) {
// Remove useful / notuseful if the current user is not part of the users who receive the insight (e.g. a site manager
// who looks at the generated insights for a particular user).
$insightusers = $target->get_insights_users($context);
if (empty($insightusers[$USER->id])) {
foreach ($bulkactions as $key => $action) {
if ($action->get_action_name() === 'useful' || $action->get_action_name() === 'notuseful') {
unset($bulkactions[$key]);
}
}
}
}
if (!$bulkactions) {
return false;
}
$actionsmenu = [];
// All the predictions share a common predicted value.
$predictionvalue = reset($predictions)->get_prediction_data()->prediction;
// Add all actions defined by the target.
foreach ($bulkactions as $action) {
$action->get_action_link()->set_attribute('data-togglegroup', 'insight-bulk-action-' . $predictionvalue);
$actionsmenu[] = $action->get_action_link()->export_for_template($output);
}
if (empty($actionsmenu)) {
return false;
}
return $actionsmenu;
}
}
+265
View File
@@ -0,0 +1,265 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Single insight view page.
*
* @package report_insights
* @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace report_insights\output;
use core_analytics\prediction;
defined('MOODLE_INTERNAL') || die();
/**
* Single insight view page.
*
* @package report_insights
* @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class insight implements \renderable, \templatable {
/**
* @var \core_analytics\model
*/
protected $model;
/**
* @var \core_analytics\prediction
*/
protected $prediction;
/**
* @var bool
*/
protected $includedetailsaction = false;
/**
* @var \context
*/
protected $context;
/**
* Constructor
*
* @param \core_analytics\prediction $prediction
* @param \core_analytics\model $model
* @param bool $includedetailsaction
* @param \context $context
* @return void
*/
public function __construct(\core_analytics\prediction $prediction, \core_analytics\model $model, $includedetailsaction,
\context $context) {
$this->prediction = $prediction;
$this->model = $model;
$this->includedetailsaction = $includedetailsaction;
$this->context = $context;
}
/**
* Exports the data.
*
* @param \renderer_base $output
* @return \stdClass
*/
public function export_for_template(\renderer_base $output) {
// Get the prediction data.
$predictiondata = $this->prediction->get_prediction_data();
$target = $this->model->get_target();
$data = new \stdClass();
$data->modelid = $this->model->get_id();
$data->contextid = $this->context->id;
$data->predictionid = $predictiondata->id;
$targetname = $target->get_name();
$data->insightname = format_string($targetname);
$targetinfostr = $targetname->get_identifier() . 'info';
if (get_string_manager()->string_exists($targetinfostr, $targetname->get_component())) {
$data->insightdescription = get_string($targetinfostr, $targetname->get_component());
}
$data->showpredictionheading = true;
if (!$target->is_linear()) {
$nclasses = count($target::get_classes());
$nignoredclasses = count($target->ignored_predicted_classes());
if ($nclasses - $nignoredclasses <= 1) {
// Hide the prediction heading if there is only 1 class displayed. Otherwise it is redundant with the insight name.
$data->showpredictionheading = false;
}
}
// Get the details.
$data->timecreated = userdate($predictiondata->timecreated);
$data->timerange = '';
if (!empty($predictiondata->timestart) && !empty($predictiondata->timeend)) {
$timerange = new \stdClass();
$timerange->timestart = userdate($predictiondata->timestart);
$timerange->timeend = userdate($predictiondata->timeend);
$data->timerange = get_string('timerangewithdata', 'report_insights', $timerange);
}
// Sample info (determined by the analyser).
list($data->sampledescription, $samplerenderable) = $this->model->prediction_sample_description($this->prediction);
// Sampleimage is a renderable we should pass it to HTML.
if ($samplerenderable) {
$data->sampleimage = $output->render($samplerenderable);
}
// Prediction info.
$predictedvalue = $predictiondata->prediction;
$data->predictiondisplayvalue = $target->get_display_value($predictedvalue);
list($data->style, $data->outcomeicon) = self::get_calculation_display($target,
floatval($predictedvalue), $output);
$data->actions = actions_exporter::add_prediction_actions($target, $output, $this->prediction,
$this->includedetailsaction);
$data->bulkactions = actions_exporter::add_bulk_actions($target, $output, [$this->prediction], $this->context);
// Calculated indicators values.
$data->calculations = array();
$calculations = $this->prediction->get_calculations();
foreach ($calculations as $calculation) {
// Hook for indicators with extra features that should not be displayed (e.g. discrete indicators).
if (!$calculation->indicator->should_be_displayed($calculation->value, $calculation->subtype)) {
continue;
}
if ($calculation->value === null) {
// We don't show values that could not be calculated.
continue;
}
$obj = new \stdClass();
$obj->name = call_user_func(array($calculation->indicator, 'get_name'));
$obj->displayvalue = $calculation->indicator->get_display_value($calculation->value, $calculation->subtype);
list($obj->style, $obj->outcomeicon) = self::get_calculation_display($calculation->indicator,
floatval($calculation->value), $output, $calculation->subtype);
$identifier = $calculation->indicator->get_name()->get_identifier() . 'def';
$component = $calculation->indicator->get_name()->get_component();
if (get_string_manager()->string_exists($identifier, $component)) {
$obj->outcomehelp = (new \help_icon($identifier, $component))->export_for_template($output);
}
$data->calculations[] = $obj;
}
if (empty($data->calculations)) {
$data->nocalculations = (object)array(
'message' => get_string('nodetailsavailable', 'report_insights'),
'closebutton' => false
);
}
// 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);
}
return $data;
}
/**
* Returns display info for the calculated value outcome.
*
* @param \core_analytics\calculable $calculable
* @param float $value
* @param \renderer_base $output
* @param string|false $subtype
* @return array The style as 'success', 'info', 'warning' or 'danger' and pix_icon
*/
public static function get_calculation_display(\core_analytics\calculable $calculable, $value, $output, $subtype = false) {
$outcome = $calculable->get_calculation_outcome($value, $subtype);
switch ($outcome) {
case \core_analytics\calculable::OUTCOME_NEUTRAL:
$style = '';
$text = get_string('outcomeneutral', 'report_insights');
$icon = 't/check';
break;
case \core_analytics\calculable::OUTCOME_VERY_POSITIVE:
$style = 'success';
$text = get_string('outcomeverypositive', 'report_insights');
$icon = 't/approve';
break;
case \core_analytics\calculable::OUTCOME_OK:
$style = 'info';
$text = get_string('outcomeok', 'report_insights');
$icon = 't/check';
break;
case \core_analytics\calculable::OUTCOME_NEGATIVE:
$style = 'warning';
$text = get_string('outcomenegative', 'report_insights');
$icon = 'i/warning';
break;
case \core_analytics\calculable::OUTCOME_VERY_NEGATIVE:
$style = 'danger';
$text = get_string('outcomeverynegative', 'report_insights');
$icon = 'i/warning';
break;
default:
throw new \coding_exception('The outcome returned by ' . get_class($calculable) . '::get_calculation_outcome is ' .
'not one of the accepted values. Please use \core_analytics\calculable::OUTCOME_VERY_POSITIVE, ' .
'\core_analytics\calculable::OUTCOME_OK, \core_analytics\calculable::OUTCOME_NEGATIVE, ' .
'\core_analytics\calculable::OUTCOME_VERY_NEGATIVE or \core_analytics\calculable::OUTCOME_NEUTRAL');
}
$icon = new \pix_icon($icon, $text);
return array($style, $icon->export_for_template($output));
}
/**
* Model getter.
*
* @return \core_analytics\model
*/
public function get_model(): \core_analytics\model {
return $this->model;
}
}
@@ -0,0 +1,224 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Insights list page.
*
* @package report_insights
* @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace report_insights\output;
defined('MOODLE_INTERNAL') || die();
/**
* Shows report_insights insights list.
*
* @package report_insights
* @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class insights_list implements \renderable, \templatable {
/**
* @var \core_analytics\model
*/
protected $model;
/**
* @var \context
*/
protected $context;
/**
* @var \core_analytics\model[]
*/
protected $othermodels;
/**
* @var int
*/
protected $page;
/**
* @var int
*/
protected $perpage;
/**
* Constructor
*
* @param \core_analytics\model $model
* @param \context $context
* @param \core_analytics\model[] $othermodels
* @param int $page
* @param int $perpage The max number of results to fetch
* @return void
*/
public function __construct(\core_analytics\model $model, \context $context, $othermodels, $page = 0, $perpage = 100) {
$this->model = $model;
$this->context = $context;
$this->othermodels = $othermodels;
$this->page = $page;
$this->perpage = $perpage;
}
/**
* Exports the data.
*
* @param \renderer_base $output
* @return \stdClass
*/
public function export_for_template(\renderer_base $output) {
global $PAGE;
$target = $this->model->get_target();
$data = new \stdClass();
$data->modelid = $this->model->get_id();
$data->contextid = $this->context->id;
$targetname = $target->get_name();
$data->insightname = format_string($targetname);
$targetinfostr = $targetname->get_identifier() . 'info';
if (get_string_manager()->string_exists($targetinfostr, $targetname->get_component())) {
$data->insightdescription = get_string($targetinfostr, $targetname->get_component());
}
$data->showpredictionheading = true;
if (!$target->is_linear()) {
$nclasses = count($target::get_classes());
$nignoredclasses = count($target->ignored_predicted_classes());
if ($nclasses - $nignoredclasses <= 1) {
// Hide the prediction heading if there is only 1 class displayed. Otherwise it is redundant with the insight name.
$data->showpredictionheading = false;
}
}
$total = 0;
if ($this->model->uses_insights()) {
$target->add_bulk_actions_js();
$predictionsdata = $this->model->get_predictions($this->context, true, $this->page, $this->perpage);
if (!$this->model->is_static()) {
$notification = new \core\output\notification(get_string('justpredictions', 'report_insights'));
$data->nostaticmodelnotification = $notification->export_for_template($output);
}
$data->predictions = array();
$predictionvalues = array();
$insights = array();
if ($predictionsdata) {
list($total, $predictions) = $predictionsdata;
if ($predictions) {
// No bulk actions if no predictions.
$data->bulkactions = actions_exporter::add_bulk_actions($target, $output, $predictions, $this->context);
}
$data->multiplepredictions = count($predictions) > 1 ? true : false;
foreach ($predictions as $prediction) {
$predictedvalue = $prediction->get_prediction_data()->prediction;
// Only need to fill this data once.
if (!isset($predictionvalues[$predictedvalue])) {
$preddata = array();
$preddata['predictiondisplayvalue'] = $target->get_display_value($predictedvalue);
list($preddata['style'], $preddata['outcomeicon']) =
insight::get_calculation_display($target, floatval($predictedvalue), $output);
$predictionvalues[$predictedvalue] = $preddata;
}
$insightrenderable = new \report_insights\output\insight($prediction, $this->model, true, $this->context);
$insights[$predictedvalue][] = $insightrenderable->export_for_template($output);
}
// Order predicted values.
if ($target->is_linear()) {
// During regression what we will be interested on most of the time is in low values so let's show them first.
ksort($predictionvalues);
} else {
// During classification targets flag "not that important" samples as 0 so let's show them at the end.
krsort($predictionvalues);
}
// Ok, now we have all the data we want, put it into a format that mustache can handle.
foreach ($predictionvalues as $key => $prediction) {
if (isset($insights[$key])) {
$toggleall = new \core\output\checkbox_toggleall('insight-bulk-action-' . $key, true, [
'id' => 'id-toggle-all-' . $key,
'name' => 'toggle-all-' . $key,
'label' => get_string('selectall'),
'labelclasses' => 'sr-only',
'checked' => false
]);
$prediction['checkboxtoggleall'] = $output->render($toggleall);
$prediction['predictedvalue'] = $key;
$prediction['insights'] = $insights[$key];
}
$data->predictions[] = $prediction;
}
}
if (empty($insights) && $this->page == 0) {
if ($this->model->any_prediction_obtained()) {
$data->noinsights = get_string('noinsights', 'analytics');
} else {
$data->noinsights = get_string('nopredictionsyet', 'analytics');
}
}
} else {
$data->noinsights = get_string('noinsights', 'analytics');
}
if (!empty($data->noinsights)) {
$notification = new \core\output\notification($data->noinsights);
$data->noinsights = $notification->export_for_template($output);
}
$url = $PAGE->url;
if ($this->othermodels) {
$options = array();
foreach ($this->othermodels as $model) {
$options[$model->get_id()] = $model->get_target()->get_name();
}
// New moodle_url instance returned by magic_get_url.
$url->remove_params('modelid');
$modelselector = new \single_select($url, 'modelid', $options, '',
array('' => get_string('selectotherinsights', 'report_insights')));
$data->modelselector = $modelselector->export_for_template($output);
}
// Add the 'perpage' parameter to the url which is later used to generate the pagination links.
$url->param('perpage', $this->perpage);
$data->pagingbar = $output->render(new \paging_bar($total, $this->page, $this->perpage, $url));
return $data;
}
}
+146
View File
@@ -0,0 +1,146 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Renderer.
*
* @package report_insights
* @copyright 2016 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace report_insights\output;
defined('MOODLE_INTERNAL') || die();
use plugin_renderer_base;
use templatable;
use renderable;
/**
* Renderer class.
*
* @package report_insights
* @copyright 2016 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class renderer extends plugin_renderer_base {
/**
* Renders the list of insights
*
* @param renderable $renderable
* @return string HTML
*/
protected function render_insights_list(renderable $renderable) {
$data = $renderable->export_for_template($this);
return parent::render_from_template('report_insights/insights_list', $data);
}
/**
* Renders an insight
*
* @param renderable $renderable
* @return string HTML
*/
protected function render_insight(renderable $renderable) {
$data = $renderable->export_for_template($this);
$renderable->get_model()->get_target()->add_bulk_actions_js();
return parent::render_from_template('report_insights/insight_details', $data);
}
/**
* Model disabled info.
*
* @param \stdClass $insightinfo
* @return string HTML
*/
public function render_model_disabled($insightinfo) {
// We don't want to disclose the name of the model if it has not been enabled.
$this->page->set_title($insightinfo->contextname);
$this->page->set_heading($insightinfo->contextname);
$output = $this->output->header();
$output .= $this->output->notification(get_string('disabledmodel', 'report_insights'),
\core\output\notification::NOTIFY_INFO);
$output .= $this->output->footer();
return $output;
}
/**
* Model without insights info.
*
* @param \context $context
* @return string HTML
*/
public function render_no_insights(\context $context) {
// We don't want to disclose the name of the model if it has not been enabled.
$this->page->set_title($context->get_context_name());
$this->page->set_heading($context->get_context_name());
$output = $this->output->header();
$output .= $this->output->notification(get_string('noinsights', 'analytics'),
\core\output\notification::NOTIFY_INFO);
$output .= $this->output->footer();
return $output;
}
/**
* Model which target does not generate insights.
*
* @param \context $context
* @return string HTML
*/
public function render_no_insights_model(\context $context) {
// We don't want to disclose the name of the model if it has not been enabled.
$this->page->set_title($context->get_context_name());
$this->page->set_heading($context->get_context_name());
$output = $this->output->header();
$output .= $this->output->notification(get_string('noinsightsmodel', 'analytics'),
\core\output\notification::NOTIFY_INFO);
$output .= $this->output->footer();
return $output;
}
/**
* Renders an analytics disabled notification.
*
* @return string HTML
*/
public function render_analytics_disabled() {
global $FULLME;
$this->page->set_url($FULLME);
$this->page->set_title(get_string('pluginname', 'report_insights'));
$this->page->set_heading(get_string('pluginname', 'report_insights'));
$output = $this->output->header();
$output .= $this->output->notification(get_string('analyticsdisabled', 'analytics'),
\core\output\notification::NOTIFY_INFO);
$output .= \html_writer::tag('a', get_string('continue'), ['class' => 'btn btn-primary',
'href' => (new \moodle_url('/'))->out()]);
$output .= $this->output->footer();
return $output;
}
}
@@ -0,0 +1,46 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Privacy Subsystem implementation for report_insights.
*
* @package report_insights
* @copyright 2018 Zig Tan <zig@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace report_insights\privacy;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy Subsystem for report_insights implementing null_provider.
*
* @copyright 2018 Zig Tan <zig@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider {
/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason(): string {
return 'privacy:metadata';
}
}