LangLinks.php
1.38 KB
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
<?php
/**
* Created by PhpStorm.
* User: stes
* Date: 03.08.18
* Time: 14:34
*/
namespace frontend\widgets;
use yii\helpers\Html;
use artbox\core\models\Language;
use yii\jui\Widget;
class LangLinks extends Widget
{
public $links;
public $mobile = false;
public function init()
{
/**
* @var \frontend\components\LangComponent $langComponent ;
*/
$langComponent = \Yii::$app->get('langLinks');
$this->links = $langComponent->getLinks();
}
public function run()
{
$items = [];
$langs = Language::getActive();
foreach ($langs as $key => $item) {
if ($item->id == Language::getCurrent()->id) {
$items[ $key ] = Html::tag('li', Html::a(($this->mobile ? $item->short : $item->name), '', ['class' => 'active']));
} else {
$items[ $key ] = Html::tag('li', Html::a(($this->mobile ? $item->short : $item->name), $this->links[ $key ]));
}
}
if ($this->mobile){
return $this->render('links_mobile', [ 'links' => $items ]);
}
return $this->render('links', [ 'links' => $items ]);
}
}