-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocallib.php
58 lines (48 loc) · 1.83 KB
/
locallib.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
/**
* SUAP Integration
*
* This module provides extensive analytics on a platform of choice
* Currently support Google Analytics and Piwik
*
* @package auth_suap
* @category upgrade
* @copyright 2020 Kelson Medeiros <kelsoncm@gmail.com>
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
function get_last_sort_order($tablename) {
global $DB;
$l = $DB->get_record_sql('SELECT coalesce(max(sortorder), 0) + 1 as sortorder from {' . $tablename . '}');
return $l->sortorder;
}
function get_or_create($tablename, $keys, $values) {
global $DB;
$record = $DB->get_record($tablename, $keys);
if (!$record) {
$record = (object)array_merge($keys, $values);
$record->id = $DB->insert_record($tablename, $record);
}
return $record;
}
function create_or_update($tablename, $keys, $inserts, $updates=[], $insert_only=[]) {
global $DB;
$record = $DB->get_record($tablename, $keys);
if ($record) {
foreach (array_merge($keys, $inserts, $updates) as $attr => $value) {
$record->{$attr} = $value;
}
$DB->update_record($tablename, $record);
} else {
$record = (object)array_merge($keys, $inserts, $insert_only);
$record->id = $DB->insert_record($tablename, $record);
}
return $record;
}
function create_setting_configtext($settings, $name, $default='') {
$theme_name = 'auth_suap';
$settings->add(new admin_setting_configtext("$theme_name/$name", get_string($name, $theme_name), get_string("{$name}_desc", $theme_name), $default));
}
function create_setting_configtextarea($settings, $name, $default='') {
$theme_name = 'auth_suap';
$settings->add(new admin_setting_configtextarea("$theme_name/$name", get_string($name, $theme_name), get_string("{$name}_desc", $theme_name), $default));
}