Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
namespace mod_lti;
18
 
19
defined('MOODLE_INTERNAL') || die();
20
 
21
/**
22
 * Helper class for LTI activity.
23
 *
24
 * @package    mod_lti
25
 * @author     Andrew Madden <andrewmadden@catalyst-au.net>
26
 * @copyright  2020 Catalyst IT
27
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28
 */
29
class helper {
30
 
31
    /**
32
     * Get SQL to query DB for LTI tool proxy records.
33
     *
34
     * @param bool $orphanedonly If true, return SQL to get orphaned proxies only.
35
     * @param bool $count If true, return SQL to get the count of the records instead of the records themselves.
36
     * @return string SQL.
37
     */
38
    public static function get_tool_proxy_sql(bool $orphanedonly = false, bool $count = false): string {
39
        if ($count) {
40
            $select = "SELECT count(*) as type_count";
41
            $sort = "";
42
        } else {
43
            // We only want the fields from lti_tool_proxies table. Must define every column to be compatible with mysqli.
44
            $select = "SELECT ltp.id, ltp.name, ltp.regurl, ltp.state, ltp.guid, ltp.secret, ltp.vendorcode,
45
                              ltp.capabilityoffered, ltp.serviceoffered, ltp.toolproxy, ltp.createdby,
46
                              ltp.timecreated, ltp.timemodified";
47
            $sort = " ORDER BY ltp.name ASC, ltp.state DESC, ltp.timemodified DESC";
48
        }
49
        $from = " FROM {lti_tool_proxies} ltp";
50
        if ($orphanedonly) {
51
            $join = " LEFT JOIN {lti_types} lt ON ltp.id = lt.toolproxyid";
52
            $where = " WHERE lt.toolproxyid IS null";
53
        } else {
54
            $join = "";
55
            $where = "";
56
        }
57
 
58
        return $select . $from . $join . $where . $sort;
59
    }
60
}