From e692c326cbef33e588145a48a18b28a89746390c Mon Sep 17 00:00:00 2001 From: Marco Villegas Date: Sun, 4 Jul 2010 00:02:16 -0500 Subject: [PATCH] feature #811694 by marvil07, Soren Jones, jsalinas and McO Artista: New widget for splitting of votes in positives/negatives Provide implementation fo two new aggregation functions for voting_api: 'positives' and 'negatives'. Add the new widget showing that new values. Thanks a lot to jsalinas y McO Artista for the design review at DrupalCamp in Peru --- WIDGETAPI.txt | 9 +- vud.module | 58 ++++++++++ vud.theme.inc | 30 +++++ widgets/upanddown/arrows.png | Bin 0 -> 2505 bytes widgets/upanddown/arrows.svg | 201 +++++++++++++++++++++++++++++++++++ widgets/upanddown/status-active.gif | Bin 0 -> 2196 bytes widgets/upanddown/upanddown.css | 75 +++++++++++++ widgets/upanddown/upanddown.inc | 17 +++ widgets/upanddown/widget.tpl.php | 25 +++++ 9 files changed, 412 insertions(+), 3 deletions(-) create mode 100644 widgets/upanddown/arrows.png create mode 100644 widgets/upanddown/arrows.svg create mode 100644 widgets/upanddown/status-active.gif create mode 100644 widgets/upanddown/upanddown.css create mode 100644 widgets/upanddown/upanddown.inc create mode 100644 widgets/upanddown/widget.tpl.php diff --git a/WIDGETAPI.txt b/WIDGETAPI.txt index 635737a..05c752b 100644 --- a/WIDGETAPI.txt +++ b/WIDGETAPI.txt @@ -154,15 +154,18 @@ specify__ them. 'up' link. Needed for javascript. `$link_class_down` :: String with the classes that should be put onto the "down" link. Needed for javascript. -`$class` :: 'negative', 'positive' or 'neutral' depending on +`$class` :: 'negative', 'positive' or 'neutral' depending on number of votes. `$vote_label` :: The pluralized vote label. -`$raw_points` :: Raw value for total vote points for the vote object +`$raw_points` :: Raw value for total vote points for the vote object (It can be a NULL if there are no votes or a signed value). -`$points` :: Number of total vote points for the vote object +`$points` :: Number of total vote points for the vote object (signed). `$unsigned_points` :: Number of total vote points for the object (unsigned). +`$up_points` :: Number of total positive vote points for the vote object. +`$down_points` :: Number of total positive vote points for the vote object. +`$vote_count` :: Number of total votes for the vote object. `$readonly` :: Boolean that indicates if the actual user can vote on the object where the widget is displayed. `$show_links` :: Boolean that indicates if the links need to be diff --git a/vud.module b/vud.module index 4d6fa87..731bbae 100644 --- a/vud.module +++ b/vud.module @@ -193,3 +193,61 @@ function vud_ctools_plugin_directory($module, $plugin) { return $plugin; } } + +/** + * Implementation of votingapi hook_votingapi_results_alter(). + */ +function vud_votingapi_results_alter(&$cache, $content_type, $content_id) { + $vud_cache = _vud_get_standard_results($content_type, $content_id); + $cache = array_merge_recursive($cache, $vud_cache); +} + +/** + * Implementation of hook_votingapi_metadata_alter(). + */ +function vud_votingapi_metadata_alter(&$data) { + $data['functions']['positives'] = array( + 'name' => t('Positives'), + 'description' => t('The sum of all positive votes for a content.'), + 'module' => 'vud', + ); + $data['functions']['negatives'] = array( + 'name' => t('Negatives'), + 'description' => t('The sum of all negative votes for a content.'), + 'module' => 'vud', + ); +} + +/** + * Calculate positive/negative results for VotingAPI cache. + * + * We provide 0 if not votes found. + */ +function _vud_get_standard_results($content_type, $content_id) { + $cache = array(); + $tag = variable_get('vud_tag', 'vote'); + + $sql = "SELECT SUM(v.value) as value_positives "; + $sql .= "FROM {votingapi_vote} v "; + $sql .= "WHERE v.content_type = '%s' AND v.content_id = %d AND v.value_type = 'points' AND v.value > 0 "; + $sql .= "GROUP BY v.value_type, v.tag"; + $value_positives = db_result(db_query($sql, $content_type, $content_id)); + + if ($value_positives === FALSE) { + $value_positives = 0; + } + $cache[$tag]['points']['positives'] = $value_positives; + + $sql = "SELECT SUM(v.value) as value_negatives "; + $sql .= "FROM {votingapi_vote} v "; + $sql .= "WHERE v.content_type = '%s' AND v.content_id = %d AND v.value_type = 'points' AND v.value < 0 "; + $sql .= "GROUP BY v.value_type, v.tag"; + $value_negatives = db_result(db_query($sql, $content_type, $content_id)); + + if ($value_negatives === FALSE) { + $value_negatives = 0; + } + $cache[$tag]['points']['negatives'] = $value_negatives; + + return $cache; +} diff --git a/vud.theme.inc b/vud.theme.inc index bebc4e0..93f0894 100644 --- a/vud.theme.inc +++ b/vud.theme.inc @@ -178,8 +178,38 @@ function vud_widget_proxy($content_id, $type, $tag, $widget_theme, $readonly=NUL $raw_points = votingapi_select_single_result_value($result_criteria); $variables['raw_points'] = $raw_points; $vote_result = (int)$raw_points; + + $criteria = array( + 'content_type' => $type, + 'content_id' => $content_id, + 'value_type' => 'points', + 'tag' => $tag, + 'function' => 'count' + ); + $vote_count = (int)votingapi_select_single_result_value($criteria); + $variables['vote_count'] = $vote_count; + $variables['unsigned_points'] = $vote_result; + $criteria = array( + 'content_type' => $type, + 'content_id' => $content_id, + 'value_type' => 'points', + 'tag' => $tag, + 'function' => 'positives' + ); + $positives = (int)votingapi_select_single_result_value($criteria); + $variables['up_points'] = $positives; + $criteria = array( + 'content_type' => $type, + 'content_id' => $content_id, + 'value_type' => 'points', + 'tag' => $tag, + 'function' => 'negatives' + ); + $negatives = (int)votingapi_select_single_result_value($criteria); + $variables['down_points'] = $negatives; + if ($vote_result > 0) { $variables['class'] = 'positive'; $variables['points'] = '+'. $vote_result; diff --git a/widgets/upanddown/arrows.png b/widgets/upanddown/arrows.png new file mode 100644 index 0000000000000000000000000000000000000000..c8979a64f03eab97a0ca1218366456244b546120 GIT binary patch literal 2505 zcmV;)2{!hLP)Xlut*4JL}T1OQrD)AeYVec_dfe$ByD1!?_6uZB!BKh404r4i zD^(S+QdI#fm0)F1|G-`CF=u_4dU{wn1K(TU+0OC$x^jFN(c62chQhW1gZFm(1cBeu zq)Z+MfJ5a3^TzxUrE&T?0$Oax9*Lr!>EX!2cGE|Uh^PtNCL$0S!4-iAZ(C6gU=O{d zqs|Thpyi!Mz^q#{p6ekhur&p2+Hw1pNEn>GHgw$NyMLRv9LU|V!ASu6yOo{6)4`tj z$V{=mqJWJ%?x-h5pPSc6AUh2F2KM%r^hQ)c}fhesY89~d_6U)X@Xy&MN@ zGa>N>eL#Vx%*hSq0QL|uVA=sfG735g$6b>HhfDbv05+zlt|ov+GY7`#%E0%_n~#r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3U!SBw6-f=$GQa<;a(d7pQy z*wOxZyO1OK%o{UC{@KxND*t*a7R~a8>AX8vNJN0apwA)VC|~PQk>_nKti%k#NT!6m zYIM-VglS!SuDTG#8L6gU2mbDG?u@O4|0AzS8WG)7M2cPeYSC1ws(_WM3RtPCfR)M? zpcD#t{?{O8vRtU8P(VgO7$jZas7A*7tp*H9ZZD4*_VS|2**LdVOa>62G&G43wOjsl zOGzXYL%(%cO(#k| zVks0@#e3X0IG2Y+SLcdloJ-zgC%{m4=EA0;ba8^1I99I(K8K&Pn$6#hGceLH< zY+c&Qx#YRFnoHODIj8d(DHM>bf<;s%oMHMC5jCya1$;}1$Ft1X7EzVCqk2UFrBI*_ z9pZ!Xs0!4OS9f3ws@Oi)HY-_PRgcea1Ek{Q8J4&KxRW~b*7`&|{q8X-l7qBdBaJIF4 zR`mNmEz~VCef%}+*DU5_=?N(ma9Kf)<%%bN9KbQ8K&Q5<~s){ zg#xXdOTNX<8#*iZC7pGgEbWs*0m}t>Fgx?Ja4sFru(Rv@o9TEg$BY{zs$%-4&jE67 z`I*@@&#q7qz}>Ybz`5k7?AT|Re$(vQctTawq@g`MmP?mBNx}gD$SYg7O2MWM-c$a+ zO40A*9ZURIIae&Z!OAwGDg!A)dwwLB()u!I-perkJ}Vz|v^0B>=fb?#qXNgB*T)?U z#v93$M2xkok?}++(~#tr1>^>GVjCl>Vwrq=EM;d%a(g1GlCoo4t&1zwCm!%WC3xUQ T&dlRe00000NkvXXu0mjfmC3o< literal 0 HcmV?d00001 diff --git a/widgets/upanddown/arrows.svg b/widgets/upanddown/arrows.svg new file mode 100644 index 0000000..de8ff8e --- /dev/null +++ b/widgets/upanddown/arrows.svg @@ -0,0 +1,201 @@ + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + inactive + active + + + + + + diff --git a/widgets/upanddown/status-active.gif b/widgets/upanddown/status-active.gif new file mode 100644 index 0000000000000000000000000000000000000000..207e95c3fa8cc31a89af150ad74059b1667922b6 GIT binary patch literal 2196 zcmeH{Urbw79LLW&_xASmFQt@HSs}NhO2-Jh1BM+kb4v^B62vmdY!-sIxUi{Y-eKaZ zd%2gEe>0H6h_VE=!^E(JL`)>X2jVS^Zcfvn5<-k2WvFCNG`ghG7rZ6$WnPVsKJ5GO zJ8$RvJD>CY{Z5~0cApFxfB|GdPWa6w{k0|AwWK|oJQ2I!Je@i}^Zo0eZod2F_QJwK zJhi*9v9}~^YcH8hrc$Ymjg76Xt@{st+t|%+?PYgm$u+ybCo8+3&1pZopVPthPs$Sl z|6c-*eO+r)N4wV(XsWJa2q<^z_?=Wy@>!YdIyWW&Uj-18tONF|3Mu0pM+@E|b#0}^ z!~zi%9q%)3&a(p~G`B1c3*4%%lzk?{ByJ6=pegKss;|dO;n%+FeCW7{V%4V@w$Z{GnR7Ggdfd96mCSRsm(IU3X`eH-@mY!nv5{mPH7adf{@tFd+{D#Z*P7E4Cu( zNI<&yxF8`-(K~6DmV_bgDJSM6QPSy-`a53zHsK*ro@??84uYGYiss#G335cQ(q^ z%wp~p0g$crQ*_&{2!a61R3ETvWG(*SZ8O_GR^u5Yc|OD{*}kN}6zL0fe!xt};GOz%hKaYMskC&qRw=<`U&U>^cAo zLBAqcYczaZ@J3LHlNVx%1c};=4Y#YG7RXW%xDepEe!!I1`hwd%{Td?N=QPn}&`2C( ze3|@EBBE1Mq|)`TYFdd2uA0le6o z6d!7|&nD=vC$NZI_5Tu^++t8Y=|vzw z1Q9I-fe?vcx1AJNZgm0}!B}H#d-&TI?-^oT* zRA10W&q#7unMxBUvZJU0H>48~K*CV@D7`H;MzIa8(QDnFN!<(7r69X=cc1~zTKw(l Pm4SkyKc+`yv*-Q t('Up and down'), + 'widget template' => 'widget', + ); +} diff --git a/widgets/upanddown/widget.tpl.php b/widgets/upanddown/widget.tpl.php new file mode 100644 index 0000000..f32f672 --- /dev/null +++ b/widgets/upanddown/widget.tpl.php @@ -0,0 +1,25 @@ + +
+
+ + " title=""> + + +
+ +
+ + " title=""> + + +
+
-- 1.7.1