YiiWheels
  • Package
  • Class
  • Tree

Packages

  • yiiwheels
    • behaviors
    • widgets
    • widgets
      • ace
      • box
      • datepicker
      • daterangepicker
      • datetimepicker
      • detail
      • editable
      • fileupload
      • fileuploader
      • formhelpers
      • gallery
      • google
      • grid
        • behaviors
        • operations
      • highcharts
      • maskInput
      • maskmoney
      • modal
      • multiselect
      • rangeslider
      • redactor
      • select2
      • sparklines
      • switch
      • timeago
      • timepicker
      • toggle
      • typeahead

Classes

  • WhCountries
  • WhDatePickerHelper
  • WhFonts
  • WhFontSizes
  • WhGoogleFonts
  • WhLanguages
  • WhPhone
  • WhSelectBox
  • WhStates
  • WhTimePickerHelper
  • WhTimezones
  1 <?php
  2 /**
  3  * WhCountry widget class
  4  *
  5  * @author Antonio Ramirez <amigo.cobos@gmail.com>
  6  * @copyright Copyright &copy; 2amigos.us 2013-
  7  * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
  8  * @package YiiWheels.widgets.formhelpers
  9  * @uses YiiStrap.helpers.TbArray
 10  * @uses YiiStrap.helpers.TbHtml
 11  */
 12 Yii::import('bootstrap.helpers.TbArray');
 13 Yii::import('bootstrap.helpers.TbHtml');
 14 
 15 class WhLanguages extends CInputWidget
 16 {
 17     /**
 18      * Editor options that will be passed to the editor.
 19      *
 20      * - language
 21      * - available
 22      * - flags
 23      * @see http://vincentlamanna.com/BootstrapFormHelpers/language.html
 24      */
 25     public $pluginOptions = array();
 26 
 27     /**
 28      * @var bool whether to display the language selection read only or not.
 29      */
 30     public $readOnly = false;
 31 
 32     /**
 33      * @var bool whether to use bootstrap helper select Box widget
 34      */
 35     public $useHelperSelectBox = false;
 36 
 37     /**
 38      * @var array extra config options for helper select box
 39      */
 40     public $helperOptions = array();
 41 
 42     /**
 43      * Widget's initialization method
 44      * @throws CException
 45      */
 46     public function init()
 47     {
 48 
 49         $this->attachBehavior('ywplugin', array('class' => 'yiiwheels.behaviors.WhPlugin'));
 50 
 51         TbHtml::addCssClass('bfh-languages', $this->htmlOptions);
 52     }
 53 
 54     /**
 55      * Runs the widget.
 56      */
 57     public function run()
 58     {
 59         $this->renderField();
 60         $this->registerClientScript();
 61     }
 62 
 63     /**
 64      * Renders the input file field
 65      */
 66     public function renderField()
 67     {
 68         list($name, $id) = $this->resolveNameID();
 69 
 70         TbArray::defaultValue('id', $id, $this->htmlOptions);
 71         TbArray::defaultValue('name', $name, $this->htmlOptions);
 72 
 73         if ($this->useHelperSelectBox) {
 74             $select = Yii::createComponent(CMap::mergeArray($this->helperOptions, array(
 75                 'class' => 'yiiwheels.widgets.formhelpers.WhSelectBox',
 76                 'htmlOptions' => $this->htmlOptions,
 77                 'model' => $this->model,
 78                 'attribute' => $this->attribute,
 79                 'name' => $this->name,
 80                 'value' => $this->value,
 81                 'wrapperOptions' => array(
 82                     'class' => 'bfh-languages',
 83                     'data-language' => $this->hasModel() ? $this->model->{$this->attribute} : $this->value,
 84                     'data-flags' => isset($this->pluginOptions['flags']) && $this->pluginOptions['flags']
 85                         ? 'true'
 86                         : 'false',
 87                     'data-available' => isset($this->pluginOptions['available'])
 88                         ? $this->pluginOptions['available']
 89                         : null
 90                 )
 91             )));
 92             $select->init();
 93             $select->run();
 94         } else {
 95             $this->htmlOptions['data-language'] = $this->hasModel()
 96                 ? $this->model->{$this->attribute}
 97                 : $this->value;
 98             if (!$this->readOnly) {
 99                 if ($this->hasModel()) {
100                     echo CHtml::activeDropDownList($this->model, $this->attribute, array(), $this->htmlOptions);
101                 } else {
102                     echo CHtml::dropDownList($name, $this->value, array(), $this->htmlOptions);
103                 }
104             } else {
105                 echo CHtml::tag('span', $this->htmlOptions);
106             }
107         }
108     }
109 
110     /**
111      * Registers client script
112      */
113     public function registerClientScript()
114     {
115         /* publish assets dir */
116         $path = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'assets';
117         $assetsUrl = $this->getAssetsUrl($path);
118 
119         /* @var $cs CClientScript */
120         $cs = Yii::app()->getClientScript();
121 
122         $cs->registerCssFile($assetsUrl . '/css/bootstrap-formhelpers.css');
123         if (isset($this->pluginOptions['flags']) && $this->pluginOptions['flags'] == true) {
124             $cs->registerCssFile($assetsUrl . '/css/bootstrap-formhelpers-countries.flags.css');
125         }
126         $cs->registerScriptFile($assetsUrl . '/js/bootstrap-formhelpers-countries.en_US.js');
127         $cs->registerScriptFile($assetsUrl . '/js/bootstrap-formhelpers-languages.codes.js');
128         $cs->registerScriptFile($assetsUrl . '/js/bootstrap-formhelpers-languages.js');
129 
130         /* initialize plugin */
131         if (!$this->useHelperSelectBox) {
132             $selector = '#' . TbArray::getValue('id', $this->htmlOptions, $this->getId());
133             $this->getApi()->registerPlugin('bfhlanguages', $selector, $this->pluginOptions);
134         }
135     }
136 }
YiiWheels API documentation generated by ApiGen 2.8.0