language_list.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class Language_List extends oxAdminList
00007 {
00013     protected $_sDefSortField = 'sort';
00014 
00020     protected $_sDefSortOrder = 'asc';
00021 
00027     public function deleteEntry()
00028     {
00029         $myConfig = $this->getConfig();
00030 
00031 
00032         $sOxId = $this->getEditObjectId();
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             $aSorting = $this->getListSorting();
00106 
00107             if ( is_array( $aSorting ) ) {
00108                 foreach ( $aSorting as $aFieldSorting ) {
00109                     foreach ( $aFieldSorting as $sField => $sDir ) {
00110                         $this->_sDefSortField = $sField;
00111                         $this->_sDefSortOrder = $sDir;
00112 
00113                         if ( $sField == 'active' ) {
00114                             //reverting sort order for field 'active'
00115                             $this->_sDefSortOrder = 'desc';
00116                         }
00117                         break 2;
00118                     }
00119                 }
00120             }
00121 
00122             uasort( $aLanguages, array($this, '_sortLanguagesCallback' ) );
00123         }
00124 
00125         return $aLanguages;
00126     }
00127 
00137     protected function _sortLanguagesCallback( $oLang1, $oLang2 )
00138     {
00139         $sSortParam = $this->_sDefSortField;
00140         $sVal1 = is_string( $oLang1->$sSortParam ) ? strtolower( $oLang1->$sSortParam ) : $oLang1->$sSortParam;
00141         $sVal2 = is_string( $oLang2->$sSortParam ) ? strtolower( $oLang2->$sSortParam ) : $oLang2->$sSortParam;
00142 
00143         if ( $this->_sDefSortOrder == 'asc' ) {
00144             return ( $sVal1 < $sVal2 ) ? -1 : 1;
00145         } else {
00146             return ( $sVal1 > $sVal2 ) ? -1 : 1;
00147         }
00148     }
00149 
00158     protected function _resetMultiLangDbFields( $iLangId )
00159     {
00160         $iLangId = (int) $iLangId;
00161 
00162         //skipping reseting language with id = 0
00163         if ( $iLangId ) {
00164 
00165             oxDb::startTransaction();
00166 
00167             try {
00168                 $oDbMeta = oxNew( "oxDbMetaDataHandler" );
00169                 $oDbMeta->resetLanguage( $iLangId );
00170 
00171                 oxDb::commitTransaction();
00172             } catch( Exception $oEx ) {
00173 
00174                 // if exception, rollBack everything
00175                 oxDb::rollbackTransaction();
00176 
00177                 //show warning
00178                 $oEx = new oxExceptionToDisplay();
00179                 $oEx->setMessage( 'LANGUAGE_ERROR_RESETING_MULTILANG_FIELDS' );
00180                 oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
00181             }
00182         }
00183     }
00184 }