Esempio n. 1
0
 /**
  * Test the competency framework created event.
  *
  */
 public function test_competency_framework_created()
 {
     $this->resetAfterTest(true);
     $this->setAdminUser();
     $lpg = $this->getDataGenerator()->get_plugin_generator('core_competency');
     // Use DataGenerator to have a record framework with the right format.
     $record = $lpg->create_framework()->to_record();
     $record->id = 0;
     $record->shortname = "New shortname";
     $record->idnumber = "New idnumber";
     // Trigger and capture the event.
     $sink = $this->redirectEvents();
     $framework = api::create_framework((object) $record);
     // Get our event event.
     $events = $sink->get_events();
     $event = reset($events);
     // Check that the event data is valid.
     $this->assertInstanceOf('\\core\\event\\competency_framework_created', $event);
     $this->assertEquals($framework->get_id(), $event->objectid);
     $this->assertEquals($framework->get_contextid(), $event->contextid);
     $this->assertEventContextNotUsed($event);
     $this->assertDebuggingNotCalled();
 }
Esempio n. 2
0
 /**
  * Create a new competency framework
  *
  * @param array $competencyframework A single param with all the fields for a competency framework.
  * @return \stdClass The new record
  */
 public static function create_competency_framework($competencyframework)
 {
     global $PAGE;
     $params = self::validate_parameters(self::create_competency_framework_parameters(), array('competencyframework' => $competencyframework));
     $params = $params['competencyframework'];
     $context = self::get_context_from_params($params);
     self::validate_context($context);
     $output = $PAGE->get_renderer('core');
     unset($params['contextlevel']);
     unset($params['instanceid']);
     $params['contextid'] = $context->id;
     $params = (object) $params;
     $result = api::create_framework($params);
     $exporter = new competency_framework_exporter($result);
     $record = $exporter->export($output);
     return $record;
 }
 /**
  * Do the job.
  */
 public function import()
 {
     $record = clone $this->framework;
     unset($record->children);
     $record->scaleid = $this->get_scale_id($record->scalevalues, $record->shortname);
     $record->scaleconfiguration = $this->get_scale_configuration($record->scaleid, $record->scaleconfiguration);
     unset($record->scalevalues);
     $record->contextid = context_system::instance()->id;
     $framework = api::create_framework($record);
     // Now all the children;
     foreach ($this->framework->children as $comp) {
         $this->create_competency($comp, null, $framework);
     }
     // Now create the rules.
     foreach ($this->framework->children as $record) {
         $this->set_rules($record);
         $this->set_related($record);
     }
     $this->importer->cleanup();
     return $framework;
 }
// 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 {
    if ($data = $form->get_data()) {
        if (empty($data->id)) {
            // Create new framework.
            $data->contextid = $context->id;
            $framework = \core_competency\api::create_framework($data);
            $frameworkmanageurl = new moodle_url('/admin/tool/lp/competencies.php', array('pagecontextid' => $pagecontextid, 'competencyframeworkid' => $framework->get_id()));
            $messagesuccess = get_string('competencyframeworkcreated', 'tool_lp');
            redirect($frameworkmanageurl, $messagesuccess, 0, \core\output\notification::NOTIFY_SUCCESS);
        } else {
            \core_competency\api::update_framework($data);
            $messagesuccess = get_string('competencyframeworkupdated', 'tool_lp');
            redirect($frameworksurl, $messagesuccess, 0, \core\output\notification::NOTIFY_SUCCESS);
        }
    }
}
echo $output->header();
echo $output->heading($pagetitle, 2);
echo $output->heading($pagesubtitle, 3);
$form->display();
echo $output->footer();