-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlocallib.php
88 lines (77 loc) · 2.42 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
// This file is part of Moodle - http://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/>.
/**
* Internal library of functions for Aiken generator
*
* All the aikengen specific functions, needed to implement the module
* logic, should go here. Never include this file from your lib.php!
*
* @package tool_aikengen
* @copyright 2016 Jamal Aruna <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Checks if user has an existing file in the system
*
* @param int $userid
* @return bool
*/
function tool_aikengen_user_has_aiken_file_name($userid) {
global $DB;
$user = $DB->record_exists('tool_aiken_filename', array('userid' => $userid));
return $user;
}
/**
* Checks if user owns a file
*
* @param int $userid
* @param int $fileid
* @return bool
*/
function tool_aikengen_user_own_aiken_file_id($userid, $fileid) {
global $DB;
$own = $DB->record_exists('tool_aiken_filename', array('userid' => $userid, 'id' => $fileid));
return $own;
}
/**
* Checks if user owns a question
*
* @param int $userid
* @param int $fileid
* @param int $questionid
* @return bool
*/
function tool_aikengen_user_own_aiken_question_id($userid, $fileid, $questionid) {
global $DB;
$ownfile = $DB->record_exists('tool_aiken_filename', array('userid' => $userid, 'id' => $fileid));
$ownquestion = $DB->record_exists('tool_aiken_question', array('id' => $questionid, 'fileid' => $fileid));
$own = false;
if ($ownfile && $ownquestion) {
$own = true;
}
return $own;
}
/**
* Get the records of files owned by a user
*
* @param int $userid
* @return object
*/
function tool_aikengen_get_aiken_file_name($userid) {
global $DB;
$result = $DB->get_records_menu('tool_aiken_filename', array('userid' => $userid), null, 'id, filename');
return $result;
}