~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-05-29 18:04:54 UTC
  • Revision ID: hughitt1@kore-20090529180454-1q1r4pxa3nw881os
nightly build 2009-05-29: fixed uri field performance issues

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
        }
14
14
 
15
15
        public function getClosestImage($obsTime, $src) {
16
 
                $query = sprintf("SELECT image.uri AS uri, image.lengthX as width, image.lengthY as height, image.imgScaleX as naturalImageScale,
 
16
                $query = sprintf("SELECT image.id as mysqlId, image.lengthX as width, image.lengthY as height, image.imgScaleX as naturalImageScale,
17
17
                                                        measurement.abbreviation AS measurement, measurementType.name AS measurementType, unit,
18
18
                                                        CONCAT(instrument.name, \" \", detector.name, \" \", measurement.name) AS name, detector.minZoom as minZoom,
19
19
                                                        detector.abbreviation AS detector, detector.opacityGroupId AS opacityGroupId,
42
42
 
43
43
                $query .= " ORDER BY timediffAbs LIMIT 0,1";
44
44
                
45
 
        //echo "<br><br>$query<br><br>";
 
45
        //echo "$query<br><br>";
46
46
        //exit();
47
47
 
48
48
                $result = $this->dbConnection->query($query);
49
 
                return mysqli_fetch_array($result, MYSQL_ASSOC);
 
49
        $im = mysqli_fetch_array($result, MYSQL_ASSOC);
 
50
        
 
51
        // get uri
 
52
        $im["uri"] = $this->idToURI($im["mysqlId"]);
 
53
 
 
54
                return $im;
50
55
        }
51
56
 
52
57
    /**
53
 
     * getJP2Location
 
58
     * getJP2Filename
54
59
     * @author Keith Hughitt <Vincent.K.Hughitt@nasa.gov>
55
60
     * @return string $url
56
61
     * @param object $obsTime
62
67
     * is saved.
63
68
     * 
64
69
     */
65
 
        public function getJP2Location($obsTime, $src) {
 
70
        public function getJP2Filename($obsTime, $src) {
66
71
                // Find ID of JP2
67
72
        $id = $this->getJP2Id($obsTime, $src);
68
73
        
69
74
        // Use ID to find the JP2 URL
70
 
        $query = "SELECT uri as url FROM image WHERE id=$id";
 
75
        return $this->idToURI($id);
 
76
        }
 
77
    
 
78
     /**
 
79
     * getJP2Id
 
80
     * @return string $id
 
81
     * @param object $obsTime
 
82
     * @param object $src
 
83
     */
 
84
    public function getJP2Id ($obsTime, $src) {
 
85
        $query = sprintf("SELECT image.id as id, ABS(UNIX_TIMESTAMP(timestamp) - %d) AS timediffAbs
 
86
                                        FROM image
 
87
                                        LEFT JOIN measurement on measurementId = measurement.id
 
88
                                        LEFT JOIN detector on detectorId = detector.id
 
89
                                        LEFT JOIN instrument on instrumentId = instrument.id
 
90
                                        LEFT JOIN observatory on observatoryId = observatory.id
 
91
                          WHERE ", $obsTime);
 
92
    
 
93
        // Layer-settings
 
94
        $i=0;
 
95
        foreach($src as $key => $value) {
 
96
                if ($i>0) $query .= " AND";
 
97
                $query .= sprintf(" $key='%s'", mysqli_real_escape_string($this->dbConnection->link, $value));
 
98
                $i++;
 
99
        }
 
100
        $query .= " ORDER BY timediffAbs LIMIT 0,1";
 
101
    
 
102
        $result = $this->dbConnection->query($query);
 
103
        $result_array = mysqli_fetch_array($result, MYSQL_ASSOC);
 
104
    
 
105
        return $result_array["id"];
 
106
    }
 
107
    
 
108
    /**
 
109
     * idToURI
 
110
     * @return 
 
111
     * @param object $id
 
112
     */
 
113
    private function idToURI ($id) {
 
114
        $query = "SELECT uri FROM image WHERE id = $id";
71
115
        $result = $this->dbConnection->query($query);
72
 
                $result_array = mysqli_fetch_array($result, MYSQL_ASSOC);
73
 
        
74
 
        return $result_array["url"];
75
 
        }
 
116
        $result_array = mysqli_fetch_array($result, MYSQL_ASSOC);
 
117
    
 
118
        return $result_array["uri"];
 
119
    }
76
120
}
77
121
?>
 
 
b'\\ No newline at end of file'