/**
  * Do the job.
  */
 public function execute()
 {
     if (!api::is_enabled()) {
         return;
     }
     $missingplans = template_cohort::get_all_missing_plans(self::get_last_run_time());
     foreach ($missingplans as $missingplan) {
         foreach ($missingplan['userids'] as $userid) {
             try {
                 api::create_plan_from_template($missingplan['template'], $userid);
             } catch (\Exception $e) {
                 debugging(sprintf('Exception caught while creating plan for user %d from template %d. Message: %s', $userid, $missingplan['template']->get_id(), $e->getMessage()), DEBUG_DEVELOPER);
             }
         }
     }
 }
示例#2
0
文件: api_test.php 项目: dg711/moodle
 /**
  * Test when using hidden template in plan/cohort.
  */
 public function test_hidden_template()
 {
     $this->resetAfterTest(true);
     $this->setAdminUser();
     $dg = $this->getDataGenerator();
     $lpg = $this->getDataGenerator()->get_plugin_generator('core_competency');
     $user = $dg->create_user();
     // Create a cohort.
     $cohort = $dg->create_cohort();
     // Create a hidden template.
     $template = $lpg->create_template(array('visible' => false));
     // Can not link hidden template to plan.
     try {
         api::create_plan_from_template($template->get_id(), $user->id);
         $this->fail('Can not link a hidden template to plan');
     } catch (coding_exception $e) {
         $this->assertTrue(true);
     }
     // Can associate hidden template to cohort.
     $templatecohort = api::create_template_cohort($template->get_id(), $cohort->id);
     $this->assertInstanceOf('\\core_competency\\template_cohort', $templatecohort);
 }
示例#3
0
$template = \core_competency\api::read_template($id);
$context = $template->get_context();
$canreadtemplate = $template->can_read();
$canmanagetemplate = $template->can_manage();
if (!$canreadtemplate) {
    throw new required_capability_exception($context, 'moodle/competency:templateview', 'nopermissions', '');
}
// Set up the page.
$url = new moodle_url('/admin/tool/lp/template_plans.php', array('id' => $id, 'pagecontextid' => $pagecontextid));
list($title, $subtitle) = \tool_lp\page_helper::setup_for_template($pagecontextid, $url, $template, get_string('userplans', 'core_competency'));
// Capture the form submission.
$form = new \tool_lp\form\template_plans($url->out(false));
if ($canmanagetemplate && ($data = $form->get_data()) && !empty($data->users)) {
    $i = 0;
    foreach ($data->users as $userid) {
        $result = \core_competency\api::create_plan_from_template($template->get_id(), $userid);
        if ($result) {
            $i++;
        }
    }
    if ($i == 0) {
        $notification = get_string('noplanswerecreated', 'tool_lp');
    } else {
        if ($i == 1) {
            $notification = get_string('oneplanwascreated', 'tool_lp');
        } else {
            $notification = get_string('aplanswerecreated', 'tool_lp', $i);
        }
    }
    redirect($url, $notification);
}