1 <?php
2 3 4 5 6 7
8 namespace Hawk;
9
10
11 12 13 14 15
16 class Language extends Model{
17 18 19
20 protected static $tablename = "Language";
21
22 23 24
25 protected static $primaryColumn = 'tag';
26
27
28 29 30
31 private static $instances = array();
32
33
34 35 36 37 38 39 40
41 public static function getByTag($tag){
42 if(!isset(self::$instances[$tag])) {
43 self::$instances[$tag] = self::getById($tag);
44 }
45
46 return self::$instances[$tag];
47 }
48
49 50 51 52 53
54 public static function getAllActive(){
55 return self::getListByExample(
56 new DBExample(
57 array(
58 'active' => 1
59 )
60 )
61 );
62 }
63
64 65 66 67 68
69 public static function current(){
70 return self::getByTag(LANGUAGE);
71 }
72
73 74 75
76 public function setDefault(){
77 $this->dbo->query('UPDATE '. self::getTable() . ' SET isDefault = CASE WHEN `tag` = :tag THEN 1 ELSE 0 END', array('tag' => $this->tag));
78 }
79
80
81 82 83 84 85
86 public function saveTranslations($translations){
87 foreach($translations as $plugin => $trs){
88 $currentData = Lang::getUserTranslations($plugin, $this->tag);
89
90 if(empty($currentData)) {
91 $data = $trs;
92 }
93 else{
94 $data = array_merge($currentData, $trs);
95 }
96 Lang::saveUserTranslations($plugin, $this->tag, $data);
97 }
98 }
99
100 101 102 103 104
105 public function removeTranslations($translations){
106 foreach ($translations as $plugin => $keys) {
107 $currentData = Lang::getUserTranslations($plugin, $this->tag);
108 foreach($keys as $key){
109 unset($currentData[$key]);
110 }
111 Lang::saveUserTranslations($plugin, $this->tag, $currentData);
112 }
113 }
114 }