category_main.php

Go to the documentation of this file.
00001 <?php
00002 
00009 class Category_Main extends oxAdminDetails
00010 {
00017     public function render()
00018     {
00019         $myConfig  = $this->getConfig();
00020 
00021         parent::render();
00022 
00023         $this->_aViewData["edit"] = $oCategory = oxNew( "oxcategory" );;
00024         $sChosenArtCat = oxConfig::getParameter( "artcat");
00025         $soxId = $this->_aViewData["oxid"] = $this->getEditObjectId();
00026         if ( $soxId != "-1" && isset( $soxId)) {
00027 
00028             // generating category tree for select list
00029             $sChosenArtCat = $this->_getCategoryTree( "artcattree", $sChosenArtCat, $soxId );
00030 
00031             // load object
00032             $oCategory->loadInLang( $this->_iEditLang, $soxId );
00033 
00034 
00035             $oOtherLang = $oCategory->getAvailableInLangs();
00036             if (!isset($oOtherLang[$this->_iEditLang])) {
00037                 // echo "language entry doesn't exist! using: ".key($oOtherLang);
00038                 $oCategory->loadInLang( key($oOtherLang), $soxId );
00039             }
00040 
00041             // remove already created languages
00042             $aLang = array_diff ( oxLang::getInstance()->getLanguageNames(), $oOtherLang );
00043             if ( count( $aLang))
00044                 $this->_aViewData["posslang"] = $aLang;
00045 
00046             foreach ( $oOtherLang as $id => $language) {
00047                 $oLang = new oxStdClass();
00048                 $oLang->sLangDesc = $language;
00049                 $oLang->selected = ($id == $this->_iEditLang);
00050                 $this->_aViewData["otherlang"][$id] =  clone $oLang;
00051             }
00052 
00053             if ( $oCategory->oxcategories__oxparentid->value == 'oxrootid')
00054                 $oCategory->oxcategories__oxparentid->setValue('');
00055 
00056             $this->_getCategoryTree( "cattree", $oCategory->oxcategories__oxparentid->value, $oCategory->oxcategories__oxid->value, true, $oCategory->oxcategories__oxshopid->value);
00057 
00058             $this->_aViewData["defsort"] = $oCategory->oxcategories__oxdefsort->value;
00059         } else
00060             $this->_getCategoryTree( "cattree", "", "", true, $myConfig->getShopId());
00061 
00062         $this->_aViewData["sortableFields"] = $this->getSortableFields();
00063 
00064         if ( oxConfig::getParameter("aoc") ) {
00065 
00066             $aColumns = array();
00067             include_once 'inc/'.strtolower(__CLASS__).'.inc.php';
00068             $this->_aViewData['oxajax'] = $aColumns;
00069 
00070             return "popups/category_main.tpl";
00071         }
00072         return "category_main.tpl";
00073     }
00074 
00080     public function getSortableFields()
00081     {
00082         $aSkipFields = array( "OXID", "OXSHOPID", "OXSHOPINCL", "OXSHOPEXCL", "OXPARENTID", "OXACTIVE", "OXACTIVEFROM"
00083             , "OXACTIVETO", "OXSHORTDESC"
00084             , "OXUNITNAME", "OXUNITQUANTITY", "OXEXTURL", "OXURLDESC", "OXURLIMG", "OXVAT"
00085             , "OXTHUMB", "OXPICSGENERATED", "OXPIC1", "OXPIC2", "OXPIC3", "OXPIC4", "OXPIC5"
00086             , "OXPIC6", "OXPIC7", "OXPIC8", "OXPIC9", "OXPIC10", "OXPIC11", "OXPIC12", "OXSTOCKFLAG"
00087             , "OXSTOCKTEXT", "OXNOSTOCKTEXT", "OXDELIVERY", "OXFILE", "OXSEARCHKEYS", "OXTEMPLATE"
00088             , "OXQUESTIONEMAIL", "OXISSEARCH", "OXISCONFIGURABLE", "OXBUNDLEID", "OXFOLDER", "OXSUBCLASS"
00089             , "OXREMINDACTIVE", "OXREMINDAMOUNT", "OXVENDORID", "OXMANUFACTURERID", "OXSKIPDISCOUNTS"
00090             , "OXBLFIXEDPRICE", "OXICON", "OXVARSELECT", "OXAMITEMID", "OXAMTASKID", "OXPIXIEXPORT", "OXPIXIEXPORTED", "OXSORT"
00091         );
00092 
00093         $oDbHandler = oxNew( "oxDbMetaDataHandler" );
00094         $aFields = array_merge( $oDbHandler->getMultilangFields( 'oxarticles' ), $oDbHandler->getSinglelangFields( 'oxarticles', 0 ) );
00095         $aFields = array_diff( $aFields, $aSkipFields );
00096         $aFields = array_unique( $aFields );
00097 
00098         return $aFields;
00099     }
00100 
00106     public function save()
00107     {
00108         parent::save();
00109 
00110         $myConfig  = $this->getConfig();
00111 
00112         $soxId = $this->getEditObjectId();
00113         $aParams = oxConfig::getParameter( "editval");
00114 
00115         // checkbox handling
00116         if ( !isset( $aParams['oxcategories__oxactive']))
00117             $aParams['oxcategories__oxactive'] = 0;
00118         if ( !isset( $aParams['oxcategories__oxhidden']))
00119             $aParams['oxcategories__oxhidden'] = 0;
00120         if ( !isset( $aParams['oxcategories__oxdefsortmode']))
00121             $aParams['oxcategories__oxdefsortmode'] = 0;
00122 
00123         // null values
00124         if ($aParams['oxcategories__oxvat'] === '')
00125             $aParams['oxcategories__oxvat'] = null;
00126 
00127             // shopid
00128             $aParams['oxcategories__oxshopid'] = oxSession::getVar( "actshop" );
00129 
00130         $oCategory = oxNew( "oxcategory" );
00131 
00132         if ( $soxId != "-1") {
00133             $this->resetCounter( "catArticle", $soxId );
00134             $oCategory->load( $soxId);
00135             $oCategory->loadInLang( $this->_iEditLang, $soxId );
00136                 $myUtilsPic = oxUtilsPic::getInstance();
00137                 // #1173M - not all pic are deleted, after article is removed
00138                 $myUtilsPic->overwritePic( $oCategory, 'oxcategories', 'oxthumb', 'TC', '0', $aParams, $myConfig->getPictureDir(false) );
00139                 $myUtilsPic->overwritePic( $oCategory, 'oxcategories', 'oxicon', 'CICO', 'icon', $aParams, $myConfig->getPictureDir(false) );
00140                 $myUtilsPic->overwritePic( $oCategory, 'oxcategories', 'oxpromoicon', 'PICO', 'icon', $aParams, $myConfig->getPictureDir(false) );
00141 
00142         } else {
00143             //#550A - if new category is made then is must be default activ
00144             $aParams['oxcategories__oxactive'] = 1;
00145             $aParams['oxcategories__oxid'] = null;
00146         }
00147 
00148 
00149         $oCategory->setLanguage(0);
00150         if ( isset( $aParams["oxcategories__oxlongdesc"] ) ) {
00151             $aParams["oxcategories__oxlongdesc"] = $this->_processLongDesc( $aParams["oxcategories__oxlongdesc"] );
00152         }
00153 
00154 
00155         $oCategory->assign( $aParams );
00156         $oCategory->setLanguage($this->_iEditLang);
00157 
00158         $oCategory = oxUtilsFile::getInstance()->processFiles( $oCategory );
00159         $oCategory->save();
00160 
00161         $this->setEditObjectId( $oCategory->getId() );
00162     }
00163 
00171     protected function _processLongDesc( $sValue )
00172     {
00173         // workaround for firefox showing &lang= as &9001;= entity, mantis#0001272
00174         return str_replace( '&lang=', '&amp;lang=', $sValue );
00175     }
00176 
00182     public function saveinnlang()
00183     {
00184         $this->save();
00185     }
00186 }