/adei/trunk

To get this branch, use:
bzr branch http://darksoft.org/webbzr/adei/trunk

« back to all changes in this revision

Viewing changes to setups/katrin/classes/kdbsql.php

  • Committer: Suren A. Chilingaryan
  • Date: 2010-08-13 14:18:27 UTC
  • Revision ID: csa@dside.dyndns.org-20100813141827-u3o97425ppvd5g7y
Revert back to SetConfiguration from SetCustomProperties while handling certain property in search; trully support HTML content in description field within search results; support execution in XMLModule; support for setup-specific javascript code; KATRIN update

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
        $this->fPassword = $password;
19
19
    }
20
20
 
21
 
    function ListLastRuns($date, $offset, $limit, &$total)
 
21
    function ListRuns(array $filter, &$total)
22
22
    {
23
23
        $this->Connect();
24
24
 
25
 
        if ($date > 999999) {
26
 
            $start = $date;
27
 
            $end = "$start + INTERVAL 1 DAY";
28
 
        }
29
 
        elseif ($date > 9999) {
30
 
            $start = "${date}01";
31
 
            $end = "$start + INTERVAL 1 MONTH";
32
 
        }
33
 
        else {
34
 
            $start = "${date}0101";
35
 
            $end_date = $date + 1;
36
 
            $end = "${end_date}0101";
 
25
        $where = $this->BuildFilter($filter);
 
26
 
 
27
        if (array_key_exists('limit', $filter)) {
 
28
            if (array_key_exists('offset', $filter)) {
 
29
                $limit = "{$filter['offset']}, {$filter['limit']}";
 
30
            }
 
31
            else {
 
32
                $limit = $filter['limit'];
 
33
            }
37
34
        }
38
35
 
39
36
        $query = "SELECT SQL_CALC_FOUND_ROWS run.system AS system, ";
40
37
        $query .= "run.number AS number, run.start AS start, ";
 
38
        $query .= "run.end AS end, ";
41
39
        $query .= "TIMEDIFF(run.end, run.start) AS duration, ";
42
40
        $query .= "run.comment AS comment, run.data_types AS data, ";
43
 
        $query .= "COUNT(*) AS subruns FROM run, subrun ";
44
 
        $query .= "WHERE run.id = subrun.run AND ";
45
 
        $query .= "run.start BETWEEN $start AND $end - INTERVAL 1 SECOND ";
46
 
        $query .= "GROUP BY subrun.run ORDER BY run.start ";
47
 
        $query .= "LIMIT $offset, $limit";
 
41
        $query .= "COUNT(*) AS subruns FROM run, subrun";
 
42
 
 
43
        $query .= ' WHERE subrun.run = run.id';
 
44
        if ($where) {
 
45
            $query .= ' AND ' . implode(' AND ', $where);
 
46
        }
 
47
        $query .= ' GROUP BY subrun.run ORDER BY run.start';
 
48
        if ($limit) {
 
49
            $query .= " LIMIT $limit";
 
50
        }
48
51
 
49
52
        $result = mysql_query($query, $this->fMysql);
50
 
        
 
53
 
51
54
        $runs = array();
52
55
        while ($row = mysql_fetch_assoc($result)) {
53
56
            $runs[] = $row;
155
158
        return $parameters;
156
159
    }
157
160
    
158
 
    function GetDates()
 
161
    function GetDates(array $filter)
159
162
    {
160
163
        $this->Connect();
161
 
        
162
 
        $query = "SELECT UNIX_TIMESTAMP(CAST(start AS DATE)) AS d " .
163
 
                 "FROM run GROUP BY d ORDER BY d";
 
164
 
 
165
        $where = $this->BuildFilter($filter);
 
166
 
 
167
        $query = 'SELECT UNIX_TIMESTAMP(CAST(start AS DATE)) AS d FROM run';
 
168
        if ($where) {
 
169
            $query .= ' WHERE ' . implode(' AND ', $where);
 
170
        }
 
171
        $query .= ' GROUP BY d ORDER BY d';
164
172
        $result = mysql_query($query, $this->fMysql);
165
173
 
166
174
        $dates = array();
268
276
    {
269
277
        return "FROM_UNIXTIME(" . $tstamp . ")";
270
278
    }
 
279
 
 
280
    private function BuildFilter($filter)
 
281
    {
 
282
        $where = array();
 
283
        if (array_key_exists('date', $filter)) {
 
284
            $date = $filter['date'];
 
285
            if ($date != 0 && $date != "all") {
 
286
                if ($date > 999999) {
 
287
                    $start = $date;
 
288
                    $end = "$start + INTERVAL 1 DAY";
 
289
                }
 
290
                elseif ($date > 9999) {
 
291
                    $start = "${date}01";
 
292
                    $end = "$start + INTERVAL 1 MONTH";
 
293
                }
 
294
                else {
 
295
                    $start = "${date}0101";
 
296
                    $end_date = $date + 1;
 
297
                    $end = "${end_date}0101";
 
298
                }
 
299
                $where[] =
 
300
                    "run.start BETWEEN $start AND $end - INTERVAL 1 SECOND";
 
301
            }
 
302
        }
 
303
 
 
304
        if (array_key_exists('system', $filter)) {
 
305
            $where[] = "run.system = {$filter['system']}";
 
306
        }
 
307
 
 
308
        $from = $filter['from'];
 
309
        $to = $filter['to'];
 
310
 
 
311
        if ($from) {
 
312
            if ($to) {
 
313
                $where[] = "run.number BETWEEN $from AND $to";
 
314
            }
 
315
            else {
 
316
                $where[] = "run.number = $from";
 
317
            }
 
318
        }
 
319
        return $where;
 
320
    }
271
321
}
272
322
 
273
323
?>