Esempio n. 1
0
 public function test_update_framework_scale()
 {
     $this->setUser($this->creator);
     $lpg = $this->getDataGenerator()->get_plugin_generator('core_competency');
     $s1 = $this->getDataGenerator()->create_scale();
     $f1 = $lpg->create_framework(array('scaleid' => 1));
     $f2 = $lpg->create_framework(array('scaleid' => 1));
     $c1 = $lpg->create_competency(array('competencyframeworkid' => $f1->get_id()));
     $c2 = $lpg->create_competency(array('competencyframeworkid' => $f2->get_id()));
     $this->assertEquals(1, $f1->get_scaleid());
     // Make the scale of f2 being used.
     $lpg->create_user_competency(array('userid' => $this->user->id, 'competencyid' => $c2->get_id()));
     // Changing the framework where the scale is not used.
     $result = $this->update_competency_framework($f1->get_id(), 3, true);
     $f1 = new \core_competency\competency_framework($f1->get_id());
     $this->assertEquals(3, $f1->get_scaleid());
     // Changing the framework where the scale is used.
     try {
         $result = $this->update_competency_framework($f2->get_id(), 4, true);
         $this->fail('The scale cannot be changed once used.');
     } catch (\core_competency\invalid_persistent_exception $e) {
         $this->assertRegexp('/scaleid/', $e->getMessage());
     }
 }
 * This page lets users to manage site wide competencies.
 *
 * @package    tool_lp
 * @copyright  2015 Damyon Wiese
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
require_once __DIR__ . '/../../../config.php';
require_once $CFG->libdir . '/adminlib.php';
$id = optional_param('id', 0, PARAM_INT);
$returntype = optional_param('return', null, PARAM_TEXT);
$pagecontextid = required_param('pagecontextid', PARAM_INT);
// Reference to where we can from.
$framework = null;
if (!empty($id)) {
    // Always use the context from the framework when it exists.
    $framework = new \core_competency\competency_framework($id);
    $context = $framework->get_context();
} else {
    $context = context::instance_by_id($pagecontextid);
}
// We check that we have the permission to edit this framework, in its own context.
require_login();
\core_competency\api::require_enabled();
require_capability('moodle/competency:competencymanage', $context);
// Set up the framework page.
list($pagetitle, $pagesubtitle, $url, $frameworksurl) = tool_lp\page_helper::setup_for_framework($id, $pagecontextid, $framework, $returntype);
$output = $PAGE->get_renderer('tool_lp');
$form = new \tool_lp\form\competency_framework($url->out(false), array('context' => $context, 'persistent' => $framework));
if ($form->is_cancelled()) {
    redirect($frameworksurl);
} else {