Cheetah
ChPollView.php
Go to the documentation of this file.
1 <?php
2 
8 ch_import('ChWsbPageView');
9 ch_import('ChTemplVotingView');
10 
11 require_once('ChPollCmts.php');
12 
14 {
15  // contain link on current module's object;
16  var $oModule;
17 
18  var $iPollId;
19 
20  // contain some information about current poll;
21  var $aPollInfo = array();
22 
23  // need for vote objects;
25 
27 
28  // logged member's id;
30 
31  // contain some info about current module;
32  var $aModule = array();
33 
34  // count of polls in poll's home page;
37 
45  function __construct($sPageName, &$aModule, &$oPollModule, $iPollId)
46  {
47  parent::__construct($sPageName);
48 
49  // define member's Id;
51  $this -> iMemberId = ( isset($aProfileInfo['ID']) )
52  ? $aProfileInfo['ID']
53  : 0;
54 
55  $this -> oModule = $oPollModule;
56  $this -> iPollId = $iPollId;
57 
58  if($this -> iPollId) {
59  $this -> aPollInfo = $this -> oModule -> _oDb -> getPollInfo($this -> iPollId);
60  if(!$this -> oModule -> oPrivacy -> check('view', $this -> aPollInfo[0]['id_poll'], $this -> iMemberId) ) {
61  echo $this -> oModule -> _oTemplate -> defaultPage( _t('_ch_poll'), MsgBox(_t('_ch_poll_access_denied')), 2 );
62  exit;
63  }
64  }
65 
66  if($this -> aPollInfo) {
67  $this -> aPollInfo = array_shift($this -> aPollInfo);
68  }
69 
70  $this -> oVotingView = new ChTemplVotingView('ch_poll', $this -> iPollId);
71  $this -> oCmtsView = new ChPollCmts('ch_poll', $this -> iPollId);
72 
73  $this -> aModule = $aModule;
74 
75  if($sPageName == 'show_poll_info')
76  $GLOBALS['oTopMenu']->setCustomSubHeaderUrl(CH_WSB_URL_ROOT . $this -> oModule -> _oConfig -> getBaseUri() . '&action=show_poll_info&id=' . $this -> iPollId);
77 
78  $GLOBALS['oTopMenu']->setCustomBreadcrumbs(array(
79  _t('_ch_poll') => CH_WSB_URL_ROOT . $this -> oModule -> _oConfig -> getBaseUri() . '&action=poll_home',
80  $this -> aPollInfo['poll_question'] => '',
81  ));
82  }
83 
84  function genColumnsHeader()
85  {
86  parent::genColumnsHeader();
87 
88  $this -> sCode .= $this -> oModule -> getInitPollPage();
89  }
90 
95  {
96  // ** init some variables;
97  $sPaginate = null;
98 
99  $iPage = ( isset($_GET['page']) )
100  ? (int) $_GET['page']
101  : 1;
102 
103  $iPerPage = ( isset($_GET['per_page']) )
104  ? (int) $_GET['per_page']
105  : $this -> iHomePage_countFeatured;
106 
107  if ($iPerPage <= 0 ) {
108  $iPerPage = $this -> iHomePage_countFeatured;
109  }
110 
111  if ( !$iPage ) {
112  $iPage = 1;
113  }
114 
115  // get only the member's polls ;
116  $iTotalNum = $this -> oModule -> _oDb -> getFeaturedCount(1, true);
117 
118  if ( !$iTotalNum ) {
119  $sOutputCode = MsgBox( _t( '_Empty' ) );
120  } else {
121  $sLimitFrom = ($iPage - 1) * $iPerPage;
122  $sqlLimit = "LIMIT {$sLimitFrom}, {$iPerPage}";
123  $aPolls = $this -> oModule -> _oDb -> getAllFeaturedPolls($sqlLimit, 1, true);
124  $sOutputCode = $this -> oModule -> genPollsList($aPolls);
125 
126  // define path to module;
127  $sModulePath = $this -> oModule -> getModulePath() . '?action=featured';
128 
129  // build paginate block;
130  $oPaginate = new ChWsbPaginate(array(
131  'page_url' => $sModulePath,
132  'count' => $iTotalNum,
133  'per_page' => $iPerPage,
134  'page' => $iPage,
135  'on_change_page' => 'return !loadDynamicBlock({id}, \'' . $sModulePath . '&action=poll_home&page={page}&per_page={per_page}\');',
136  ));
137 
138  $sPaginate = $oPaginate -> getSimplePaginate($sModulePath);
139  }
140 
141  return array($sOutputCode, array(), $sPaginate);
142  }
143 
148  {
149  // ** init some variables;
150  $sPaginate = null;
151 
152  $iPage = ( isset($_GET['page']) )
153  ? (int) $_GET['page']
154  : 1;
155 
156  $iPerPage = ( isset($_GET['per_page']) )
157  ? (int) $_GET['per_page']
158  : $this -> iHomePage_countLatest;
159 
160  if ($iPerPage <= 0 ) {
161  $iPerPage = $this -> iHomePage_countLatest;
162  }
163 
164  if ( !$iPage ) {
165  $iPage = 1;
166  }
167 
168  // get only the member's polls ;
169  $iTotalNum = $this -> oModule -> _oDb -> getFeaturedCount(0, true);
170 
171  if ( !$iTotalNum ) {
172  $sOutputCode = MsgBox( _t( '_Empty' ) );
173  } else {
174  $sLimitFrom = ($iPage - 1) * $iPerPage;
175  $sqlLimit = "LIMIT {$sLimitFrom}, {$iPerPage}";
176  $aPolls = $this -> oModule -> _oDb -> getAllFeaturedPolls($sqlLimit, 0, true);
177  $sOutputCode = $this -> oModule -> genPollsList($aPolls);
178 
179  // define path to module;
180  $sModulePath = $this -> oModule -> getModulePath();
181 
182  // build paginate block;
183  $oPaginate = new ChWsbPaginate(array(
184  'page_url' => $sModulePath,
185  'count' => $iTotalNum,
186  'per_page' => $iPerPage,
187  'page' => $iPage,
188  'on_change_page' => 'return !loadDynamicBlock({id}, \'' . $sModulePath . '&action=poll_home&page={page}&per_page={per_page}\');',
189  ));
190 
191  $sPaginate = $oPaginate -> getSimplePaginate($sModulePath);
192  }
193 
194  return array($sOutputCode, array(), $sPaginate);
195  }
196 
201  {
202  $sCode = '';
203 
204  if(!$this -> aPollInfo)
205  return MsgBox(_t('_Empty'));
206 
207  // prepare all needed keys
208  $aUnitInfo = array(
209  'ViewerID' => (int)$this->iMemberId,
210  'ID' => (int)$this->aPollInfo['id_poll'],
211  'BaseUri' => $this->oModule->_oConfig->getBaseUri(),
212  );
213 
214  $aUnitInfo['base_url'] = CH_WSB_URL_ROOT . $aUnitInfo['BaseUri'];
215  $aUnitInfo['approved_cpt'] = '';
216  $aUnitInfo['featured_cpt'] = '';
217 
218  $aUnitInfo['del_poll_title'] = $aUnitInfo['del_poll_url'] = $aUnitInfo['del_poll_script'];
219  if(isLogged() && ($this -> aPollInfo['id_profile'] == $this->iMemberId || isAdmin())) {
220  $sDeleteLink = $this->oModule->getModulePath() . '&action=delete_poll&id=' . $aUnitInfo['ID'];
221 
222  $aUnitInfo['del_poll_title'] = _t('_ch_poll_delete');
223  $aUnitInfo['del_poll_url'] = $sDeleteLink;
224  $aUnitInfo['del_poll_script'] = "if(confirm('" . ch_js_string(_t('_Are_you_sure')) . "')) window.open ('" . $sDeleteLink . "','_self'); return false;";
225  }
226 
227  $sMainPrefix = 'ch_poll';
228 
229  if (isAdmin($this->iMemberId) || (isModerator($this->iMemberId) && $this->aPollInfo['id_profile'] != $this->iMemberId))
230  {
231  $aUnitInfo['approved_cpt'] = _t('_' . $sMainPrefix . ($this->aPollInfo['poll_approval'] ? '_dis' : '_') . 'approve');
232  $aUnitInfo['featured_cpt'] = _t('_' . $sMainPrefix . ($this->aPollInfo['poll_featured'] ? '_un' : '_') . 'featured');
233  }
234 
236  $aButton = $oSubscription -> getButton($this -> iMemberId, $sMainPrefix, '', $this -> aPollInfo['id_poll']);
237  $sCode .= $oSubscription -> getData();
238  $aUnitInfo['sbs_poll_title'] = $aButton['title'];
239  $aUnitInfo['sbs_poll_script'] = $aButton['script'];
240 
241  $aUnitInfo['TitleShare'] = $this->oModule->isAllowedShare($this -> aPollInfo) ? _t('_Share') : '';
242 
243  $aUnitInfo['repostCpt'] = $aUnitInfo['repostScript'] = '';
244  if(ChWsbRequest::serviceExists('wall', 'get_repost_js_click')) {
245  $sCode .= ChWsbService::call('wall', 'get_repost_js_script');
246 
247  $aUnitInfo['repostCpt'] = _t('_Repost');
248  $aUnitInfo['repostScript'] = ChWsbService::call('wall', 'get_repost_js_click', array($this->iMemberId, $sMainPrefix, 'add', $this->aPollInfo['id_poll']));
249  }
250 
251  $sActions = $GLOBALS['oFunctions'] -> genObjectsActions($aUnitInfo, $sMainPrefix);
252  if(empty($sActions))
253  return '';
254 
255  return $sCode . $sActions;
256  }
257 
262  {
263  if(!$this -> aPollInfo) {
264  return MsgBox( _t('_Empty') );
265  }
266 
267  return $this -> oModule -> getOwnerBlock($this -> aPollInfo['id_profile'], $this -> aPollInfo);
268  }
269 
274  {
275  if(!$this -> aPollInfo)
276  return MsgBox( _t('_Empty') );
277 
278  $sContent = $this -> oModule -> getPollBlock($this -> aPollInfo, false, true);
279  return array($sContent);
280  }
281 
286  {
287  if(!$this -> aPollInfo)
288  return MsgBox(_t('_Empty'));
289 
290  if( $this -> oModule -> oPrivacy -> check('comment', $this -> aPollInfo['id_poll'], $oPoll -> aPollSettings['member_id']) ) {
291  $sOutputCode = $this -> oCmtsView -> getExtraCss();
292  $sOutputCode .= $this -> oCmtsView -> getExtraJs();
293 
294  $sOutputCode .= ( !$this -> oCmtsView -> isEnabled() )
295  ? null
296  : $this -> oCmtsView -> getCommentsFirst();
297  } else
298  $sOutputCode = MsgBox( _t( '_ch_poll_privacy_comment_error' ) );
299 
300  return $sOutputCode;
301  }
302 
307  {
308  if(!$this -> aPollInfo)
309  return MsgBox(_t('_Empty'));
310 
311  if( $this -> oModule -> oPrivacy -> check('vote', $this -> aPollInfo['id_poll'], $oPoll -> aPollSettings['member_id']) ) {
312  if ( $this -> oVotingView -> isEnabled()){
313  $sOutputCode = $this -> oVotingView -> getBigVoting();
314  }
315  } else
316  $sOutputCode = MsgBox( _t( '_ch_poll_privacy_vote_error' ) );
317 
318  return array($sOutputCode);
319  }
320 
322  {
323  if(!$this->oModule->isAllowedShare($this->aPollInfo))
324  return '';
325 
326  $sUrl = CH_WSB_URL_ROOT . $this -> oModule -> _oConfig -> getBaseUri() . '&action=show_poll_info&id=' . $this -> aPollInfo['id_poll'];
327  $sTitle = $this -> aPollInfo['poll_question'];
328 
329  ch_import('ChTemplSocialSharing');
331  return array($sCode, array(), array(), false);
332  }
333 }
ChPollView\getBlockCode_PoolBlock
getBlockCode_PoolBlock()
Definition: ChPollView.php:273
ChWsbSocialSharing\getInstance
static getInstance()
Definition: ChWsbSocialSharing.php:50
ChPollView\$oCmtsView
$oCmtsView
Definition: ChPollView.php:26
ChPollView\$aModule
$aModule
Definition: ChPollView.php:32
ChPollView\getBlockCode_ActionsBlock
getBlockCode_ActionsBlock()
Definition: ChPollView.php:200
$sModulePath
$sModulePath
Definition: ChSoundsUploader.php:21
MsgBox
MsgBox($sText, $iTimer=0)
Definition: design.inc.php:175
$sLimitFrom
$sLimitFrom
Definition: post_mod_crss.php:49
ChWsbPageView
Definition: ChWsbPageView.php:99
ChWsbRequest\serviceExists
static serviceExists($mixedModule, $sMethod, $sClass="Module")
Definition: ChWsbRequest.php:70
ch_js_string
ch_js_string($mixedInput, $iQuoteType=CH_ESCAPE_STR_AUTO)
Definition: utils.inc.php:1294
ChPollView\$iHomePage_countLatest
$iHomePage_countLatest
Definition: ChPollView.php:35
ch_import
ch_import($sClassName, $aModule=array())
Definition: utils.inc.php:1218
$sUrl
$sUrl
Definition: cart.php:15
ChPollView\$aPollInfo
$aPollInfo
Definition: ChPollView.php:21
php
ChPollView\$oModule
$oModule
Definition: ChPollView.php:16
isLogged
isLogged()
Definition: profiles.inc.php:24
ChWsbSubscription\getInstance
static getInstance()
Definition: ChWsbSubscription.php:67
$iPerPage
else $iPerPage
Definition: browse.php:61
isAdmin
isAdmin()
Definition: index.php:649
ChPollView
Definition: ChPollView.php:14
isModerator
isModerator($iId=0)
Definition: profiles.inc.php:58
$oPoll
$oPoll
Definition: index.php:71
ChPollView\getBlockCode_FeaturedHome
getBlockCode_FeaturedHome()
Definition: ChPollView.php:94
exit
exit
Definition: cart.php:21
$_GET
$_GET['debug']
Definition: index.php:67
ChPollView\__construct
__construct($sPageName, &$aModule, &$oPollModule, $iPollId)
Definition: ChPollView.php:45
$sTitle
$sTitle
Definition: actions.inc.php:13
ChPollView\$oVotingView
$oVotingView
Definition: ChPollView.php:24
ChPollView\$iPollId
$iPollId
Definition: ChPollView.php:18
ChPollView\getBlockCode_OwnerBlock
getBlockCode_OwnerBlock()
Definition: ChPollView.php:261
ChPollView\getBlockCode_CommentsBlock
getBlockCode_CommentsBlock()
Definition: ChPollView.php:285
ChWsbPaginate
Definition: ChWsbPaginate.php:69
ChPollView\getBlockCode_VotingsBlock
getBlockCode_VotingsBlock()
Definition: ChPollView.php:306
ChPollView\$iHomePage_countFeatured
$iHomePage_countFeatured
Definition: ChPollView.php:36
ChPollView\$iMemberId
$iMemberId
Definition: ChPollView.php:29
$sContent
$sContent
Definition: bottom_menu_compose.php:169
_t
_t($key, $arg0="", $arg1="", $arg2="")
Definition: languages.inc.php:509
ChPollView\getBlockCode_LatestHome
getBlockCode_LatestHome()
Definition: ChPollView.php:147
ChPollCmts
Definition: ChPollCmts.php:11
ChWsbPageView\$sPageName
$sPageName
Definition: ChWsbPageView.php:100
$aProfileInfo
$aProfileInfo
Definition: short_profile_info.php:23
ChPollView\genColumnsHeader
genColumnsHeader()
Definition: ChPollView.php:84
$iPage
$iPage
Definition: browse.php:50
getProfileInfo
getProfileInfo($iProfileID=0, $checkActiveStatus=false, $forceCache=false)
Definition: profiles.inc.php:249
ChPollView\getBlockCode_SocialSharing
getBlockCode_SocialSharing()
Definition: ChPollView.php:321
$iTotalNum
if(isset($_POST['crsss']) &&is_array($_POST['crsss'])) $iTotalNum
Definition: post_mod_crss.php:40
empty
Attr AllowedRel this is empty
Definition: Attr.AllowedRel.txt:7
ChWsbService\call
static call($mixed, $sMethod, $aParams=array(), $sClass='Module')
Definition: ChWsbService.php:32
ChTemplVotingView
Definition: ChTemplVotingView.php:14
ChWsbPageView\$sCode
$sCode
Definition: ChWsbPageView.php:102
$GLOBALS
$GLOBALS['iAdminPage']
Definition: advanced_settings.php:10
$oSubscription
$oSubscription
Definition: notifies.php:28