[ Index ]

PHP Cross Reference of Joomla 1.5.26 DE

title

Body

[close]

/components/com_poll/views/poll/ -> view.html.php (source)

   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  
  15  // Check to ensure this file is included in Joomla!
  16  defined('_JEXEC') or die( 'Restricted access' );
  17  
  18  jimport( 'joomla.application.component.view');
  19  
  20  /**
  21   * HTML View class for the Poll component
  22   *
  23   * @static
  24   * @package        Joomla
  25   * @subpackage    Poll
  26   * @since 1.0
  27   */
  28  class PollViewPoll extends JView
  29  {
  30  	function display($tpl = null)
  31      {
  32          global $mainframe;
  33  
  34          $db       =& JFactory::getDBO();
  35          $document =& JFactory::getDocument();
  36          $pathway  =& $mainframe->getPathway();
  37  
  38          $poll_id = JRequest::getVar( 'id', 0, '', 'int' );
  39  
  40          $poll =& JTable::getInstance('poll', 'Table');
  41          $poll->load( $poll_id );
  42  
  43          // if id value is passed and poll not published then exit
  44          if ($poll->id > 0 && $poll->published != 1) {
  45              JError::raiseError( 403, JText::_('Access Forbidden') );
  46              return;
  47          }
  48  
  49          // Adds parameter handling
  50          $params = $mainframe->getParams();
  51  
  52          //Set page title information
  53          $menus    = &JSite::getMenu();
  54          $menu    = $menus->getActive();
  55  
  56          // because the application sets a default page title, we need to get it
  57          // right from the menu item itself
  58          if (is_object( $menu )) {
  59              $menu_params = new JParameter( $menu->params );
  60              if (!$menu_params->get( 'page_title')) {
  61                  $params->set('page_title',    $poll->title);
  62              }
  63          } else {
  64              $params->set('page_title',    $poll->title);
  65          }
  66          $document->setTitle( $params->get( 'page_title' ) );
  67  
  68          //Set pathway information
  69          $pathway->addItem($poll->title, '');
  70  
  71          $params->def( 'show_page_title', 1 );
  72          $params->def( 'page_title', $poll->title );
  73  
  74          $first_vote = '';
  75          $last_vote     = '';
  76          $votes        = '';
  77  
  78          // Check if there is a poll corresponding to id and if poll is published
  79          if ($poll->id > 0)
  80          {
  81              if (empty( $poll->title )) {
  82                  $poll->id = 0;
  83                  $poll->title = JText::_( 'Select Poll from the list' );
  84              }
  85  
  86              $query = 'SELECT MIN( date ) AS mindate, MAX( date ) AS maxdate'
  87                  . ' FROM #__poll_date'
  88                  . ' WHERE poll_id = '. (int) $poll->id;
  89              $db->setQuery( $query );
  90              $dates = $db->loadObject();
  91  
  92              if (isset( $dates->mindate )) {
  93                  $first_vote = JHTML::_('date',  $dates->mindate, JText::_('DATE_FORMAT_LC2') );
  94                  $last_vote     = JHTML::_('date',  $dates->maxdate, JText::_('DATE_FORMAT_LC2') );
  95              }
  96  
  97              $query = 'SELECT a.id, a.text, a.hits, b.voters '
  98                  . ' FROM #__poll_data AS a'
  99                  . ' INNER JOIN #__polls AS b ON b.id = a.pollid'
 100                  . ' WHERE a.pollid = '. (int) $poll->id
 101                  . ' AND a.text <> ""'
 102                  . ' ORDER BY a.hits DESC';
 103              $db->setQuery( $query );
 104              $votes = $db->loadObjectList();
 105          } else {
 106              $votes = array();
 107          }
 108  
 109          // list of polls for dropdown selection
 110          $query = 'SELECT id, title, alias'
 111              . ' FROM #__polls'
 112              . ' WHERE published = 1'
 113              . ' ORDER BY id'
 114          ;
 115          $db->setQuery( $query );
 116          $pList = $db->loadObjectList();
 117  
 118          foreach ($pList as $k=>$p)
 119          {
 120              $pList[$k]->url = JRoute::_('index.php?option=com_poll&id='.$p->id.':'.$p->alias);
 121          }
 122  
 123          array_unshift( $pList, JHTML::_('select.option',  '', JText::_( 'Select Poll from the list' ), 'url', 'title' ));
 124  
 125          // dropdown output
 126          $lists = array();
 127  
 128          $lists['polls'] = JHTML::_('select.genericlist',   $pList, 'id',
 129              'class="inputbox" size="1" style="width:200px" onchange="if (this.options[selectedIndex].value != \'\') {document.location.href=this.options[selectedIndex].value}"',
 130               'url', 'title',
 131               JRoute::_('index.php?option=com_poll&id='.$poll->id.':'.$poll->alias)
 132               );
 133  
 134  
 135          $graphwidth = 200;
 136          $barheight     = 4;
 137          $maxcolors     = 5;
 138          $barcolor     = 0;
 139          $tabcnt     = 0;
 140          $colorx     = 0;
 141  
 142          $maxval        = isset($votes[0]) ? $votes[0]->hits : 0;
 143          $sumval        = isset($votes[0]) ? $votes[0]->voters : 0;
 144  
 145          $k = 0;
 146          for ($i = 0; $i < count( $votes ); $i++)
 147          {
 148              $vote =& $votes[$i];
 149  
 150              if ($maxval > 0 && $sumval > 0)
 151              {
 152                  $vote->width    = ceil( $vote->hits * $graphwidth / $maxval );
 153                  $vote->percent = round( 100 * $vote->hits / $sumval, 1 );
 154              }
 155              else
 156              {
 157                  $vote->width    = 0;
 158                  $vote->percent    = 0;
 159              }
 160  
 161              $vote->class = '';
 162              if ($barcolor == 0)
 163              {
 164                  if ($colorx < $maxcolors) {
 165                      $colorx = ++$colorx;
 166                  } else {
 167                      $colorx = 1;
 168                  }
 169                  $vote->class = "polls_color_".$colorx;
 170              } else {
 171                  $vote->class = "polls_color_".$barcolor;
 172              }
 173  
 174              $vote->barheight = $barheight;
 175  
 176              $vote->odd        = $k;
 177              $vote->count    = $i;
 178              $k = 1 - $k;
 179          }
 180  
 181          $this->assign('first_vote',    $first_vote);
 182          $this->assign('last_vote',    $last_vote);
 183  
 184          $this->assignRef('lists',    $lists);
 185          $this->assignRef('params',    $params);
 186          $this->assignRef('poll',    $poll);
 187          $this->assignRef('votes',    $votes);
 188  
 189          parent::display($tpl);
 190      }
 191  }
 192  ?>


Generated: Wed Mar 28 15:54:07 2012 Cross-referenced by PHPXref 0.7.1