Skip to content

Commit

Permalink
MDL-52690 tool_lp: Only create a few plans when add template cohorts
Browse files Browse the repository at this point in the history
  • Loading branch information
Frederic Massart committed Apr 18, 2016
1 parent 68600f8 commit 5fb76f2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
3 changes: 2 additions & 1 deletion admin/tool/lp/lang/en/tool_lp.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
$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.';
Expand Down
17 changes: 14 additions & 3 deletions admin/tool/lp/template_cohorts.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,32 @@
// 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);
}
Expand Down

0 comments on commit 5fb76f2

Please sign in to comment.