From 94fc00a8dbf82c513d2de85d38b8968e732004c1 Mon Sep 17 00:00:00 2001 From: zhegal Date: Fri, 26 Jan 2018 12:32:38 +0200 Subject: [PATCH] main page + carousel + contacts --- common/models/Carousel.php | 181 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ frontend/views/layouts/main.php | 10 +++++++--- frontend/views/site/contact.php | 38 ++++++++++++++++++++++---------------- frontend/views/site/index.php | 15 +++++++++------ frontend/web/css/main.css | 33 ++++++++++++++++++++++++++------- 5 files changed, 245 insertions(+), 32 deletions(-) create mode 100644 common/models/Carousel.php diff --git a/common/models/Carousel.php b/common/models/Carousel.php new file mode 100644 index 0000000..bbbf8a0 --- /dev/null +++ b/common/models/Carousel.php @@ -0,0 +1,181 @@ + [ + * // the item contains only the image + * '', + * // equivalent to the above + * ['content' => ''], + * // the item contains both the image and the caption + * [ + * 'content' => '', + * 'caption' => '

This is title

This is the caption text

', + * 'options' => [...], + * ], + * ] + * ]); + * ``` + * + * @see http://getbootstrap.com/javascript/#carousel + * @author Antonio Ramirez + * @since 2.0 + */ +class Carousel extends \yii\bootstrap\Widget +{ + /** + * @var array|boolean the labels for the previous and the next control buttons. + * If false, it means the previous and the next control buttons should not be displayed. + */ + public $controls = ['', '']; + /** + * @var boolean + * If false carousel indicators (
    tag with anchors to items) should not be displayed. + */ + public $showIndicators = false; + /** + * @var array list of slides in the carousel. Each array element represents a single + * slide with the following structure: + * + * ```php + * [ + * // required, slide content (HTML), such as an image tag + * 'content' => '', + * // optional, the caption (HTML) of the slide + * 'caption' => '

    This is title

    This is the caption text

    ', + * // optional the HTML attributes of the slide container + * 'options' => [], + * ] + * ``` + */ + public $items = []; + + + /** + * Initializes the widget. + */ + public function init() + { + parent::init(); + \yii\bootstrap\Html::addCssClass($this->options, ['widget' => 'carousel']); + } + + /** + * Renders the widget. + */ + public function run() + { + $this->registerPlugin('carousel'); + return implode("\n", [ + \yii\bootstrap\Html::beginTag('div', $this->options), + $this->renderIndicators(), + $this->renderItems(), + $this->renderControls(), + \yii\bootstrap\Html::endTag('div') + ]) . "\n"; + } + + /** + * Renders carousel indicators. + * @return string the rendering result + */ + public function renderIndicators() + { + if ($this->showIndicators === false) { + return ''; + } + $indicators = []; + for ($i = 0, $count = count($this->items); $i < $count; $i++) { + $options = ['data-target' => '#' . $this->options['id'], 'data-slide-to' => $i]; + if ($i === 0) { + \yii\bootstrap\Html::addCssClass($options, 'active'); + } + $indicators[] = Html::tag('li', '', $options); + } + + return \yii\bootstrap\Html::tag('ol', implode("\n", $indicators), ['class' => 'carousel-indicators']); + } + + /** + * Renders carousel items as specified on [[items]]. + * @return string the rendering result + */ + public function renderItems() + { + $items = []; + for ($i = 0, $count = count($this->items); $i < $count; $i++) { + $items[] = $this->renderItem($this->items[$i], $i); + } + + return \yii\bootstrap\Html::tag('div', implode("\n", $items), ['class' => 'carousel-inner']); + } + + /** + * Renders a single carousel item + * @param string|array $item a single item from [[items]] + * @param int $index the item index as the first item should be set to `active` + * @return string the rendering result + * @throws InvalidConfigException if the item is invalid + */ + public function renderItem($item, $index) + { + if (is_string($item)) { + $content = $item; + $caption = null; + $options = []; + } elseif (isset($item['content'])) { + $content = $item['content']; + $caption = ArrayHelper::getValue($item, 'caption'); + if ($caption !== null) { + $caption = \yii\bootstrap\Html::tag('div', $caption, ['class' => 'carousel-caption']); + } + $options = ArrayHelper::getValue($item, 'options', []); + } else { + throw new InvalidConfigException('The "content" option is required.'); + } + + \yii\bootstrap\Html::addCssClass($options, ['widget' => 'item']); + if ($index === 0) { + \yii\bootstrap\Html::addCssClass($options, 'active'); + } + + return \yii\bootstrap\Html::tag('div', $content . "\n" . $caption, $options); + } + + /** + * Renders previous and next control buttons. + * @throws InvalidConfigException if [[controls]] is invalid. + */ + public function renderControls() + { + if (isset($this->controls[0], $this->controls[1])) { + return \yii\bootstrap\Html::a($this->controls[0], '#' . $this->options['id'], [ + 'class' => 'left carousel-control', + 'data-slide' => 'prev', + ]) . "\n" + . \yii\bootstrap\Html::a($this->controls[1], '#' . $this->options['id'], [ + 'class' => 'right carousel-control', + 'data-slide' => 'next', + ]); + } elseif ($this->controls === false) { + return ''; + } else { + throw new InvalidConfigException('The "controls" property must be either false or an array of two elements.'); + } + } +} diff --git a/frontend/views/layouts/main.php b/frontend/views/layouts/main.php index 2283f04..2024881 100644 --- a/frontend/views/layouts/main.php +++ b/frontend/views/layouts/main.php @@ -453,7 +453,7 @@ _________________________________________________________ -->