2 class VanillaVotingHistory
extends Control
{
4 var $VanillaVotingHistory;
9 function VanillaVotingHistory(&$Context, $UserID) {
10 $this->Name
= 'VanillaVotingHistory';
11 $this->Control($Context);
12 $this->UserID
= $UserID;
13 $this->PostBackAction
= ForceIncomingString('PostBackAction', '');
14 if ($this->PostBackAction
== '') {
15 $this->GetVanillaVotingHistoryTotals($UserID);
16 $this->GetVanillaVotingHistoryPerUserID($UserID);
20 function GetVanillaVotingHistoryTotals($UserID) {
21 $sql = $this->Context
->ObjectFactory
->NewContextObject($this->Context
, 'SqlBuilder');
22 $sql->SetMainTable('UserDiscussionVote', 'UserDiscussionVote');
23 $sql->AddSelect('Vote' ,'UserDiscussionVote');
24 $sql->AddSelect('Vote', 'UserDiscussionVote', 'Total', 'COUNT');
25 $sql->AddWhere('UserDiscussionVote', 'UserID', '', $UserID, '=', '', '', 0);
26 $sql->AddGroupBy('Vote','UserDiscussionVote');
28 $ResultSet = $this->Context
->Database
->Select($sql, $this->Name
, 'GetVanillaVotingHistoryTotals', 'Failed to get love/hate totals.');
29 while ($Row = $this->Context
->Database
->GetRow($ResultSet)) {
30 if ($Row['Vote'] == 0) {
31 $this->TotalHated
= $Row['Total'];
32 } else if ($Row['Vote'] != 0) {
33 $this->TotalLoved
= $Row['Total'];
38 function GetVanillaVotingHistoryPerUserID($UserID) {
39 $sql = $this->Context
->ObjectFactory
->NewContextObject($this->Context
, 'SqlBuilder');
40 $sql->SetMainTable('UserDiscussionVote', 'UserDiscussionVote');
41 $sql->AddSelect(array('DiscussionID','Vote') ,'UserDiscussionVote');
42 $sql->AddJoin('Discussion', 'Discussion', 'DiscussionID', 'UserDiscussionVote', 'DiscussionID', 'left join');
43 $sql->AddSelect('Name' ,'Discussion', 'Title');
44 $sql->AddJoin('User', 'User', 'UserID', 'Discussion', 'AuthUserID', 'left join');
45 $sql->AddSelect('Name' ,'User','UserName');
46 $sql->AddWhere('UserDiscussionVote', 'UserID', '', $UserID, '=', '', '', 0);
48 $this->VanillaVotingHistory
= $this->Context
->Database
->Select($sql, $this->Name
, 'GetVanillaVotingHistoryPerUserID', 'Failed to get love history.');
52 $this->CallDelegate('PreRender');
53 if ($this->PostBackAction
== '') {
55 <h2><span>Total Loved ('.$this->TotalLoved
.') Total Hated ('.$this->TotalHated
.')</span>'.$this->Context
->GetDefinition('VanillaVotingHistory').'</h2>
56 <ul class="VanillaVotingHistory">';
58 while ($Row = $this->Context
->Database
->GetRow($this->VanillaVotingHistory
)) {
59 $Alternate = FlipBool($Alternate);
60 ($Alternate) ?
$class='even': $class='odd';
61 echo'<li class="'.$class.'">';
62 if ($this->UserID
== $this->Context
->Session
->UserID
) {
63 echo '<span class="UnLove"><a href="">'.($Row['Vote'] == 0 ?
$this->Context
->GetDefinition('UnHate'): $this->Context
->GetDefinition('UnLove')).'</a></span>';
65 echo '<span class="LoveResult">'.($Row['Vote'] == 0 ?
$this->Context
->GetDefinition('Hated'): $this->Context
->GetDefinition('Loved')).'</span>
66 <span class="DiscussionTitle"><a href="">'.$Row['Title'].'</a></span>
67 <span class="DiscussionAuthor">by '.$Row['UserName'].'</span>
73 $this->CallDelegate('PostRender');