article_extend.inc.php

Go to the documentation of this file.
00001 <?php
00002 
00003 $aColumns = array( 'container1' => array(    // field , table,         visible, multilanguage, ident
00004                                         array( 'oxtitle', 'oxcategories', 1, 1, 0 ),
00005                                         array( 'oxdesc',  'oxcategories', 1, 1, 0 ),
00006                                         array( 'oxid',    'oxcategories', 0, 0, 1 )
00007                                         ),
00008                      'container2' => array(
00009                                         array( 'oxtitle', 'oxcategories', 1, 1, 0 ),
00010                                         array( 'oxdesc',  'oxcategories', 1, 1, 0 ),
00011                                         array( 'oxid',    'oxobject2category', 0, 0, 1 ),
00012                                         array( 'oxtime',  'oxobject2category', 0, 0, 1 ),
00013                                         array( 'oxid',    'oxcategories',      0, 0, 1 )
00014                                         ),
00015                    );
00019 class ajaxComponent extends ajaxListComponent
00020 {
00026     protected function _getQuery()
00027     {
00028         $sCategoriesTable = getViewName( 'oxcategories' );
00029         $sO2CView = getViewName( 'oxobject2category' );
00030         $oDb = oxDb::getDb();
00031 
00032         $sOxid      = oxConfig::getParameter( 'oxid' );
00033         $sSynchOxid = oxConfig::getParameter( 'synchoxid' );
00034 
00035         if ( $sOxid ) {
00036             // all categories article is in
00037             $sQAdd  = " from $sO2CView left join $sCategoriesTable on $sCategoriesTable.oxid=$sO2CView.oxcatnid ";
00038             $sQAdd .= " where $sO2CView.oxobjectid = " . $oDb->quote( $sOxid ) . " and $sCategoriesTable.oxid is not null ";
00039         } else {
00040             $sQAdd  = " from $sCategoriesTable where $sCategoriesTable.oxid not in ( ";
00041             $sQAdd .= " select $sCategoriesTable.oxid from $sO2CView left join $sCategoriesTable on $sCategoriesTable.oxid=$sO2CView.oxcatnid ";
00042             $sQAdd .= " where $sO2CView.oxobjectid = " . $oDb->quote( $sSynchOxid ) . " and $sCategoriesTable.oxid is not null ) and $sCategoriesTable.oxpriceto = '0'";
00043         }
00044 
00045         return $sQAdd;
00046     }
00047 
00055     protected function _getDataFields( $sQ )
00056     {
00057         $aDataFields = parent::_getDataFields( $sQ );
00058         if ( oxConfig::getParameter( 'oxid' ) && is_array( $aDataFields ) && count( $aDataFields ) ) {
00059 
00060             // looking for smallest time value to mark record as main category ..
00061             $iMinPos = null;
00062             $iMinVal = null;
00063             reset( $aDataFields );
00064             while ( list( $iPos, $aField ) = each( $aDataFields ) ) {
00065 
00066                 // allready set ?
00067                 if ( $aField['_3'] == '0' ) {
00068                     $iMinPos = null;
00069                     break;
00070                 }
00071 
00072                 if ( !$iMinVal ) {
00073                     $iMinVal = $aField['_3'];
00074                     $iMinPos = $iPos;
00075                 } elseif ( $iMinVal > $aField['_3'] ) {
00076                     $iMinPos = $iPos;
00077                 }
00078             }
00079 
00080             // setting primary category
00081             if ( isset( $iMinPos ) ) {
00082                 $aDataFields[$iMinPos]['_3'] = '0';
00083             }
00084         }
00085 
00086         return $aDataFields;
00087     }
00088 
00094     public function removecat()
00095     {
00096         $myConfig   = $this->getConfig();
00097         $aRemoveCat = $this->_getActionIds( 'oxobject2category.oxid' );
00098         $soxId      = oxConfig::getParameter( 'oxid' );
00099         $sShopID    = $myConfig->getShopId();
00100         $sO2CView = getViewName( 'oxobject2category' );
00101         $oDb = oxDb::getDb();
00102 
00103         // removing all
00104         if ( oxConfig::getParameter( 'all' ) ) {
00105 
00106             $sQ = $this->_addFilter( "delete $sO2CView.* ".$this->_getQuery() );
00107             $oDb->Execute( $sQ );
00108 
00109         } elseif ( is_array( $aRemoveCat ) && count( $aRemoveCat ) ) {
00110 
00111             $sQ = 'delete from oxobject2category where oxid in (' . implode( ', ', oxDb::getInstance()->quoteArray( $aRemoveCat ) ) . ')';
00112             $oDb->Execute( $sQ );
00113 
00114         }
00115 
00116         $this->resetContentCache();
00117     }
00118 
00124     public function addcat()
00125     {
00126         $myConfig = $this->getConfig();
00127         $oDb      = oxDb::getDb();
00128         $aAddCat  = $this->_getActionIds( 'oxcategories.oxid' );
00129         $soxId    = oxConfig::getParameter( 'synchoxid' );
00130         $sShopID  = $myConfig->getShopId();
00131         $sO2CView = getViewName('oxobject2category');
00132 
00133         // adding
00134         if ( oxConfig::getParameter( 'all' ) ) {
00135             $sCategoriesTable = getViewName( 'oxcategories' );
00136             $aAddCat = $this->_getAll( $this->_addFilter( "select $sCategoriesTable.oxid ".$this->_getQuery() ) );
00137         }
00138 
00139         if ( isset( $aAddCat) && is_array($aAddCat)) {
00140 
00141             $oDb = oxDb::getDb();
00142 
00143             $oNew = oxNew( 'oxbase' );
00144             $oNew->init( 'oxobject2category' );
00145             $myUtilsObj = oxUtilsObject::getInstance();
00146 
00147             foreach ( $aAddCat as $sAdd ) {
00148 
00149                 // check, if it's already in, then don't add it again
00150                 $sSelect = "select 1 from " . $sO2CView . " as oxobject2category where oxobject2category.oxcatnid= " . $oDb->quote( $sAdd ) . " and oxobject2category.oxobjectid = " . $oDb->quote( $soxId ) . " ";
00151                 if ( $oDb->getOne( $sSelect ) )
00152                     continue;
00153 
00154                 $oNew->setId( $myUtilsObj->generateUID() );
00155                 $oNew->oxobject2category__oxobjectid = new oxField($soxId);
00156                 $oNew->oxobject2category__oxcatnid   = new oxField($sAdd);
00157                 $oNew->oxobject2category__oxtime     = new oxField(time());
00158 
00159 
00160                 $oNew->save();
00161             }
00162 
00163             $this->resetContentCache();
00164         }
00165     }
00166 
00172     public function setAsDefault()
00173     {
00174         $myConfig = $this->getConfig();
00175         $sDefCat  = oxConfig::getParameter( "defcat" );
00176         $soxId    = oxConfig::getParameter( "oxid" );
00177         $sShopId  = $myConfig->getShopId();
00178         $oDb      = oxDb::getDb();
00179 
00180         $sShopCheck = "";
00181 
00182         $sQ = "update oxobject2category set oxtime = oxtime + 10 where oxobjectid = " . $oDb->quote( $soxId ) . " $sShopCheck ";
00183         oxDb::getInstance()->getDb()->Execute($sQ);
00184         $sQ = "update oxobject2category set oxtime = 0 where oxobjectid = " . $oDb->quote( $soxId ) . " and oxcatnid = " . $oDb->quote( $sDefCat ) . " $sShopCheck ";
00185         oxDb::getInstance()->getDb()->Execute($sQ);
00186     }
00187 }

Generated on Tue Sep 29 16:45:12 2009 for OXID eShop CE by  doxygen 1.5.5