]> dev.renevier.net Git - syp.git/blobdiff - inc/db/mysql.php
rss feed
[syp.git] / inc / db / mysql.php
index 8fa49d52b68730a1a7edf980a18692e67cb06b6a..8e3fcf85394d618b97c7d1bbd4e68e8ee7abf859 100644 (file)
@@ -120,7 +120,7 @@ class mysqlConnection implements anydbConnection {
                 $id = mysql_insert_id ();
                 return new feature ($id, $feature->lon, $feature->lat,
                                     $feature->imgpath, $feature->title,
-                                    $feature->description);
+                                    $feature->description, $feature->date);
         }
     }
 
@@ -134,7 +134,8 @@ class mysqlConnection implements anydbConnection {
 
     public function getfeature ($id) {
         $query = sprintf ("SELECT id, imgpath, title, description, AsText(location)
-                           AS location FROM %sitems WHERE id = '%s';", 
+                           AS location, UNIX_TIMESTAMP(date) AS date FROM %sitems
+                           WHERE id = '%s';", 
                         $this->dbprefix, mysql_real_escape_string ($id));
         $row = mysql_fetch_assoc ($this->_execute_query ($query));
         if ($row === false) {
@@ -145,7 +146,7 @@ class mysqlConnection implements anydbConnection {
 
     public function listfeatures () {
         $query = sprintf ("SELECT id, imgpath, title, description, AsText(location)
-                            AS location FROM %sitems;",
+                            AS location, UNIX_TIMESTAMP(date) AS date FROM %sitems;",
                           $this->dbprefix);
 
         $features = array ();
@@ -159,6 +160,25 @@ class mysqlConnection implements anydbConnection {
         return $features;
     }
 
+    public function mostrecentfeatures ($num_features) {
+        $query = sprintf ("SELECT id, imgpath, title, description,
+                           AsText(location) AS location, UNIX_TIMESTAMP(date)
+                           AS date FROM %sitems ORDER BY date DESC",
+                           $this->dbprefix);
+        if ($num_features) {
+            $query .= sprintf (" LIMIT %d", $num_features);
+        }
+        $features = array ();
+        $res = $this->_execute_query ($query);
+        while ($row = mysql_fetch_assoc ($res)) {
+            $feature = $this->_feature_frow_row ($row);
+            if (isset ($feature)) {
+                $features[] = $feature;
+            }
+        }
+        return $features;
+    }
+
     public function imgpath_exists ($imgpath) {
         $query = sprintf ("SELECT COUNT(*) FROM %sitems WHERE imgpath LIKE '%s';",
                            $this->dbprefix, mysql_real_escape_string ($imgpath));
@@ -226,7 +246,8 @@ class mysqlConnection implements anydbConnection {
         $lat = $matches [2];
         try {
             $feature = new feature ($row ["id"], $lon, $lat, $row ["imgpath"],
-                                    $row ["title"], $row ["description"]);
+                                    $row ["title"], $row ["description"],
+                                    $row ["date"]);
         } catch (Exception $e) {
             return null;
         }