language_list.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class Language_List extends oxAdminList
00007 {
00008 
00014     protected $_sDefSortField = 'sort';
00015 
00021     protected $_sDefSortOrder = 'asc';
00022 
00028     public function deleteEntry()
00029     {
00030         $myConfig = $this->getConfig();
00031 
00032 
00033         $sOxId = $this->getEditObjectId();
00034 
00035         $aLangData['params'] = $myConfig->getConfigParam('aLanguageParams');
00036         $aLangData['lang'] = $myConfig->getConfigParam('aLanguages');
00037         $aLangData['urls'] = $myConfig->getConfigParam('aLanguageURLs');
00038         $aLangData['sslUrls'] = $myConfig->getConfigParam('aLanguageSSLURLs');
00039 
00040         $iBaseId = (int) $aLangData['params'][$sOxId]['baseId'];
00041 
00042         // preventing deleting main language with base id = 0
00043         if ($iBaseId == 0) {
00044             $oEx = oxNew("oxExceptionToDisplay");
00045             $oEx->setMessage('LANGUAGE_DELETINGMAINLANG_WARNING');
00046             oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx);
00047 
00048             return;
00049         }
00050 
00051         // unsetting selected lang from languages arrays
00052         unset($aLangData['params'][$sOxId]);
00053         unset($aLangData['lang'][$sOxId]);
00054         unset($aLangData['urls'][$iBaseId]);
00055         unset($aLangData['sslUrls'][$iBaseId]);
00056 
00057         //saving languages info back to DB
00058         $myConfig->saveShopConfVar('aarr', 'aLanguageParams', $aLangData['params']);
00059         $myConfig->saveShopConfVar('aarr', 'aLanguages', $aLangData['lang']);
00060         $myConfig->saveShopConfVar('arr', 'aLanguageURLs', $aLangData['urls']);
00061         $myConfig->saveShopConfVar('arr', 'aLanguageSSLURLs', $aLangData['sslUrls']);
00062 
00063         //if deleted language was default, setting defalt lang to 0
00064         if ($iBaseId == $myConfig->getConfigParam('sDefaultLang')) {
00065             $myConfig->saveShopConfVar('str', 'sDefaultLang', 0);
00066         }
00067 
00068         // reseting all multilanguage DB fields with deleted lang id
00069         // to default value
00070         $this->_resetMultiLangDbFields($iBaseId);
00071     }
00072 
00079     public function render()
00080     {
00081 
00082         parent::render();
00083         $this->_aViewData['mylist'] = $this->_getLanguagesList();
00084 
00085         return "language_list.tpl";
00086     }
00087 
00093     protected function _getLanguagesList()
00094     {
00095         $aLangParams = $this->getConfig()->getConfigParam('aLanguageParams');
00096         $aLanguages = oxRegistry::getLang()->getLanguageArray();
00097         $sDefaultLang = $this->getConfig()->getConfigParam('sDefaultLang');
00098 
00099         foreach ($aLanguages as $sKey => $sValue) {
00100             $sOxId = $sValue->oxid;
00101             $aLanguages[$sKey]->active = (!isset($aLangParams[$sOxId]["active"])) ? 1 : $aLangParams[$sOxId]["active"];
00102             $aLanguages[$sKey]->default = ($aLangParams[$sOxId]["baseId"] == $sDefaultLang) ? true : false;
00103             $aLanguages[$sKey]->sort = $aLangParams[$sOxId]["sort"];
00104         }
00105 
00106         if (is_array($aLangParams)) {
00107             $aSorting = $this->getListSorting();
00108 
00109             if (is_array($aSorting)) {
00110                 foreach ($aSorting as $aFieldSorting) {
00111                     foreach ($aFieldSorting as $sField => $sDir) {
00112                         $this->_sDefSortField = $sField;
00113                         $this->_sDefSortOrder = $sDir;
00114 
00115                         if ($sField == 'active') {
00116                             //reverting sort order for field 'active'
00117                             $this->_sDefSortOrder = 'desc';
00118                         }
00119                         break 2;
00120                     }
00121                 }
00122             }
00123 
00124             uasort($aLanguages, array($this, '_sortLanguagesCallback'));
00125         }
00126 
00127         return $aLanguages;
00128     }
00129 
00139     protected function _sortLanguagesCallback($oLang1, $oLang2)
00140     {
00141         $sSortParam = $this->_sDefSortField;
00142         $sVal1 = is_string($oLang1->$sSortParam) ? strtolower($oLang1->$sSortParam) : $oLang1->$sSortParam;
00143         $sVal2 = is_string($oLang2->$sSortParam) ? strtolower($oLang2->$sSortParam) : $oLang2->$sSortParam;
00144 
00145         if ($this->_sDefSortOrder == 'asc') {
00146             return ($sVal1 < $sVal2) ? -1 : 1;
00147         } else {
00148             return ($sVal1 > $sVal2) ? -1 : 1;
00149         }
00150     }
00151 
00158     protected function _resetMultiLangDbFields($iLangId)
00159     {
00160         $iLangId = (int) $iLangId;
00161 
00162         //skipping reseting language with id = 0
00163         if ($iLangId) {
00164 
00165             oxDb::getDb()->startTransaction();
00166 
00167             try {
00168                 $oDbMeta = oxNew("oxDbMetaDataHandler");
00169                 $oDbMeta->resetLanguage($iLangId);
00170 
00171                 oxDb::getDb()->commitTransaction();
00172             } catch (Exception $oEx) {
00173 
00174                 // if exception, rollBack everything
00175                 oxDb::getDb()->rollbackTransaction();
00176 
00177                 //show warning
00178                 $oEx = oxNew("oxExceptionToDisplay");
00179                 $oEx->setMessage('LANGUAGE_ERROR_RESETING_MULTILANG_FIELDS');
00180                 oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx);
00181             }
00182         }
00183     }
00184 }