MDL-51033 tool_lp: Create user plans from page listing template plans

This commit is contained in:
Frederic Massart
2016-04-18 10:58:44 +08:00
parent ac9e4b8188
commit a8a05b81cd
3 changed files with 79 additions and 0 deletions
@@ -0,0 +1,53 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Template plans form.
*
* @package tool_lp
* @copyright 2015 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lp\form;
defined('MOODLE_INTERNAL') || die();
use moodleform;
require_once($CFG->libdir . '/formslib.php');
/**
* Template plans form class.
*
* @package tool_lp
* @copyright 2015 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class template_plans extends moodleform {
public function definition() {
$mform = $this->_form;
$options = array(
'ajax' => 'tool_lp/form-user-selector',
'multiple' => true,
'data-capability' => 'tool/lp:planmanage'
);
$mform->addElement('autocomplete', 'users', get_string('selectuserstocreateplansfor', 'tool_lp'), array(), $options);
$mform->addElement('submit', 'submit', get_string('createplans', 'tool_lp'));
}
}
+5
View File
@@ -30,6 +30,7 @@ $string['addnewplan'] = 'Add new learning plan';
$string['addnewtemplate'] = 'Add new learning plan template';
$string['addrelatedcompetency'] = 'Add related competency';
$string['allchildrenarecomplete'] = 'All children are complete';
$string['aplanswerecreated'] = '{$a} plans were created';
$string['assigncohorts'] = 'Assign cohorts';
$string['cannotaddrules'] = 'This competency cannot be configured.';
$string['cohortssyncedtotemplate'] = 'Cohorts synced to this template';
@@ -56,6 +57,7 @@ $string['configurescale'] = 'Configure scales';
$string['coursecompetencies'] = 'Course competencies';
$string['coursesusingthiscompetency'] = 'Courses linked to this competency';
$string['coveragesummary'] = '{$a->competenciescoveredcount} of {$a->competenciescount} competencies are covered ( {$a->coveragepercentage} % )';
$string['createplans'] = 'Create plans';
$string['default'] = 'Default';
$string['deletecompetency'] = 'Delete competency \'{$a}\'?';
$string['deletecompetencyframework'] = 'Delete competency framework \'{$a}\'?';
@@ -125,9 +127,11 @@ $string['nocompetenciesintemplate'] = 'No competencies have been linked to this
$string['nocompetencyframeworks'] = 'No competency frameworks have been created yet.';
$string['nocompetencyselected'] = 'No competency selected';
$string['nolinkedcourses'] = 'No courses are linked to this competency';
$string['noplanswerecreated'] = 'No plans were created.';
$string['norelatedcompetencies'] = 'No other competencies have been related to this competency.';
$string['notemplates'] = 'No learning plan templates have been created yet.';
$string['nouserplans'] = 'No learning plans have been created yet.';
$string['oneplanwascreated'] = 'A plan was created';
$string['outcome'] = 'Outcome';
$string['parentcompetency'] = 'Parent competency';
$string['plancreated'] = 'Learning plan created';
@@ -154,6 +158,7 @@ $string['scalevalue'] = 'Scale value';
$string['search'] = 'Search...';
$string['selectcompetencymovetarget'] = 'Select a location to move this competency to:';
$string['selectedcompetency'] = 'Selected competency';
$string['selectuserstocreateplansfor'] = 'Select users to create plans for';
$string['shortname'] = 'Name';
$string['state'] = 'State';
$string['status'] = 'Status';
+21
View File
@@ -40,11 +40,32 @@ $url = new moodle_url('/admin/tool/lp/template_plans.php', array(
));
list($title, $subtitle) = \tool_lp\page_helper::setup_for_template($pagecontextid, $url, $template, get_string('userplans', 'tool_lp'));
// Capture the form submission.
$form = new \tool_lp\form\template_plans($url->out(false));
if (($data = $form->get_data()) && !empty($data->users)) {
$i = 0;
foreach ($data->users as $userid) {
$result = \tool_lp\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);
}
// Display the page.
$output = $PAGE->get_renderer('tool_lp');
echo $output->header();
echo $output->heading($title);
echo $output->heading($subtitle, 3);
echo $form->display();
$page = new \tool_lp\output\template_plans_page($template, $url);
echo $output->render($page);
echo $output->footer();