Index: openacs-4/packages/photo-album/www/random-photo-postgresql.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/photo-album/www/random-photo-postgresql.xql,v
diff -u -r1.2 -r1.3
--- openacs-4/packages/photo-album/www/random-photo-postgresql.xql 27 Aug 2003 20:45:19 -0000 1.2
+++ openacs-4/packages/photo-album/www/random-photo-postgresql.xql 1 Feb 2004 22:04:16 -0000 1.3
@@ -1,66 +1,82 @@
-
- postgresql7.2
+
+ postgresql
+ 7.2
+
-
-
-
+
+
select ci.item_id as photo_id,
- (select pp.caption from pa_photos pp where pp.pa_photo_id = ci.live_revision) as caption,
- i.image_id as thumb_path,
- i.height as thumb_height,
- i.width as thumb_width,
- random() as seed
- from cr_items ci,
- cr_items ci2,
- cr_items root,
- cr_child_rels ccr2,
- images i
- where
- $size_clause
+ (select pp.caption
+ from pa_photos pp
+ where pp.pa_photo_id = ci.live_revision) as caption,
+ i.image_id as thumb_path,
+ i.height as thumb_height,
+ i.width as thumb_width,
+ random() as seed
+ from cr_items ci, cr_items ci2, cr_child_rels ccr2, images i
+ where $size_clause
and ci.item_id = ccr2.parent_id
and ccr2.child_id = ci2.item_id
and ci2.live_revision = i.image_id
and ci.live_revision is not null
- $folder_clause
- order by seed limit 1
-
-
+ $photo_clause
+ order by seed limit 1
+
+
+
+
+
+ select site_node__url(sn.node_id)
+ from site_nodes sn
+ inner join pa_package_root_folder_map pm on (sn.object_id = pm.package_id)
+ inner join cr_items parent on (pm.folder_id = parent.item_id)
+ inner join cr_items child on (parent.tree_sortkey <= child.tree_sortkey)
+ where child.tree_sortkey between parent.tree_sortkey and tree_right(parent.tree_sortkey)
+ and tree_level(parent.tree_sortkey) = 2
+ and child.item_id = :photo_id
+
+
+
+
+
+ select ci.item_id as photo_id,
+ (select pp.caption
+ from pa_photos pp
+ where pp.pa_photo_id = ci.live_revision) as caption,
+ i.image_id as thumb_path,
+ i.height as thumb_height,
+ i.width as thumb_width,
+ random() as seed
+ from cr_items ci, cr_items ci2, ci_items root, cr_child_rels ccr2, images i
+ where $size_clause
+ and ci.item_id = ccr2.parent_id
+ and ccr2.child_id = ci2.item_id
+ and ci2.live_revision = i.image_id
+ and ci.live_revision is not null
+ and ci.tree_sortkey between root.tree_sortkey and tree_right(root.tree_sortkey)
+ and root.item_id = :root_folder_id
+ order by seed limit 1
+
+
-
-
- select site_node__url(sn.node_id)
- from site_nodes sn
- inner join pa_package_root_folder_map pm on
- (sn.object_id = pm.package_id)
- inner join cr_items parent on
- (pm.folder_id = parent.item_id)
- inner join cr_items child on
- (parent.tree_sortkey <= child.tree_sortkey)
- where child.tree_sortkey between parent.tree_sortkey and tree_right(parent.tree_sortkey)
- and tree_level(parent.tree_sortkey) = 2
- and child.item_id = :photo_id
-
-
+
+
+ and ci.item_id = :photo_id
+
+
-
-
-and ci.tree_sortkey between root.tree_sortkey and tree_right(root.tree_sortkey)
-and root.item_id = :root_folder_id
-
-
-
-
-
+
+
ccr2.relation_tag = 'viewer'
-
-
-
-
-
+
+
+
+
+
ccr2.relation_tag = 'thumb'
-
-
-
+
+
+
Index: openacs-4/packages/photo-album/www/random-photo.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/photo-album/www/random-photo.tcl,v
diff -u -r1.2 -r1.3
--- openacs-4/packages/photo-album/www/random-photo.tcl 27 Aug 2003 20:45:19 -0000 1.2
+++ openacs-4/packages/photo-album/www/random-photo.tcl 1 Feb 2004 22:04:16 -0000 1.3
@@ -1,79 +1,106 @@
# Includable template pair that can be used to show a random photo
# from a photo-album instance or from all instances on the server.
-#
-# written by Jarkko Laine (jarkko.m.laine@tut.fi)
-#
-# Usage:
-#
+
+# written by Jarkko Laine (jarkko.m.laine@tut.fi)
+# @author: Bart Teeuwisse (bart.teeuwisse@thecodemill.biz)
+
+# Usage:
+#
# or
-# where 1473
-# is the package_id of your photo-album instance.
-#
+# where 1473
+# is the package_id of your photo-album instance.
+# or
+# where 9912
+# is the photo_id of a photo in one of your albums.
+
# If neither package_id nor url is defined, the random photo is taken from all photos
# in the system.
-#
+
# Expects:
+# photo_id:optional
# package_id:optional
# url:optional
# size:optional (thumb, viewer) (thumb is default)
-#
+# Use the position specified by the caller, default is left.
+if {![info exists random:position]} {
+ set random:position left
+}
-
# If the caller specified a URL, then we gather the package_id from that URL
-if { [info exists url] } {
- # let's add the leading/tailing slashes so the url's will always work
+
+if {[info exists url]} {
+
+ # Let's add the leading/tailing slashes so the url's will always work
+
set url [string trim $url]
- if { ![string equal [string index $url 0] "/"] } {
+ if {![string equal [string index $url 0] "/"]} {
set url "/$url"
}
- if { ![string equal [string index $url end] "/"] } {
+ if {![string equal [string index $url end] "/"]} {
set url "$url/"
}
-
- array set pa_site_node [site_node::get -url $url]
+
+ array set pa_site_node [site_node::get \
+ -url $url]
set package_id $pa_site_node(object_id)
}
-set found_p 1
+# Determain the display size of the photo.
-# If they supplied neither url nor package_id, the random photo
-# is shuffled across all the photos in the system
-if { ![info exists package_id] } {
- set folder_clause ""
-} else {
- set root_folder_id [pa_get_root_folder $package_id]
- set folder_clause [db_map folder_clause]
-}
-
-if { ![info exists size] } {
+if {![info exists size]} {
set size "thumb"
}
-
switch -exact $size {
viewer {
+
# Get the normal size photo
+
set size_clause [db_map size_clause_normal]
}
default {
+
# Grab the thumbnail
+
set size_clause [db_map size_clause_thumb]
}
}
-# Get the photo information
-if {[catch {db_1row get_random_photo {}}] } {
- # No photos found
- set found_p 0
-}
+# If they supplied neither url nor package_id, the random photo
+# is shuffled across all the photos in the system.
+if {![info exists package_id]} {
+ if {![info exists photo_id]} {
+ set photo_clause ""
+ } else {
+ # A photo ID was provided. Limit the query to that photo.
+
+ set photo_clause [db_map photo_clause]
+ }
+ if {[catch {db_1row get_random_photo_all {}} err_msg]} {
+ ns_log error "No random photo found: $err_msg"
+ set found_p 0
+ } else {
+ set found_p 1
+ }
+} else {
+ set root_folder_id [pa_get_root_folder $package_id]
+ if {[catch {db_1row get_random_photo_folder {}} err_msg]} {
+ ns_log error "No random photo found in folder $root_folder_id: $err_msg"
+ set found_p 0
+ } else {
+ set found_p 1
+ }
+}
+
# if no url or package_id were given, we have to find out
# which package the photo belongs to
-if { ![info exists package_id] && ![info exists url] && $found_p == 1} {
+
+if {![info exists package_id]
+ && ![info exists url] && $found_p == 1} {
set url [db_string get_url ""]
}
-
-ad_return_template
+ad_return_template