~jstys-z/helioviewer.org/client5

« back to all changes in this revision

Viewing changes to api/lib/helioviewer/ImgIndex.php

  • Committer: V. Keith Hughitt
  • Date: 2009-04-01 21:08:05 UTC
  • Revision ID: hughitt1@kore-20090401210805-372f7dgih07vxk42
nightly build 04-01-2009

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
class ImgIndex {
 
3
        private $dbConnection;
 
4
 
 
5
        public function __construct($dbConnection) {
 
6
                date_default_timezone_set('UTC');
 
7
                $this->dbConnection = $dbConnection;
 
8
        }
 
9
 
 
10
        public function getClosestImage($timestamp, $src, $debug = false) {
 
11
                $query = sprintf("SELECT image.id AS imageId, image.lengthX as width, image.lengthY as height, image.imgScaleX as naturalImageScale,
 
12
                                                        measurement.abbreviation AS measurement, measurementType.name AS measurementType, unit,
 
13
                                                        CONCAT(instrument.name, \" \", detector.name, \" \", measurement.name) AS name, detector.minZoom as minZoom,
 
14
                                                        detector.abbreviation AS detector, detector.opacityGroupId AS opacityGroupId,
 
15
                                                        opacityGroup.description AS opacityGroupDescription,
 
16
                                                        instrument.abbreviation AS instrument, observatory.abbreviation AS observatory,
 
17
                                                        UNIX_TIMESTAMP(timestamp) AS timestamp,
 
18
                                                                UNIX_TIMESTAMP(timestamp) - %d AS timediff,
 
19
                                                                ABS(UNIX_TIMESTAMP(timestamp) - %d) AS timediffAbs
 
20
                                                        FROM image
 
21
                                                        LEFT JOIN measurement on measurementId = measurement.id
 
22
                                                        LEFT JOIN measurementType on measurementTypeId = measurementType.id
 
23
                                                        LEFT JOIN detector on detectorId = detector.id
 
24
                                                        LEFT JOIN opacityGroup on opacityGroupId = opacityGroup.id
 
25
                                                        LEFT JOIN instrument on instrumentId = instrument.id
 
26
                                                        LEFT JOIN observatory on observatoryId = observatory.id
 
27
                                WHERE ", $timestamp, $timestamp);
 
28
 
 
29
                // Layer-settings
 
30
                $i=0;
 
31
                foreach($src as $key => $value) {
 
32
                        if ($i>0) $query .= " AND";
 
33
                        $query .= sprintf(" $key='%s'", mysqli_real_escape_string($this->dbConnection->link, $value));
 
34
                        $i++;
 
35
                }
 
36
 
 
37
                $query .= " ORDER BY timediffAbs LIMIT 0,1";
 
38
                
 
39
                //if ($debug == "true")
 
40
                //      echo "<br><br>$query<br><br>";
 
41
 
 
42
                $result = $this->dbConnection->query($query);
 
43
                return mysqli_fetch_array($result, MYSQL_ASSOC);
 
44
        }
 
45
 
 
46
        public function getJP2Location($timestamp, $src) {
 
47
                //WORKAROUND FOR MySQL TimeZone differences (HostGator is not using UTC by default)
 
48
                //$offset = (5 * 3600); // 5 hours in seconds
 
49
                $offset = 0; //local installation of MySQL set to use UTC by default...
 
50
                
 
51
                $query = sprintf("SELECT image.uri as url, ABS(UNIX_TIMESTAMP(timestamp) - %d - %d) AS timediffAbs
 
52
                                                FROM image
 
53
                                                LEFT JOIN measurement on measurementId = measurement.id
 
54
                                                LEFT JOIN detector on detectorId = detector.id
 
55
                                                LEFT JOIN instrument on instrumentId = instrument.id
 
56
                                                LEFT JOIN observatory on observatoryId = observatory.id
 
57
                                  WHERE ", $timestamp, $offset);
 
58
 
 
59
                // Layer-settings
 
60
                $i=0;
 
61
                foreach($src as $key => $value) {
 
62
                        if ($i>0) $query .= " AND";
 
63
                        $query .= sprintf(" $key='%s'", mysqli_real_escape_string($this->dbConnection->link, $value));
 
64
                        $i++;
 
65
                }
 
66
 
 
67
                $query .= " ORDER BY timediffAbs LIMIT 0,1";
 
68
 
 
69
                //echo $query . "<br><br>";
 
70
                $result = $this->dbConnection->query($query);
 
71
                $result_array = mysqli_fetch_array($result, MYSQL_ASSOC);
 
72
                
 
73
                return $result_array["url"];
 
74
                
 
75
        }
 
76
}
 
77
?>