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 = $this->_getViewName( 'oxcategories' );
00029         $sO2CView = $this->_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( 'oxcategories.oxid' );
00098 
00099         $soxId   = oxConfig::getParameter( 'oxid' );
00100         $sShopID = $myConfig->getShopId();
00101         $oDb = oxDb::getDb();
00102 
00103             // adding
00104         if ( oxConfig::getParameter( 'all' ) ) {
00105             $sCategoriesTable = $this->_getViewName( 'oxcategories' );
00106             $aRemoveCat = $this->_getAll( $this->_addFilter( "select {$sCategoriesTable}.oxid ".$this->_getQuery() ) );
00107         }
00108 
00109         // removing all
00110         if ( is_array( $aRemoveCat ) && count( $aRemoveCat ) ) {
00111 
00112             $sQ = "delete from oxobject2category where oxobject2category.oxobjectid= " . oxDb::getDb()->quote( $soxId ) . " and ";
00113             $sQ .= " oxcatnid in (" . implode( ', ', oxDb::getInstance()->quoteArray( $aRemoveCat ) ) . ')';
00114             $oDb->Execute( $sQ );
00115 
00116 
00117             // updating oxtime values
00118             $this->_updateOxTime( $soxId );
00119         }
00120 
00121         $this->resetArtSeoUrl( $soxId, $aRemoveCat );
00122         $this->resetContentCache();
00123     }
00124 
00130     public function addcat()
00131     {
00132         $myConfig = $this->getConfig();
00133         $oDb      = oxDb::getDb();
00134         $aAddCat  = $this->_getActionIds( 'oxcategories.oxid' );
00135         $soxId    = oxConfig::getParameter( 'synchoxid' );
00136         $sShopID  = $myConfig->getShopId();
00137         $sO2CView = $this->_getViewName('oxobject2category');
00138 
00139         // adding
00140         if ( oxConfig::getParameter( 'all' ) ) {
00141             $sCategoriesTable = $this->_getViewName( 'oxcategories' );
00142             $aAddCat = $this->_getAll( $this->_addFilter( "select $sCategoriesTable.oxid ".$this->_getQuery() ) );
00143         }
00144 
00145         if ( isset( $aAddCat) && is_array($aAddCat)) {
00146 
00147             $oDb = oxDb::getDb();
00148 
00149             $oNew = oxNew( 'oxbase' );
00150             $oNew->init( 'oxobject2category' );
00151             $myUtilsObj = oxUtilsObject::getInstance();
00152 
00153             foreach ( $aAddCat as $sAdd ) {
00154 
00155                 // check, if it's already in, then don't add it again
00156                 $sSelect = "select 1 from " . $sO2CView . " as oxobject2category where oxobject2category.oxcatnid= " . $oDb->quote( $sAdd ) . " and oxobject2category.oxobjectid = " . $oDb->quote( $soxId ) . " ";
00157                 if ( $oDb->getOne( $sSelect ) )
00158                     continue;
00159 
00160                 $oNew->setId( $myUtilsObj->generateUID() );
00161                 $oNew->oxobject2category__oxobjectid = new oxField( $soxId );
00162                 $oNew->oxobject2category__oxcatnid   = new oxField( $sAdd );
00163                 $oNew->oxobject2category__oxtime     = new oxField( time() );
00164 
00165 
00166                 $oNew->save();
00167             }
00168 
00169             $this->_updateOxTime( $soxId );
00170 
00171             $this->resetArtSeoUrl( $soxId );
00172             $this->resetContentCache();
00173         }
00174     }
00175 
00183     protected function _updateOxTime( $soxId )
00184     {
00185         $oDb = oxDb::getDb();
00186         $sO2CView = $this->_getViewName('oxobject2category');
00187         $soxId = $oDb->quote( $soxId );
00188 
00189         // updating oxtime values
00190         $sQ  = "update oxobject2category set oxtime = 0 where oxobjectid = {$soxId} and oxid = (
00191                     select oxid from (
00192                         select oxid from {$sO2CView} where oxobjectid = {$soxId} order by oxtime limit 1
00193                     ) as _tmp
00194                 )";
00195         $oDb->execute( $sQ );
00196     }
00197 
00203     public function setAsDefault()
00204     {
00205         $myConfig = $this->getConfig();
00206         $sDefCat  = oxConfig::getParameter( "defcat" );
00207         $soxId    = oxConfig::getParameter( "oxid" );
00208         $sShopId  = $myConfig->getShopId();
00209         $oDb      = oxDb::getDb();
00210 
00211         $sShopCheck = "";
00212 
00213         $sQ = "update oxobject2category set oxtime = oxtime + 10 where oxobjectid = " . $oDb->quote( $soxId ) . " $sShopCheck ";
00214         oxDb::getInstance()->getDb()->Execute($sQ);
00215         $sQ = "update oxobject2category set oxtime = 0 where oxobjectid = " . $oDb->quote( $soxId ) . " and oxcatnid = " . $oDb->quote( $sDefCat ) . " $sShopCheck ";
00216         oxDb::getInstance()->getDb()->Execute($sQ);
00217 
00218         $this->resetArtSeoUrl( $soxId );
00219         $this->resetContentCache();
00220     }
00221 }