[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * List cohorts linked to a template. 19 * 20 * @package tool_lp 21 * @copyright 2015 Frédéric Massart - FMCorz.net 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 require(__DIR__ . '/../../../config.php'); 26 27 $id = required_param('id', PARAM_INT); 28 $pagecontextid = required_param('pagecontextid', PARAM_INT); // Reference to the context we came from. 29 30 require_login(0, false); 31 \core_competency\api::require_enabled(); 32 33 $template = \core_competency\api::read_template($id); 34 $context = $template->get_context(); 35 $canreadtemplate = $template->can_read(); 36 $canmanagetemplate = $template->can_manage(); 37 $duedatereached = $template->get_duedate() > 0 && $template->get_duedate() < time(); 38 39 if (!$canreadtemplate) { 40 throw new required_capability_exception($context, 'moodle/competency:templateview', 'nopermissions', ''); 41 } 42 43 // Set up the page. 44 $url = new moodle_url('/admin/tool/lp/template_cohorts.php', array( 45 'id' => $id, 46 'pagecontextid' => $pagecontextid 47 )); 48 list($title, $subtitle) = \tool_lp\page_helper::setup_for_template($pagecontextid, $url, $template, 49 get_string('cohortssyncedtotemplate', 'tool_lp')); 50 51 // Remove cohort. 52 if ($canmanagetemplate && ($removecohort = optional_param('removecohort', false, PARAM_INT)) !== false && confirm_sesskey()) { 53 \core_competency\api::delete_template_cohort($template, $removecohort); 54 } 55 56 // Capture the form submission. 57 $form = new \tool_lp\form\template_cohorts($url->out(false), array('pagecontextid' => $pagecontextid)); 58 if ($canmanagetemplate && ($data = $form->get_data()) && !empty($data->cohorts)) { 59 $maxtocreate = 50; 60 $maxreached = false; 61 $i = 0; 62 foreach ($data->cohorts as $cohortid) { 63 64 // Create the template/cohort relationship. 65 $relation = \core_competency\api::create_template_cohort($template, $cohortid); 66 67 // Create a plan for each member if template visible, and the due date is not reached, and we didn't reach our limit yet. 68 if ($template->get_visible() && $i < $maxtocreate && !$duedatereached) { 69 70 // Only create a few plans right now. 71 $tocreate = \core_competency\template_cohort::get_missing_plans($template->get_id(), $cohortid); 72 if ($i + count($tocreate) <= $maxtocreate) { 73 $i += \core_competency\api::create_plans_from_template_cohort($template, $cohortid); 74 } else { 75 $maxreached = true; 76 } 77 } 78 } 79 if ($i == 0) { 80 $notification = get_string('noplanswerecreated', 'tool_lp'); 81 } else if ($i == 1) { 82 $notification = get_string('oneplanwascreated', 'tool_lp'); 83 } else if ($maxreached) { 84 $notification = get_string('aplanswerecreatedmoremayrequiresync', 'tool_lp', $i); 85 } else { 86 $notification = get_string('aplanswerecreated', 'tool_lp', $i); 87 } 88 redirect($url, $notification); 89 } 90 91 // Display the page. 92 $output = $PAGE->get_renderer('tool_lp'); 93 echo $output->header(); 94 echo $output->heading($title); 95 echo $output->heading($subtitle, 3); 96 if ($canmanagetemplate) { 97 if ($template->get_visible() == false) { 98 // Display message to prevent that cohort will not be synchronzed if the template is hidden. 99 echo $output->notify_message(get_string('templatecohortnotsyncedwhilehidden', 'tool_lp')); 100 } else if ($duedatereached) { 101 echo $output->notify_message(get_string('templatecohortnotsyncedwhileduedateispassed', 'tool_lp')); 102 } 103 echo $form->display(); 104 } 105 106 $page = new \tool_lp\output\template_cohorts_page($template, $url); 107 echo $output->render($page); 108 echo $output->footer();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |