art-web r571 - in branches/art-hub: controllers models



Author: thos
Date: Wed Dec 17 20:34:22 2008
New Revision: 571
URL: http://svn.gnome.org/viewvc/art-web?rev=571&view=rev

Log:
Add support for selecting single items by id


Modified:
   branches/art-hub/controllers/backgrounds.php
   branches/art-hub/controllers/themes.php
   branches/art-hub/models/art.php
   branches/art-hub/models/backgrounds.php
   branches/art-hub/models/themes.php

Modified: branches/art-hub/controllers/backgrounds.php
==============================================================================
--- branches/art-hub/controllers/backgrounds.php	(original)
+++ branches/art-hub/controllers/backgrounds.php	Wed Dec 17 20:34:22 2008
@@ -24,8 +24,9 @@
 
 $bg = new BackgroundsModel();
 
-preg_match ('/^\/backgrounds\/(abstract|gnome|nature|other|search)\/?$/', $_SERVER['PHP_SELF'], $params);
+preg_match ('/^\/backgrounds\/(abstract|gnome|nature|other|search)\/?([0-9]+)?$/', $_SERVER['PHP_SELF'], $params);
 $category = $params[1];
+$background_id = $params[2];
 
 $page = $_GET['page'];
 if (!is_numeric ($page))
@@ -49,8 +50,16 @@
   }
   else
   {
-    $view_data = $bg->get_items ($category, $start, $limit, "name");
-    $total_backgrounds = $bg->get_total ($category);
+    if ($background_id)
+    {
+      $view_data = $bg->get_single_item ($category, $background_id);
+      $total_backgrounds = 1;
+    }
+    else
+    {
+      $view_data = $bg->get_items ($category, $start, $limit, "name");
+      $total_backgrounds = $bg->get_total ($category);
+    }
   }
 else
   $view_data = null;

Modified: branches/art-hub/controllers/themes.php
==============================================================================
--- branches/art-hub/controllers/themes.php	(original)
+++ branches/art-hub/controllers/themes.php	Wed Dec 17 20:34:22 2008
@@ -24,10 +24,12 @@
 
 $themes = new ThemesModel();
 
-preg_match ('/^\/themes\/(gtk2|metacity|icon|gdm_greeter|splash_screens|gtk_engines|search)\/?$/',
+preg_match ('/^\/themes\/(gtk2|metacity|icon|gdm_greeter|splash_screens|gtk_engines|search)\/?([0-9]+)?$/',
             $_SERVER['PHP_SELF'], $params);
 $category = $params[1];
 
+$theme_id = $params[2];
+
 $page = $_GET['page'];
 if (!is_numeric ($page))
   $page = 1;
@@ -50,8 +52,16 @@
   }
   else
   {
-    $view_data = $themes->get_items ($category, $start, $limit, "name");
-    $total_themes = $themes->get_total ($category);
+    if ($theme_id)
+    {
+      $view_data = $themes->get_single_item ($category, $theme_id);
+      $total_themes = 1;
+    }
+    else
+    {
+      $view_data = $themes->get_items ($category, $start, $limit, "name");
+      $total_themes = $themes->get_total ($category);
+    }
   }
 else
   $view_data = null;

Modified: branches/art-hub/models/art.php
==============================================================================
--- branches/art-hub/models/art.php	(original)
+++ branches/art-hub/models/art.php	Wed Dec 17 20:34:22 2008
@@ -61,6 +61,29 @@
     return $total[0];
   }
 
+  function get_single_item ($category, $item_id)
+  {
+    /* check that item_id is numeric */
+    if (!is_numeric ($item_id))
+      return;
+
+    $sql = sprintf ($this->get_single_item_sql, $category, $item_id);
+
+    if ($sql === '')
+      return;
+
+    $bg_select_result = mysql_query ($sql);
+    if (!$bg_select_result)
+      printf ("Database error: %s", mysql_error());
+
+    $table = Array ();
+    while ($row = mysql_fetch_assoc ($bg_select_result))
+    {
+      $table[] = $row;
+    }
+
+    return $table;
+  }
   function get_items ($category, $start, $length, $order)
   {
     /* check that start and length values are numeric */

Modified: branches/art-hub/models/backgrounds.php
==============================================================================
--- branches/art-hub/models/backgrounds.php	(original)
+++ branches/art-hub/models/backgrounds.php	Wed Dec 17 20:34:22 2008
@@ -21,6 +21,11 @@
 
 class BackgroundsModel extends ArtModel
 {
+  var $get_single_item_sql = "SELECT * FROM background,user
+            WHERE status='active' AND category = '%s'
+            AND background.userID = user.userID
+            AND background.backgroundID = %s";
+
   var $get_items_sql = "SELECT * FROM background,user
             WHERE status='active' AND category = '%s'
             AND background.userID = user.userID

Modified: branches/art-hub/models/themes.php
==============================================================================
--- branches/art-hub/models/themes.php	(original)
+++ branches/art-hub/models/themes.php	Wed Dec 17 20:34:22 2008
@@ -21,6 +21,11 @@
 
 class ThemesModel extends ArtModel
 {
+  var $get_single_item_sql = "SELECT * FROM theme,user
+            WHERE status='active' AND category = '%s'
+            AND theme.userID = user.userID
+            AND theme.themeID = %s";
+
   var $get_items_sql = "SELECT * FROM theme,user
             WHERE status='active' AND category = '%s'
             AND theme.userID = user.userID



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]