From 984b068b1369819a44bbfc4412476da0da49607f Mon Sep 17 00:00:00 2001 From: Andreas Unterkircher Date: Tue, 17 Jul 2007 20:24:56 +0000 Subject: [PATCH] issue50, further code changes to be able to combine tag- and date-search git-svn-id: file:///var/lib/svn/phpfspot/trunk@219 fa6a889d-dae6-447d-9e79-4ba9a3039384 --- phpfspot.class.php | 118 ++++++++++++++++++------------------- phpfspot.js | 43 ++++++++++---- rpc.php | 12 +--- stylesheet.css | 2 +- templates/photo_index.tpl | 23 ++++---- templates/search.tpl | 9 +-- templates/single_photo.tpl | 2 +- 7 files changed, 111 insertions(+), 98 deletions(-) diff --git a/phpfspot.class.php b/phpfspot.class.php index 0113fe6..f71a0db 100644 --- a/phpfspot.class.php +++ b/phpfspot.class.php @@ -457,9 +457,6 @@ class PHPFSPOT { */ public function addTag($tag) { - // if the result of a date search are displayed, reset them - $this->resetDateSearch(); - if(!isset($_SESSION['selected_tags'])) $_SESSION['selected_tags'] = Array(); @@ -550,18 +547,33 @@ class PHPFSPOT { { $matched_photos = Array(); + if(isset($_SESSION['from_date']) && isset($_SESSION['to_date'])) { + $from_date = strtotime($_SESSION['from_date']); + $to_date = strtotime($_SESSION['to_date']); + $additional_where_cond = " + p.time>='". $from_date ."' + AND + p.time<='". $to_date ."' + "; + } + /* return a search result */ if(isset($_SESSION['searchfor']) && $_SESSION['searchfor'] != '') { - $result = $this->db->db_query(" + $query_str = " SELECT DISTINCT photo_id FROM photo_tags pt INNER JOIN photos p ON p.id=pt.photo_id INNER JOIN tags t ON pt.tag_id=t.id - WHERE t.name LIKE '%". $_SESSION['searchfor'] ."%' - ORDER BY p.time ASC - "); + WHERE t.name LIKE '%". $_SESSION['searchfor'] ."%'"; + + if(isset($additional_where_cond)) + $query_str.= "AND ". $additional_where_cond ." "; + $query_str.= " + ORDER BY p.time ASC + "; + $result = $this->db->db_query($query_str); while($row = $this->db->db_fetch_object($result)) { array_push($matched_photos, $row['photo_id']); } @@ -576,14 +588,19 @@ class PHPFSPOT { $selected = substr($selected, 0, strlen($selected)-1); if($_SESSION['tag_condition'] == 'or') { - $result = $this->db->db_query(" + $query_str = " SELECT DISTINCT photo_id FROM photo_tags pt INNER JOIN photos p ON p.id=pt.photo_id WHERE pt.tag_id IN (". $selected .") + "; + if(isset($additional_where_cond)) + $query_str.= "AND ". $additional_where_cond ." "; + + $query_str.= " ORDER BY p.time ASC - "); + "; } elseif($_SESSION['tag_condition'] == 'and') { @@ -619,43 +636,30 @@ class PHPFSPOT { AND pt". ($i+1) .".tag_id=". $_SESSION['selected_tags'][$i] ." "; } - $result = $this->db->db_query($query_str); + if(isset($additional_where_cond)) + $query_str.= "AND ". $additional_where_cond; } + $result = $this->db->db_query($query_str); while($row = $this->db->db_fetch_object($result)) { array_push($matched_photos, $row['photo_id']); } return $matched_photos; } - if(isset($_SESSION['from_date']) && isset($_SESSION['to_date'])) { - $from_date = strtotime($_SESSION['from_date']); - $to_date = strtotime($_SESSION['to_date']); - $result = $this->db->db_query(" - SELECT DISTINCT photo_id - FROM photo_tags pt - INNER JOIN photos p - ON p.id=pt.photo_id - WHERE - time>='". $from_date ."' - AND - time<='". $to_date ."' - ORDER BY p.time ASC - "); - while($row = $this->db->db_fetch_object($result)) { - array_push($matched_photos, $row['photo_id']); - } - return $matched_photos; - } - /* return all available photos */ - $result = $this->db->db_query(" + $query_str = " SELECT DISTINCT photo_id FROM photo_tags pt INNER JOIN photos p ON p.id=pt.photo_id + "; + if(isset($additional_where_cond)) + $query_str.= "WHERE ". $additional_where_cond ." "; + $query_str.= " ORDER BY p.time ASC - "); + "; + $result = $this->db->db_query($query_str); while($row = $this->db->db_fetch_object($result)) { array_push($matched_photos, $row['photo_id']); } @@ -1172,39 +1176,29 @@ class PHPFSPOT { } // setTagCondition() /** - * invoke tag search + * invoke tag & date search * * this function will return all matching tags and store - * them in the session variable selected_tags. + * them in the session variable selected_tags. furthermore + * it also handles the date search. * getPhotoSelection() will then only return the matching * photos. */ - public function startTagSearch($searchfor) + public function startSearch($searchfor, $from, $to) { $_SESSION['searchfor'] = $searchfor; - $_SESSION['selected_tags'] = Array(); - - foreach($this->avail_tags as $tag) { - if(preg_match('/'. $searchfor .'/i', $this->tags[$tag])) - array_push($_SESSION['selected_tags'], $tag); - } - - $this->resetDateSearch(); - - } // startTagSearch() - - /** - * invoke date search - * - * this function in fact does nothing then only setting - * the from- and to-date in the users session variables. - * the result is generated by getPhotoSelection(). - */ - public function startDateSearch($from, $to) - { $_SESSION['from_date'] = $from; $_SESSION['to_date'] = $to; - } + + if($searchfor != "") { + /* new search, reset the current selected tags */ + $_SESSION['selected_tags'] = Array(); + foreach($this->avail_tags as $tag) { + if(preg_match('/'. $searchfor .'/i', $this->tags[$tag])) + array_push($_SESSION['selected_tags'], $tag); + } + } + } // startSearch() /** * rotate image @@ -1406,9 +1400,15 @@ class PHPFSPOT { $month = $_SESSION[$mode .'_date'] ? date("m", strtotime($_SESSION[$mode .'_date'])) : date("m"); $day = $_SESSION[$mode .'_date'] ? date("d", strtotime($_SESSION[$mode .'_date'])) : date("d"); - $output = "\n"; - $output.= "\n"; - $output.= "\n"; + $output = "showCredits(); break; - case 'tag_search': + case 'search': - $fspot->resetDateSearch(); - $fspot->startTagSearch($_GET['for']); - break; - - case 'date_search': - - $fspot->resetTagSearch(); - $fspot->resetTags(); - $fspot->startDateSearch($_GET['from'], $_GET['to']); + $fspot->startSearch($_GET['for'], $_GET['from'], $_GET['to']); break; case 'get_export': diff --git a/stylesheet.css b/stylesheet.css index fe2b2ef..610e7aa 100644 --- a/stylesheet.css +++ b/stylesheet.css @@ -65,7 +65,7 @@ td.index_header { white-space: nowrap; } -td.photo_name { +td.content_title { background-color: #eeeeee; padding: 10px; vertical-align: middle; diff --git a/templates/photo_index.tpl b/templates/photo_index.tpl index 2b4c827..f9c651d 100644 --- a/templates/photo_index.tpl +++ b/templates/photo_index.tpl @@ -4,33 +4,30 @@ -
+ Photo Index {if $searchfor } {if $count == 1} - {$count} image is the result for your search about "{$searchfor}" + {$count} image is the result for your search about "{$searchfor}". {else} - {$count} images are the result for your search about "{$searchfor}" - {/if} - {elseif $from_date } - {if $count == 1} - {$count} image is the result for your search between {$from_date} to {$to_date} - {else} - {$count} images are the result for your search between {$from_date} to {$to_date} + {$count} images are the result for your search about "{$searchfor}". {/if} {elseif $tag_result} {if $count == 1} - {$count} image has been found for the selected tags + {$count} image has been found for the selected tags. {else} - {$count} images have been found for the selected tags + {$count} images have been found for the selected tags. {/if} {else} {if $count == 1} - {$count} image has been found + {$count} image has been found. {else} - {$count} images have been found + {$count} images have been found. {/if} {/if} + {if $from_date && $to_date } + Results are limited to a date between {$from_date} to {$to_date}. + {/if} {if $extern_link } diff --git a/templates/search.tpl b/templates/search.tpl index f0f8c0d..c87d29e 100644 --- a/templates/search.tpl +++ b/templates/search.tpl @@ -7,7 +7,7 @@
- + - - - + + + diff --git a/templates/single_photo.tpl b/templates/single_photo.tpl index 5275843..8dfd433 100644 --- a/templates/single_photo.tpl +++ b/templates/single_photo.tpl @@ -1,7 +1,7 @@
Tag: @@ -17,12 +17,13 @@
Date:{$from_date} consider date-search +
 {$from_date}
 
- -- 2.25.1
+ Photo {$image_name}
 {$description}