Ejemplo n.º 1
0
 public function test_sync_plans_from_cohorts_with_passed_duedate()
 {
     global $DB;
     $this->resetAfterTest(true);
     $this->setAdminUser();
     $dg = $this->getDataGenerator();
     $lpg = $dg->get_plugin_generator('core_competency');
     $user1 = $dg->create_user();
     $user2 = $dg->create_user();
     $cohort = $dg->create_cohort();
     $tpl = $lpg->create_template(array('duedate' => time() + 1000));
     $templatecohort = api::create_template_cohort($tpl->get_id(), $cohort->id);
     $task = \core\task\manager::get_scheduled_task('\\core\\task\\sync_plans_from_template_cohorts_task');
     // Add 1 user to the cohort.
     cohort_add_member($cohort->id, $user1->id);
     // Creating plans from template cohort.
     $task->execute();
     $this->assertEquals(1, \core_competency\plan::count_records());
     // Now add another user, but this time the template will be expired.
     cohort_add_member($cohort->id, $user2->id);
     $record = $tpl->to_record();
     $record->duedate = time() - 10000;
     $DB->update_record(\core_competency\template::TABLE, $record);
     $tpl->read();
     $task->execute();
     $this->assertEquals(1, \core_competency\plan::count_records());
     // Still only one plan.
     // Pretend it wasn't expired.
     $tpl->set_duedate(time() + 100);
     $tpl->update();
     $task->execute();
     $this->assertEquals(2, \core_competency\plan::count_records());
     // Now there is two.
 }
Ejemplo n.º 2
0
 /**
  * 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);
 }
Ejemplo n.º 3
0
// Set up the page.
$url = new moodle_url('/admin/tool/lp/template_cohorts.php', array('id' => $id, 'pagecontextid' => $pagecontextid));
list($title, $subtitle) = \tool_lp\page_helper::setup_for_template($pagecontextid, $url, $template, get_string('cohortssyncedtotemplate', 'tool_lp'));
// Remove cohort.
if ($canmanagetemplate && ($removecohort = optional_param('removecohort', false, PARAM_INT)) !== false && confirm_sesskey()) {
    \core_competency\api::delete_template_cohort($template, $removecohort);
}
// Capture the form submission.
$form = new \tool_lp\form\template_cohorts($url->out(false), array('pagecontextid' => $pagecontextid));
if ($canmanagetemplate && ($data = $form->get_data()) && !empty($data->cohorts)) {
    $maxtocreate = 50;
    $maxreached = false;
    $i = 0;
    foreach ($data->cohorts as $cohortid) {
        // Create the template/cohort relationship.
        $relation = \core_competency\api::create_template_cohort($template, $cohortid);
        // Create a plan for each member if template visible, and the due date is not reached, and we didn't reach our limit yet.
        if ($template->get_visible() && $i < $maxtocreate && !$duedatereached) {
            // Only create a few plans right now.
            $tocreate = \core_competency\template_cohort::get_missing_plans($template->get_id(), $cohortid);
            if ($i + count($tocreate) <= $maxtocreate) {
                $i += \core_competency\api::create_plans_from_template_cohort($template, $cohortid);
            } else {
                $maxreached = true;
            }
        }
    }
    if ($i == 0) {
        $notification = get_string('noplanswerecreated', 'tool_lp');
    } else {
        if ($i == 1) {