article_extend_ajax.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class article_extend_ajax extends ajaxListComponent
00007 {
00013     protected $_aColumns = array( 'container1' => array(    // field , table,         visible, multilanguage, ident
00014                                         array( 'oxtitle', 'oxcategories', 1, 1, 0 ),
00015                                         array( 'oxdesc',  'oxcategories', 1, 1, 0 ),
00016                                         array( 'oxid',    'oxcategories', 0, 0, 0 ),
00017                                         array( 'oxid',    'oxcategories', 0, 0, 1 )
00018                                         ),
00019                                     'container2' => array(
00020                                         array( 'oxtitle', 'oxcategories', 1, 1, 0 ),
00021                                         array( 'oxdesc',  'oxcategories', 1, 1, 0 ),
00022                                         array( 'oxid',    'oxcategories', 0, 0, 0 ),
00023                                         array( 'oxid',    'oxobject2category', 0, 0, 1 ),
00024                                         array( 'oxtime',  'oxobject2category', 0, 0, 1 ),
00025                                         array( 'oxid',    'oxcategories',      0, 0, 1 )
00026                                         ),
00027                                 );
00028 
00034     protected function _getQuery()
00035     {
00036         $sCategoriesTable = $this->_getViewName( 'oxcategories' );
00037         $sO2CView = $this->_getViewName( 'oxobject2category' );
00038         $oDb = oxDb::getDb();
00039 
00040         $sOxid      = oxConfig::getParameter( 'oxid' );
00041         $sSynchOxid = oxConfig::getParameter( 'synchoxid' );
00042 
00043         if ( $sOxid ) {
00044             // all categories article is in
00045             $sQAdd  = " from $sO2CView left join $sCategoriesTable on $sCategoriesTable.oxid=$sO2CView.oxcatnid ";
00046             $sQAdd .= " where $sO2CView.oxobjectid = " . $oDb->quote( $sOxid ) . " and $sCategoriesTable.oxid is not null ";
00047         } else {
00048             $sQAdd  = " from $sCategoriesTable where $sCategoriesTable.oxid not in ( ";
00049             $sQAdd .= " select $sCategoriesTable.oxid from $sO2CView left join $sCategoriesTable on $sCategoriesTable.oxid=$sO2CView.oxcatnid ";
00050             $sQAdd .= " where $sO2CView.oxobjectid = " . $oDb->quote( $sSynchOxid ) . " and $sCategoriesTable.oxid is not null ) and $sCategoriesTable.oxpriceto = '0'";
00051         }
00052 
00053         return $sQAdd;
00054     }
00055 
00063     protected function _getDataFields( $sQ )
00064     {
00065         $aDataFields = parent::_getDataFields( $sQ );
00066         if ( oxConfig::getParameter( 'oxid' ) && is_array( $aDataFields ) && count( $aDataFields ) ) {
00067 
00068             // looking for smallest time value to mark record as main category ..
00069             $iMinPos = null;
00070             $iMinVal = null;
00071             reset( $aDataFields );
00072             while ( list( $iPos, $aField ) = each( $aDataFields ) ) {
00073 
00074                 // already set ?
00075                 if ( $aField['_3'] == '0' ) {
00076                     $iMinPos = null;
00077                     break;
00078                 }
00079 
00080                 if ( !$iMinVal ) {
00081                     $iMinVal = $aField['_3'];
00082                     $iMinPos = $iPos;
00083                 } elseif ( $iMinVal > $aField['_3'] ) {
00084                     $iMinPos = $iPos;
00085                 }
00086             }
00087 
00088             // setting primary category
00089             if ( isset( $iMinPos ) ) {
00090                 $aDataFields[$iMinPos]['_3'] = '0';
00091             }
00092         }
00093 
00094         return $aDataFields;
00095     }
00096 
00102     public function removeCat()
00103     {
00104         $myConfig = $this->getConfig();
00105         $aRemoveCat = $this->_getActionIds( 'oxcategories.oxid' );
00106 
00107         $soxId   = oxConfig::getParameter( 'oxid' );
00108         $sShopID = $myConfig->getShopId();
00109         $oDb = oxDb::getDb();
00110 
00111             // adding
00112         if ( oxConfig::getParameter( 'all' ) ) {
00113             $sCategoriesTable = $this->_getViewName( 'oxcategories' );
00114             $aRemoveCat = $this->_getAll( $this->_addFilter( "select {$sCategoriesTable}.oxid ".$this->_getQuery() ) );
00115         }
00116 
00117         // removing all
00118         if ( is_array( $aRemoveCat ) && count( $aRemoveCat ) ) {
00119 
00120             $sQ = "delete from oxobject2category where oxobject2category.oxobjectid= " . oxDb::getDb()->quote( $soxId ) . " and ";
00121             $sQ .= " oxcatnid in (" . implode( ', ', oxDb::getInstance()->quoteArray( $aRemoveCat ) ) . ')';
00122             $oDb->Execute( $sQ );
00123             //echo "\n$sQ\n___________________";
00124 
00125 
00126             // updating oxtime values
00127             $this->_updateOxTime( $soxId );
00128         }
00129 
00130         $this->resetArtSeoUrl( $soxId, $aRemoveCat );
00131         $this->resetContentCache();
00132 
00133     }
00134 
00140     public function addCat()
00141     {
00142         $myConfig = $this->getConfig();
00143         $oDb      = oxDb::getDb();
00144         $aAddCat  = $this->_getActionIds( 'oxcategories.oxid' );
00145         $soxId    = oxConfig::getParameter( 'synchoxid' );
00146         $sShopID  = $myConfig->getShopId();
00147         $sO2CView = $this->_getViewName('oxobject2category');
00148 
00149         // adding
00150         if ( oxConfig::getParameter( 'all' ) ) {
00151             $sCategoriesTable = $this->_getViewName( 'oxcategories' );
00152             $aAddCat = $this->_getAll( $this->_addFilter( "select $sCategoriesTable.oxid ".$this->_getQuery() ) );
00153         }
00154 
00155         if ( isset( $aAddCat) && is_array($aAddCat)) {
00156 
00157             $oDb = oxDb::getDb();
00158 
00159             $oNew = oxNew( 'oxbase' );
00160             $oNew->init( 'oxobject2category' );
00161             $myUtilsObj = oxUtilsObject::getInstance();
00162 
00163             foreach ( $aAddCat as $sAdd ) {
00164 
00165                 // check, if it's already in, then don't add it again
00166                 $sSelect = "select 1 from " . $sO2CView . " as oxobject2category where oxobject2category.oxcatnid= " . $oDb->quote( $sAdd ) . " and oxobject2category.oxobjectid = " . $oDb->quote( $soxId ) . " ";
00167                 if ( $oDb->getOne( $sSelect, false, false ) )
00168                     continue;
00169 
00170                 $oNew->setId( $myUtilsObj->generateUID() );
00171                 $oNew->oxobject2category__oxobjectid = new oxField( $soxId );
00172                 $oNew->oxobject2category__oxcatnid   = new oxField( $sAdd );
00173                 $oNew->oxobject2category__oxtime     = new oxField( time() );
00174 
00175 
00176                 $oNew->save();
00177             }
00178 
00179             $this->_updateOxTime( $soxId );
00180 
00181             $this->resetArtSeoUrl( $soxId );
00182             $this->resetContentCache();
00183 
00184 
00185         }
00186     }
00187 
00195     protected function _updateOxTime( $soxId )
00196     {
00197         $oDb = oxDb::getDb();
00198         $sO2CView = $this->_getViewName('oxobject2category');
00199         $soxId = $oDb->quote( $soxId );
00200 
00201         // updating oxtime values
00202         $sQ  = "update oxobject2category set oxtime = 0 where oxobjectid = {$soxId} and oxid = (
00203                     select oxid from (
00204                         select oxid from {$sO2CView} where oxobjectid = {$soxId} order by oxtime limit 1
00205                     ) as _tmp
00206                 )";
00207         $oDb->execute( $sQ );
00208     }
00209 
00215     public function setAsDefault()
00216     {
00217         $myConfig = $this->getConfig();
00218         $sDefCat  = oxConfig::getParameter( "defcat" );
00219         $soxId    = oxConfig::getParameter( "oxid" );
00220         $sShopId  = $myConfig->getShopId();
00221         $oDb      = oxDb::getDb();
00222 
00223         $sShopCheck = "";
00224 
00225         // #0003650: increment all product references independent to active shop
00226         $sQ = "update oxobject2category set oxtime = oxtime + 10 where oxobjectid = " . $oDb->quote( $soxId );
00227         oxDb::getDb()->Execute($sQ);
00228 
00229         // set main category for active shop
00230         $sQ = "update oxobject2category set oxtime = 0 where oxobjectid = " . $oDb->quote( $soxId ) . " and oxcatnid = " . $oDb->quote( $sDefCat ) . " $sShopCheck ";
00231         oxDb::getDb()->Execute($sQ);
00232         //echo "\n$sQ\n";
00233 
00234         // #0003366: invalidate article SEO for all shops
00235         oxRegistry::get("oxSeoEncoder")->markAsExpired( $soxId, null, 1, null, "oxtype='oxarticle'" );
00236         $this->resetContentCache();
00237     }
00238 }