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  * WhPhone 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  */
 11 Yii::import('bootstrap.helpers.TbArray');
 12 
 13 class WhPhone extends CInputWidget
 14 {
 15 
 16     /**
 17      * @var string the formatting options
 18      */
 19     public $format = false;
 20 
 21     /**
 22      * @var bool whether to display the language selection read only or not.
 23      */
 24     public $readOnly = false;
 25 
 26     /**
 27      * @var array
 28      */
 29     public $pluginOptions = array();
 30 
 31 
 32     /**
 33      * Widget's initialization method
 34      * @throws CException
 35      */
 36     public function init()
 37     {
 38 
 39         $this->attachBehavior('ywplugin', array('class' => 'yiiwheels.behaviors.WhPlugin'));
 40 
 41         TbHtml::addCssClass('bfh-phone', $this->htmlOptions);
 42         $this->htmlOptions['data-format'] = $this->format;
 43         if ($this->readOnly) {
 44             $this->htmlOptions['data-number'] = $this->hasModel()
 45                 ? $this->model->{$this->attribute}
 46                 : $this->value;
 47         } else {
 48             $this->pluginOptions['format'] = $this->format;
 49             $this->pluginOptions['value'] = $this->hasModel()
 50                 ? $this->model->{$this->attribute}
 51                 : $this->value;
 52         }
 53 
 54     }
 55 
 56     /**
 57      * Runs the widget.
 58      */
 59     public function run()
 60     {
 61         $this->renderField();
 62         $this->registerClientScript();
 63     }
 64 
 65     /**
 66      * Renders the input file field
 67      */
 68     public function renderField()
 69     {
 70         list($name, $id) = $this->resolveNameID();
 71 
 72         TbArray::defaultValue('id', $id, $this->htmlOptions);
 73         TbArray::defaultValue('name', $name, $this->htmlOptions);
 74 
 75 
 76         if (!$this->readOnly) {
 77             if ($this->hasModel()) {
 78                 echo CHtml::activeTextField($this->model, $this->attribute, $this->htmlOptions);
 79             } else {
 80                 echo CHtml::textField($name, $this->value, $this->htmlOptions);
 81             }
 82         } else {
 83             echo CHtml::tag('span', $this->htmlOptions);
 84         }
 85     }
 86 
 87     /**
 88      * Registers client script
 89      */
 90     public function registerClientScript()
 91     {
 92         /* publish assets dir */
 93         $path = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'assets';
 94         $assetsUrl = $this->getAssetsUrl($path);
 95 
 96         /* @var $cs CClientScript */
 97         $cs = Yii::app()->getClientScript();
 98 
 99         $cs->registerCssFile($assetsUrl . '/css/bootstrap-formhelpers.css');
100         $cs->registerScriptFile($assetsUrl . '/js/bootstrap-formhelpers-phone.js');
101 
102         /* initialize plugin */
103         if(!$this->readOnly)
104         {
105             $selector = '#' . TbArray::getValue('id', $this->htmlOptions, $this->getId());
106             $this->getApi()->registerPlugin('bfhphone', $selector, $this->pluginOptions);
107         }
108     }
109 }
YiiWheels API documentation generated by ApiGen 2.8.0