OXID eShop CE  4.9.7
 All Classes Files Functions Variables Pages
language_list.php
Go to the documentation of this file.
1 <?php
2 
7 {
8 
14  protected $_sDefSortField = 'sort';
15 
21  protected $_sDefSortOrder = 'asc';
22 
28  public function deleteEntry()
29  {
30  $myConfig = $this->getConfig();
31 
32 
33  $sOxId = $this->getEditObjectId();
34 
35  $aLangData['params'] = $myConfig->getConfigParam('aLanguageParams');
36  $aLangData['lang'] = $myConfig->getConfigParam('aLanguages');
37  $aLangData['urls'] = $myConfig->getConfigParam('aLanguageURLs');
38  $aLangData['sslUrls'] = $myConfig->getConfigParam('aLanguageSSLURLs');
39 
40  $iBaseId = (int) $aLangData['params'][$sOxId]['baseId'];
41 
42  // preventing deleting main language with base id = 0
43  if ($iBaseId == 0) {
44  $oEx = oxNew("oxExceptionToDisplay");
45  $oEx->setMessage('LANGUAGE_DELETINGMAINLANG_WARNING');
46  oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx);
47 
48  return;
49  }
50 
51  // unsetting selected lang from languages arrays
52  unset($aLangData['params'][$sOxId]);
53  unset($aLangData['lang'][$sOxId]);
54  unset($aLangData['urls'][$iBaseId]);
55  unset($aLangData['sslUrls'][$iBaseId]);
56 
57  //saving languages info back to DB
58  $myConfig->saveShopConfVar('aarr', 'aLanguageParams', $aLangData['params']);
59  $myConfig->saveShopConfVar('aarr', 'aLanguages', $aLangData['lang']);
60  $myConfig->saveShopConfVar('arr', 'aLanguageURLs', $aLangData['urls']);
61  $myConfig->saveShopConfVar('arr', 'aLanguageSSLURLs', $aLangData['sslUrls']);
62 
63  //if deleted language was default, setting defalt lang to 0
64  if ($iBaseId == $myConfig->getConfigParam('sDefaultLang')) {
65  $myConfig->saveShopConfVar('str', 'sDefaultLang', 0);
66  }
67 
68  // reseting all multilanguage DB fields with deleted lang id
69  // to default value
70  $this->_resetMultiLangDbFields($iBaseId);
71  }
72 
79  public function render()
80  {
81 
83  $this->_aViewData['mylist'] = $this->_getLanguagesList();
84 
85  return "language_list.tpl";
86  }
87 
93  protected function _getLanguagesList()
94  {
95  $aLangParams = $this->getConfig()->getConfigParam('aLanguageParams');
96  $aLanguages = oxRegistry::getLang()->getLanguageArray();
97  $sDefaultLang = $this->getConfig()->getConfigParam('sDefaultLang');
98 
99  foreach ($aLanguages as $sKey => $sValue) {
100  $sOxId = $sValue->oxid;
101  $aLanguages[$sKey]->active = (!isset($aLangParams[$sOxId]["active"])) ? 1 : $aLangParams[$sOxId]["active"];
102  $aLanguages[$sKey]->default = ($aLangParams[$sOxId]["baseId"] == $sDefaultLang) ? true : false;
103  $aLanguages[$sKey]->sort = $aLangParams[$sOxId]["sort"];
104  }
105 
106  if (is_array($aLangParams)) {
107  $aSorting = $this->getListSorting();
108 
109  if (is_array($aSorting)) {
110  foreach ($aSorting as $aFieldSorting) {
111  foreach ($aFieldSorting as $sField => $sDir) {
112  $this->_sDefSortField = $sField;
113  $this->_sDefSortOrder = $sDir;
114 
115  if ($sField == 'active') {
116  //reverting sort order for field 'active'
117  $this->_sDefSortOrder = 'desc';
118  }
119  break 2;
120  }
121  }
122  }
123 
124  uasort($aLanguages, array($this, '_sortLanguagesCallback'));
125  }
126 
127  return $aLanguages;
128  }
129 
139  protected function _sortLanguagesCallback($oLang1, $oLang2)
140  {
141  $sSortParam = $this->_sDefSortField;
142  $sVal1 = is_string($oLang1->$sSortParam) ? strtolower($oLang1->$sSortParam) : $oLang1->$sSortParam;
143  $sVal2 = is_string($oLang2->$sSortParam) ? strtolower($oLang2->$sSortParam) : $oLang2->$sSortParam;
144 
145  if ($this->_sDefSortOrder == 'asc') {
146  return ($sVal1 < $sVal2) ? -1 : 1;
147  } else {
148  return ($sVal1 > $sVal2) ? -1 : 1;
149  }
150  }
151 
158  protected function _resetMultiLangDbFields($iLangId)
159  {
160  $iLangId = (int) $iLangId;
161 
162  //skipping reseting language with id = 0
163  if ($iLangId) {
164 
165  oxDb::getDb()->startTransaction();
166 
167  try {
168  $oDbMeta = oxNew("oxDbMetaDataHandler");
169  $oDbMeta->resetLanguage($iLangId);
170 
171  oxDb::getDb()->commitTransaction();
172  } catch (Exception $oEx) {
173 
174  // if exception, rollBack everything
175  oxDb::getDb()->rollbackTransaction();
176 
177  //show warning
178  $oEx = oxNew("oxExceptionToDisplay");
179  $oEx->setMessage('LANGUAGE_ERROR_RESETING_MULTILANG_FIELDS');
180  oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx);
181  }
182  }
183  }
184 }