diff --git a/admin/tool/lp/classes/form/template_plans.php b/admin/tool/lp/classes/form/template_plans.php new file mode 100644 index 00000000000..86f7ad7fa9f --- /dev/null +++ b/admin/tool/lp/classes/form/template_plans.php @@ -0,0 +1,53 @@ +. + +/** + * 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')); + } + +} diff --git a/admin/tool/lp/lang/en/tool_lp.php b/admin/tool/lp/lang/en/tool_lp.php index 7fe1b84715c..7c7ce7a96df 100644 --- a/admin/tool/lp/lang/en/tool_lp.php +++ b/admin/tool/lp/lang/en/tool_lp.php @@ -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'; diff --git a/admin/tool/lp/template_plans.php b/admin/tool/lp/template_plans.php index 47ef47eb1b8..6ba059e7640 100644 --- a/admin/tool/lp/template_plans.php +++ b/admin/tool/lp/template_plans.php @@ -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();