/** * Test updating a template. * * @expectedException coding_exception */ public function test_update_template() { $cat = $this->getDataGenerator()->create_category(); $this->resetAfterTest(true); $this->setAdminUser(); $syscontext = context_system::instance(); $template = api::create_template((object) array('shortname' => 'testing', 'contextid' => $syscontext->id)); $this->assertEquals('testing', $template->get_shortname()); $this->assertEquals($syscontext->id, $template->get_contextid()); // Simple update. api::update_template((object) array('id' => $template->get_id(), 'shortname' => 'success')); $template = api::read_template($template->get_id()); $this->assertEquals('success', $template->get_shortname()); // Trying to change the context. api::update_template((object) array('id' => $template->get_id(), 'contextid' => context_coursecat::instance($cat->id))); }
// You should have received a copy of the GNU General Public License // along with Moodle. If not, see <http://www.gnu.org/licenses/>. /** * List cohorts linked to a template. * * @package tool_lp * @copyright 2015 Frédéric Massart - FMCorz.net * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ require __DIR__ . '/../../../config.php'; $id = required_param('id', PARAM_INT); $pagecontextid = required_param('pagecontextid', PARAM_INT); // Reference to the context we came from. require_login(0, false); \core_competency\api::require_enabled(); $template = \core_competency\api::read_template($id); $context = $template->get_context(); $canreadtemplate = $template->can_read(); $canmanagetemplate = $template->can_manage(); $duedatereached = $template->get_duedate() > 0 && $template->get_duedate() < time(); if (!$canreadtemplate) { throw new required_capability_exception($context, 'moodle/competency:templateview', 'nopermissions', ''); } // Set up the page. $url = new moodle_url('/admin/tool/lp/template_cohorts.php', array('id' => $id, 'pagecontextid' => $pagecontextid)); list($title, $subtitle) = \tool_lp\page_helper::setup_for_template($pagecontextid, $url, $template, get_string('cohortssyncedtotemplate', 'tool_lp')); // Remove cohort. if ($canmanagetemplate && ($removecohort = optional_param('removecohort', false, PARAM_INT)) !== false && confirm_sesskey()) { \core_competency\api::delete_template_cohort($template, $removecohort); } // Capture the form submission.
/** * Log the template viewed event. * * @param int $id the template id * @return array of warnings and status result * @throws moodle_exception */ public static function template_viewed($id) { $params = self::validate_parameters(self::view_book_parameters(), array('id' => $id)); $template = api::read_template($params['id']); self::validate_context($template->get_context()); return api::template_viewed($params['id']); }
/** * Loads the data required to render the template_competencies_page template. * * @param int $templateid Template id. * @param array $pagecontext The page context info. * @return boolean */ public static function data_for_template_competencies_page($templateid, $pagecontext) { global $PAGE; $params = self::validate_parameters(self::data_for_template_competencies_page_parameters(), array('templateid' => $templateid, 'pagecontext' => $pagecontext)); $context = self::get_context_from_params($params['pagecontext']); self::validate_context($context); $template = api::read_template($params['templateid']); $renderable = new output\template_competencies_page($template, $context); $renderer = $PAGE->get_renderer('tool_lp'); $data = $renderable->export_for_template($renderer); return $data; }