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 |
|
|
|
18 |
namespace tool_licensemanager;
|
|
|
19 |
|
|
|
20 |
use moodle_url;
|
|
|
21 |
|
|
|
22 |
|
|
|
23 |
/**
|
|
|
24 |
* License manager helper class.
|
|
|
25 |
*
|
|
|
26 |
* @package tool_licensemanager
|
|
|
27 |
* @copyright 2019 Tom Dickman <tomdickman@catalyst-au.net>
|
|
|
28 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
29 |
*/
|
|
|
30 |
class helper {
|
|
|
31 |
|
|
|
32 |
/**
|
|
|
33 |
* Moodle relative path to the licenses manager.
|
|
|
34 |
*/
|
|
|
35 |
const MANAGER_PATH = '/admin/tool/licensemanager/index.php';
|
|
|
36 |
|
|
|
37 |
/**
|
|
|
38 |
* Get the URL for viewing the license manager interface.
|
|
|
39 |
*
|
|
|
40 |
* @return \moodle_url
|
|
|
41 |
*/
|
|
|
42 |
public static function get_licensemanager_url(): moodle_url {
|
|
|
43 |
return new moodle_url(self::MANAGER_PATH);
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
/**
|
|
|
47 |
* Get the URL for endpoint enabling a license.
|
|
|
48 |
*
|
|
|
49 |
* @param string $licenseshortname the shortname of license to enable.
|
|
|
50 |
*
|
|
|
51 |
* @return \moodle_url
|
|
|
52 |
*/
|
|
|
53 |
public static function get_enable_license_url(string $licenseshortname): moodle_url {
|
|
|
54 |
$url = new moodle_url(self::MANAGER_PATH,
|
|
|
55 |
['action' => manager::ACTION_ENABLE, 'license' => $licenseshortname, 'sesskey' => sesskey()]);
|
|
|
56 |
|
|
|
57 |
return $url;
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
/**
|
|
|
61 |
* Get the URL for endpoint disabling a license.
|
|
|
62 |
*
|
|
|
63 |
* @param string $licenseshortname the shortname of license to disable.
|
|
|
64 |
*
|
|
|
65 |
* @return \moodle_url
|
|
|
66 |
*/
|
|
|
67 |
public static function get_disable_license_url(string $licenseshortname): moodle_url {
|
|
|
68 |
$url = new moodle_url(self::MANAGER_PATH,
|
|
|
69 |
['action' => manager::ACTION_DISABLE, 'license' => $licenseshortname, 'sesskey' => sesskey()]);
|
|
|
70 |
|
|
|
71 |
return $url;
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
/**
|
|
|
75 |
* Get the URL endpoint to create a new license.
|
|
|
76 |
*
|
|
|
77 |
* @return \moodle_url
|
|
|
78 |
*/
|
|
|
79 |
public static function get_create_license_url(): moodle_url {
|
|
|
80 |
$url = self::get_licensemanager_url();
|
|
|
81 |
$url->params(['action' => manager::ACTION_CREATE]);
|
|
|
82 |
return $url;
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
/**
|
|
|
86 |
* Get the URL endpoint to update an existing license.
|
|
|
87 |
*
|
|
|
88 |
* @param string $licenseshortname the shortname of license to update.
|
|
|
89 |
*
|
|
|
90 |
* @return \moodle_url
|
|
|
91 |
*/
|
|
|
92 |
public static function get_update_license_url(string $licenseshortname): moodle_url {
|
|
|
93 |
$url = self::get_licensemanager_url();
|
|
|
94 |
$url->params(['action' => manager::ACTION_UPDATE, 'license' => $licenseshortname]);
|
|
|
95 |
return $url;
|
|
|
96 |
}
|
|
|
97 |
|
|
|
98 |
/**
|
|
|
99 |
* Get the URL endpoint to move a license up order.
|
|
|
100 |
*
|
|
|
101 |
* @param string $licenseshortname the shortname of license to move up.
|
|
|
102 |
*
|
|
|
103 |
* @return \moodle_url
|
|
|
104 |
*/
|
|
|
105 |
public static function get_moveup_license_url(string $licenseshortname): moodle_url {
|
|
|
106 |
$url = new moodle_url(self::MANAGER_PATH,
|
|
|
107 |
['action' => manager::ACTION_MOVE_UP, 'license' => $licenseshortname, 'sesskey' => sesskey()]);
|
|
|
108 |
|
|
|
109 |
return $url;
|
|
|
110 |
}
|
|
|
111 |
|
|
|
112 |
/**
|
|
|
113 |
* Get the URL endpoint to move a license down order.
|
|
|
114 |
*
|
|
|
115 |
* @param string $licenseshortname the shortname of license to move down.
|
|
|
116 |
*
|
|
|
117 |
* @return \moodle_url
|
|
|
118 |
*/
|
|
|
119 |
public static function get_movedown_license_url(string $licenseshortname): moodle_url {
|
|
|
120 |
$url = new moodle_url(self::MANAGER_PATH,
|
|
|
121 |
['action' => manager::ACTION_MOVE_DOWN, 'license' => $licenseshortname, 'sesskey' => sesskey()]);
|
|
|
122 |
|
|
|
123 |
return $url;
|
|
|
124 |
}
|
|
|
125 |
|
|
|
126 |
/**
|
|
|
127 |
* Convert a license version number string to a UNIX epoch.
|
|
|
128 |
*
|
|
|
129 |
* @param string $version
|
|
|
130 |
*
|
|
|
131 |
* @return int $epoch
|
|
|
132 |
*/
|
|
|
133 |
public static function convert_version_to_epoch(string $version): int {
|
|
|
134 |
$date = substr($version, 0, 8);
|
|
|
135 |
$epoch = strtotime($date);
|
|
|
136 |
|
|
|
137 |
return $epoch;
|
|
|
138 |
}
|
|
|
139 |
}
|