YiiFoundation
  • Namespace
  • Class
  • Tree

Namespaces

  • foundation
    • enum
    • exception
    • helpers
    • widgets
      • base
  • PHP

Classes

  • Alert
  • Breadcrumbs
  • Clearing
  • Dropdown
  • FlexVideo
  • Interchange
  • JoyRide
  • Magellan
  • Orbit
  • Pager
  • Reveal
  • Section
  • SwitchButton
  • Tooltip
  • TopBar
 1 <?php
 2 /**
 3  * @copyright Copyright &copy; 2amigOS! Consulting Group 2013-
 4  * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
 5  * @package foundation.components
 6  * @version 1.0.0
 7  */
 8 namespace foundation\widgets;
 9 
10 use foundation\helpers\Html;
11 use foundation\enum\Enum;
12 
13 /**
14  * SwitchButton renders a foundation switch.
15  *
16  * @see http://foundation.zurb.com/docs/components/switch.html
17  *
18  * @author Antonio Ramirez <amigo.cobos@gmail.com>
19  * @package foundation\widgets
20  */
21 class SwitchButton extends base\Input
22 {
23     /**
24      * @var string size of the switch button
25      */
26     public $size = Enum::SIZE_SMALL;
27     /**
28      * @var string radius style of the switch button
29      */
30     public $radius = ENum::RADIUS_ROUND;
31     /**
32      * @var string the On Label
33      */
34     public $onLabel = 'On';
35     /**
36      * @var string the Off Label
37      */
38     public $offLabel = 'Off';
39 
40 
41     /**
42      * Widget's initialization
43      */
44     public function init()
45     {
46         Html::addCssClass($this->htmlOptions, Enum::SWITCH_BUTTON);
47         if ($this->size) {
48             Html::addCssClass($this->htmlOptions, $this->size);
49         }
50         if ($this->radius) {
51             Html::addCssClass($this->htmlOptions, $this->radius);
52         }
53         parent::init();
54     }
55 
56     /**
57      * Renders the widget
58      */
59     public function run()
60     {
61         echo $this->renderButtons();
62     }
63 
64     /**
65      * Returns the formatted button
66      * @return string the resulting HTML
67      */
68     public function renderButtons()
69     {
70         list($name, $id) = $this->resolveNameID();
71         $buttons   = array();
72         $checked   = $this->hasModel() ? (!$this->model->{$this->attribute}) : true;
73         $buttons[] = \CHtml::radioButton($name, $checked, array('id' => $id . '_on', 'value' => 1));
74         $buttons[] = \CHtml::label($this->offLabel, $id . '_on');
75         $checked   = $checked ? false : true;
76         $buttons[] = \CHtml::radioButton($name, $checked, array('id' => $id . '_off', 'value' => 1));
77         $buttons[] = \CHtml::label($this->onLabel, $id . '_off');
78         $buttons[] = '<span></span>';
79 
80         return \CHtml::tag('div', $this->htmlOptions, implode("\n", $buttons));
81     }
82 }
YiiFoundation API documentation generated by ApiGen 2.8.0