language_list.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class Language_List extends oxAdminList
00007 {
00013     protected $_sDefSort = 'sort';
00014 
00020     protected $_sDefSortOrder = 'asc';
00021 
00027     public function deleteEntry()
00028     {
00029         $myConfig = $this->getConfig();
00030 
00031 
00032         $sOxId = oxConfig::getParameter( 'oxid' );
00033 
00034         $aLangData['params']  = $myConfig->getConfigParam( 'aLanguageParams' );
00035         $aLangData['lang']    = $myConfig->getConfigParam( 'aLanguages' );
00036         $aLangData['urls']    = $myConfig->getConfigParam( 'aLanguageURLs' );
00037         $aLangData['sslUrls'] = $myConfig->getConfigParam( 'aLanguageSSLURLs' );
00038 
00039         $iBaseId = (int) $aLangData['params'][$sOxId]['baseId'];
00040 
00041         // preventing deleting main language with base id = 0
00042         if ( $iBaseId == 0 ) {
00043             $oEx = new oxExceptionToDisplay();
00044             $oEx->setMessage( 'LANGUAGE_DELETINGMAINLANG_WARNING' );
00045             oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
00046             return;
00047         }
00048 
00049         // unsetting selected lang from languages arrays
00050         unset( $aLangData['params'][$sOxId] );
00051         unset( $aLangData['lang'][$sOxId] );
00052         unset( $aLangData['urls'][$iBaseId] );
00053         unset( $aLangData['sslUrls'][$iBaseId] );
00054 
00055         //saving languages info back to DB
00056         $myConfig->saveShopConfVar( 'aarr', 'aLanguageParams', $aLangData['params'] );
00057         $myConfig->saveShopConfVar( 'aarr', 'aLanguages', $aLangData['lang'] );
00058         $myConfig->saveShopConfVar( 'arr', 'aLanguageURLs', $aLangData['urls'] );
00059         $myConfig->saveShopConfVar( 'arr', 'aLanguageSSLURLs', $aLangData['sslUrls'] );
00060 
00061         //if deleted language was default, setting defalt lang to 0
00062         if ( $iBaseId == $myConfig->getConfigParam( 'sDefaultLang' ) ) {
00063             $myConfig->saveShopConfVar( 'str', 'sDefaultLang', 0 );
00064         }
00065 
00066             // reseting all multilanguage DB fields with deleted lang id
00067             // to default value
00068             $this->_resetMultiLangDbFields( $iBaseId );
00069     }
00070 
00077     public function render()
00078     {
00079 
00080         parent::render();
00081         $this->_aViewData['mylist'] = $this->_getLanguagesList();
00082 
00083         return "language_list.tpl";
00084     }
00085 
00091     protected function _getLanguagesList()
00092     {
00093         $aLangParams  = $this->getConfig()->getConfigParam( 'aLanguageParams' );
00094         $aLanguages   = oxLang::getInstance()->getLanguageArray();
00095         $sDefaultLang = $this->getConfig()->getConfigParam( 'sDefaultLang' );
00096 
00097         foreach ( $aLanguages as $sKey => $sValue ) {
00098             $sOxId = $sValue->oxid;
00099             $aLanguages[$sKey]->active  = ( !isset( $aLangParams[$sOxId]["active"] ) ) ? 1 : $aLangParams[$sOxId]["active"];
00100             $aLanguages[$sKey]->default = ( $aLangParams[$sOxId]["baseId"] == $sDefaultLang ) ? true : false;
00101             $aLanguages[$sKey]->sort    = $aLangParams[$sOxId]["sort"];
00102         }
00103 
00104         if ( is_array( $aLangParams ) ) {
00105             if ( $sSrotParam = $this->getConfig()->getParameter( 'sort' ) ) {
00106                 $this->_sDefSort = $sSrotParam;
00107 
00108                 if ( $sSrotParam == 'active' ) {
00109                     //reverting sort order for field 'active'
00110                     $this->_sDefSortOrder = 'desc';
00111                 }
00112             }
00113 
00114             uasort( $aLanguages, array($this, '_sortLanguagesCallback' ) );
00115         }
00116 
00117         return $aLanguages;
00118     }
00119 
00129     protected function _sortLanguagesCallback( $oLang1, $oLang2 )
00130     {
00131         $sSortParam = $this->_sDefSort;
00132         $sVal1 = is_string( $oLang1->$sSortParam ) ? strtolower( $oLang1->$sSortParam ) : $oLang1->$sSortParam;
00133         $sVal2 = is_string( $oLang2->$sSortParam ) ? strtolower( $oLang2->$sSortParam ) : $oLang2->$sSortParam;
00134 
00135         if ( $this->_sDefSortOrder == 'asc' ) {
00136             return ( $sVal1 < $sVal2 ) ? -1 : 1;
00137         } else {
00138             return ( $sVal1 > $sVal2 ) ? -1 : 1;
00139         }
00140     }
00141 
00150     protected function _resetMultiLangDbFields( $iLangId )
00151     {
00152         $iLangId = (int) $iLangId;
00153 
00154         //skipping reseting language with id = 0
00155         if ( $iLangId ) {
00156 
00157             oxDb::startTransaction();
00158 
00159             try {
00160                 $oDbMeta = oxNew( "oxDbMetaDataHandler" );
00161                 $oDbMeta->resetLanguage( $iLangId );
00162 
00163                 oxDb::commitTransaction();
00164             } catch( Exception $oEx ) {
00165 
00166                 // if exception, rollBack everything
00167                 oxDb::rollbackTransaction();
00168 
00169                 //show warning
00170                 $oEx = new oxExceptionToDisplay();
00171                 $oEx->setMessage( 'LANGUAGE_ERROR_RESETING_MULTILANG_FIELDS' );
00172                 oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
00173             }
00174         }
00175     }
00176 }