MDL-52690 tool_lp: Only create a few plans when add template cohorts

This commit is contained in:
Frederic Massart
2016-04-18 10:58:49 +08:00
parent 68600f80e7
commit 5fb76f227f
2 changed files with 16 additions and 4 deletions
+2 -1
View File
@@ -34,7 +34,8 @@ $string['addnewuserevidence'] = 'Add new evidence';
$string['addrelatedcompetency'] = 'Add related competency';
$string['aisrequired'] = '\'{$a}\' is required';
$string['allchildrenarecomplete'] = 'All children are complete';
$string['aplanswerecreated'] = '{$a} plans were created';
$string['aplanswerecreated'] = '{$a} plans were created.';
$string['aplanswerecreatedmoremayrequiresync'] = '{$a} plans were created, more will be created during the next synchronization.';
$string['assigncohorts'] = 'Assign cohorts';
$string['cannotaddrules'] = 'This competency cannot be configured.';
$string['cannotcreateuserplanswhentemplatehidden'] = 'New user plans can not be created while this template is hidden.';
+14 -3
View File
@@ -54,21 +54,32 @@ if ($canmanagetemplate && ($removecohort = optional_param('removecohort', false,
// 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 = \tool_lp\api::create_template_cohort($template, $cohortid);
// Create a plan for each member if template visible.
if ($template->get_visible()) {
$i += \tool_lp\api::create_plans_from_template_cohort($template, $cohortid);
// Create a plan for each member if template visible, and we didn't reach our limit yet.
if ($template->get_visible() && $i < $maxtocreate) {
// Only create a few plans right now.
$tocreate = \tool_lp\template_cohort::get_missing_plans($template->get_id(), $cohortid);
if ($i + count($tocreate) <= $maxtocreate) {
$i += \tool_lp\api::create_plans_from_template_cohort($template, $cohortid);
} else {
$maxreached = true;
}
}
}
if ($i == 0) {
$notification = get_string('noplanswerecreated', 'tool_lp');
} else if ($i == 1) {
$notification = get_string('oneplanwascreated', 'tool_lp');
} else if ($maxreached) {
$notification = get_string('aplanswerecreatedmoremayrequiresync', 'tool_lp', $i);
} else {
$notification = get_string('aplanswerecreated', 'tool_lp', $i);
}