diff options
author | Andreas Unterkircher <unki@netshadow.at> | 2007-07-17 20:24:56 +0000 |
---|---|---|
committer | Andreas Unterkircher <unki@netshadow.at> | 2007-07-17 20:24:56 +0000 |
commit | 984b068b1369819a44bbfc4412476da0da49607f (patch) | |
tree | 77742123fb1ed67c05ee4ce6b65798781dc324ae /phpfspot.class.php | |
parent | 94bb73ca0d019247d4f08fb03a7f5afc2b5323ee (diff) |
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
Diffstat (limited to 'phpfspot.class.php')
-rw-r--r-- | phpfspot.class.php | 118 |
1 files changed, 59 insertions, 59 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 = "<input type=\"text\" size=\"3\" id=\"". $mode ."year\" value=\"". $year ."\" />\n"; - $output.= "<input type=\"text\" size=\"1\" id=\"". $mode ."month\" value=\"". $month ."\" />\n"; - $output.= "<input type=\"text\" size=\"1\" id=\"". $mode ."day\" value=\"". $day ."\" />\n"; + $output = "<input type=\"text\" size=\"3\" id=\"". $mode ."year\" value=\"". $year ."\""; + if(!isset($_SESSION[$mode .'_date'])) $output.= " disabled=\"disabled\""; + $output.= " />\n"; + $output.= "<input type=\"text\" size=\"1\" id=\"". $mode ."month\" value=\"". $month ."\""; + if(!isset($_SESSION[$mode .'_date'])) $output.= " disabled=\"disabled\""; + $output.= " />\n"; + $output.= "<input type=\"text\" size=\"1\" id=\"". $mode ."day\" value=\"". $day ."\""; + if(!isset($_SESSION[$mode .'_date'])) $output.= " disabled=\"disabled\""; + $output.= " />\n"; return $output; } // get_calendar() |