weekly on-sync release 3.2dev
[moodle.git] / admin / tool / mobile / classes / api.php
CommitLineData
b2478ed0
JL
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 * Class for Moodle Mobile tools.
19 *
20 * @package tool_mobile
21 * @copyright 2016 Juan Leyva
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 * @since Moodle 3.1
24 */
25namespace tool_mobile;
26
27use core_component;
28use core_plugin_manager;
29
30/**
31 * API exposed by tool_mobile
32 *
33 * @copyright 2016 Juan Leyva
34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35 * @since Moodle 3.1
36 */
37class api {
38
39 /**
40 * Returns a list of Moodle plugins supporting the mobile app.
41 *
42 * @return array an array of objects containing the plugin information
43 */
44 public static function get_plugins_supporting_mobile() {
45 global $CFG;
46 require_once($CFG->libdir . '/adminlib.php');
47
48 $pluginsinfo = [];
49 $plugintypes = core_component::get_plugin_types();
50
51 foreach ($plugintypes as $plugintype => $unused) {
52 // We need to include files here.
53 $pluginswithfile = core_component::get_plugin_list_with_file($plugintype, 'db' . DIRECTORY_SEPARATOR . 'mobile.php');
54 foreach ($pluginswithfile as $plugin => $notused) {
55 $path = core_component::get_plugin_directory($plugintype, $plugin);
56 $component = $plugintype . '_' . $plugin;
57 $version = get_component_version($component);
58
59 require_once("$path/db/mobile.php");
60 foreach ($addons as $addonname => $addoninfo) {
61 $plugininfo = array(
62 'component' => $component,
63 'version' => $version,
64 'addon' => $addonname,
b4baee42 65 'dependencies' => !empty($addoninfo['dependencies']) ? $addoninfo['dependencies'] : array(),
b2478ed0
JL
66 'fileurl' => '',
67 'filehash' => '',
68 'filesize' => 0
69 );
70
71 // All the mobile packages must be under the plugin mobile directory.
72 $package = $path . DIRECTORY_SEPARATOR . 'mobile' . DIRECTORY_SEPARATOR . $addonname . '.zip';
73 if (file_exists($package)) {
74 $plugininfo['fileurl'] = $CFG->wwwroot . '' . str_replace($CFG->dirroot, '', $package);
75 $plugininfo['filehash'] = sha1_file($package);
76 $plugininfo['filesize'] = filesize($package);
77 }
78 $pluginsinfo[] = $plugininfo;
79 }
80 }
81 }
82 return $pluginsinfo;
83 }
84
85}