Source for file moduleorder.php

Documentation is available at moduleorder.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Libraries
  4.  * @subpackage  Form
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE.txt
  8.  */
  9.  
  10. defined('JPATH_BASE') or die;
  11.  
  12. /**
  13.  * Form Field class for the Joomla! CMS.
  14.  *
  15.  * @package     Joomla.Libraries
  16.  * @subpackage  Form
  17.  * @since       1.6
  18.  */
  19. {
  20.     /**
  21.      * The form field type.
  22.      *
  23.      * @var        string 
  24.      * @since   1.6
  25.      */
  26.     protected $type = 'ModuleOrder';
  27.  
  28.     /**
  29.      * Method to get the field input markup.
  30.      *
  31.      * @return  string    The field input markup.
  32.      *
  33.      * @since   1.6
  34.      */
  35.     protected function getInput()
  36.     {
  37.         $html = array();
  38.         $attr = '';
  39.  
  40.         // Initialize some field attributes.
  41.         $attr .= !empty($this->class) ? ' class="' . $this->class . '"' : '';
  42.         $attr .= $this->disabled ? ' disabled' : '';
  43.         $attr .= !empty($this->size) ? ' size="' . $this->size . '"' : '';
  44.  
  45.         // Initialize JavaScript field attributes.
  46.         $attr .= !empty($this->onchange) ? ' onchange="' . $this->onchange . '"' : '';
  47.  
  48.         $html[] = '<script type="text/javascript">';
  49.  
  50.         $ordering = $this->form->getValue('ordering');
  51.         $position = $this->form->getValue('position');
  52.         $clientId = $this->form->getValue('client_id');
  53.  
  54.         $html[] = 'var originalOrder = "' . $ordering . '";';
  55.         $html[] = 'var originalPos = "' . $position . '";';
  56.         $html[] = 'var orders = new Array();';
  57.  
  58.         $db        = JFactory::getDbo();
  59.         $query    = $db->getQuery(true)
  60.             ->select('position, ordering, title')
  61.             ->from('#__modules')
  62.             ->where('client_id = ' . (int) $clientId)
  63.             ->order('ordering');
  64.  
  65.         $db->setQuery($query);
  66.  
  67.         try
  68.         {
  69.             $orders = $db->loadObjectList();
  70.         }
  71.         catch (RuntimeException $e)
  72.         {
  73.             JError::raiseWarning(500, $e->getMessage());
  74.  
  75.             return false;
  76.         }
  77.  
  78.         $orders2 = array();
  79.  
  80.         for ($i = 0, $n = count($orders); $i < $n; $i++)
  81.         {
  82.             if (!isset($orders2[$orders[$i]->position]))
  83.             {
  84.                 $orders2[$orders[$i]->position] = 0;
  85.             }
  86.  
  87.             $orders2[$orders[$i]->position]++;
  88.             $ord = $orders2[$orders[$i]->position];
  89.             $title = JText::sprintf('COM_MODULES_OPTION_ORDER_POSITION', $ord, addslashes($orders[$i]->title));
  90.  
  91.             $html[] = 'orders[' . $i . '] =  new Array("' . $orders[$i]->position . '","' . $ord . '","' . $title . '");';
  92.         }
  93.  
  94.         $html[] = 'writeDynaList(\'name="' . $this->name . '" id="' . $this->id . '"' . $attr . '\', orders, originalPos, originalPos, originalOrder);';
  95.         $html[] = '</script>';
  96.  
  97.         return implode("\n", $html);
  98.     }
  99. }

Documentation generated on Tue, 19 Nov 2013 15:08:49 +0100 by phpDocumentor 1.4.3