language_list.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class Language_List extends oxAdminList
00007 {
00008 
00014     protected $_sDefSort = 'sort';
00015 
00021     protected $_sDefSortOrder = 'asc';
00022 
00029     public function deleteEntry()
00030     {
00031 
00032         $myConfig = $this->getConfig();
00033 
00034         $sOxId = oxConfig::getParameter( 'oxid' );
00035 
00036         $aLangData['params']  = $myConfig->getConfigParam( 'aLanguageParams' );
00037         $aLangData['lang']    = $myConfig->getConfigParam( 'aLanguages' );
00038         $aLangData['urls']    = $myConfig->getConfigParam( 'aLanguageURLs' );
00039         $aLangData['sslUrls'] = $myConfig->getConfigParam( 'aLanguageSSLURLs' );
00040 
00041         $iBaseId = (int)$aLangData['params'][$sOxId]['baseId'];
00042 
00043         // preventing deleting main language with base id = 0
00044         if ( $iBaseId == 0 ) {
00045             $oEx = new oxExceptionToDisplay();
00046             $oEx->setMessage( 'LANGUAGE_DELETINGMAINLANG_WARNING' );
00047             oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
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', serialize($aLangData['params']) );
00059         $myConfig->saveShopConfVar( 'aarr', 'aLanguages', serialize($aLangData['lang']) );
00060         $myConfig->saveShopConfVar( 'arr',  'aLanguageURLs', serialize($aLangData['urls']) );
00061         $myConfig->saveShopConfVar( 'arr',  'aLanguageSSLURLs', serialize($aLangData['sslUrls']) );
00062 
00063         //updating oConfig object
00064         $myConfig->setConfigParam( 'aLanguageParams', $aLangData['params'] );
00065         $myConfig->setConfigParam( 'aLanguages', $aLangData['lang'] );
00066         $myConfig->setConfigParam( 'aLanguageURLs', $aLangData['urls'] );
00067         $myConfig->setConfigParam( 'aLanguageSSLURLs', $aLangData['sslUrls'] );
00068 
00069         //if deleted language was default, setting defalt lang to 0
00070         if ( $iBaseId == $myConfig->getConfigParam( 'sDefaultLang' ) ) {
00071             $myConfig->saveShopConfVar( 'str',  'sDefaultLang', 0 );
00072             $myConfig->setConfigParam( 'sDefaultLang', 0 );
00073         }
00074     }
00075 
00082     public function render()
00083     {
00084 
00085         parent::render();
00086         $this->_aViewData['mylist'] = $this->_getLanguagesList();
00087 
00088         return "language_list.tpl";
00089     }
00090 
00096     protected function _getLanguagesList()
00097     {
00098         $aLangParams  = $this->getConfig()->getConfigParam( 'aLanguageParams' );
00099         $aLanguages   = oxLang::getInstance()->getLanguageArray();
00100         $sDefaultLang = $this->getConfig()->getConfigParam( 'sDefaultLang' );
00101 
00102         foreach( $aLanguages as $sKey => $sValue ) {
00103             $sOxId = $sValue->oxid;
00104             $aLanguages[$sKey]->active  = (!isset($aLangParams[$sOxId]["active"])) ? 1 : $aLangParams[$sOxId]["active"];
00105             $aLanguages[$sKey]->default = ($aLangParams[$sOxId]["baseId"] == $sDefaultLang) ? true : false;
00106             $aLanguages[$sKey]->sort   = $aLangParams[$sOxId]["sort"];
00107         }
00108 
00109         if ( is_array($aLangParams) ) {
00110             $sSrotParam = $this->getConfig()->getParameter( 'sort' );
00111 
00112             if ( !empty($sSrotParam) ) {
00113                 $this->_sDefSort = $sSrotParam;
00114 
00115                 if ( $sSrotParam == 'active' ) {
00116                     //reverting sort order for field 'active'
00117                     $this->_sDefSortOrder = 'desc';
00118                 }
00119             }
00120 
00121             uasort( $aLanguages, array($this, '_sortLanguagesCallback') );
00122         }
00123 
00124         return $aLanguages;
00125     }
00126 
00136     protected function _sortLanguagesCallback( $oLang1, $oLang2 )
00137     {
00138         $sSortParam = $this->_sDefSort;
00139         $sVal1 = is_string($oLang1->$sSortParam) ? strtolower( $oLang1->$sSortParam ) : $oLang1->$sSortParam;
00140         $sVal2 = is_string($oLang2->$sSortParam) ? strtolower( $oLang2->$sSortParam ) : $oLang2->$sSortParam;
00141 
00142         if ( $this->_sDefSortOrder == 'asc' ) {
00143             return ($sVal1 < $sVal2) ? -1 : 1;
00144         } else {
00145             return ($sVal1 > $sVal2) ? -1 : 1;
00146         }
00147     }
00148 }

Generated on Wed May 13 13:25:50 2009 for OXID eShop CE by  doxygen 1.5.5