PageRenderTime 46ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/components/com_poll/views/poll/view.html.php

https://bitbucket.org/asosso/joomla15
PHP | 192 lines | 129 code | 33 blank | 30 comment | 18 complexity | ae132aefea74d3719022c9da4eca9510 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. <?php
  2. /**
  3. * @version $Id: view.html.php 14401 2010-01-26 14:10:00Z louis $
  4. * @package Joomla
  5. * @subpackage Poll
  6. * @copyright Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
  7. * @license GNU/GPL, see LICENSE.php
  8. * Joomla! is free software. This version may have been modified pursuant
  9. * to the GNU General Public License, and as distributed it includes or
  10. * is derivative of works licensed under the GNU General Public License or
  11. * other free or open source software licenses.
  12. * See COPYRIGHT.php for copyright notices and details.
  13. */
  14. // Check to ensure this file is included in Joomla!
  15. defined('_JEXEC') or die( 'Restricted access' );
  16. jimport( 'joomla.application.component.view');
  17. /**
  18. * HTML View class for the Poll component
  19. *
  20. * @static
  21. * @package Joomla
  22. * @subpackage Poll
  23. * @since 1.0
  24. */
  25. class PollViewPoll extends JView
  26. {
  27. function display($tpl = null)
  28. {
  29. global $mainframe;
  30. $db =& JFactory::getDBO();
  31. $document =& JFactory::getDocument();
  32. $pathway =& $mainframe->getPathway();
  33. $poll_id = JRequest::getVar( 'id', 0, '', 'int' );
  34. $poll =& JTable::getInstance('poll', 'Table');
  35. $poll->load( $poll_id );
  36. // if id value is passed and poll not published then exit
  37. if ($poll->id > 0 && $poll->published != 1) {
  38. JError::raiseError( 403, JText::_('Access Forbidden') );
  39. return;
  40. }
  41. // Adds parameter handling
  42. $params = $mainframe->getParams();
  43. //Set page title information
  44. $menus = &JSite::getMenu();
  45. $menu = $menus->getActive();
  46. // because the application sets a default page title, we need to get it
  47. // right from the menu item itself
  48. if (is_object( $menu )) {
  49. $menu_params = new JParameter( $menu->params );
  50. if (!$menu_params->get( 'page_title')) {
  51. $params->set('page_title', $poll->title);
  52. }
  53. } else {
  54. $params->set('page_title', $poll->title);
  55. }
  56. $document->setTitle( $params->get( 'page_title' ) );
  57. //Set pathway information
  58. $pathway->addItem($poll->title, '');
  59. $params->def( 'show_page_title', 1 );
  60. $params->def( 'page_title', $poll->title );
  61. $first_vote = '';
  62. $last_vote = '';
  63. $votes = '';
  64. // Check if there is a poll corresponding to id and if poll is published
  65. if ($poll->id > 0)
  66. {
  67. if (empty( $poll->title )) {
  68. $poll->id = 0;
  69. $poll->title = JText::_( 'Select Poll from the list' );
  70. }
  71. $query = 'SELECT MIN( date ) AS mindate, MAX( date ) AS maxdate'
  72. . ' FROM #__poll_date'
  73. . ' WHERE poll_id = '. (int) $poll->id;
  74. $db->setQuery( $query );
  75. $dates = $db->loadObject();
  76. if (isset( $dates->mindate )) {
  77. $first_vote = JHTML::_('date', $dates->mindate, JText::_('DATE_FORMAT_LC2') );
  78. $last_vote = JHTML::_('date', $dates->maxdate, JText::_('DATE_FORMAT_LC2') );
  79. }
  80. $query = 'SELECT a.id, a.text, a.hits, b.voters '
  81. . ' FROM #__poll_data AS a'
  82. . ' INNER JOIN #__polls AS b ON b.id = a.pollid'
  83. . ' WHERE a.pollid = '. (int) $poll->id
  84. . ' AND a.text <> ""'
  85. . ' ORDER BY a.hits DESC';
  86. $db->setQuery( $query );
  87. $votes = $db->loadObjectList();
  88. } else {
  89. $votes = array();
  90. }
  91. // list of polls for dropdown selection
  92. $query = 'SELECT id, title, alias'
  93. . ' FROM #__polls'
  94. . ' WHERE published = 1'
  95. . ' ORDER BY id'
  96. ;
  97. $db->setQuery( $query );
  98. $pList = $db->loadObjectList();
  99. foreach ($pList as $k=>$p)
  100. {
  101. $pList[$k]->url = JRoute::_('index.php?option=com_poll&id='.$p->id.':'.$p->alias);
  102. }
  103. array_unshift( $pList, JHTML::_('select.option', '', JText::_( 'Select Poll from the list' ), 'url', 'title' ));
  104. // dropdown output
  105. $lists = array();
  106. $lists['polls'] = JHTML::_('select.genericlist', $pList, 'id',
  107. 'class="inputbox" size="1" style="width:200px" onchange="if (this.options[selectedIndex].value != \'\') {document.location.href=this.options[selectedIndex].value}"',
  108. 'url', 'title',
  109. JRoute::_('index.php?option=com_poll&id='.$poll->id.':'.$poll->alias)
  110. );
  111. $graphwidth = 200;
  112. $barheight = 4;
  113. $maxcolors = 5;
  114. $barcolor = 0;
  115. $tabcnt = 0;
  116. $colorx = 0;
  117. $maxval = isset($votes[0]) ? $votes[0]->hits : 0;
  118. $sumval = isset($votes[0]) ? $votes[0]->voters : 0;
  119. $k = 0;
  120. for ($i = 0; $i < count( $votes ); $i++)
  121. {
  122. $vote =& $votes[$i];
  123. if ($maxval > 0 && $sumval > 0)
  124. {
  125. $vote->width = ceil( $vote->hits * $graphwidth / $maxval );
  126. $vote->percent = round( 100 * $vote->hits / $sumval, 1 );
  127. }
  128. else
  129. {
  130. $vote->width = 0;
  131. $vote->percent = 0;
  132. }
  133. $vote->class = '';
  134. if ($barcolor == 0)
  135. {
  136. if ($colorx < $maxcolors) {
  137. $colorx = ++$colorx;
  138. } else {
  139. $colorx = 1;
  140. }
  141. $vote->class = "polls_color_".$colorx;
  142. } else {
  143. $vote->class = "polls_color_".$barcolor;
  144. }
  145. $vote->barheight = $barheight;
  146. $vote->odd = $k;
  147. $vote->count = $i;
  148. $k = 1 - $k;
  149. }
  150. $this->assign('first_vote', $first_vote);
  151. $this->assign('last_vote', $last_vote);
  152. $this->assignRef('lists', $lists);
  153. $this->assignRef('params', $params);
  154. $this->assignRef('poll', $poll);
  155. $this->assignRef('votes', $votes);
  156. parent::display($tpl);
  157. }
  158. }
  159. ?>