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->resetArtSeoUrl( $soxId );
00117         $this->resetContentCache();
00118     }
00119 
00125     public function addcat()
00126     {
00127         $myConfig = $this->getConfig();
00128         $oDb      = oxDb::getDb();
00129         $aAddCat  = $this->_getActionIds( 'oxcategories.oxid' );
00130         $soxId    = oxConfig::getParameter( 'synchoxid' );
00131         $sShopID  = $myConfig->getShopId();
00132         $sO2CView = getViewName('oxobject2category');
00133 
00134         // adding
00135         if ( oxConfig::getParameter( 'all' ) ) {
00136             $sCategoriesTable = getViewName( 'oxcategories' );
00137             $aAddCat = $this->_getAll( $this->_addFilter( "select $sCategoriesTable.oxid ".$this->_getQuery() ) );
00138         }
00139 
00140         if ( isset( $aAddCat) && is_array($aAddCat)) {
00141 
00142             $oDb = oxDb::getDb();
00143 
00144             $oNew = oxNew( 'oxbase' );
00145             $oNew->init( 'oxobject2category' );
00146             $myUtilsObj = oxUtilsObject::getInstance();
00147 
00148             foreach ( $aAddCat as $sAdd ) {
00149 
00150                 // check, if it's already in, then don't add it again
00151                 $sSelect = "select 1 from " . $sO2CView . " as oxobject2category where oxobject2category.oxcatnid= " . $oDb->quote( $sAdd ) . " and oxobject2category.oxobjectid = " . $oDb->quote( $soxId ) . " ";
00152                 if ( $oDb->getOne( $sSelect ) )
00153                     continue;
00154 
00155                 $oNew->setId( $myUtilsObj->generateUID() );
00156                 $oNew->oxobject2category__oxobjectid = new oxField($soxId);
00157                 $oNew->oxobject2category__oxcatnid   = new oxField($sAdd);
00158                 $oNew->oxobject2category__oxtime     = new oxField(time());
00159 
00160 
00161                 $oNew->save();
00162             }
00163 
00164             $this->resetArtSeoUrl( $soxId );
00165             $this->resetContentCache();
00166         }
00167     }
00168 
00174     public function setAsDefault()
00175     {
00176         $myConfig = $this->getConfig();
00177         $sDefCat  = oxConfig::getParameter( "defcat" );
00178         $soxId    = oxConfig::getParameter( "oxid" );
00179         $sShopId  = $myConfig->getShopId();
00180         $oDb      = oxDb::getDb();
00181 
00182         $sShopCheck = "";
00183 
00184         $sQ = "update oxobject2category set oxtime = oxtime + 10 where oxobjectid = " . $oDb->quote( $soxId ) . " $sShopCheck ";
00185         oxDb::getInstance()->getDb()->Execute($sQ);
00186         $sQ = "update oxobject2category set oxtime = 0 where oxobjectid = " . $oDb->quote( $soxId ) . " and oxcatnid = " . $oDb->quote( $sDefCat ) . " $sShopCheck ";
00187         oxDb::getInstance()->getDb()->Execute($sQ);
00188 
00189         $this->resetArtSeoUrl( $soxId );
00190         $this->resetContentCache();
00191     }
00192 }