Blame view

frontend/widgets/BannerWidget.php 2.05 KB
4253cbec   root   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
  <?php
  
  namespace frontend\widgets;
  use yii\base\Widget;
  use Yii;
  use yii\web\View;
  use common\models\Banner;
  
  class BannerWidget extends Widget
  {
      /**
       * @var string SYSTEM NAME точки-размещения в шаблоне
       */
      public $title = '';
  
      public function init ()
      {
          parent::init ();
      }
  
      public function run ()
      {
          // слайдер
          $banner = Banner::find()->where([Banner::tableName().'.title'=>$this->title, Banner::tableName().'.status' => '1'] )->one();
          if (! empty ($banner))
          {
              // html
              return $this->htmlBanner($banner);
          }
      }
  
  
      // ==== DISPLAY ====
  
      public function htmlBanner ($banner)
      {
          ob_start();
  
          echo '<div class="banner-widget '.$banner->title.'">';
  
              if (Banner::getFileExtension ($banner->image) == 'swf')
              {
                  echo '
                  <object width="'.$banner->width.'" height="'.$banner->height.'">
                      <param name="movie" value="'.$banner->image.'">
                      <param name="quality" value="high" />
                      <param name="menu" value="false" />
                      <param name="wmode" value="" />
                      <embed src="'.$banner->image.'" width="'.$banner->location->width.'" height="'.$banner->location->height.'" type="application/x-shockwave-flash" wmode="" quality="high" menu="false"></embed>
                  </object>';
              }
              else
              {
                  if ($banner->image == '')
                  {
                      $banner->image = 'notpic.gif';
                  }
  
                  if ($banner->url != '')
                  {
                      echo '<a href="'.$banner->url.'">';
                  }
  
                  echo '<img src="'.$banner->image.'"  width="'.$banner->width.'" height="'.$banner->height.'" alt="'.$banner->alt.'">';
  
                  if ($banner->url != '')
                  {
                      echo '</a>';
                  }
              }
  
          echo '</div>';
  
          return ob_get_clean();
      }
  }