MultilangFields.trait.php
1.88 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
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
77
78
79
80
<?php
namespace Cpeople\Traits;
trait MultilangFields
{
static $sites;
public function getLangPropValue($key)
{
return $this->getPropValue($this->getCurrentLanguageKey() . '_' . $key);
}
public function getLangPropText($key)
{
return $this->getPropText($this->getCurrentLanguageKey() . '_' . $key);
}
public function getLangPropTextUnesc($key)
{
return html_entity_decode($this->getLangPropText($key));
}
public function getLangPropDescription($key)
{
return $this->getPropDescription($this->getCurrentLanguageKey() . '_' . $key);
}
public function hasLangProp($key)
{
return $this->hasProp($this->getCurrentLanguageKey() . '_' . $key);
}
private function fetchSites()
{
if (!isset($this->sites))
{
$res = \CSite::GetList();
self::$sites = $res->arResult;
}
}
private function getSiteById($id)
{
$this->fetchSites();
$retval = false;
foreach (self::$sites as $site)
{
if ($site['LID'] == $id)
{
$retval = $site;
}
}
return $retval;
}
private function getCurrentSite()
{
return $this->getSiteById(SITE_ID);
}
private function getCurrentLanguageKey()
{
$currentSite = $this->getCurrentSite();
return strtoupper($currentSite['LANGUAGE_ID']);
}
public function getLangActiveFromDate($format)
{
return lang_date_nominative($format, strtotime($this->data['ACTIVE_FROM']), $this->getCurrentLanguageKey());
}
public function getLangActiveToDate($format)
{
return lang_date_nominative($format, strtotime($this->data['DATE_ACTIVE_TO']), $this->getCurrentLanguageKey());
}
}