joomla.php
111 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @package VikAppointments |
| 4 | * @subpackage core |
| 5 | * @author E4J s.r.l. |
| 6 | * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved. |
| 7 | * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL |
| 8 | * @link https://vikwp.com |
| 9 | */ |
| 10 | |
| 11 | // No direct access |
| 12 | defined('ABSPATH') or die('No script kiddies please!'); |
| 13 | |
| 14 | // load parent class |
| 15 | VAPLoader::import('libraries.widget.radio.radio'); |
| 16 | |
| 17 | /** |
| 18 | * This class provides the construction of a radio button (toggle) using the Joomla style. |
| 19 | * |
| 20 | * @since 1.6 |
| 21 | */ |
| 22 | class UIRadioJoomla extends UIRadio |
| 23 | { |
| 24 | /** |
| 25 | * Call this method to build and return the HTML of the input. |
| 26 | * @override |
| 27 | * |
| 28 | * @return string The input HTML. |
| 29 | */ |
| 30 | public function display() |
| 31 | { |
| 32 | $name = parent::getName(); |
| 33 | $elements = parent::getElements(); |
| 34 | $options = parent::getoptions(); |
| 35 | |
| 36 | if (count($elements) != 2) |
| 37 | { |
| 38 | return ''; |
| 39 | } |
| 40 | |
| 41 | $elem_1 = $elements[0]; |
| 42 | $elem_2 = $elements[1]; |
| 43 | |
| 44 | if (!$elem_1->checked && !$elem_2->checked) |
| 45 | { |
| 46 | $elem_1->checked = true; |
| 47 | } |
| 48 | |
| 49 | if (empty($elem_1->htmlAttr)) |
| 50 | { |
| 51 | $elem_1->htmlAttr = ''; |
| 52 | } |
| 53 | if (empty($elem_2->htmlAttr)) |
| 54 | { |
| 55 | $elem_2->htmlAttr = ''; |
| 56 | } |
| 57 | |
| 58 | if (empty($elem_1->label)) |
| 59 | { |
| 60 | $elem_1->label = JText::translate('JYES'); |
| 61 | } |
| 62 | if (empty($elem_2->label)) |
| 63 | { |
| 64 | $elem_2->label = JText::translate('JNO'); |
| 65 | } |
| 66 | |
| 67 | if (empty($elem_1->id)) |
| 68 | { |
| 69 | $elem_1->id = $name . '1'; |
| 70 | } |
| 71 | if (empty($elem_2->id)) |
| 72 | { |
| 73 | $elem_2->id = $name . '0'; |
| 74 | } |
| 75 | |
| 76 | $wrapped = false; |
| 77 | if (array_key_exists('wrapped', $options)) |
| 78 | { |
| 79 | $wrapped = $options['wrapped']; |
| 80 | } |
| 81 | |
| 82 | $html = ''; |
| 83 | |
| 84 | if (VersionListener::isJoomla25()) |
| 85 | { |
| 86 | // 2.5 |
| 87 | $html = '<input type="radio" name="'.$name.'" value="1" id="'.$elem_1->id.'" '.($elem_1->checked ? "checked=\"checked\"" : "" ).' '.$elem_1->htmlAttr.'/> |
| 88 | <label for="'.$elem_1->id.'">'.$elem_1->label.'</label> |
| 89 | <input type="radio" name="'.$name.'" value="0" id="'.$elem_2->id.'" '.($elem_2->checked ? "checked=\"checked\"" : "" ).' '.$elem_2->htmlAttr.'/> |
| 90 | <label for="'.$elem_2->id.'">'.$elem_2->label.'</label>'; |
| 91 | } |
| 92 | else |
| 93 | { |
| 94 | // 3.x |
| 95 | $html = '<fieldset class="radio btn-group btn-group-yesno"> |
| 96 | <input type="radio" name="'.$name.'" value="1" id="'.$elem_1->id.'" '.($elem_1->checked ? "checked=\"checked\"" : "" ).'/> |
| 97 | <label for="'.$elem_1->id.'" '.$elem_1->htmlAttr.'>'.$elem_1->label.'</label> |
| 98 | <input type="radio" name="'.$name.'" value="0" id="'.$elem_2->id.'" '.($elem_2->checked ? "checked=\"checked\"" : "" ).'/> |
| 99 | <label for="'.$elem_2->id.'" '.$elem_2->htmlAttr.'>'.$elem_2->label.'</label> |
| 100 | </fieldset>'; |
| 101 | |
| 102 | if ($wrapped) |
| 103 | { |
| 104 | $html = '<div class="controls" style="display: inline-block;">'.$html.'</div>'; |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | return $html; |
| 109 | } |
| 110 | } |
| 111 |