public static function update_template($record) {
        global $DB;
        static::require_enabled();
        $template = new template($record->id);

        // First we do a permissions check.
        if (!$template->can_manage()) {
            throw new required_capability_exception($template->get_context(), 'moodle/competency:templatemanage',
                'nopermissions', '');

        } else if (isset($record->contextid) && $record->contextid != $template->get('contextid')) {
            // We can never change the context of a template.
            throw new coding_exception('Changing the context of an existing tempalte is forbidden.');

        }

        $updateplans = false;
        $before = $template->to_record();

        $template->from_record($record);
        $after = $template->to_record();

        // Should we update the related plans?
        if ($before->duedate != $after->duedate ||
                $before->shortname != $after->shortname ||
                $before->description != $after->description ||
                $before->descriptionformat != $after->descriptionformat) {
            $updateplans = true;
        }

        $transaction = $DB->start_delegated_transaction();
        $success = $template->update();

        if (!$success) {
            $transaction->rollback(new moodle_exception('Error while updating the template.'));
            return $success;
        }

        // Trigger a template updated event.
        \core\event\competency_template_updated::create_from_template($template)->trigger();

        if ($updateplans) {
            plan::update_multiple_from_template($template);
        }

        $transaction->allow_commit();

        return $success;
    }
public static function update_template($record) {
        global $DB;
        static::require_enabled();
        $template = new template($record->id);

        // First we do a permissions check.
        if (!$template->can_manage()) {
            throw new required_capability_exception($template->get_context(), 'moodle/competency:templatemanage',
                'nopermissions', '');

        } else if (isset($record->contextid) && $record->contextid != $template->get('contextid')) {
            // We can never change the context of a template.
            throw new coding_exception('Changing the context of an existing tempalte is forbidden.');

        }

        $updateplans = false;
        $before = $template->to_record();

        $template->from_record($record);
        $after = $template->to_record();

        // Should we update the related plans?
        if ($before->duedate != $after->duedate ||
                $before->shortname != $after->shortname ||
                $before->description != $after->description ||
                $before->descriptionformat != $after->descriptionformat) {
            $updateplans = true;
        }

        $transaction = $DB->start_delegated_transaction();
        $success = $template->update();

        if (!$success) {
            $transaction->rollback(new moodle_exception('Error while updating the template.'));
            return $success;
        }

        // Trigger a template updated event.
        \core\event\competency_template_updated::create_from_template($template)->trigger();

        if ($updateplans) {
            plan::update_multiple_from_template($template);
        }

        $transaction->allow_commit();

        return $success;
    }
public static function update_template ( $ record ) { global $ DB ; static :: require_enabled ( ) ; $ template = new template ( $ record -> id ) ; // First we do a permissions check. if ( ! $ template -> can_manage ( ) ) { throw new required_capability_exception ( $ template -> get_context ( ) , 'moodle/competency:templatemanage' , 'nopermissions' , '' ) ; } else if ( isset ( $ record -> contextid ) && $ record -> contextid != $ template -> get ( 'contextid' ) ) { // We can never change the context of a template. throw new coding_exception ( 'Changing the context of an existing tempalte is forbidden.' ) ; } $ updateplans = false ; $ before = $ template -> to_record ( ) ; $ template -> from_record ( $ record ) ; $ after = $ template -> to_record ( ) ; // Should we update the related plans? if ( $ before -> duedate != $ after -> duedate || $ before -> shortname != $ after -> shortname || $ before -> description != $ after -> description || $ before -> descriptionformat != $ after -> descriptionformat ) { $ updateplans = true ; } $ transaction = $ DB -> start_delegated_transaction ( ) ; $ success = $ template -> update ( ) ; if ( ! $ success ) { $ transaction -> rollback ( new moodle_exception ( 'Error while updating the template.' ) ) ; return $ success ; } // Trigger a template updated event. \ core \ event \ competency_template_updated :: create_from_template ( $ template ) -> trigger ( ) ; if ( $ updateplans ) { plan :: update_multiple_from_template ( $ template ) ; } $ transaction -> allow_commit ( ) ; return $ success ; }
Update the details for a learning plan template.

Requires moodle/competency:templatemanage capability.

@param stdClass $record The new details for the template. Note - must contain an id that points to the template to update.
@return boolean
Update the details for a learning plan template .