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

/redirect/code/trunk/administrator/components/com_redirect/libraries/jxtended/form/fields/category.php

https://bitbucket.org/eddieajau/the-art-of-joomla-archive
PHP | 84 lines | 50 code | 9 blank | 25 comment | 6 complexity | 911d3020acef6729cc66d659849b879a MD5 | raw file
  1. <?php
  2. /**
  3. * @version $Id: category.php 390 2010-11-05 11:35:33Z eddieajau $
  4. * @copyright Copyright 2005 - 2010 New Life in IT Pty Ltd. All rights reserved.
  5. * @license GNU General Public License
  6. * @link http://www.theartofjoomla.com
  7. */
  8. defined('JPATH_BASE') or die;
  9. jimport('joomla.html.html');
  10. require_once dirname(__FILE__).'/list.php';
  11. /**
  12. * Supports an HTML select list of categories
  13. *
  14. * @package JXtended.Libraries
  15. * @subpackage Form
  16. * @since 1.1
  17. */
  18. class JFormFieldCategory extends JFormFieldList
  19. {
  20. /**
  21. * The field type.
  22. *
  23. * @var string
  24. */
  25. public $type = 'Category';
  26. /**
  27. * Method to get a list of options for a list input.
  28. *
  29. * @return array An array of JHtml options.
  30. */
  31. protected function _getOptions()
  32. {
  33. $db = &JFactory::getDBO();
  34. $section = $this->_element->attributes('section');
  35. $published = $this->_element->attributes('published');
  36. $allowNone = $this->_element->attributes('allow_none');
  37. if ($published === '') {
  38. $published = null;
  39. }
  40. if ($section == 'content') {
  41. // This might get a conflict with the dynamic translation - TODO: search for better solution
  42. $db->setQuery(
  43. 'SELECT c.id AS value, CONCAT_WS("/",s.title, c.title) AS text' .
  44. ' FROM #__categories AS c' .
  45. ' LEFT JOIN #__sections AS s ON s.id=c.section' .
  46. ' WHERE s.scope = '.$db->Quote($section).
  47. ($published !== null ? ' AND published = '.(int) $published : '').
  48. ' ORDER BY s.title, c.title'
  49. );
  50. }
  51. else if (!empty($section))
  52. {
  53. $db->setQuery(
  54. 'SELECT c.id AS value, c.title As text' .
  55. ' FROM #__categories AS c' .
  56. ' WHERE c.section = '.$db->Quote($section).
  57. ($published !== null ? ' AND published = '.(int) $published : '').
  58. ' ORDER BY c.title'
  59. );
  60. }
  61. else {
  62. JError::raiseWarning(500, JText::_('JFramework_Form_Fields_Category_Error_section_empty'));
  63. }
  64. try {
  65. $options = $db->loadObjectList();
  66. }
  67. catch(JException $e)
  68. {
  69. JError::raiseWarning(500, JText::_('JFramework_Form_Fields_Category_Error_extension_empty'));
  70. }
  71. // Merge any additional options in the XML definition.
  72. $options = array_merge(parent::_getOptions(), $options);
  73. return $options;
  74. }
  75. }