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
+43
View File
@@ -0,0 +1,43 @@
<?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/>.
/**
* Class for exporting competency data.
*
* @package core_competency
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_competency\external;
defined('MOODLE_INTERNAL') || die();
/**
* Class for exporting competency data.
*
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class competency_exporter extends \core\external\persistent_exporter {
protected static function define_class() {
return \core_competency\competency::class;
}
protected static function define_related() {
// We cache the context so it does not need to be retrieved from the framework every time.
return array('context' => '\\context');
}
}
@@ -0,0 +1,95 @@
<?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/>.
/**
* Class for exporting competency_framework data.
*
* @package core_competency
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_competency\external;
defined('MOODLE_INTERNAL') || die();
use core_competency\api;
use renderer_base;
/**
* Class for exporting competency_framework data.
*
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class competency_framework_exporter extends \core\external\persistent_exporter {
/**
* Define the name of persistent class.
*
* @return string
*/
protected static function define_class() {
return \core_competency\competency_framework::class;
}
/**
* Get other values that do not belong to the basic persisent.
*
* @param renderer_base $output
* @return Array
*/
protected function get_other_values(renderer_base $output) {
$filters = array('competencyframeworkid' => $this->persistent->get('id'));
$context = $this->persistent->get_context();
$competenciescount = 0;
try {
$competenciescount = api::count_competencies($filters);
} catch (\required_capability_exception $re) {
$competenciescount = 0;
}
return array(
'canmanage' => has_capability('moodle/competency:competencymanage', $context),
'competenciescount' => $competenciescount,
'contextname' => $context->get_context_name(),
'contextnamenoprefix' => $context->get_context_name(false)
);
}
/**
* Define other properties that do not belong to the basic persisent.
*
* @return Array
*/
protected static function define_other_properties() {
return array(
'canmanage' => array(
'type' => PARAM_BOOL
),
'competenciescount' => array(
'type' => PARAM_INT
),
// Both contexts need to be PARAM_RAW because the method context::get_context_name()
// already applies the formatting and thus could return HTML content.
'contextname' => array(
'type' => PARAM_RAW
),
'contextnamenoprefix' => array(
'type' => PARAM_RAW
)
);
}
}
@@ -0,0 +1,38 @@
<?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/>.
/**
* Class for exporting course competency data.
*
* @package core_competency
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_competency\external;
defined('MOODLE_INTERNAL') || die();
/**
* Class for exporting course competency data.
*
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class course_competency_exporter extends \core\external\persistent_exporter {
protected static function define_class() {
return \core_competency\course_competency::class;
}
}
@@ -0,0 +1,40 @@
<?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/>.
/**
* Class for exporting course_competency_settings data.
*
* @package core_competency
* @copyright 2016 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_competency\external;
defined('MOODLE_INTERNAL') || die();
/**
* Class for exporting course_competency_settings data.
*
* @package core_competency
* @copyright 2016 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class course_competency_settings_exporter extends \core\external\persistent_exporter {
protected static function define_class() {
return \core_competency\course_competency_settings::class;
}
}
@@ -0,0 +1,38 @@
<?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/>.
/**
* Class for exporting course module competency data.
*
* @package core_competency
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_competency\external;
defined('MOODLE_INTERNAL') || die();
/**
* Class for exporting course module competency data.
*
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class course_module_competency_exporter extends \core\external\persistent_exporter {
protected static function define_class() {
return \core_competency\course_module_competency::class;
}
}
+138
View File
@@ -0,0 +1,138 @@
<?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/>.
/**
* Class for exporting evidence data.
*
* @package core_competency
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_competency\external;
defined('MOODLE_INTERNAL') || die();
use context_system;
use renderer_base;
use core_competency\evidence;
use core_competency\user_competency;
use core_user\external\user_summary_exporter;
/**
* Class for exporting evidence data.
*
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class evidence_exporter extends \core\external\persistent_exporter {
/**
* Constructor.
*
* @param mixed $data The data.
* @param array $related Array of relateds.
*/
public function __construct($data, $related = array()) {
if (!isset($related['context'])) {
// Previous code was automatically using the system context which was not correct.
// We let developers know that they must fix their code without breaking anything, and
// fallback on the previous behaviour. This should be removed at a later stage: Moodle 3.5.
debugging('Missing related context in evidence_exporter.', DEBUG_DEVELOPER);
$related['context'] = context_system::instance();
}
parent::__construct($data, $related);
}
protected static function define_related() {
return array(
'actionuser' => 'stdClass?',
'context' => 'context',
'scale' => 'grade_scale',
'usercompetency' => 'core_competency\\user_competency?',
'usercompetencyplan' => 'core_competency\\user_competency_plan?',
);
}
protected static function define_class() {
return evidence::class;
}
protected function get_other_values(renderer_base $output) {
$other = array();
if (!empty($this->related['actionuser'])) {
$exporter = new user_summary_exporter($this->related['actionuser']);
$actionuser = $exporter->export($output);
$other['actionuser'] = $actionuser;
}
$other['description'] = $this->persistent->get_description();
$other['userdate'] = userdate($this->persistent->get('timecreated'));
if ($this->persistent->get('grade') === null) {
$gradename = '-';
} else {
$gradename = $this->related['scale']->scale_items[$this->persistent->get('grade') - 1];
}
$other['gradename'] = $gradename;
// Try to guess the user from the user competency.
$userid = null;
if ($this->related['usercompetency']) {
$userid = $this->related['usercompetency']->get('userid');
} else if ($this->related['usercompetencyplan']) {
$userid = $this->related['usercompetencyplan']->get('userid');
} else {
$uc = user_competency::get_record(['id' => $this->persistent->get('usercompetencyid')]);
$userid = $uc->get('userid');
}
$other['candelete'] = evidence::can_delete_user($userid);
return $other;
}
/**
* Get the format parameters for gradename.
*
* @return array
*/
protected function get_format_parameters_for_gradename() {
return [
'context' => context_system::instance(), // The system context is cached, so we can get it right away.
];
}
public static function define_other_properties() {
return array(
'actionuser' => array(
'type' => user_summary_exporter::read_properties_definition(),
'optional' => true
),
'description' => array(
'type' => PARAM_TEXT, // The description may contain course names, etc.. which may need filtering.
),
'gradename' => array(
'type' => PARAM_TEXT,
),
'userdate' => array(
'type' => PARAM_NOTAGS
),
'candelete' => array(
'type' => PARAM_BOOL
)
);
}
}
+123
View File
@@ -0,0 +1,123 @@
<?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/>.
/**
* Performance helper.
*
* @package core_competency
* @copyright 2016 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_competency\external;
defined('MOODLE_INTERNAL') || die();
use core_competency\competency;
use core_competency\competency_framework;
/**
* Performance helper class.
*
* This tool keeps a local cache of certain items, which means that subsequent
* calls to get the resource will not query the database. You will want to use
* this when many resources could be shared and need to be queried in a loop.
*
* Note that some of these improvements can only be achieved by knowing the
* logic deeper in other modules. For instance we know that a competency's context
* is the one of its framework. This tool must be kept in sync with those APIs.
*
* @package core_competency
* @copyright 2016 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class performance_helper {
/** @var \context Cache of contexts by framework ID. */
protected $frameworkscontexts = [];
/** @var competency_framework Cache of frameworks by framework ID. */
protected $frameworks = [];
/** @var \grade_scale[] Cache of scales by scale ID. */
protected $scales = [];
/**
* Get the context of a competency.
*
* @param competency $competency The competency.
* @return \context
*/
public function get_context_from_competency(competency $competency) {
$frameworkid = $competency->get('competencyframeworkid');
if (!isset($this->frameworkscontexts[$frameworkid])) {
$framework = $this->get_framework_from_competency($competency);
$this->frameworkscontexts[$frameworkid] = $framework->get_context();
}
return $this->frameworkscontexts[$frameworkid];
}
/**
* Get the framework of a competency.
*
* @param competency $competency The competency.
* @return competency_framework
*/
public function get_framework_from_competency(competency $competency) {
$frameworkid = $competency->get('competencyframeworkid');
if (!isset($this->frameworks[$frameworkid])) {
$this->frameworks[$frameworkid] = $competency->get_framework();
}
return $this->frameworks[$frameworkid];
}
/**
* Get the scale of a competency.
*
* /!\ Make sure that this is always kept in sync with:
* - core_competency\competency::get_scale()
* - core_competency\competency_framework::get_scale()
*
* @param competency $competency The competency.
* @return \grade_scale
*/
public function get_scale_from_competency(competency $competency) {
$scaleid = $competency->get('scaleid');
if ($scaleid !== null && !isset($this->scales[$scaleid])) {
$this->scales[$scaleid] = $competency->get_scale();
} else if ($scaleid === null) {
$framework = $this->get_framework_from_competency($competency);
$scaleid = $framework->get('scaleid');
if (!isset($this->scales[$scaleid])) {
$this->scales[$scaleid] = $framework->get_scale();
}
}
return $this->scales[$scaleid];
}
/**
* Ingest a framework to avoid additional fetching.
*
* @param competency_framework $framework The framework.
* @return void
*/
public function ingest_framework(competency_framework $framework) {
$id = $framework->get('id');
$this->frameworks[$id] = $framework;
}
}
@@ -0,0 +1,38 @@
<?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/>.
/**
* Class for exporting plan competency data.
*
* @package core_competency
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_competency\external;
defined('MOODLE_INTERNAL') || die();
/**
* Class for exporting plan competency data.
*
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class plan_competency_exporter extends \core\external\persistent_exporter {
protected static function define_class() {
return \core_competency\plan_competency::class;
}
}
+191
View File
@@ -0,0 +1,191 @@
<?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/>.
/**
* Class for exporting plan data.
*
* @package core_competency
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_competency\external;
defined('MOODLE_INTERNAL') || die();
use core_user;
use renderer_base;
use stdClass;
use moodle_url;
use core_competency\url;
use core_comment\external\comment_area_exporter;
use core_user\external\user_summary_exporter;
/**
* Class for exporting plan data.
*
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class plan_exporter extends \core\external\persistent_exporter {
protected static function define_class() {
return \core_competency\plan::class;
}
protected static function define_related() {
return array('template' => 'core_competency\\template?');
}
protected function get_other_values(renderer_base $output) {
$classname = static::define_class();
$status = $this->persistent->get('status');
$values = new stdClass();
$values->statusname = $this->persistent->get_statusname();
$values->isbasedontemplate = $this->persistent->is_based_on_template();
$values->canmanage = $this->persistent->can_manage();
$values->canrequestreview = $this->persistent->can_request_review();
$values->canreview = $this->persistent->can_review();
$values->canbeedited = $this->persistent->can_be_edited();
$values->isactive = $status == $classname::STATUS_ACTIVE;
$values->isdraft = $status == $classname::STATUS_DRAFT;
$values->iscompleted = $status == $classname::STATUS_COMPLETE;
$values->isinreview = $status == $classname::STATUS_IN_REVIEW;
$values->iswaitingforreview = $status == $classname::STATUS_WAITING_FOR_REVIEW;
$values->isreopenallowed = $values->canmanage && $values->iscompleted;
$values->iscompleteallowed = $values->canmanage && $values->isactive;
$values->isunlinkallowed = $values->canmanage && !$values->iscompleted && $values->isbasedontemplate;
$values->isrequestreviewallowed = false;
$values->iscancelreviewrequestallowed = false;
$values->isstartreviewallowed = false;
$values->isstopreviewallowed = false;
$values->isapproveallowed = false;
$values->isunapproveallowed = false;
if (!$values->isbasedontemplate) {
$values->isrequestreviewallowed = $values->canrequestreview && $values->isdraft;
$values->iscancelreviewrequestallowed = $values->canrequestreview && $values->iswaitingforreview;
$values->isstartreviewallowed = $values->canreview && $values->iswaitingforreview;
$values->isstopreviewallowed = $values->canreview && $values->isinreview;
$values->isapproveallowed = $values->canreview && !$values->iscompleted && !$values->isactive;
$values->isunapproveallowed = $values->canreview && $values->isactive;
}
$values->duedateformatted = userdate($this->persistent->get('duedate'));
if ($this->persistent->is_based_on_template()) {
$exporter = new template_exporter($this->related['template']);
$values->template = $exporter->export($output);
}
if (!empty($values->isinreview)) {
// TODO Make this more efficient.
$userexporter = new user_summary_exporter(core_user::get_user($this->persistent->get('reviewerid'), '*', MUST_EXIST));
$values->reviewer = $userexporter->export($output);
}
$commentareaexporter = new comment_area_exporter($this->persistent->get_comment_object());
$values->commentarea = $commentareaexporter->export($output);
$values->url = url::plan($this->persistent->get('id'))->out(false);
return (array) $values;
}
public static function define_other_properties() {
return array(
'statusname' => array(
'type' => PARAM_RAW,
),
'isbasedontemplate' => array(
'type' => PARAM_BOOL,
),
'canmanage' => array(
'type' => PARAM_BOOL,
),
'canrequestreview' => array(
'type' => PARAM_BOOL,
),
'canreview' => array(
'type' => PARAM_BOOL,
),
'canbeedited' => array(
'type' => PARAM_BOOL,
),
'isactive' => array(
'type' => PARAM_BOOL
),
'isdraft' => array(
'type' => PARAM_BOOL
),
'iscompleted' => array(
'type' => PARAM_BOOL
),
'isinreview' => array(
'type' => PARAM_BOOL
),
'iswaitingforreview' => array(
'type' => PARAM_BOOL
),
'isreopenallowed' => array(
'type' => PARAM_BOOL
),
'iscompleteallowed' => array(
'type' => PARAM_BOOL
),
'isunlinkallowed' => array(
'type' => PARAM_BOOL
),
'isrequestreviewallowed' => array(
'type' => PARAM_BOOL
),
'iscancelreviewrequestallowed' => array(
'type' => PARAM_BOOL
),
'isstartreviewallowed' => array(
'type' => PARAM_BOOL
),
'isstopreviewallowed' => array(
'type' => PARAM_BOOL
),
'isapproveallowed' => array(
'type' => PARAM_BOOL
),
'isunapproveallowed' => array(
'type' => PARAM_BOOL
),
'duedateformatted' => array(
'type' => PARAM_TEXT
),
'commentarea' => array(
'type' => comment_area_exporter::read_properties_definition(),
),
'reviewer' => array(
'type' => user_summary_exporter::read_properties_definition(),
'optional' => true
),
'template' => array(
'type' => template_exporter::read_properties_definition(),
'optional' => true,
),
'url' => array(
'type' => PARAM_URL
)
);
}
}
@@ -0,0 +1,38 @@
<?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/>.
/**
* Class for exporting plan data.
*
* @package core_competency
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_competency\external;
defined('MOODLE_INTERNAL') || die();
/**
* Class for exporting related competency data.
*
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class related_competency_exporter extends \core\external\persistent_exporter {
protected static function define_class() {
return \core_competency\related_competency::class;
}
}
@@ -0,0 +1,38 @@
<?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/>.
/**
* Class for exporting template competency data.
*
* @package core_competency
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_competency\external;
defined('MOODLE_INTERNAL') || die();
/**
* Class for exporting template competency data.
*
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class template_competency_exporter extends \core\external\persistent_exporter {
protected static function define_class() {
return \core_competency\template_competency::class;
}
}
+82
View File
@@ -0,0 +1,82 @@
<?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/>.
/**
* Class for exporting template data.
*
* @package core_competency
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_competency\external;
defined('MOODLE_INTERNAL') || die();
use moodle_url;
use renderer_base;
use core_competency\plan;
use core_competency\template_cohort;
/**
* Class for exporting template data.
*
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class template_exporter extends \core\external\persistent_exporter {
protected static function define_class() {
return \core_competency\template::class;
}
protected function get_other_values(renderer_base $output) {
$context = $this->persistent->get_context();
return array(
'duedateformatted' => userdate($this->persistent->get('duedate')),
'cohortscount' => template_cohort::count_records(array('templateid' => $this->persistent->get('id'))),
'planscount' => plan::count_records(array('templateid' => $this->persistent->get('id'))),
'canmanage' => $this->persistent->can_manage(),
'canread' => $this->persistent->can_read(),
'contextname' => $context->get_context_name(),
'contextnamenoprefix' => $context->get_context_name(false)
);
}
protected static function define_other_properties() {
return array(
'duedateformatted' => array(
'type' => PARAM_RAW
),
'cohortscount' => array(
'type' => PARAM_INT
),
'planscount' => array(
'type' => PARAM_INT
),
'canmanage' => array(
'type' => PARAM_BOOL
),
'canread' => array(
'type' => PARAM_BOOL
),
'contextname' => array(
'type' => PARAM_TEXT,
),
'contextnamenoprefix' => array(
'type' => PARAM_TEXT,
)
);
}
}
@@ -0,0 +1,89 @@
<?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/>.
/**
* Class for exporting user competency course data.
*
* @package core_competency
* @copyright 2016 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_competency\external;
defined('MOODLE_INTERNAL') || die();
use context_system;
use renderer_base;
use stdClass;
/**
* Class for exporting user competency course data.
*
* @copyright 2016 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class user_competency_course_exporter extends \core\external\persistent_exporter {
protected static function define_class() {
return \core_competency\user_competency_course::class;
}
protected static function define_related() {
// We cache the scale so it does not need to be retrieved from the framework every time.
return array('scale' => 'grade_scale');
}
protected function get_other_values(renderer_base $output) {
$result = new stdClass();
if ($this->persistent->get('grade') === null) {
$gradename = '-';
} else {
$gradename = $this->related['scale']->scale_items[$this->persistent->get('grade') - 1];
}
$result->gradename = $gradename;
if ($this->persistent->get('proficiency') === null) {
$proficiencyname = get_string('no');
} else {
$proficiencyname = get_string($this->persistent->get('proficiency') ? 'yes' : 'no');
}
$result->proficiencyname = $proficiencyname;
return (array) $result;
}
/**
* Get the format parameters for gradename.
*
* @return array
*/
protected function get_format_parameters_for_gradename() {
return [
'context' => context_system::instance(), // The system context is cached, so we can get it right away.
];
}
protected static function define_other_properties() {
return array(
'gradename' => array(
'type' => PARAM_TEXT
),
'proficiencyname' => array(
'type' => PARAM_RAW
)
);
}
}
+156
View File
@@ -0,0 +1,156 @@
<?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/>.
/**
* Class for exporting user competency data.
*
* @package core_competency
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_competency\external;
defined('MOODLE_INTERNAL') || die();
use context_system;
use core_user;
use renderer_base;
use stdClass;
use core_competency\url;
use core_competency\user_competency;
use core_user\external\user_summary_exporter;
/**
* Class for exporting user competency data.
*
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class user_competency_exporter extends \core\external\persistent_exporter {
protected static function define_class() {
return user_competency::class;
}
protected static function define_related() {
// We cache the scale so it does not need to be retrieved from the framework every time.
return array('scale' => 'grade_scale');
}
protected function get_other_values(renderer_base $output) {
$result = new stdClass();
if ($this->persistent->get('grade') === null) {
$gradename = '-';
} else {
$gradename = $this->related['scale']->scale_items[$this->persistent->get('grade') - 1];
}
$result->gradename = $gradename;
if ($this->persistent->get('proficiency') === null) {
$proficiencyname = get_string('no');
} else {
$proficiencyname = get_string($this->persistent->get('proficiency') ? 'yes' : 'no');
}
$result->proficiencyname = $proficiencyname;
$statusname = '-';
if ($this->persistent->get('status') != user_competency::STATUS_IDLE) {
$statusname = (string) user_competency::get_status_name($this->persistent->get('status'));
}
$result->statusname = $statusname;
$result->canrequestreview = $this->persistent->can_request_review();
$result->canreview = $this->persistent->can_review();
$result->isstatusidle = $this->persistent->get('status') == user_competency::STATUS_IDLE;
$result->isstatusinreview = $this->persistent->get('status') == user_competency::STATUS_IN_REVIEW;
$result->isstatuswaitingforreview = $this->persistent->get('status') == user_competency::STATUS_WAITING_FOR_REVIEW;
$result->isrequestreviewallowed = $result->canrequestreview && $result->isstatusidle;
$result->iscancelreviewrequestallowed = $result->canrequestreview && $result->isstatuswaitingforreview;
$result->isstartreviewallowed = $result->canreview && $result->isstatuswaitingforreview;
$result->isstopreviewallowed = $result->canreview && $result->isstatusinreview;
if (!empty($result->isstatusinreview)) {
// TODO Make this more efficient.
$userexporter = new user_summary_exporter(core_user::get_user($this->persistent->get('reviewerid'), '*', MUST_EXIST));
$result->reviewer = $userexporter->export($output);
}
$result->url = url::user_competency($this->persistent->get('id'))->out(false);
return (array) $result;
}
/**
* Get the format parameters for gradename.
*
* @return array
*/
protected function get_format_parameters_for_gradename() {
return [
'context' => context_system::instance(), // The system context is cached, so we can get it right away.
];
}
protected static function define_other_properties() {
return array(
'canrequestreview' => array(
'type' => PARAM_BOOL,
),
'canreview' => array(
'type' => PARAM_BOOL,
),
'gradename' => array(
'type' => PARAM_TEXT
),
'isrequestreviewallowed' => array(
'type' => PARAM_BOOL,
),
'iscancelreviewrequestallowed' => array(
'type' => PARAM_BOOL,
),
'isstartreviewallowed' => array(
'type' => PARAM_BOOL,
),
'isstopreviewallowed' => array(
'type' => PARAM_BOOL,
),
'isstatusidle' => array(
'type' => PARAM_BOOL,
),
'isstatusinreview' => array(
'type' => PARAM_BOOL,
),
'isstatuswaitingforreview' => array(
'type' => PARAM_BOOL,
),
'proficiencyname' => array(
'type' => PARAM_RAW
),
'reviewer' => array(
'type' => user_summary_exporter::read_properties_definition(),
'optional' => true
),
'statusname' => array(
'type' => PARAM_RAW
),
'url' => array(
'type' => PARAM_URL
),
);
}
}
@@ -0,0 +1,89 @@
<?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/>.
/**
* Class for exporting plan competency data.
*
* @package core_competency
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_competency\external;
defined('MOODLE_INTERNAL') || die();
use context_system;
use renderer_base;
use stdClass;
/**
* Class for exporting plan competency data.
*
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class user_competency_plan_exporter extends \core\external\persistent_exporter {
protected static function define_class() {
return \core_competency\user_competency_plan::class;
}
protected static function define_related() {
// We cache the scale so it does not need to be retrieved from the framework every time.
return array('scale' => 'grade_scale');
}
protected function get_other_values(renderer_base $output) {
$result = new stdClass();
if ($this->persistent->get('grade') === null) {
$gradename = '-';
} else {
$gradename = $this->related['scale']->scale_items[$this->persistent->get('grade') - 1];
}
$result->gradename = $gradename;
if ($this->persistent->get('proficiency') === null) {
$proficiencyname = get_string('no');
} else {
$proficiencyname = get_string($this->persistent->get('proficiency') ? 'yes' : 'no');
}
$result->proficiencyname = $proficiencyname;
return (array) $result;
}
/**
* Get the format parameters for gradename.
*
* @return array
*/
protected function get_format_parameters_for_gradename() {
return [
'context' => context_system::instance(), // The system context is cached, so we can get it right away.
];
}
protected static function define_other_properties() {
return array(
'gradename' => array(
'type' => PARAM_TEXT
),
'proficiencyname' => array(
'type' => PARAM_RAW
),
);
}
}
@@ -0,0 +1,41 @@
<?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/>.
/**
* User evidence competency exporter.
*
* @package core_competency
* @copyright 2015 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_competency\external;
defined('MOODLE_INTERNAL') || die();
/**
* User evidence competency exporter class.
*
* @package core_competency
* @copyright 2015 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class user_evidence_competency_exporter extends \core\external\persistent_exporter {
protected static function define_class() {
return \core_competency\user_evidence_competency::class;
}
}
+120
View File
@@ -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/>.
/**
* Class for exporting user_evidence data.
*
* @package core_competency
* @copyright 2015 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_competency\external;
defined('MOODLE_INTERNAL') || die();
use moodle_url;
use renderer_base;
use core_competency\external\performance_helper;
use core_files\external\stored_file_exporter;
/**
* Class for exporting user_evidence data.
*
* @package core_competency
* @copyright 2015 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class user_evidence_exporter extends \core\external\persistent_exporter {
protected static function define_class() {
return \core_competency\user_evidence::class;
}
protected static function define_other_properties() {
return array(
'canmanage' => array(
'type' => PARAM_BOOL
),
'competencycount' => array(
'type' => PARAM_INT
),
'competencies' => array(
'type' => competency_exporter::read_properties_definition(),
'multiple' => true
),
'filecount' => array(
'type' => PARAM_INT
),
'files' => array(
'type' => stored_file_exporter::read_properties_definition(),
'multiple' => true
),
'hasurlorfiles' => array(
'type' => PARAM_BOOL
),
'urlshort' => array(
'type' => PARAM_TEXT
),
);
}
protected static function define_related() {
return array(
'context' => 'context',
'competencies' => 'core_competency\\competency[]'
);
}
protected function get_other_values(renderer_base $output) {
$helper = new performance_helper();
$competencies = array();
foreach ($this->related['competencies'] as $competency) {
$context = $helper->get_context_from_competency($competency);
$compexporter = new competency_exporter($competency, array('context' => $context));
$competencies[] = $compexporter->export($output);
}
$urlshort = '';
$url = $this->persistent->get('url');
if (!empty($url)) {
$murl = new moodle_url($url);
$shorturl = preg_replace('@^https?://(www\.)?@', '', $murl->out(false));
$urlshort = shorten_text($shorturl, 30, true);
}
$files = array();
$storedfiles = $this->persistent->get_files();
if (!empty($storedfiles)) {
foreach ($storedfiles as $storedfile) {
$fileexporter = new stored_file_exporter($storedfile, array('context' => $this->related['context']));
$files[] = $fileexporter->export($output);
}
}
$values = array(
'canmanage' => $this->persistent->can_manage(),
'competencycount' => count($competencies),
'competencies' => $competencies,
'filecount' => count($files),
'files' => $files,
'hasurlorfiles' => !empty($files) || !empty($url),
'urlshort' => $urlshort
);
return $values;
}
}