- Timestamp:
- Jul 15, 2008, 3:29:23 AM (16 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/functions_rate.inc.php
r2299 r2435 37 37 or !in_array($rate, $conf['rate_items'])) 38 38 { 39 return ;39 return false; 40 40 } 41 41 … … 44 44 if ($user_anonymous and !$conf['rate_anonymous']) 45 45 { 46 return ;46 return false; 47 47 } 48 48 … … 119 119 // update of images.average_rate field 120 120 $query = ' 121 SELECT ROUND(AVG(rate),2) AS average_rate 121 SELECT COUNT(rate) AS count 122 , ROUND(AVG(rate),2) AS average 123 , ROUND(STD(rate),2) AS stdev 122 124 FROM '.RATE_TABLE.' 123 125 WHERE element_id = '.$image_id.' 124 126 ;'; 125 $row = mysql_fetch_a rray(pwg_query($query));127 $row = mysql_fetch_assoc(pwg_query($query)); 126 128 $query = ' 127 129 UPDATE '.IMAGES_TABLE.' 128 SET average_rate = '.$row['average _rate'].'130 SET average_rate = '.$row['average'].' 129 131 WHERE id = '.$image_id.' 130 132 ;'; 131 133 pwg_query($query); 134 return $row; 132 135 } 133 136 -
trunk/include/ws_functions.inc.php
r2429 r2435 775 775 return new PwgNamedStruct('image',$ret, null, array('name','comment') ); 776 776 } 777 778 779 /** 780 * rates the image_id in the parameter 781 */ 782 function ws_images_Rate($params, &$service) 783 { 784 $image_id = (int)$params['image_id']; 785 $query = ' 786 SELECT DISTINCT id FROM '.IMAGES_TABLE.' 787 INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id=image_id 788 WHERE id='.$image_id 789 .get_sql_condition_FandF( 790 array( 791 'forbidden_categories' => 'category_id', 792 'forbidden_images' => 'id', 793 ), 794 ' AND' 795 ).' 796 LIMIT 1'; 797 if ( mysql_num_rows( pwg_query($query) )==0 ) 798 { 799 return new PwgError(404, "Invalid image_id or access denied" ); 800 } 801 $rate = (int)$params['rate']; 802 include_once(PHPWG_ROOT_PATH.'include/functions_rate.inc.php'); 803 $res = rate_picture( $image_id, $rate ); 804 if ($res==false) 805 { 806 global $conf; 807 return new PwgError( 403, "Forbidden or rate not in ". implode(',',$conf['rate_items'])); 808 } 809 return $res; 810 } 811 777 812 778 813 /** -
trunk/template/yoga/picture.tpl
r2429 r2435 163 163 selectElement.disabled = true; 164 164 var y = new PwgWS(rootUrl); 165 166 165 y.callService( 167 166 "pwg.images.setPrivacyLevel", {image_id: id, level:level} , … … 183 182 <tr> 184 183 <td class="label">{'Average rate'|@translate}</td> 185 <td class="value" >184 <td class="value" id="ratingSummary"> 186 185 {if $rate_summary.count} 187 186 {assign var='rate_text' value='%.2f (rated %d times, standard deviation = %.2f)'|@translate } … … 214 213 <form action="{$rating.F_ACTION}" method="post" id="rateForm"> 215 214 <div> 216 {if isset($rating.USER_RATE)}{'update_rate'|@translate}{else}{'new_rate'|@translate}{/if} 215 <span id="updateRate">{if isset($rating.USER_RATE)}{'update_rate'|@translate}{else}{'new_rate'|@translate}{/if}</span> 217 216 : 218 217 {foreach from=$rating.marks item=mark name=rate_loop} … … 225 224 {/foreach} 226 225 <script type="text/javascript" src="{$ROOT_URL}{$themeconf.template_dir}/rating.js"></script> 226 <script type="text/javascript"> 227 makeNiceRatingForm( {ldelim}rootUrl: '{$ROOT_URL|@escape:"javascript"}', image_id: {$current.id}, 228 updateRateText: "{'update_rate'|@translate|@escape:'javascript'}", updateRateElement: document.getElementById("updateRate"), 229 ratingSummaryText: "{'%.2f (rated %d times, standard deviation = %.2f)'|@translate|@escape:'javascript'}", ratingSummaryElement: document.getElementById("ratingSummary") {rdelim} ); 230 </script> 227 231 </div> 228 232 </form> -
trunk/template/yoga/rating.js
r1912 r2435 1 makeNiceRatingForm();1 var gRatingOptions, gRatingButtons, gUserRating; 2 2 3 function makeNiceRatingForm( )3 function makeNiceRatingForm(options) 4 4 { 5 var form = document.getElementById('rateForm');6 if (!form) return; //? template changed 7 gRatingButtons = form.getElementsByTagName('input'); 5 gRatingOptions = options || {}; 6 var form = document.getElementById('rateForm'); 7 if (!form) return; //? template changed 8 8 9 gUserRating = ""; 10 for (var i=0; i<gRatingButtons.length; i++) 11 { 12 if ( gRatingButtons[i].type=="button" ) 13 { 14 gUserRating = gRatingButtons[i].value; 15 break; 16 } 17 } 9 gRatingButtons = form.getElementsByTagName('input'); 10 gUserRating = ""; 11 for (var i=0; i<gRatingButtons.length; i++) 12 { 13 if ( gRatingButtons[i].type=="button" ) 14 { 15 gUserRating = gRatingButtons[i].value; 16 break; 17 } 18 } 18 19 19 for (var i=0; i<gRatingButtons.length; i++) 20 { 21 var rateButton = gRatingButtons[i]; 22 rateButton.initialRateValue = rateButton.value; // save it as a property 20 for (var i=0; i<gRatingButtons.length; i++) 21 { 22 var rateButton = gRatingButtons[i]; 23 rateButton.initialRateValue = rateButton.value; // save it as a property 24 try { rateButton.type = "button"; } catch (e){}// avoid normal submit (use ajax); not working in IE6 23 25 24 rateButton.value = ""; //hide the text IE/Opera 25 26 27 28 29 26 if (navigator.userAgent.indexOf('AppleWebKit/') == -1 ) rateButton.value = ""; //hide the text IE/Opera - breaks safari 27 with (rateButton.style) 28 { 29 textIndent = "-50px"; //hide the text FF 30 marginLeft = marginRight = 0; 31 } 30 32 31 32 33 34 33 if (i!=gRatingButtons.length-1 && rateButton.nextSibling.nodeType == 3 /*TEXT_NODE*/) 34 rateButton.parentNode.removeChild(rateButton.nextSibling); 35 if (i>0 && rateButton.previousSibling.nodeType == 3 /*TEXT_NODE*/) 36 rateButton.parentNode.removeChild(rateButton.previousSibling); 35 37 36 37 38 39 40 41 42 43 44 45 46 47 38 if(window.addEventListener){ // Mozilla, Netscape, Firefox 39 rateButton.addEventListener("click", updateRating, false ); 40 rateButton.addEventListener("mouseout", resetRatingStarDisplay, false ); 41 rateButton.addEventListener("mouseover", updateRatingStarDisplayEvt, false ); 42 } 43 else if(window.attachEvent) { // IE 44 rateButton.attachEvent("onclick", updateRating); 45 rateButton.attachEvent("onmouseout", resetRatingStarDisplay); 46 rateButton.attachEvent("onmouseover", updateRatingStarDisplayEvt); 47 } 48 } 49 resetRatingStarDisplay(); 48 50 } 49 51 50 52 function resetRatingStarDisplay() 51 53 { 52 54 updateRatingStarDisplay( gUserRating ); 53 55 } 54 56 55 57 function updateRatingStarDisplay(userRating) 56 58 { 57 for (i=0; i<gRatingButtons.length; i++) 58 { 59 var rateButton = gRatingButtons[i]; 60 if (userRating!=="" && userRating>=rateButton.initialRateValue ) 61 { 62 rateButton.className = "rateButtonStarFull"; 63 } 64 else 65 { 66 rateButton.className = "rateButtonStarEmpty"; 67 } 68 } 59 for (var i=0; i<gRatingButtons.length; i++) 60 gRatingButtons[i].className = (userRating!=="" && userRating>=gRatingButtons[i].initialRateValue ) ? "rateButtonStarFull" : "rateButtonStarEmpty"; 69 61 } 70 62 71 63 function updateRatingStarDisplayEvt(e) 72 64 { 73 if (e.target) 74 updateRatingStarDisplay(e.target.initialRateValue); 75 else //IE 76 updateRatingStarDisplay(e.srcElement.initialRateValue); 65 updateRatingStarDisplay( 66 e.target ? e.target.initialRateValue : e.srcElement.initialRateValue); 77 67 } 78 68 79 69 function updateRating(e) 80 70 { 81 if (e.target) 82 var rateButton = e.target; 83 else //IE 84 var rateButton = e.srcElement; 85 if (rateButton.initialRateValue == gUserRating) 86 return false; //nothing to do 87 // some ajax here one day would be nice 88 rateButton.value = rateButton.initialRateValue; // put back real value 89 return true; 71 var rateButton = e.target || e.srcElement; 72 if (rateButton.initialRateValue == gUserRating) 73 return false; //nothing to do 74 75 for (var i=0; i<gRatingButtons.length; i++) gRatingButtons[i].disabled=true; 76 var y = new PwgWS(gRatingOptions.rootUrl); 77 y.callService( 78 "pwg.images.rate", {image_id: gRatingOptions.image_id, rate: rateButton.initialRateValue } , 79 { 80 onFailure: function(num, text) { 81 alert(num + " " + text); 82 document.location = rateButton.form.action + "&rate="+rateButton.initialRateValue; 83 }, 84 onSuccess: function(result) { 85 gUserRating = rateButton.initialRateValue; 86 for (var i=0; i<gRatingButtons.length; i++) gRatingButtons[i].disabled=false; 87 if (gRatingOptions.updateRateElement) gRatingOptions.updateRateElement.innerHTML = gRatingOptions.updateRateText; 88 if (gRatingOptions.ratingSummaryElement) 89 { 90 var t = gRatingOptions.ratingSummaryText; 91 var args =[result.average, result.count, result.stdev], idx = 0, rexp = new RegExp( /%\.?\d*[sdf]/ ); 92 _xxx = t.match( rexp ); 93 while (idx<args.length) t=t.replace(rexp, args[idx++]); 94 gRatingOptions.ratingSummaryElement.innerHTML = t; 95 } 96 } 97 } 98 ); 99 return false; 90 100 } -
trunk/ws.php
r2429 r2435 44 44 'retrieves the PWG version'); 45 45 46 $service->addMethod('pwg.caddie.add', 'ws_caddie_add', 46 $service->addMethod('pwg.caddie.add', 'ws_caddie_add', 47 47 array( 48 48 'image_id'=> array( 'flags'=>WS_PARAM_FORCE_ARRAY ), … … 95 95 'image_id' => array(), 96 96 'comments_page' => array('default'=>0 ), 97 'comments_per_page' => array( 98 'default' => $conf['nb_comment_page'], 97 'comments_per_page' => array( 98 'default' => $conf['nb_comment_page'], 99 99 'maxValue' => 2*$conf['nb_comment_page'], 100 100 ), 101 101 ), 102 102 'retrieves information about the given photo' ); 103 104 $service->addMethod('pwg.images.rate', 'ws_images_rate', 105 array( 106 'image_id' => array(), 107 'rate' => array(), 108 ), 109 'rate the image' ); 103 110 104 111 $service->addMethod('pwg.images.search', 'ws_images_search',
Note: See TracChangeset
for help on using the changeset viewer.