Overview

Packages

  • bootstrap
    • behaviors
    • components
    • form
    • gii
    • helpers
    • widgets

Classes

  • TbActiveForm
  • TbAffix
  • TbAlert
  • TbBreadcrumb
  • TbButtonColumn
  • TbCollapse
  • TbDataColumn
  • TbDetailView
  • TbGridView
  • TbHeroUnit
  • TbListView
  • TbModal
  • TbNav
  • TbNavbar
  • TbPager
  • TbScrollspy
  • TbTabs
  • TbThumbnails
  • TbTypeAhead
  • Overview
  • Package
  • Class
  • Tree
 1: <?php
 2: /**
 3:  * TbAlert class file.
 4:  * @author Christoffer Niska <christoffer.niska@gmail.com>
 5:  * @copyright Copyright &copy; Christoffer Niska 2013-
 6:  * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
 7:  * @package bootstrap.widgets
 8:  */
 9: 
10: Yii::import('bootstrap.behaviors.TbWidget');
11: 
12: /**
13:  * Bootstrap alert widget.
14:  * @see http://twitter.github.com/bootstrap/javascript.html#alerts
15:  */
16: class TbAlert extends CWidget
17: {
18:     /**
19:      * @var array the alerts configurations (style=>config).
20:      */
21:     public $alerts;
22:     /**
23:      * @var string|boolean the close link text. If this is set false, no close link will be displayed.
24:      */
25:     public $closeText = TbHtml::CLOSE_TEXT;
26:     /**
27:      * @var boolean indicates whether the alert should be an alert block. Defaults to 'true'.
28:      */
29:     public $block = true;
30:     /**
31:      * @var boolean indicates whether alerts should use transitions. Defaults to 'true'.
32:      */
33:     public $fade = true;
34:     /**
35:      * @var string[] the JavaScript event configuration (name=>handler).
36:      */
37:     public $events = array();
38:     /**
39:      * @var array the HTML attributes for the alert container.
40:      */
41:     public $htmlOptions = array();
42: 
43:     /**
44:      * Initializes the widget.
45:      */
46:     public function init()
47:     {
48:         $this->attachBehavior('TbWidget', new TbWidget);
49:         $this->copyId();
50:         if (is_string($this->alerts)) {
51:             $colors = explode(' ', $this->alerts);
52:         } else {
53:             if (!isset($this->alerts)) {
54:                 $colors = array(
55:                     TbHtml::ALERT_COLOR_SUCCESS,
56:                     TbHtml::ALERT_COLOR_WARNING,
57:                     TbHtml::ALERT_COLOR_INFO,
58:                     TbHtml::ALERT_COLOR_ERROR
59:                 ); // render all styles by default
60:             }
61:         }
62:         if (isset($colors)) {
63:             $this->alerts = array();
64:             foreach ($colors as $color) {
65:                 $this->alerts[$color] = array();
66:             }
67:         }
68:     }
69: 
70:     /**
71:      * Runs the widget.
72:      */
73:     public function run()
74:     {
75:         /* @var $user CWebUser */
76:         $user = Yii::app()->getUser();
77:         if (count($user->getFlashes(false)) == 0) {
78:             return;
79:         }
80:         echo TbHtml::openTag('div', $this->htmlOptions);
81:         foreach ($this->alerts as $color => $alert) {
82:             if (isset($alert['visible']) && !$alert['visible']) {
83:                 continue;
84:             }
85: 
86:             if ($user->hasFlash($color)) {
87:                 $htmlOptions = TbArray::popValue('htmlOptions', $alert, array());
88:                 TbArray::defaultValue('closeText', $this->closeText, $htmlOptions);
89:                 TbArray::defaultValue('block', $this->block, $htmlOptions);
90:                 TbArray::defaultValue('fade', $this->fade, $htmlOptions);
91:                 echo TbHtml::alert($color, $user->getFlash($color), $htmlOptions);
92:             }
93:         }
94:         echo '</div>';
95:         $this->registerEvents("#{$this->htmlOptions['id']} > .alert", $this->events);
96:     }
97: }
Yiistrap API documentation generated by ApiGen 2.8.0