|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2011 - 2014 Aleksandr Torosh (http://wezoom.net) |
|
4
|
|
|
* @author Aleksandr Torosh <[email protected]> |
|
5
|
|
|
*/ |
|
6
|
|
|
|
|
7
|
|
|
namespace Cms\Model; |
|
8
|
|
|
|
|
9
|
|
|
use Application\Mvc\Helper\CmsCache; |
|
10
|
|
|
use Phalcon\DI; |
|
11
|
|
|
use Phalcon\Mvc\Model; |
|
12
|
|
|
|
|
13
|
|
|
class Translate extends Model |
|
14
|
|
|
{ |
|
15
|
|
|
|
|
16
|
|
|
public function getSource() |
|
17
|
|
|
{ |
|
18
|
|
|
return "translate"; |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
public $id; |
|
22
|
|
|
public $lang; |
|
23
|
|
|
public $phrase; |
|
24
|
|
|
public $translation; |
|
25
|
|
|
|
|
26
|
|
|
public static function translates() |
|
27
|
|
|
{ |
|
28
|
|
|
return CmsCache::getInstance()->get('translates'); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public static function findCachedByLangInArray($lang = null) |
|
32
|
|
|
{ |
|
33
|
|
|
$translates = self::translates(); |
|
34
|
|
|
return $translates[$lang]; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function findByPhraseAndLang($phrase, $lang = null) |
|
38
|
|
|
{ |
|
39
|
|
|
if (!$lang) { |
|
40
|
|
|
$lang = LANG; |
|
41
|
|
|
} |
|
42
|
|
|
$result = self::findFirst([ |
|
|
|
|
|
|
43
|
|
|
'phrase = :phrase: AND lang = :lang:', |
|
44
|
|
|
'bind' => [ |
|
45
|
|
|
'phrase' => $phrase, |
|
46
|
|
|
'lang' => $lang, |
|
47
|
|
|
] |
|
48
|
|
|
]); |
|
49
|
|
|
return $result; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public static function buildCmsTranslatesCache() |
|
53
|
|
|
{ |
|
54
|
|
|
$save = []; |
|
55
|
|
|
$languages = Language::find(); |
|
|
|
|
|
|
56
|
|
|
foreach($languages as $lang) { |
|
|
|
|
|
|
57
|
|
|
$save[$lang->getIso()] = [""=>""]; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
$entries = Translate::find(); |
|
|
|
|
|
|
61
|
|
|
foreach ($entries as $el) { |
|
|
|
|
|
|
62
|
|
|
$save[$el->getLang()][$el->getPhrase()] = $el->getTranslation(); |
|
63
|
|
|
} |
|
64
|
|
|
return $save; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @param mixed $id |
|
69
|
|
|
*/ |
|
70
|
|
|
public function setId($id) |
|
71
|
|
|
{ |
|
72
|
|
|
$this->id = $id; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @return mixed |
|
77
|
|
|
*/ |
|
78
|
|
|
public function getId() |
|
79
|
|
|
{ |
|
80
|
|
|
return $this->id; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @param mixed $lang |
|
85
|
|
|
*/ |
|
86
|
|
|
public function setLang($lang) |
|
87
|
|
|
{ |
|
88
|
|
|
$this->lang = $lang; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @return mixed |
|
93
|
|
|
*/ |
|
94
|
|
|
public function getLang() |
|
95
|
|
|
{ |
|
96
|
|
|
return $this->lang; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @param mixed $phrase |
|
101
|
|
|
*/ |
|
102
|
|
|
public function setPhrase($phrase) |
|
103
|
|
|
{ |
|
104
|
|
|
$this->phrase = $phrase; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* @return mixed |
|
109
|
|
|
*/ |
|
110
|
|
|
public function getPhrase() |
|
111
|
|
|
{ |
|
112
|
|
|
return $this->phrase; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* @param mixed $translation |
|
117
|
|
|
*/ |
|
118
|
|
|
public function setTranslation($translation) |
|
119
|
|
|
{ |
|
120
|
|
|
$this->translation = $translation; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* @return mixed |
|
125
|
|
|
*/ |
|
126
|
|
|
public function getTranslation() |
|
127
|
|
|
{ |
|
128
|
|
|
return $this->translation; |
|
129
|
|
|
} |
|
130
|
|
|
} |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.