[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

/libraries/joomla/html/html/ -> list.php (source)

   1  <?php
   2  /**
   3   * @package     Joomla.Platform
   4   * @subpackage  HTML
   5   *
   6   * @copyright   Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
   7   * @license     GNU General Public License version 2 or later; see LICENSE
   8   */
   9  
  10  defined('JPATH_PLATFORM') or die;
  11  
  12  /**
  13   * Utility class for creating different select lists
  14   *
  15   * @package     Joomla.Platform
  16   * @subpackage  HTML
  17   * @since       11.1
  18   */
  19  abstract class JHtmlList
  20  {
  21      /**
  22       * Get a grouped list of pre-Joomla 1.6 access levels
  23       *
  24       * @param   object  &$row  The object (must have an access property).
  25       *
  26       * @return  string
  27       *
  28       * @since   11.1
  29       *
  30       * @deprecated  12.1 Use JHtml::_('access.assetgrouplist', 'access', $selected) instead
  31       * @see     JHtmlAccess::assetgrouplist
  32       */
  33  	public static function accesslevel(&$row)
  34      {
  35          // Deprecation warning.
  36          JLog::add('JList::accesslevel is deprecated.', JLog::WARNING, 'deprecated');
  37  
  38          return JHtml::_('access.assetgrouplist', 'access', $row->access);
  39      }
  40  
  41      /**
  42       * Build the select list to choose an image
  43       *
  44       * @param   string  $name        The name of the field
  45       * @param   string  $active      The selected item
  46       * @param   string  $javascript  Alternative javascript
  47       * @param   string  $directory   Directory the images are stored in
  48       * @param   string  $extensions  Allowed extensions
  49       *
  50       * @return  array  Image names
  51       *
  52       * @since   11.1
  53       */
  54  	public static function images($name, $active = null, $javascript = null, $directory = null, $extensions = "bmp|gif|jpg|png")
  55      {
  56          if (!$directory)
  57          {
  58              $directory = '/images/';
  59          }
  60  
  61          if (!$javascript)
  62          {
  63              $javascript = "onchange=\"if (document.forms.adminForm." . $name
  64                  . ".options[selectedIndex].value!='') {document.imagelib.src='..$directory' + document.forms.adminForm." . $name
  65                  . ".options[selectedIndex].value} else {document.imagelib.src='media/system/images/blank.png'}\"";
  66          }
  67  
  68          jimport('joomla.filesystem.folder');
  69          $imageFiles = JFolder::files(JPATH_SITE . '/' . $directory);
  70          $images = array(JHtml::_('select.option', '', JText::_('JOPTION_SELECT_IMAGE')));
  71  
  72          foreach ($imageFiles as $file)
  73          {
  74              if (preg_match('#(' . $extensions . ')$#', $file))
  75              {
  76                  $images[] = JHtml::_('select.option', $file);
  77              }
  78          }
  79  
  80          $images = JHtml::_(
  81              'select.genericlist',
  82              $images,
  83              $name,
  84              array(
  85                  'list.attr' => 'class="inputbox" size="1" ' . $javascript,
  86                  'list.select' => $active
  87              )
  88          );
  89  
  90          return $images;
  91      }
  92  
  93      /**
  94       * Returns an array of options
  95       *
  96       * @param   string   $sql      SQL with 'ordering' AS value and 'name field' AS text
  97       * @param   integer  $chop  The length of the truncated headline
  98       *
  99       * @return  array  An array of objects formatted for JHtml list processing
 100       *
 101       * @since   11.1
 102       */
 103  	public static function genericordering($sql, $chop = '30')
 104      {
 105          $db = JFactory::getDbo();
 106          $options = array();
 107          $db->setQuery($sql);
 108  
 109          $items = $db->loadObjectList();
 110  
 111          // Check for a database error.
 112          if ($db->getErrorNum())
 113          {
 114              JError::raiseNotice(500, $db->getErrorMsg());
 115              return false;
 116          }
 117  
 118          if (empty($items))
 119          {
 120              $options[] = JHtml::_('select.option', 1, JText::_('JOPTION_ORDER_FIRST'));
 121              return $options;
 122          }
 123  
 124          $options[] = JHtml::_('select.option', 0, '0 ' . JText::_('JOPTION_ORDER_FIRST'));
 125          for ($i = 0, $n = count($items); $i < $n; $i++)
 126          {
 127              $items[$i]->text = JText::_($items[$i]->text);
 128              if (JString::strlen($items[$i]->text) > $chop)
 129              {
 130                  $text = JString::substr($items[$i]->text, 0, $chop) . "...";
 131              }
 132              else
 133              {
 134                  $text = $items[$i]->text;
 135              }
 136  
 137              $options[] = JHtml::_('select.option', $items[$i]->value, $items[$i]->value . '. ' . $text);
 138          }
 139          $options[] = JHtml::_('select.option', $items[$i - 1]->value + 1, ($items[$i - 1]->value + 1) . ' ' . JText::_('JOPTION_ORDER_LAST'));
 140  
 141          return $options;
 142      }
 143  
 144      /**
 145       * Build a select list with a specific ordering
 146       *
 147       * @param   integer  $value     The scalar value
 148       * @param   integer  $id        The id for an existing item in the list
 149       * @param   string   $query     The query
 150       * @param   integer  $neworder  1 if new and first, -1 if new and last,
 151       *                              0  or null if existing item
 152       *
 153       * @return  string  Html for the ordered list
 154       *
 155       * @since   11.1
 156       *
 157       * @see         JHtmlList::ordering
 158       * @deprecated  12.1  Use JHtml::_('list.ordering') instead
 159       */
 160  	public static function specificordering($value, $id, $query, $neworder = 0)
 161      {
 162          if (is_object($value))
 163          {
 164              $value = $value->ordering;
 165          }
 166  
 167          if ($id)
 168          {
 169              $neworder = 0;
 170          }
 171          else
 172          {
 173              if ($neworder)
 174              {
 175                  $neworder = 1;
 176              }
 177              else
 178              {
 179                  $neworder = -1;
 180              }
 181          }
 182          return JHtmlList::ordering('ordering', $query, '', $value, $neworder);
 183      }
 184  
 185      /**
 186       * Build the select list for Ordering derived from a query
 187       *
 188       * @param   integer  $name      The scalar value
 189       * @param   string   $query     The query
 190       * @param   string   $attribs   HTML tag attributes
 191       * @param   string   $selected  The selected item
 192       * @param   integer  $neworder  1 if new and first, -1 if new and last, 0  or null if existing item
 193       * @param   string   $chop      The length of the truncated headline
 194       *
 195       * @return  string   Html for the select list
 196       *
 197       * @since   11.1
 198       */
 199  	public static function ordering($name, $query, $attribs = null, $selected = null, $neworder = null, $chop = null)
 200      {
 201          if (empty($attribs))
 202          {
 203              $attribs = 'class="inputbox" size="1"';
 204          }
 205  
 206          if (empty($neworder))
 207          {
 208              $orders = JHtml::_('list.genericordering', $query);
 209              $html = JHtml::_('select.genericlist', $orders, $name, array('list.attr' => $attribs, 'list.select' => (int) $selected));
 210          }
 211          else
 212          {
 213              if ($neworder > 0)
 214              {
 215                  $text = JText::_('JGLOBAL_NEWITEMSLAST_DESC');
 216              }
 217              elseif ($neworder <= 0)
 218              {
 219                  $text = JText::_('JGLOBAL_NEWITEMSFIRST_DESC');
 220              }
 221              $html = '<input type="hidden" name="' . $name . '" value="' . (int) $selected . '" />' . '<span class="readonly">' . $text . '</span>';
 222          }
 223          return $html;
 224      }
 225  
 226      /**
 227       * Select list of active users
 228       *
 229       * @param   string   $name        The name of the field
 230       * @param   string   $active      The active user
 231       * @param   integer  $nouser      If set include an option to select no user
 232       * @param   string   $javascript  Custom javascript
 233       * @param   string   $order       Specify a field to order by
 234       * @param   string   $reg         Deprecated  Excludes users who are explicitly in group 2.
 235       *
 236       * @return  string   The HTML for a list of users list of users
 237       *
 238       * @since  11.1
 239       */
 240  	public static function users($name, $active, $nouser = 0, $javascript = null, $order = 'name', $reg = 1)
 241      {
 242          $db = JFactory::getDbo();
 243          $query = $db->getQuery(true);
 244  
 245          if ($reg)
 246          {
 247              // Does not include registered users in the list
 248              // @deprecated
 249              $query->where('m.group_id != 2');
 250          }
 251  
 252          $query->select('u.id AS value, u.name AS text');
 253          $query->from('#__users AS u');
 254          $query->join('LEFT', '#__user_usergroup_map AS m ON m.user_id = u.id');
 255          $query->where('u.block = 0');
 256          $query->order($order);
 257          $db->setQuery($query);
 258  
 259          if ($nouser)
 260          {
 261              $users[] = JHtml::_('select.option', '0', JText::_('JOPTION_NO_USER'));
 262              $users = array_merge($users, $db->loadObjectList());
 263          }
 264          else
 265          {
 266              $users = $db->loadObjectList();
 267          }
 268  
 269          $users = JHtml::_(
 270              'select.genericlist',
 271              $users,
 272              $name,
 273              array(
 274                  'list.attr' => 'class="inputbox" size="1" ' . $javascript,
 275                  'list.select' => $active
 276              )
 277          );
 278  
 279          return $users;
 280      }
 281  
 282      /**
 283       * Select list of positions - generally used for location of images
 284       *
 285       * @param   string   $name        Name of the field
 286       * @param   string   $active      The active value
 287       * @param   string   $javascript  Alternative javascript
 288       * @param   boolean  $none        Null if not assigned
 289       * @param   boolean  $center      Null if not assigned
 290       * @param   boolean  $left        Null if not assigned
 291       * @param   boolean  $right       Null if not assigned
 292       * @param   boolean  $id          Null if not assigned
 293       *
 294       * @return  array  The positions
 295       *
 296       * @since   11.1
 297       */
 298  	public static function positions($name, $active = null, $javascript = null, $none = 1, $center = 1, $left = 1, $right = 1, $id = false)
 299      {
 300          $pos = array();
 301          if ($none)
 302          {
 303              $pos[''] = JText::_('JNONE');
 304          }
 305  
 306          if ($center)
 307          {
 308              $pos['center'] = JText::_('JGLOBAL_CENTER');
 309          }
 310  
 311          if ($left)
 312          {
 313              $pos['left'] = JText::_('JGLOBAL_LEFT');
 314          }
 315  
 316          if ($right)
 317          {
 318              $pos['right'] = JText::_('JGLOBAL_RIGHT');
 319          }
 320  
 321          $positions = JHtml::_(
 322              'select.genericlist', $pos, $name,
 323              array(
 324                  'id' => $id,
 325                  'list.attr' => 'class="inputbox" size="1"' . $javascript,
 326                  'list.select' => $active,
 327                  'option.key' => null,
 328              )
 329          );
 330  
 331          return $positions;
 332      }
 333  
 334      /**
 335       * Crates a select list of categories
 336       *
 337       * @param   string   $name        Name of the field
 338       * @param   string   $extension   Extension for which the categories will be listed
 339       * @param   string   $selected    Selected value
 340       * @param   string   $javascript  Custom javascript
 341       * @param   integer  $order       Not used.
 342       * @param   integer  $size        Size of the field
 343       * @param   boolean  $sel_cat     If null do not include a Select Categories row
 344       *
 345       * @return  string
 346       *
 347       * @deprecated    12.1  Use JHtmlCategory instead
 348       * @since   11.1
 349       * @see     JHtmlCategory
 350       */
 351  	public static function category($name, $extension, $selected = null, $javascript = null, $order = null, $size = 1, $sel_cat = 1)
 352      {
 353          // Deprecation warning.
 354          JLog::add('JList::category is deprecated.', JLog::WARNING, 'deprecated');
 355  
 356          $categories = JHtml::_('category.options', $extension);
 357          if ($sel_cat)
 358          {
 359              array_unshift($categories, JHtml::_('select.option', '0', JText::_('JOPTION_SELECT_CATEGORY')));
 360          }
 361  
 362          $category = JHtml::_(
 363              'select.genericlist', $categories, $name, 'class="inputbox" size="' . $size . '" ' . $javascript, 'value', 'text',
 364              $selected
 365          );
 366  
 367          return $category;
 368      }
 369  }


Generated: Tue Apr 3 11:40:28 2012 Cross-referenced by PHPXref 0.7.1