Cheetah
ChBaseVotingView.php
Go to the documentation of this file.
1 <?php
2 
8 ch_import('ChWsbVoting');
9 
14 {
15  var $_iSizeStarBigX = 18;
16  var $_iSizeStarBigY = 18;
19 
20  function __construct( $sSystem, $iId, $iInit = 1 )
21  {
22  parent::__construct( $sSystem, $iId, $iInit );
23  }
24 
25  function getSmallVoting($iCanRate = 1, $iRateOverride = false)
26  {
27  if($iCanRate != 0 && !$this->checkAction())
28  $iCanRate = 0;
29 
30  return $this->getVoting('small', 0, array(
31  'show_count' => true,
32  'can_rate' => $iCanRate,
33  'override_rate' => $iRateOverride
34  ));
35  }
36 
37  function getBigVoting($iCanRate = 1, $iRateOverride = false)
38  {
39  if($iCanRate != 0 && !$this->checkAction())
40  $iCanRate = 0;
41 
42  return $this->getVoting('big', 0, array(
43  'show_count' => true,
44  'can_rate' => $iCanRate,
45  'override_rate' => $iRateOverride
46  ));
47  }
48 
49  function getJustVotingElement($iCanRate = 1, $iObjectId = 0, $iRateOverride = false)
50  {
51  return $this->getVoting('small', $iObjectId, array(
52  'show_count' => false,
53  'can_rate' => $iCanRate,
54  'override_rate' => $iRateOverride
55  ));
56  }
57 
58  function getVoting($sType, $iObjectId = 0, $aParams = array())
59  {
60  $iMax = $this->getMaxVote();
61  list($iSizeX, $iSizeY) = $this->_getSizeByType($sType);
62  $iWidth = $iSizeX * $iMax;
63 
64  if(empty($iObjectId))
65  $iObjectId = $this->getId();
66 
67  $sHtmlId = $this->_sSystem . '_voting_' . $sType . '_' . $iObjectId;
68  $sJsObject = ch_gen_method_name($sHtmlId);
69 
70  $sRet = '<div class="votes_'.$sType.'" id="' . $sHtmlId . '">';
71 
72  $iCanRate = !empty($aParams['can_rate']);
73  if ($iCanRate) {
74  $aJsParams = array(
75  'sSystem' => $this->_sSystem,
76  'iObjId' => $iObjectId,
77  'sBaseUrl' => CH_WSB_URL_ROOT,
78  'iSize' => $iSizeX,
79  'iMax' => $iMax,
80  'sHtmlId' => $sHtmlId,
81  );
82  $sRet .= $GLOBALS['oSysTemplate']->_wrapInTagJsCode('var ' . $sJsObject . ' = new ChWsbVoting(' . json_encode($aJsParams) . ');');
83  }
84 
85  $sRet .= '<div class="votes_gray_'.$sType.'" style="width:' . $iWidth . 'px;">';
86 
87  // clickable/hoverable vote buttons
88  if ($iCanRate) {
89  $sRet .= '<div class="votes_buttons">';
90  for ($i=1 ; $i<=$iMax ; ++$i)
91  $sRet .= '<a href="javascript:void(0);" onmouseover="' . $sJsObject . '.over(' . $i . ');" onmouseout="' . $sJsObject . '.out();" onclick="' . $sJsObject . '.vote(' . $i . ')"><i class="votes_button_' . $sType . ' sys-icon">&#61446;</i></a>';
92  $sRet .= '</div>';
93  }
94 
95  // gray stars
96  $sRet .= '<div class="votes_gray_'.$sType.'" style="width:' . $iWidth . 'px;">';
97  for ($i=1 ; $i<=$iMax ; ++$i)
98  $sRet .= '<i class="votes_button_'.$sType.' sys-icon star-o"></i>';
99  $sRet .= '</div>';
100 
101  // active stars
102  $iVoteRate = !empty($aParams['override_rate']) ? (int)$aParams['override_rate'] : $this->getVoteRate();
103  $sRet .= '<div class="votes_slider votes_active_'.$sType.'" style="width:' . round($iVoteRate * ($iMax ? $iWidth / $iMax : 0)) . 'px;">';
104  for ($i=1 ; $i<=$iMax ; ++$i)
105  $sRet .= '<i class="votes_button_'.$sType.' sys-icon star"></i>';
106  $sRet .= '</div>';
107 
108  $sRet .= '</div>';
109 
110  // vot count
111  if (!empty($aParams['show_count']))
112  $sRet .= '<span class="votes_count">' . _t('_n_votes', $this->getVoteCount()) . '</span>';
113 
114  $sRet .= '<div class="clear_both"></div>';
115  $sRet .= '</div>';
116 
117  return $sRet;
118  }
119 
120  function getExtraJs ()
121  {
122  $GLOBALS['oSysTemplate']->addJs('ChWsbVoting.js');
123  }
124 
125  protected function _getSizeByType($sType)
126  {
127  $aResult = array();
128 
129  switch($sType) {
130  case 'small':
131  $aResult = array($this->_iSizeStarSmallX, $this->_iSizeStarSmallY);
132  break;
133 
134  case 'big':
135  $aResult = array($this->_iSizeStarBigX, $this->_iSizeStarBigY);
136  break;
137  }
138 
139  return $aResult;
140  }
141 }
ChWsbVoting\getVoteRate
getVoteRate()
Definition: ChWsbVoting.php:277
ChBaseVotingView\getBigVoting
getBigVoting($iCanRate=1, $iRateOverride=false)
Definition: ChBaseVotingView.php:37
ChBaseVotingView\getVoting
getVoting($sType, $iObjectId=0, $aParams=array())
Definition: ChBaseVotingView.php:58
ChBaseVotingView\getSmallVoting
getSmallVoting($iCanRate=1, $iRateOverride=false)
Definition: ChBaseVotingView.php:25
ch_import
ch_import($sClassName, $aModule=array())
Definition: utils.inc.php:1218
$aResult
$aResult
Definition: index.php:19
php
ChWsbVoting
Definition: ChWsbVoting.php:90
$iId
$iId
Definition: license.php:15
ch_gen_method_name
ch_gen_method_name($s, $sWordsDelimiter='_')
Definition: utils.inc.php:1942
ChBaseVotingView\getExtraJs
getExtraJs()
Definition: ChBaseVotingView.php:120
ChBaseVotingView\$_iSizeStarBigX
$_iSizeStarBigX
Definition: ChBaseVotingView.php:15
ChBaseVotingView\_getSizeByType
_getSizeByType($sType)
Definition: ChBaseVotingView.php:125
$sType
$sType
Definition: actions.inc.php:11
ChBaseVotingView\__construct
__construct( $sSystem, $iId, $iInit=1)
Definition: ChBaseVotingView.php:20
ChBaseVotingView
Definition: ChBaseVotingView.php:14
ChBaseVotingView\$_iSizeStarSmallX
$_iSizeStarSmallX
Definition: ChBaseVotingView.php:17
ChWsbVoting\checkAction
checkAction($bPerformAction=false)
Definition: ChWsbVoting.php:239
ChWsbVoting\getId
getId()
Definition: ChWsbVoting.php:257
ChWsbVoting\getMaxVote
getMaxVote()
Definition: ChWsbVoting.php:267
_t
_t($key, $arg0="", $arg1="", $arg2="")
Definition: languages.inc.php:509
ChBaseVotingView\getJustVotingElement
getJustVotingElement($iCanRate=1, $iObjectId=0, $iRateOverride=false)
Definition: ChBaseVotingView.php:49
ChBaseVotingView\$_iSizeStarSmallY
$_iSizeStarSmallY
Definition: ChBaseVotingView.php:18
ChWsbVoting\getVoteCount
getVoteCount()
Definition: ChWsbVoting.php:272
ChBaseVotingView\$_iSizeStarBigY
$_iSizeStarBigY
Definition: ChBaseVotingView.php:16
empty
Attr AllowedRel this is empty
Definition: Attr.AllowedRel.txt:7
$GLOBALS
$GLOBALS['iAdminPage']
Definition: advanced_settings.php:10
if
if(!defined("VERSION")) define("VERSION"
Definition: header.inc.php:13