From f36faab3aed613fc0e1e10a34a88bf1065c80f79 Mon Sep 17 00:00:00 2001 From: Andreas Unterkircher Date: Sat, 24 May 2008 11:39:39 +0200 Subject: [PATCH] issue121, search for a specific rate-limit Signed-off-by: Andreas Unterkircher --- phpfspot.class.php | 134 ++++++++++++++++++++++++++-- phpfspot.js | 69 +++++++++++++- resources/empty_rate.png | Bin 0 -> 218 bytes rpc.php | 1 + themes/default/templates/search.tpl | 23 +++++ 5 files changed, 218 insertions(+), 9 deletions(-) create mode 100644 resources/empty_rate.png diff --git a/phpfspot.class.php b/phpfspot.class.php index 0711499..58cda4e 100644 --- a/phpfspot.class.php +++ b/phpfspot.class.php @@ -206,6 +206,7 @@ class PHPFSPOT { /* Starting with F-Spot 0.4.2, the rating-feature was available */ if($this->dbver > 10) { + $this->tmpl->assign('has_rating', true); $this->sort_orders = array_merge($this->sort_orders, array( 'rate_asc' => 'Rate ↑', 'rate_desc' => 'Rate ↓', @@ -321,15 +322,26 @@ class PHPFSPOT { } } + /* if date-search variables are registered in the session, set the check + for "consider date-range" in the html output + */ if(isset($_SESSION['from_date']) && isset($_SESSION['to_date'])) $this->tmpl->assign('date_search_enabled', true); + /* if rate-search variables are registered in the session, set the check + for "consider rate-range" in the html output + */ + if(isset($_SESSION['rate_from']) && isset($_SESSION['rate_to'])) { + $this->tmpl->assign('rate_search_enabled', true); + } + $this->tmpl->register_function("sort_select_list", array(&$this, "smarty_sort_select_list"), false); $this->tmpl->assign('search_from_date', $this->get_calendar('from')); $this->tmpl->assign('search_to_date', $this->get_calendar('to')); $this->tmpl->assign('preset_selected_tags', $this->getSelectedTags()); $this->tmpl->assign('preset_available_tags', $this->getAvailableTags()); + $this->tmpl->assign('rate_search', $this->get_rate_search()); if(!isset($content)) { if(isset($_SESSION['selected_tags']) && !empty($_SESSION['selected_tags'])) @@ -528,6 +540,53 @@ class PHPFSPOT { } // get_photo_rating() + /** + * get rate-search bars + * + * this function will return the rating-bars for the + * search field. + * @return string + */ + public function get_rate_search() + { + $bar = ""; + + for($i = 1; $i <= 5; $i++) { + + $bar.= "cfg->web_path ."/resources/star.png"; + else + $bar.= $this->cfg->web_path ."/resources/empty_rate.png"; + + $bar.= "\" + onmouseover=\"show_rate('from', ". $i .");\" + onmouseout=\"reset_rate('from');\" + onclick=\"set_rate('from', ". $i .")\" />"; + } + + $bar.= "
\n"; + + for($i = 1; $i <= 5; $i++) { + + $bar.= "cfg->web_path ."/resources/star.png"; + else + $bar.= $this->cfg->web_path ."/resources/empty_rate.png"; + + $bar.= "\" + onmouseover=\"show_rate('to', ". $i .");\" + onmouseout=\"reset_rate('to');\" + onclick=\"set_rate('to', ". $i .");\" />"; + } + + return $bar; + + } // get_rate_search() + /** * shrink text according provided limit * @@ -997,8 +1056,7 @@ class PHPFSPOT { /** * reset date search * - * if any date search has taken place, reset - * it now + * if any date search has taken place, reset it now. */ public function resetDateSearch() { @@ -1009,6 +1067,20 @@ class PHPFSPOT { } // resetDateSearch(); + /** + * reset rate search + * + * if any rate search has taken place, reset it now. + */ + public function resetRateSearch() + { + if(isset($_SESSION['rate_from'])) + unset($_SESSION['rate_from']); + if(isset($_SESSION['rate_to'])) + unset($_SESSION['rate_to']); + + } // resetRateSearch(); + /** * return all photo according selection * @@ -1034,6 +1106,12 @@ class PHPFSPOT { } if(isset($_SESSION['searchfor_name'])) { + + /* check for previous conditions. if so add 'AND' */ + if(!empty($additional_where_cond)) { + $additional_where_cond.= " AND "; + } + if($this->dbver < 9) { $additional_where_cond.= " ( @@ -1054,6 +1132,24 @@ class PHPFSPOT { } } + /* limit result based on rate-search */ + if(isset($_SESSION['rate_from']) && isset($_SESSION['rate_to'])) { + + if($this->dbver > 10) { + + /* check for previous conditions. if so add 'AND' */ + if(!empty($additional_where_cond)) { + $additional_where_cond.= " AND "; + } + + $additional_where_cond.= " + p.rating >= ". $_SESSION['rate_from'] ." + AND + p.rating <= ". $_SESSION['rate_to'] ." + "; + } + } + if(isset($_SESSION['sort_order'])) { $order_str = $this->get_sort_order(); } @@ -1073,7 +1169,7 @@ class PHPFSPOT { ON pt2.tag_id=t2.id WHERE t.name LIKE '%". $_SESSION['searchfor_tag'] ."%' "; - if(isset($additional_where_cond) && !empty($additional_where_cond)) + if(!empty($additional_where_cond)) $query_str.= "AND ". $additional_where_cond ." "; if(isset($this->cfg->show_tags) && !empty($this->cfg->show_tags)) { @@ -1110,7 +1206,7 @@ class PHPFSPOT { ON pt1.photo_id=p.id WHERE pt1.tag_id IN (". $selected .") "; - if(isset($additional_where_cond) && !empty($additional_where_cond)) + if(!empty($additional_where_cond)) $query_str.= "AND ". $additional_where_cond ." "; if(isset($this->cfg->show_tags) && !empty($this->cfg->show_tags)) { @@ -1166,7 +1262,7 @@ class PHPFSPOT { AND pt". ($i+2) .".tag_id=". $_SESSION['selected_tags'][$i] ." "; } - if(isset($additional_where_cond) && !empty($additional_where_cond)) + if(!empty($additional_where_cond)) $query_str.= "AND ". $additional_where_cond; if(isset($this->cfg->show_tags) && !empty($this->cfg->show_tags)) { @@ -1195,11 +1291,11 @@ class PHPFSPOT { ON pt.tag_id=t.id "; - if(isset($additional_where_cond) && !empty($additional_where_cond)) + if(!empty($additional_where_cond)) $query_str.= "WHERE ". $additional_where_cond ." "; if(isset($this->cfg->show_tags) && !empty($this->cfg->show_tags)) { - if(isset($additional_where_cond) && !empty($additional_where_cond)) + if(!empty($additional_where_cond)) $query_str.= "AND t.name IN ('".implode("','",$this->cfg->show_tags). "')"; else $query_str.= "WHERE t.name IN ('".implode("','",$this->cfg->show_tags). "')"; @@ -1890,6 +1986,7 @@ class PHPFSPOT { */ public function startSearch() { + /* date search */ if(isset($_POST['from']) && $this->isValidDate($_POST['from'])) { $from = $_POST['from']; } @@ -1897,15 +1994,36 @@ class PHPFSPOT { $to = $_POST['to']; } + /* tag-name search */ if(isset($_POST['for_tag']) && is_string($_POST['for_tag'])) { $searchfor_tag = $_POST['for_tag']; $_SESSION['searchfor_tag'] = $_POST['for_tag']; } + else { + unset($_SESSION['searchfor_tag']); + } + /* file-name search */ if(isset($_POST['for_name']) && is_string($_POST['for_name'])) { - $searchfor_name = $_POST['for_name']; $_SESSION['searchfor_name'] = $_POST['for_name']; } + else { + unset($_SESSION['searchfor_name']); + } + + /* rate-search */ + if(isset($_POST['rate_from']) && is_numeric($_POST['rate_from'])) { + + $_SESSION['rate_from'] = $_POST['rate_from']; + + if(isset($_POST['rate_to']) && is_numeric($_POST['rate_to'])) { + $_SESSION['rate_to'] = $_POST['rate_to']; + } + } + else { + /* delete any previously set value */ + unset($_SESSION['rate_to'], $_SESSION['rate_from']); + } $this->get_tags(); diff --git a/phpfspot.js b/phpfspot.js index 2aee155..be62cfb 100644 --- a/phpfspot.js +++ b/phpfspot.js @@ -287,6 +287,10 @@ function startSearch() objTemp['from'] = from; objTemp['to'] = to; } + if(document.getElementsByName('consider_rate')[0].checked == true) { + objTemp['rate_from'] = rate_search['from']; + objTemp['rate_to'] = rate_search['to']; + } var retr = HTML_AJAX.post(web_path + '/rpc.php', objTemp); if(retr == "ok") { @@ -348,7 +352,11 @@ function clearSearch() if(document.getElementsByName('consider_date')[0].checked == true) { document.getElementsByName('consider_date')[0].checked = false; datesearch(); - } + } + if(document.getElementsByName('consider_rate')[0].checked == true) { + document.getElementsByName('consider_rate')[0].checked = false; + datesearch(); + } } // clearSearch() @@ -799,6 +807,64 @@ function update_sort_order(obj) } // update_sort_order() +/** + * show rate stars + * + * this function will show the requested amount of + * rate-stars. + * + * @param string mode + * @param int level + */ +function show_rate(mode, level) +{ + var i; + + for(i = 1; i <= 5; i++) { + if(i <= level) { + document.getElementById('rate_' + mode + '_' + i).src = web_path + '/resources/star.png'; + } + else { + document.getElementById('rate_' + mode + '_' + i).src = web_path + '/resources/empty_rate.png'; + } + } + +} // show_rate() + +/** + * set rate stars + * + * + * this function will set the requested rate-stars-amount into a global + * variable (which will then later be used on form-submit) and will also + * update the display. + * + * @param string mode + * @param int level + */ +function set_rate(mode, level) +{ + rate_search[mode] = level; + show_rate(mode, level); + +} // set_rate() + +/** + * reset rate stars + * + * this function will reset the rate-star to their initial value. + * + * @param string mode + */ +function reset_rate(mode) +{ + if(rate_search[mode] == undefined) + rate_search[mode] = 0; + + show_rate(mode, rate_search[mode]); + +} // reset_rate() + /** * handle key events */ @@ -858,3 +924,4 @@ var origWidth; // position of the last shown photo in photo-index var photo_details_pos; var web_path; +var rate_search = new Array(); diff --git a/resources/empty_rate.png b/resources/empty_rate.png new file mode 100644 index 0000000000000000000000000000000000000000..dcf5febace94a178dfd52b8fa6225ea15ce2fdcc GIT binary patch literal 218 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|*pj^6T^Rm@ z;DWu&Cj&(|3p^r=85p>QL70(Y)*K0-AbW|YuPgfvRtXMny||-}aX_IcPZ!4!i_>o> zZR9=Rz`^Y6=8z=t<@fmm3ezGU1_!GC2@jlAo}L)r$RqPt|0Und&W;%>iD?Dpfmhw% zyW9Yj-VhL&9`&oMomw0_`HlEpE!kp73Cvfzk^bDXa44$rjF6*2U FngEevMpgg- literal 0 HcmV?d00001 diff --git a/rpc.php b/rpc.php index f4a93ce..ada2857 100644 --- a/rpc.php +++ b/rpc.php @@ -98,6 +98,7 @@ class PHPFSPOT_RPC { $phpfspot->resetNameSearch(); $phpfspot->resetTags(); $phpfspot->resetDateSearch(); + $phpfspot->resetRateSearch(); $phpfspot->resetPhotoView(); break; diff --git a/themes/default/templates/search.tpl b/themes/default/templates/search.tpl index c1d152c..672bb35 100644 --- a/themes/default/templates/search.tpl +++ b/themes/default/templates/search.tpl @@ -60,6 +60,29 @@ + { if $has_rating } + + Rating: + + { if ! $rate_search_enabled } + + { else } + + { /if } + consider rate-range + +   + + +   + + { $rate_search } + + + + + + { /if } Sort-Order:  -- 2.25.1