MDL-50253 tool_lp: Adding related competencies
Conflicts: admin/tool/lp/classes/api.php admin/tool/lp/classes/external.php admin/tool/lp/classes/output/renderer.php admin/tool/lp/db/install.xml admin/tool/lp/db/services.php admin/tool/lp/lang/en/tool_lp.php admin/tool/lp/version.php
This commit is contained in:
committed by
Frederic Massart
parent
cf2cc1e2b0
commit
4f81545979
@@ -231,9 +231,10 @@ class api {
|
||||
* Requires tool/lp:competencyread capability at the system context.
|
||||
*
|
||||
* @param int $id The id of the competency to read.
|
||||
* @param bool $includerelated Include related tags or not.
|
||||
* @return stdClass
|
||||
*/
|
||||
public static function read_competency($id) {
|
||||
public static function read_competency($id, $includerelated = false) {
|
||||
$competency = new competency($id);
|
||||
|
||||
// First we do a permissions check.
|
||||
@@ -243,6 +244,13 @@ class api {
|
||||
}
|
||||
|
||||
// OK - all set.
|
||||
if ($includerelated) {
|
||||
$relatedcompetency = new related_competency();
|
||||
if ($related = $relatedcompetency->list_relations($id)) {
|
||||
$competency->relatedcompetencies = $related;
|
||||
}
|
||||
}
|
||||
|
||||
return $competency;
|
||||
}
|
||||
|
||||
@@ -253,9 +261,10 @@ class api {
|
||||
*
|
||||
* @param string $textsearch A string to search for.
|
||||
* @param int $competencyframeworkid The id of the framework to limit the search.
|
||||
* @param bool $includerelated Include related tags or not.
|
||||
* @return array of competencies
|
||||
*/
|
||||
public static function search_competencies($textsearch, $competencyframeworkid) {
|
||||
public static function search_competencies($textsearch, $competencyframeworkid, $includerelated = false) {
|
||||
$framework = new competency_framework($competencyframeworkid);
|
||||
|
||||
// First we do a permissions check.
|
||||
@@ -265,7 +274,18 @@ class api {
|
||||
}
|
||||
|
||||
// OK - all set.
|
||||
return competency::search($textsearch, $competencyframeworkid);
|
||||
$competencies = competency::search($textsearch, $competencyframeworkid);
|
||||
|
||||
if ($includerelated && $competencies) {
|
||||
// Getting all competencies ids to send a single DB query.
|
||||
$relatedcompetency = new related_competency();
|
||||
$relations = $relatedcompetency->list_relations_many(array_keys($competencies));
|
||||
foreach ($relations as $competencyid => $relatedcompetencies) {
|
||||
$competencies[$competencyid]->relatedcompetencies = $relatedcompetencies;
|
||||
}
|
||||
}
|
||||
|
||||
return $competencies;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1253,4 +1273,76 @@ class api {
|
||||
|
||||
return $plan->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* List all the related competencies.
|
||||
*
|
||||
* @param int $competencyid The id of the competency to check.
|
||||
* @return competency[]
|
||||
*/
|
||||
public static function list_related_competencies($competencyid) {
|
||||
|
||||
require_capability('tool/lp:competencymanage', context_system::instance());
|
||||
|
||||
// OK - all set.
|
||||
$competency = new related_competency();
|
||||
return $competency->list_relations($competencyid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a related competency.
|
||||
*
|
||||
* @param int $competencyid The id of the competency
|
||||
* @param int $relatedcompetencyid The id of the related competency.
|
||||
* @return bool
|
||||
*/
|
||||
public static function add_related_competency($competencyid, $relatedcompetencyid) {
|
||||
|
||||
require_capability('tool/lp:competencymanage', context_system::instance());
|
||||
|
||||
$record = new stdClass();
|
||||
$record->competencyid = $competencyid;
|
||||
$record->relatedcompetencyid = $relatedcompetencyid;
|
||||
|
||||
// Using set_id as the constructor queries the DB.
|
||||
$competency = new competency();
|
||||
$competency->set_id($competencyid);
|
||||
if (!$competency->read()) {
|
||||
throw new moodle_exception('errornocompetency', 'tool_lp', $competencyid);
|
||||
}
|
||||
$relatedcompetency = new competency();
|
||||
$relatedcompetency->set_id($relatedcompetencyid);
|
||||
if (!$relatedcompetency->read()) {
|
||||
throw new moodle_exception('errornocompetency', 'tool_lp', $relatedcompetencyid);
|
||||
}
|
||||
|
||||
$relatedcompetency = new related_competency();
|
||||
$exists = $relatedcompetency->load_relation($competencyid, $relatedcompetencyid);
|
||||
if (!$exists) {
|
||||
return $relatedcompetency->create();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a related competency.
|
||||
*
|
||||
* @param int $competencyid The id of the competency.
|
||||
* @param int $relatedcompetencyid The id of the related competency.
|
||||
* @return bool
|
||||
*/
|
||||
public static function remove_related_competency($competencyid, $relatedcompetencyid) {
|
||||
|
||||
require_capability('tool/lp:competencymanage', context_system::instance());
|
||||
|
||||
$record = new stdClass();
|
||||
$record->competencyid = $competencyid;
|
||||
$record->relatedcompetencyid = $relatedcompetencyid;
|
||||
|
||||
$relatedcompetency = new related_competency();
|
||||
if (!$relatedcompetency->load_relation($competencyid, $relatedcompetencyid)) {
|
||||
return false;
|
||||
}
|
||||
return $relatedcompetency->delete();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -277,7 +277,7 @@ class competency extends persistent {
|
||||
// Convert to instances of this class.
|
||||
foreach ($records as $record) {
|
||||
$newrecord = new static(0, $record);
|
||||
array_push($instances, $newrecord);
|
||||
$instances[$newrecord->get_id()] = $newrecord;
|
||||
}
|
||||
return $instances;
|
||||
}
|
||||
|
||||
@@ -784,9 +784,10 @@ class external extends external_api {
|
||||
/**
|
||||
* Returns the external structure of a full competency record.
|
||||
*
|
||||
* @param bool $includerelated Useful to avoid recursive structures.
|
||||
* @return \external_single_structure
|
||||
*/
|
||||
protected static function get_competency_external_structure() {
|
||||
protected static function get_competency_external_structure($includerelated = false) {
|
||||
$id = new external_value(
|
||||
PARAM_INT,
|
||||
'Database record id'
|
||||
@@ -863,6 +864,15 @@ class external extends external_api {
|
||||
'competencyframeworkid' => $competencyframeworkid,
|
||||
'path' => $path,
|
||||
);
|
||||
|
||||
if ($includerelated) {
|
||||
$returns['relatedcompetencies'] = new external_multiple_structure(
|
||||
self::get_competency_external_structure(false),
|
||||
'Related competencies',
|
||||
VALUE_OPTIONAL
|
||||
);
|
||||
}
|
||||
|
||||
return new external_single_structure($returns);
|
||||
}
|
||||
|
||||
@@ -1271,10 +1281,17 @@ class external extends external_api {
|
||||
'Competency framework id',
|
||||
VALUE_REQUIRED
|
||||
);
|
||||
$includerelated = new external_value(
|
||||
PARAM_BOOL,
|
||||
'Include or not related competencies',
|
||||
VALUE_OPTIONAL,
|
||||
false
|
||||
);
|
||||
|
||||
$params = array(
|
||||
'searchtext' => $searchtext,
|
||||
'competencyframeworkid' => $frameworkid
|
||||
'competencyframeworkid' => $frameworkid,
|
||||
'includerelated' => $includerelated
|
||||
);
|
||||
return new external_function_parameters($params);
|
||||
}
|
||||
@@ -1287,11 +1304,6 @@ class external extends external_api {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* List the existing competency frameworks
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
/**
|
||||
* List the existing competency frameworks
|
||||
*
|
||||
@@ -1300,22 +1312,30 @@ class external extends external_api {
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function search_competencies($searchtext, $competencyframeworkid) {
|
||||
public static function search_competencies($searchtext, $competencyframeworkid, $includerelated = false) {
|
||||
$params = self::validate_parameters(self::search_competencies_parameters(),
|
||||
array(
|
||||
'searchtext' => $searchtext,
|
||||
'competencyframeworkid' => $competencyframeworkid
|
||||
'competencyframeworkid' => $competencyframeworkid,
|
||||
'includerelated' => $includerelated
|
||||
));
|
||||
|
||||
$results = api::search_competencies($searchtext, $competencyframeworkid);
|
||||
$results = api::search_competencies($params['searchtext'], $params['competencyframeworkid'], $params['includerelated']);
|
||||
$options = array('context' => context_system::instance());
|
||||
$records = array();
|
||||
foreach ($results as $result) {
|
||||
$record = $result->to_record();
|
||||
$record->descriptionformatted = format_text($record->description, $record->descriptionformat, $options);
|
||||
if ($includerelated && !empty($result->relatedcompetencies)) {
|
||||
$record->relatedcompetencies = array();
|
||||
foreach ($result->relatedcompetencies as $relatedcompetency) {
|
||||
$record->relatedcompetencies[] = $relatedcompetency->to_record();
|
||||
}
|
||||
}
|
||||
array_push($records, $record);
|
||||
}
|
||||
return $records;
|
||||
|
||||
return external_api::clean_returnvalue(self::search_competencies_returns(), $records);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1324,7 +1344,7 @@ class external extends external_api {
|
||||
* @return \external_description
|
||||
*/
|
||||
public static function search_competencies_returns() {
|
||||
return new external_multiple_structure(self::get_competency_external_structure());
|
||||
return new external_multiple_structure(self::get_competency_external_structure(true));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3695,4 +3715,175 @@ class external extends external_api {
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the description of the add_related_competency_parameters() parameters.
|
||||
*
|
||||
* @return external_function_parameters.
|
||||
*/
|
||||
public static function add_related_competency_parameters() {
|
||||
$competencyid = new external_value(
|
||||
PARAM_INT,
|
||||
'The competency id',
|
||||
VALUE_REQUIRED
|
||||
);
|
||||
$relatedcompetencyid = new external_value(
|
||||
PARAM_INT,
|
||||
'The related competency id',
|
||||
VALUE_REQUIRED
|
||||
);
|
||||
$params = array(
|
||||
'competencyid' => $competencyid,
|
||||
'relatedcompetencyid' => $relatedcompetencyid
|
||||
);
|
||||
return new external_function_parameters($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Expose to AJAX
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function add_related_competency_is_allowed_from_ajax() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a related competency.
|
||||
*
|
||||
* @param int $competencyid
|
||||
* @param int $relatedcompetencyid
|
||||
* @return bool
|
||||
*/
|
||||
public static function add_related_competency($competencyid, $relatedcompetencyid) {
|
||||
$params = self::validate_parameters(self::add_related_competency_parameters(),
|
||||
array(
|
||||
'competencyid' => $competencyid,
|
||||
'relatedcompetencyid' => $relatedcompetencyid
|
||||
));
|
||||
|
||||
return api::add_related_competency($params['competencyid'], $params['relatedcompetencyid']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of add_related_competency_returns() result value.
|
||||
*
|
||||
* @return external_description
|
||||
*/
|
||||
public static function add_related_competency_returns() {
|
||||
return new external_value(PARAM_BOOL, 'True if successful.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the description of the remove_related_competency_parameters() parameters.
|
||||
*
|
||||
* @return external_function_parameters.
|
||||
*/
|
||||
public static function remove_related_competency_parameters() {
|
||||
$competencyid = new external_value(
|
||||
PARAM_INT,
|
||||
'The competency id',
|
||||
VALUE_REQUIRED
|
||||
);
|
||||
$relatedcompetencyid = new external_value(
|
||||
PARAM_INT,
|
||||
'The related competency id',
|
||||
VALUE_REQUIRED
|
||||
);
|
||||
$params = array(
|
||||
'competencyid' => $competencyid,
|
||||
'relatedcompetencyid' => $relatedcompetencyid
|
||||
);
|
||||
return new external_function_parameters($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Expose to AJAX
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function remove_related_competency_is_allowed_from_ajax() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a related competency.
|
||||
*
|
||||
* @param int $competencyid
|
||||
* @param int $relatedcompetencyid
|
||||
* @return bool
|
||||
*/
|
||||
public static function remove_related_competency($competencyid, $relatedcompetencyid) {
|
||||
$params = self::validate_parameters(self::remove_related_competency_parameters(),
|
||||
array(
|
||||
'competencyid' => $competencyid,
|
||||
'relatedcompetencyid' => $relatedcompetencyid
|
||||
));
|
||||
|
||||
return api::remove_related_competency($params['competencyid'], $params['relatedcompetencyid']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of remove_related_competency_returns() result value.
|
||||
*
|
||||
* @return external_description
|
||||
*/
|
||||
public static function remove_related_competency_returns() {
|
||||
return new external_value(PARAM_BOOL, 'True if successful.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the description of the data_for_related_competencies_section_parameters() parameters.
|
||||
*
|
||||
* @return external_function_parameters.
|
||||
*/
|
||||
public static function data_for_related_competencies_section_parameters() {
|
||||
$competencyid = new external_value(
|
||||
PARAM_INT,
|
||||
'The competency id',
|
||||
VALUE_REQUIRED
|
||||
);
|
||||
return new external_function_parameters(array('competencyid' => $competencyid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Expose to AJAX
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function data_for_related_competencies_section_is_allowed_from_ajax() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Data to render in the related competencies section.
|
||||
*
|
||||
* @param int $competencyid
|
||||
* @return array Related competencies and whether to show delete action button or not.
|
||||
*/
|
||||
public static function data_for_related_competencies_section($competencyid) {
|
||||
global $PAGE;
|
||||
|
||||
$params = self::validate_parameters(self::data_for_related_competencies_section_parameters(),
|
||||
array(
|
||||
'competencyid' => $competencyid,
|
||||
));
|
||||
|
||||
$renderable = new \tool_lp\output\related_competencies($params['competencyid']);
|
||||
$renderer = $PAGE->get_renderer('tool_lp');
|
||||
|
||||
return external_api::clean_returnvalue(self::data_for_related_competencies_section_returns(), $renderable->export_for_template($renderer));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of data_for_related_competencies_section_returns() result value.
|
||||
*
|
||||
* @return external_description
|
||||
*/
|
||||
public static function data_for_related_competencies_section_returns() {
|
||||
return new external_single_structure(array(
|
||||
'relatedcompetencies' => new external_multiple_structure(self::get_competency_external_structure(true)),
|
||||
'showdeleterelatedaction' => new external_value(PARAM_BOOL, 'Whether to show the delete relation link or not')
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
<?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 containing data for a competency.
|
||||
*
|
||||
* @package tool_lp
|
||||
* @copyright 2015 David Monllao
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace tool_lp\output;
|
||||
|
||||
use renderable;
|
||||
use templatable;
|
||||
use renderer_base;
|
||||
use stdClass;
|
||||
use moodle_url;
|
||||
use tool_lp\api;
|
||||
|
||||
/**
|
||||
* Class containing data for related competencies.
|
||||
*
|
||||
* @package tool_lp
|
||||
* @copyright 2015 David Monllao
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class related_competencies implements renderable, templatable {
|
||||
|
||||
var $relatedcompetencies = null;
|
||||
|
||||
/**
|
||||
* Construct this renderable.
|
||||
*
|
||||
* @param int $competencyid
|
||||
*/
|
||||
public function __construct($competencyid) {
|
||||
$this->relatedcompetencies = api::list_related_competencies($competencyid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Export this data so it can be used as the context for a mustache template.
|
||||
*
|
||||
* @param renderer_base $output
|
||||
* @return stdClass
|
||||
*/
|
||||
public function export_for_template(renderer_base $output) {
|
||||
$data = new stdClass();
|
||||
$data->relatedcompetencies = array();
|
||||
if ($this->relatedcompetencies) {
|
||||
foreach ($this->relatedcompetencies as $competency) {
|
||||
$data->relatedcompetencies[] = $competency->to_record();
|
||||
}
|
||||
}
|
||||
|
||||
// We checked the user permissions in the constructor.
|
||||
$data->showdeleterelatedaction = true;
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -100,12 +100,24 @@ class renderer extends plugin_renderer_base {
|
||||
|
||||
/**
|
||||
* Defer to template.
|
||||
* @param plans_page $page
|
||||
*
|
||||
* @param plans_page $page
|
||||
* @return bool|string
|
||||
*/
|
||||
public function render_plans_page(plans_page $page) {
|
||||
$data = $page->export_for_template($this);
|
||||
return parent::render_from_template('tool_lp/plans_page', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Defer to template.
|
||||
*
|
||||
* @param renderable $page
|
||||
* @return string
|
||||
*/
|
||||
public function render_related_competencies_section(renderable $page) {
|
||||
$data = $page->export_for_template($this);
|
||||
return parent::render_from_template('tool_lp/related_competencies', $data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,235 @@
|
||||
<?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 loading/storing related competencies from the DB.
|
||||
*
|
||||
* @package tool_lp
|
||||
* @copyright 2015 David Monllao
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace tool_lp;
|
||||
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* Class for loading/storing related_competencies from the DB.
|
||||
*
|
||||
* @package tool_lp
|
||||
* @copyright 2015 David Monllao
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class related_competency extends persistent {
|
||||
|
||||
/** @var int $competencyid The competency id */
|
||||
private $competencyid = 0;
|
||||
|
||||
/** @var int $relatedcompetencyid The related competency id */
|
||||
private $relatedcompetencyid = 0;
|
||||
|
||||
/**
|
||||
* Method that provides the table name matching this class.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_table_name() {
|
||||
return 'tool_lp_related_competency';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the competency id
|
||||
*
|
||||
* @return int The competency id
|
||||
*/
|
||||
public function get_competencyid() {
|
||||
return $this->competencyid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the competency id
|
||||
*
|
||||
* @param int $competencyid The competency id
|
||||
*/
|
||||
public function set_competencyid($competencyid) {
|
||||
$this->competencyid = $competencyid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the related competency id.
|
||||
*
|
||||
* @return int The related competency id.
|
||||
*/
|
||||
public function get_relatedcompetencyid() {
|
||||
return $this->relatedcompetencyid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the related competency id.
|
||||
*
|
||||
* @param int $relatedcompetencyid The related competency id.
|
||||
*/
|
||||
public function set_relatedcompetencyid($relatedcompetencyid) {
|
||||
$this->relatedcompetencyid = $relatedcompetencyid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Populate this class with data from a DB record.
|
||||
*
|
||||
* @param stdClass $record A DB record.
|
||||
* @return course_competency
|
||||
*/
|
||||
public function from_record($record) {
|
||||
if (isset($record->id)) {
|
||||
$this->set_id($record->id);
|
||||
}
|
||||
if (isset($record->competencyid)) {
|
||||
$this->set_competencyid($record->competencyid);
|
||||
}
|
||||
if (isset($record->relatedcompetencyid)) {
|
||||
$this->set_relatedcompetencyid($record->relatedcompetencyid);
|
||||
}
|
||||
if (isset($record->timecreated)) {
|
||||
$this->set_timecreated($record->timecreated);
|
||||
}
|
||||
if (isset($record->usermodified)) {
|
||||
$this->set_usermodified($record->usermodified);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a DB record from this class.
|
||||
*
|
||||
* @return stdClass
|
||||
*/
|
||||
public function to_record() {
|
||||
$record = new stdClass();
|
||||
$record->id = $this->get_id();
|
||||
$record->competencyid = $this->get_competencyid();
|
||||
$record->relatedcompetencyid = $this->get_relatedcompetencyid();
|
||||
$record->timecreated = $this->get_timecreated();
|
||||
$record->timemodified = $this->get_timemodified();
|
||||
$record->usermodified = $this->get_usermodified();
|
||||
|
||||
return $record;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a single relation specifying both competencies.
|
||||
*
|
||||
* @param int $competencyid
|
||||
* @param int $relatedcompetencyid
|
||||
* @return bool
|
||||
*/
|
||||
public function load_relation($competencyid, $relatedcompetencyid) {
|
||||
global $DB;
|
||||
|
||||
// Lower id always as competencyid so we know which one is competencyid and which one relatedcompetencyid.
|
||||
if ($competencyid > $relatedcompetencyid) {
|
||||
$this->set_competencyid($relatedcompetencyid);
|
||||
$this->set_relatedcompetencyid($competencyid);
|
||||
} else {
|
||||
$this->set_competencyid($competencyid);
|
||||
$this->set_relatedcompetencyid($relatedcompetencyid);
|
||||
}
|
||||
|
||||
// We can do it because we have bidirectional relations in the DB.
|
||||
$params = array('competencyid' => $this->get_competencyid(), 'relatedcompetencyid' => $this->get_relatedcompetencyid());
|
||||
if (!$record = $DB->get_record($this->get_table_name(), $params)) {
|
||||
return false;
|
||||
}
|
||||
$this->from_record($record);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all related competencies.
|
||||
*
|
||||
* @param int $competencyid
|
||||
* @return related_competency[]
|
||||
*/
|
||||
public function list_relations($competencyid) {
|
||||
$relatedcompetencies = $this->list_relations_many(array($competencyid));
|
||||
if (empty($relatedcompetencies) || empty($relatedcompetencies[$competencyid])) {
|
||||
return array();
|
||||
}
|
||||
|
||||
return $relatedcompetencies[$competencyid];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns related competencies Load relations accepting an array of competency ids.
|
||||
*
|
||||
* @param array $competencyids
|
||||
* @return array Indexed as array[competency][relatedcompetency] = \tool_lp\competency.
|
||||
*/
|
||||
public function list_relations_many(array $competencyids) {
|
||||
global $DB;
|
||||
|
||||
list($competencysql, $params) = $DB->get_in_or_equal($competencyids);
|
||||
$sql = "(SELECT " . $DB->sql_concat('rc.relatedcompetencyid', "'_'", 'rc.competencyid') . " AS rid,
|
||||
rc.competencyid AS relatedcompetencyid, c.*
|
||||
FROM {tool_lp_related_competency} rc
|
||||
JOIN {tool_lp_competency} c
|
||||
ON c.id = rc.relatedcompetencyid
|
||||
WHERE rc.competencyid $competencysql)
|
||||
UNION ALL
|
||||
(SELECT " . $DB->sql_concat('rc.competencyid', "'_'", 'rc.relatedcompetencyid') . " AS rid,
|
||||
rc.relatedcompetencyid AS relatedcompetencyid, c.*
|
||||
FROM {tool_lp_related_competency} rc
|
||||
JOIN {tool_lp_competency} c
|
||||
ON c.id = rc.competencyid
|
||||
WHERE rc.relatedcompetencyid $competencysql)
|
||||
ORDER BY path, sortorder ASC";
|
||||
$records = $DB->get_recordset_sql($sql, array_merge($params, $params));
|
||||
|
||||
$relations = array();
|
||||
if ($records->valid()) {
|
||||
$competencyids = array_flip($competencyids);
|
||||
foreach ($records as $record) {
|
||||
$relatedid = $record->relatedcompetencyid;
|
||||
if (empty($relations[$relatedid])) {
|
||||
$relations[$relatedid] = array();
|
||||
}
|
||||
unset($record->rid);
|
||||
unset($record->relatedcompetencyid);
|
||||
$relations[$relatedid][$record->id] = new competency(null, $record);
|
||||
}
|
||||
}
|
||||
$records->close();
|
||||
|
||||
return $relations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a relation between competencies.
|
||||
*
|
||||
* Overwriting the base class as we need to save it bidirectionally.
|
||||
*
|
||||
* @return related_competency
|
||||
*/
|
||||
public function create() {
|
||||
|
||||
// The lower id always competencyid.
|
||||
if ($this->competencyid > $this->relatedcompetencyid) {
|
||||
$competencyid = $this->competencyid;
|
||||
$this->competencyid = $this->relatedcompetencyid;
|
||||
$this->relatedcompetencyid = $competencyid;
|
||||
}
|
||||
return parent::create();
|
||||
}
|
||||
}
|
||||
@@ -121,5 +121,18 @@
|
||||
<KEY NAME="competencyid" TYPE="foreign" FIELDS="competencyid" REFTABLE="tool_lp_competency" REFFIELDS="id" COMMENT="Competency foreign key."/>
|
||||
</KEYS>
|
||||
</TABLE>
|
||||
<TABLE NAME="tool_lp_related_competency" COMMENT="Related competencies">
|
||||
<FIELDS>
|
||||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
|
||||
<FIELD NAME="competencyid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
|
||||
<FIELD NAME="relatedcompetencyid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
|
||||
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
|
||||
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
|
||||
<FIELD NAME="usermodified" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
|
||||
</FIELDS>
|
||||
<KEYS>
|
||||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
|
||||
</KEYS>
|
||||
</TABLE>
|
||||
</TABLES>
|
||||
</XMLDB>
|
||||
@@ -371,6 +371,31 @@ $functions = array(
|
||||
'description' => 'Fetch the values for a specific scale',
|
||||
'type' => 'read',
|
||||
'capabilities' => 'tool/lp:competencymanage',
|
||||
)
|
||||
),
|
||||
'tool_lp_add_related_competency' => array(
|
||||
'classname' => 'tool_lp\external',
|
||||
'methodname' => 'add_related_competency',
|
||||
'classpath' => '',
|
||||
'description' => 'Adds a related competency',
|
||||
'type' => 'write',
|
||||
'capabilities'=> 'tool/lp:competencymanage',
|
||||
),
|
||||
'tool_lp_remove_related_competency' => array(
|
||||
'classname' => 'tool_lp\external',
|
||||
'methodname' => 'remove_related_competency',
|
||||
'classpath' => '',
|
||||
'description' => 'Remove a related competency',
|
||||
'type' => 'write',
|
||||
'capabilities'=> 'tool/lp:competencymanage',
|
||||
),
|
||||
'tool_lp_data_for_related_competencies_section' => array(
|
||||
'classname' => 'tool_lp\external',
|
||||
'methodname' => 'data_for_related_competencies_section',
|
||||
'classpath' => '',
|
||||
'description' => 'Load the data for the related competencies template.',
|
||||
'type' => 'read',
|
||||
'capabilities'=> 'tool/lp:competencyread',
|
||||
),
|
||||
|
||||
);
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ $string['addnewcompetency'] = 'Add new competency';
|
||||
$string['addnewcompetencyframework'] = 'Add new competency framework';
|
||||
$string['addnewplan'] = 'Add new learning plan';
|
||||
$string['addnewtemplate'] = 'Add new learning plan template';
|
||||
$string['addrelatedcompetency'] = 'Add related competency';
|
||||
$string['competencies'] = 'Competencies';
|
||||
$string['competenciesforframework'] = 'Competencies for {$a}';
|
||||
$string['competencycreated'] = 'Competency created';
|
||||
@@ -36,6 +37,7 @@ $string['competencyframeworkcreated'] = 'Competency framework created.';
|
||||
$string['competencyframeworkname'] = 'Name';
|
||||
$string['competencyframeworks'] = 'Competency Frameworks';
|
||||
$string['competencyframeworkupdated'] = 'Competency framework updated.';
|
||||
$string['competencyrelatedcompetencies'] = '{$a} related competencies';
|
||||
$string['competencyupdated'] = 'Competency updated';
|
||||
$string['configurescale'] = 'Configure scales';
|
||||
$string['coursecompetencies'] = 'Course competencies';
|
||||
@@ -56,6 +58,7 @@ $string['edittemplate'] = 'Edit learning plan template';
|
||||
$string['editthisplan'] = 'Edit this learning plan';
|
||||
$string['erroreditingmodifiedplan'] = 'You can not edit a learning plan modified by another user if you don\'t have
|
||||
tool/lp:planmanage or tool/lp:planmanageown capabilities.';
|
||||
$string['errornocompetency'] = '{$a} competency can not be found';
|
||||
$string['errorplanstatus'] = 'Learning plans \'{$a}\' status unknown';
|
||||
$string['hidden'] = 'Hidden';
|
||||
$string['hiddenhint'] = '(hidden)';
|
||||
@@ -95,6 +98,7 @@ $string['nocompetenciesintemplate'] = 'No competencies have been linked to this
|
||||
$string['nocompetencyframeworks'] = 'No competency frameworks have been created yet.';
|
||||
$string['nocompetencyselected'] = 'No competency selected';
|
||||
$string['nolinkedcourses'] = 'No courses are using this competency';
|
||||
$string['norelatedcompetencies'] = 'No other competencies have been related to this competency.';
|
||||
$string['notemplates'] = 'No learning plan templates have been created yet.';
|
||||
$string['nouserplans'] = 'No learning plans have been created yet.';
|
||||
$string['parentcompetency'] = 'Parent competency';
|
||||
@@ -109,6 +113,7 @@ $string['plantemplate_help'] = 'A learning plan created from a template will con
|
||||
$string['planupdated'] = 'Learning plan updated';
|
||||
$string['pluginname'] = 'Learning Plans';
|
||||
$string['proficient'] = 'Proficient';
|
||||
$string['relatedcompetencies'] = 'Related competencies';
|
||||
$string['savechanges'] = 'Save changes';
|
||||
$string['scale'] = 'Scale';
|
||||
$string['scale_help'] = 'A scale determines how proficiency is measured in a competency. After selecting a scale, configure the scale, setting one of the scale values as default and marking all scale values that are deemed proficient.';
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->version = 2015052410; // The current plugin version (Date: YYYYMMDDXX).
|
||||
$plugin->version = 2015052411; // The current plugin version (Date: YYYYMMDDXX).
|
||||
$plugin->requires = 2014110400; // Requires this Moodle version.
|
||||
$plugin->component = 'tool_lp'; // Full name of the plugin (used for diagnostics).
|
||||
|
||||
|
||||
Reference in New Issue
Block a user