PageRenderTime 52ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/libraries/joomla/form/fields/databaseconnection.php

https://github.com/CCI-Studios/Wee-Magazine
PHP | 85 lines | 35 code | 6 blank | 44 comment | 3 complexity | 476b6f5aca49e1881bc60e28c10da899 MD5 | raw file
  1. <?php
  2. /**
  3. * @package Joomla.Platform
  4. * @subpackage Form
  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. defined('JPATH_PLATFORM') or die;
  10. JFormHelper::loadFieldClass('list');
  11. /**
  12. * Form Field class for the Joomla Platform.
  13. * Provides a list of available database connections, optionally limiting to
  14. * a given list.
  15. *
  16. * @package Joomla.Platform
  17. * @subpackage Form
  18. * @see JDatabase
  19. * @since 11.3
  20. */
  21. class JFormFieldDatabaseConnection extends JFormFieldList
  22. {
  23. /**
  24. * The form field type.
  25. *
  26. * @var string
  27. * @since 11.3
  28. */
  29. public $type = 'DatabaseConnection';
  30. /**
  31. * Method to get the list of database options.
  32. *
  33. * This method produces a drop down list of available databases supported
  34. * by JDatabase drivers that are also supported by the application.
  35. *
  36. * @return array The field option objects.
  37. *
  38. * @since 11.3
  39. * @see JDatabase
  40. */
  41. protected function getOptions()
  42. {
  43. // Initialize variables.
  44. // This gets the connectors available in the platform and supported by the server.
  45. $available = JDatabase::getConnectors();
  46. /**
  47. * This gets the list of database types supported by the application.
  48. * This should be entered in the form definition as a comma separated list.
  49. * If no supported databases are listed, it is assumed all available databases
  50. * are supported.
  51. */
  52. $supported = $this->element['supported'];
  53. if (!empty($supported))
  54. {
  55. $supported = explode(',', $supported);
  56. foreach ($supported as $support)
  57. {
  58. if (in_array($support, $available))
  59. {
  60. $options[$support] = ucfirst($support);
  61. }
  62. }
  63. }
  64. else
  65. {
  66. foreach ($available as $support)
  67. {
  68. $options[$support] = ucfirst($support);
  69. }
  70. }
  71. // This will come into play if an application is installed that requires
  72. // a database that is not available on the server.
  73. if (empty($options))
  74. {
  75. $options[''] = JText::_('JNONE');
  76. }
  77. return $options;
  78. }
  79. }