{{!
    This file is part of Moodle - https://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 file/db_services

    External functions and web services db/services.php file.

    Context variables required for this template:
    * component
    * copyright
    * self
    * self.has_external
    * self.has_services
    * external
    * services

    Example context (json):
    {
        "component": "local_test",
        "copyright": "2021 David Mudrák <david@moodle.com>",
        "self": {
            "has_external": false,
            "has_services": false
        }
    }
}}
{{< common/boilerplate_php }}
{{$ description }}External functions and services provided by the plugin are declared here.{{/ description }}
{{$ package }}{{ component }}{{/ package }}
{{$ copyright }}{{ copyright }}{{/ copyright }}
{{$ extratags }}
 * @category    external
{{/extratags}}
{{/ common/boilerplate_php }}

{{# self.has_external }}
$functions = [
    {{# external }}

    '{{ component }}_{{ .name }}' => [
        'classname' => '\{{ component }}\external\{{ .name }}',
        'methodname' => 'execute',
        {{# desc }}
        'description' => '{{{ . }}}',
        {{/ desc }}
        {{# testclientpath }}
        'testclientpath' => '{{ . }}',
        {{/ testclientpath }}
        {{# type }}
        'type' => '{{ . }}',
        {{/ type }}
        {{# ajax }}
        'ajax' => {{ . }},
        {{/ ajax }}
        {{# loginrequired }}
        'loginrequired' => {{ . }},
        {{/ loginrequired }}
        {{# readonlysession }}
        'readonlysession' => {{ . }},
        {{/ readonlysession }}
    ],
    {{/ external }}
];
{{/ self.has_external }}

{{# self.has_services }}
$services = [
    {{# services }}
    '{{ .name }}' => [
        'functions' => [
            {{# functions }}
            '{{ . }}',
            {{/ functions }}
        ],
        {{# shortname }}
        'shortname' => '{{ . }}',
        {{/ shortname }}
        {{# requiredcapability }}
        'requiredcapability' => '{{ . }}',
        {{/ requiredcapability }}
        {{# restrictedusers }}
        'restrictedusers' => {{ . }},
        {{/ restrictedusers }}
        {{# enabled }}
        'enabled' => {{ . }},
        {{/ enabled }}
        {{# downloadfiles }}
        'downloadfiles' => {{ . }},
        {{/ downloadfiles }}
        {{# uploadfiles }}
        'uploadfiles' => {{ . }},
        {{/ uploadfiles }}
    ],
    {{/ services }}
];
{{/ self.has_services }}
