Added extension: vanilla-voting-0.2beta-0.2beta.zip
[vanilla-miry.git] / extensions / VanillaVoting / library / Class.VanillaVotingHistory.php
blobcb6bcc062300380cb8dff36eb9306090fa28ebaa
1 <?php
2 class VanillaVotingHistory extends Control {
4 var $VanillaVotingHistory;
5 var $TotalLoved;
6 var $TotalHated;
7 var $UserID;
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);
47 $sql->AddLimit(0,10);
48 $this->VanillaVotingHistory = $this->Context->Database->Select($sql, $this->Name, 'GetVanillaVotingHistoryPerUserID', 'Failed to get love history.');
51 function Render() {
52 $this->CallDelegate('PreRender');
53 if ($this->PostBackAction == '') {
54 echo '
55 <h2><span>Total Loved ('.$this->TotalLoved.') Total Hated ('.$this->TotalHated.')</span>'.$this->Context->GetDefinition('VanillaVotingHistory').'</h2>
56 <ul class="VanillaVotingHistory">';
57 $Alternate = 0;
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>
69 </li>';
71 echo '</ul>';
73 $this->CallDelegate('PostRender');