issue121, search for a specific rate-limit
authorAndreas Unterkircher <unki@netshadow.at>
Sat, 24 May 2008 09:39:39 +0000 (11:39 +0200)
committerAndreas Unterkircher <unki@netshadow.at>
Sat, 24 May 2008 09:39:39 +0000 (11:39 +0200)
Signed-off-by: Andreas Unterkircher <unki@netshadow.at>
phpfspot.class.php
phpfspot.js
resources/empty_rate.png [new file with mode: 0644]
rpc.php
themes/default/templates/search.tpl

index 0711499..58cda4e 100644 (file)
@@ -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 &uarr;',
             'rate_desc' => 'Rate &darr;',
@@ -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']))
@@ -529,6 +541,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.= "<img id=\"rate_from_". $i ."\" src=\"";
+
+         if(isset($_SESSION['rate_from']) && $i <= $_SESSION['rate_from'])
+            $bar.= $this->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.= "<br />\n";
+
+       for($i = 1; $i <= 5; $i++) {
+
+         $bar.= "<img id=\"rate_to_". $i ."\" src=\"";
+
+         if(isset($_SESSION['rate_to']) && $i <= $_SESSION['rate_to'])
+            $bar.= $this->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
     *
     * If the length of the name exceeds $limit the
@@ -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()
    {
@@ -1010,6 +1068,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
     *
     * this function returns all photos based on
@@ -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();
 
index 2aee155..be62cfb 100644 (file)
@@ -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()
 
@@ -800,6 +808,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
  */
 function keyDown(e) {
@@ -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 (file)
index 0000000..dcf5feb
Binary files /dev/null and b/resources/empty_rate.png differ
diff --git a/rpc.php b/rpc.php
index f4a93ce..ada2857 100644 (file)
--- a/rpc.php
+++ b/rpc.php
@@ -98,6 +98,7 @@ class PHPFSPOT_RPC {
             $phpfspot->resetNameSearch();
             $phpfspot->resetTags();
             $phpfspot->resetDateSearch();
+            $phpfspot->resetRateSearch();
             $phpfspot->resetPhotoView();
             break;
 
index c1d152c..672bb35 100644 (file)
    <input type="image" class="submit" src="{$web_path}/resources/doit.png" alt="start search" title="start search" onclick="click(this);" />
   </td>
  </tr>
+ { if $has_rating }
+ <tr>
+  <td>Rating:</td>
+  <td class="nowarp">
+   { if ! $rate_search_enabled }
+    <input type="checkbox" class="checkbox" name="consider_rate" value="Y" />
+   { else }
+    <input type="checkbox" class="checkbox" name="consider_rate" value="Y" checked="checked" />
+   { /if }
+   consider rate-range
+  </td>
+  <td>&nbsp;</td>
+ </tr>
+ <tr>
+  <td>&nbsp;</td>
+  <td>
+   { $rate_search }
+  </td>
+  <td>
+   <input type="image" class="submit" src="{$web_path}/resources/doit.png" alt="start search" title="start search" onclick="click(this);" />
+  </td>
+ </tr>
+ { /if }
  <tr>
   <td>
    Sort-Order:&nbsp;