Passed
Pull Request — master (#6448)
by David
16:53 queued 08:47
created

BoincBatch::get_cpu_time()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
// This file is part of BOINC.
3
// http://boinc.berkeley.edu
4
// Copyright (C) 2011 University of California
5
//
6
// BOINC is free software; you can redistribute it and/or modify it
7
// under the terms of the GNU Lesser General Public License
8
// as published by the Free Software Foundation,
9
// either version 3 of the License, or (at your option) any later version.
10
//
11
// BOINC is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
// See the GNU Lesser General Public License for more details.
15
//
16
// You should have received a copy of the GNU Lesser General Public License
17
// along with BOINC.  If not, see <http://www.gnu.org/licenses/>.
18
19
// Tables related to job submission
20
21
require_once("../inc/common_defs.inc");
22
23
class BoincBatch {
24
    static function lookup_id($id) {
25
        $db = BoincDb::get();
26
        return $db->lookup_id($id, 'batch', 'BoincBatch');
27
    }
28
    static function lookup_name($name) {
29
        $db = BoincDb::get();
30
        $name = BoincDb::escape_string($name);
31
        return $db->lookup('batch', 'BoincBatch', "name='$name'");
32
    }
33
    static function enum($clause) {
34
        $db = BoincDb::get();
35
        return $db->enum('batch', 'BoincBatch', $clause);
36
    }
37
    static function insert($clause) {
38
        $db = BoincDb::get();
39
        $ret = $db->insert('batch', $clause);
40
        if (!$ret) return $ret;
41
        return $db->insert_id();
42
    }
43
    function update($clause) {
44
        $db = BoincDb::get();
45
        return $db->update($this, 'batch', $clause);
46
    }
47
    static function update_aux($clause) {
48
        $db = BoincDb::get();
49
        return $db->update_aux('batch', $clause);
50
    }
51
    static function delete_batch($batch_id) {
52
        $db = BoincDb::get();
53
        return $db->delete_aux('batch', "id = $batch_id");
54
    }
55
    function get_cpu_time() {
56
        $db = BoincDb::get();
57
        $x = $db->get_double(
58
            "select sum(result.cpu_time) as total_cpu_time from workunit join result on workunit.id = result.workunitid where workunit.batch=$this->id",
0 ignored issues
show
Bug Best Practice introduced by
The property id does not exist on BoincBatch. Did you maybe forget to declare it?
Loading history...
59
            "total_cpu_time"
60
        );
61
        return $x;
62
    }
63
}
64
65
class BoincUserSubmit {
66
    static function enum($clause) {
67
        $db = BoincDb::get();
68
        return $db->enum('user_submit', 'BoincUserSubmit', $clause);
69
    }
70
    static function insert($clause) {
71
        $db = BoincDb::get();
72
        $ret = $db->insert('user_submit', $clause);
73
        if (!$ret) return false;
74
        return true;
75
    }
76
    static function lookup_userid($user_id) {
77
        $db = BoincDb::get();
78
        return $db->lookup('user_submit', 'BoincUserSubmit', "user_id=$user_id");
79
    }
80
    function update($clause) {
81
        $db = BoincDb::get();
82
        return $db->update_aux('user_submit', "$clause where user_id=$this->user_id");
0 ignored issues
show
Bug Best Practice introduced by
The property user_id does not exist on BoincUserSubmit. Did you maybe forget to declare it?
Loading history...
83
    }
84
    static function update_aux($clause) {
85
        $db = BoincDb::get();
86
        return $db->update_aux('user_submit', $clause);
87
    }
88
89
    static function delete_user($user_id) {
90
        $db = BoincDb::get();
91
        return $db->delete_aux('user_submit', "user_id = $user_id");
92
    }
93
94
}
95
96
class BoincUserSubmitApp {
97
    static function enum($clause) {
98
        $db = BoincDb::get();
99
        return $db->enum('user_submit_app', 'BoincUserSubmitApp', $clause);
100
    }
101
    static function lookup($clause) {
102
        $db = BoincDb::get();
103
        return $db->lookup('user_submit_app', 'BoincUserSubmitApp', $clause);
104
    }
105
    static function insert($clause) {
106
        $db = BoincDb::get();
107
        $ret = $db->insert('user_submit_app', $clause);
108
        if (!$ret) return false;
109
        return true;
110
    }
111
    static function delete_user($user_id) {
112
        $db = BoincDb::get();
113
        return $db->delete_aux('user_submit_app', "user_id=$user_id");
114
    }
115
    function update($clause) {
116
        $db = BoincDb::get();
117
        return $db->update_aux('user_submit_app', "$clause where user_id=$this->user_id and app_id=$this->app_id");
0 ignored issues
show
Bug Best Practice introduced by
The property app_id does not exist on BoincUserSubmitApp. Did you maybe forget to declare it?
Loading history...
Bug Best Practice introduced by
The property user_id does not exist on BoincUserSubmitApp. Did you maybe forget to declare it?
Loading history...
118
    }
119
}
120
121
class BoincJobFile {
122
    static function insert($clause) {
123
        $db = BoincDb::get();
124
        $ret = $db->insert('job_file', $clause);
125
        if (!$ret) return false;
126
        return $db->insert_id();
127
    }
128
    static function lookup_name($name) {
129
        $db = BoincDb::get();
130
        return $db->lookup('job_file', 'BoincJobFile', "name='$name'");
131
    }
132
    function delete() {
133
        $db = BoincDb::get();
134
        return $db->delete($this, 'job_file');
135
    }
136
    function update($clause) {
137
        $db = BoincDb::get();
138
        return $db->update($this, 'job_file', $clause);
139
    }
140
}
141
142
class BoincBatchFileAssoc {
143
    static function insert($clause) {
144
        $db = BoincDb::get();
145
        $ret = $db->insert('batch_file_assoc', $clause);
146
        if (!$ret) return false;
147
        return true;
148
    }
149
    static function lookup($clause) {
150
        $db = BoincDb::get();
151
        return $db->lookup('batch_file_assoc', 'BoincBatchFileAssoc', $clause);
152
    }
153
    function delete() {
154
        $db = BoincDb::get();
155
        return $db->delete_aux('batch_file_assoc',
156
            "job_file_id=$this->job_file_id and batch_id=$this->batch_id"
0 ignored issues
show
Bug Best Practice introduced by
The property batch_id does not exist on BoincBatchFileAssoc. Did you maybe forget to declare it?
Loading history...
Bug Best Practice introduced by
The property job_file_id does not exist on BoincBatchFileAssoc. Did you maybe forget to declare it?
Loading history...
157
        );
158
    }
159
    static function delete_batch($batch_id) {
160
        $db = BoincDb::get();
161
        return $db->delete_aux('batch_file_assoc',
162
            "batch_id=$batch_id"
163
        );
164
    }
165
}
166
167
?>
168