OXID eShop CE  4.8.12
 All Classes Files Functions Variables Pages
language_list.php
Go to the documentation of this file.
1 <?php
2 
7 {
13  protected $_sDefSortField = 'sort';
14 
20  protected $_sDefSortOrder = 'asc';
21 
27  public function deleteEntry()
28  {
29  $myConfig = $this->getConfig();
30 
31 
32  $sOxId = $this->getEditObjectId();
33 
34  $aLangData['params'] = $myConfig->getConfigParam( 'aLanguageParams' );
35  $aLangData['lang'] = $myConfig->getConfigParam( 'aLanguages' );
36  $aLangData['urls'] = $myConfig->getConfigParam( 'aLanguageURLs' );
37  $aLangData['sslUrls'] = $myConfig->getConfigParam( 'aLanguageSSLURLs' );
38 
39  $iBaseId = (int) $aLangData['params'][$sOxId]['baseId'];
40 
41  // preventing deleting main language with base id = 0
42  if ( $iBaseId == 0 ) {
43  $oEx = oxNew( "oxExceptionToDisplay" );
44  $oEx->setMessage( 'LANGUAGE_DELETINGMAINLANG_WARNING' );
45  oxRegistry::get("oxUtilsView")->addErrorToDisplay( $oEx );
46  return;
47  }
48 
49  // unsetting selected lang from languages arrays
50  unset( $aLangData['params'][$sOxId] );
51  unset( $aLangData['lang'][$sOxId] );
52  unset( $aLangData['urls'][$iBaseId] );
53  unset( $aLangData['sslUrls'][$iBaseId] );
54 
55  //saving languages info back to DB
56  $myConfig->saveShopConfVar( 'aarr', 'aLanguageParams', $aLangData['params'] );
57  $myConfig->saveShopConfVar( 'aarr', 'aLanguages', $aLangData['lang'] );
58  $myConfig->saveShopConfVar( 'arr', 'aLanguageURLs', $aLangData['urls'] );
59  $myConfig->saveShopConfVar( 'arr', 'aLanguageSSLURLs', $aLangData['sslUrls'] );
60 
61  //if deleted language was default, setting defalt lang to 0
62  if ( $iBaseId == $myConfig->getConfigParam( 'sDefaultLang' ) ) {
63  $myConfig->saveShopConfVar( 'str', 'sDefaultLang', 0 );
64  }
65 
66  // reseting all multilanguage DB fields with deleted lang id
67  // to default value
68  $this->_resetMultiLangDbFields( $iBaseId );
69  }
70 
77  public function render()
78  {
79 
81  $this->_aViewData['mylist'] = $this->_getLanguagesList();
82 
83  return "language_list.tpl";
84  }
85 
91  protected function _getLanguagesList()
92  {
93  $aLangParams = $this->getConfig()->getConfigParam( 'aLanguageParams' );
94  $aLanguages = oxRegistry::getLang()->getLanguageArray();
95  $sDefaultLang = $this->getConfig()->getConfigParam( 'sDefaultLang' );
96 
97  foreach ( $aLanguages as $sKey => $sValue ) {
98  $sOxId = $sValue->oxid;
99  $aLanguages[$sKey]->active = ( !isset( $aLangParams[$sOxId]["active"] ) ) ? 1 : $aLangParams[$sOxId]["active"];
100  $aLanguages[$sKey]->default = ( $aLangParams[$sOxId]["baseId"] == $sDefaultLang ) ? true : false;
101  $aLanguages[$sKey]->sort = $aLangParams[$sOxId]["sort"];
102  }
103 
104  if ( is_array( $aLangParams ) ) {
105  $aSorting = $this->getListSorting();
106 
107  if ( is_array( $aSorting ) ) {
108  foreach ( $aSorting as $aFieldSorting ) {
109  foreach ( $aFieldSorting as $sField => $sDir ) {
110  $this->_sDefSortField = $sField;
111  $this->_sDefSortOrder = $sDir;
112 
113  if ( $sField == 'active' ) {
114  //reverting sort order for field 'active'
115  $this->_sDefSortOrder = 'desc';
116  }
117  break 2;
118  }
119  }
120  }
121 
122  uasort( $aLanguages, array($this, '_sortLanguagesCallback' ) );
123  }
124 
125  return $aLanguages;
126  }
127 
137  protected function _sortLanguagesCallback( $oLang1, $oLang2 )
138  {
139  $sSortParam = $this->_sDefSortField;
140  $sVal1 = is_string( $oLang1->$sSortParam ) ? strtolower( $oLang1->$sSortParam ) : $oLang1->$sSortParam;
141  $sVal2 = is_string( $oLang2->$sSortParam ) ? strtolower( $oLang2->$sSortParam ) : $oLang2->$sSortParam;
142 
143  if ( $this->_sDefSortOrder == 'asc' ) {
144  return ( $sVal1 < $sVal2 ) ? -1 : 1;
145  } else {
146  return ( $sVal1 > $sVal2 ) ? -1 : 1;
147  }
148  }
149 
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 }