00001 <?php
00002
00003 $aColumns = array( 'container1' => array(
00004 array( 'oxtitle', 'oxcategories', 1, 1, 0 ),
00005 array( 'oxdesc', 'oxcategories', 1, 1, 0 ),
00006 array( 'oxid', 'oxcategories', 0, 0, 0 ),
00007 array( 'oxid', 'oxcategories', 0, 0, 1 )
00008 ),
00009 'container2' => array(
00010 array( 'oxtitle', 'oxcategories', 1, 1, 0 ),
00011 array( 'oxdesc', 'oxcategories', 1, 1, 0 ),
00012 array( 'oxid', 'oxcategories', 0, 0, 0 ),
00013 array( 'oxid', 'oxobject2category', 0, 0, 1 ),
00014 array( 'oxtime', 'oxobject2category', 0, 0, 1 ),
00015 array( 'oxid', 'oxcategories', 0, 0, 1 )
00016 ),
00017 );
00021 class ajaxComponent extends ajaxListComponent
00022 {
00028 protected function _getQuery()
00029 {
00030 $sCategoriesTable = $this->_getViewName( 'oxcategories' );
00031 $sO2CView = $this->_getViewName( 'oxobject2category' );
00032 $oDb = oxDb::getDb();
00033
00034 $sOxid = oxConfig::getParameter( 'oxid' );
00035 $sSynchOxid = oxConfig::getParameter( 'synchoxid' );
00036
00037 if ( $sOxid ) {
00038
00039 $sQAdd = " from $sO2CView left join $sCategoriesTable on $sCategoriesTable.oxid=$sO2CView.oxcatnid ";
00040 $sQAdd .= " where $sO2CView.oxobjectid = " . $oDb->quote( $sOxid ) . " and $sCategoriesTable.oxid is not null ";
00041 } else {
00042 $sQAdd = " from $sCategoriesTable where $sCategoriesTable.oxid not in ( ";
00043 $sQAdd .= " select $sCategoriesTable.oxid from $sO2CView left join $sCategoriesTable on $sCategoriesTable.oxid=$sO2CView.oxcatnid ";
00044 $sQAdd .= " where $sO2CView.oxobjectid = " . $oDb->quote( $sSynchOxid ) . " and $sCategoriesTable.oxid is not null ) and $sCategoriesTable.oxpriceto = '0'";
00045 }
00046
00047 return $sQAdd;
00048 }
00049
00057 protected function _getDataFields( $sQ )
00058 {
00059 $aDataFields = parent::_getDataFields( $sQ );
00060 if ( oxConfig::getParameter( 'oxid' ) && is_array( $aDataFields ) && count( $aDataFields ) ) {
00061
00062
00063 $iMinPos = null;
00064 $iMinVal = null;
00065 reset( $aDataFields );
00066 while ( list( $iPos, $aField ) = each( $aDataFields ) ) {
00067
00068
00069 if ( $aField['_3'] == '0' ) {
00070 $iMinPos = null;
00071 break;
00072 }
00073
00074 if ( !$iMinVal ) {
00075 $iMinVal = $aField['_3'];
00076 $iMinPos = $iPos;
00077 } elseif ( $iMinVal > $aField['_3'] ) {
00078 $iMinPos = $iPos;
00079 }
00080 }
00081
00082
00083 if ( isset( $iMinPos ) ) {
00084 $aDataFields[$iMinPos]['_3'] = '0';
00085 }
00086 }
00087
00088 return $aDataFields;
00089 }
00090
00096 public function removecat()
00097 {
00098 $myConfig = $this->getConfig();
00099 $aRemoveCat = $this->_getActionIds( 'oxcategories.oxid' );
00100
00101 $soxId = oxConfig::getParameter( 'oxid' );
00102 $sShopID = $myConfig->getShopId();
00103 $oDb = oxDb::getDb();
00104
00105
00106 if ( oxConfig::getParameter( 'all' ) ) {
00107 $sCategoriesTable = $this->_getViewName( 'oxcategories' );
00108 $aRemoveCat = $this->_getAll( $this->_addFilter( "select {$sCategoriesTable}.oxid ".$this->_getQuery() ) );
00109 }
00110
00111
00112 if ( is_array( $aRemoveCat ) && count( $aRemoveCat ) ) {
00113
00114 $sQ = "delete from oxobject2category where oxobject2category.oxobjectid= " . oxDb::getDb()->quote( $soxId ) . " and ";
00115 $sQ .= " oxcatnid in (" . implode( ', ', oxDb::getInstance()->quoteArray( $aRemoveCat ) ) . ')';
00116 $oDb->Execute( $sQ );
00117
00118
00119
00120 $this->_updateOxTime( $soxId );
00121 }
00122
00123 $this->resetArtSeoUrl( $soxId, $aRemoveCat );
00124 $this->resetContentCache();
00125 }
00126
00132 public function addcat()
00133 {
00134 $myConfig = $this->getConfig();
00135 $oDb = oxDb::getDb();
00136 $aAddCat = $this->_getActionIds( 'oxcategories.oxid' );
00137 $soxId = oxConfig::getParameter( 'synchoxid' );
00138 $sShopID = $myConfig->getShopId();
00139 $sO2CView = $this->_getViewName('oxobject2category');
00140
00141
00142 if ( oxConfig::getParameter( 'all' ) ) {
00143 $sCategoriesTable = $this->_getViewName( 'oxcategories' );
00144 $aAddCat = $this->_getAll( $this->_addFilter( "select $sCategoriesTable.oxid ".$this->_getQuery() ) );
00145 }
00146
00147 if ( isset( $aAddCat) && is_array($aAddCat)) {
00148
00149 $oDb = oxDb::getDb();
00150
00151 $oNew = oxNew( 'oxbase' );
00152 $oNew->init( 'oxobject2category' );
00153 $myUtilsObj = oxUtilsObject::getInstance();
00154
00155 foreach ( $aAddCat as $sAdd ) {
00156
00157
00158 $sSelect = "select 1 from " . $sO2CView . " as oxobject2category where oxobject2category.oxcatnid= " . $oDb->quote( $sAdd ) . " and oxobject2category.oxobjectid = " . $oDb->quote( $soxId ) . " ";
00159 if ( $oDb->getOne( $sSelect, false, false ) )
00160 continue;
00161
00162 $oNew->setId( $myUtilsObj->generateUID() );
00163 $oNew->oxobject2category__oxobjectid = new oxField( $soxId );
00164 $oNew->oxobject2category__oxcatnid = new oxField( $sAdd );
00165 $oNew->oxobject2category__oxtime = new oxField( time() );
00166
00167
00168 $oNew->save();
00169 }
00170
00171 $this->_updateOxTime( $soxId );
00172
00173 $this->resetArtSeoUrl( $soxId );
00174 $this->resetContentCache();
00175 }
00176 }
00177
00185 protected function _updateOxTime( $soxId )
00186 {
00187 $oDb = oxDb::getDb();
00188 $sO2CView = $this->_getViewName('oxobject2category');
00189 $soxId = $oDb->quote( $soxId );
00190
00191
00192 $sQ = "update oxobject2category set oxtime = 0 where oxobjectid = {$soxId} and oxid = (
00193 select oxid from (
00194 select oxid from {$sO2CView} where oxobjectid = {$soxId} order by oxtime limit 1
00195 ) as _tmp
00196 )";
00197 $oDb->execute( $sQ );
00198 }
00199
00205 public function setAsDefault()
00206 {
00207 $myConfig = $this->getConfig();
00208 $sDefCat = oxConfig::getParameter( "defcat" );
00209 $soxId = oxConfig::getParameter( "oxid" );
00210 $sShopId = $myConfig->getShopId();
00211 $oDb = oxDb::getDb();
00212
00213 $sShopCheck = "";
00214
00215
00216 $sQ = "update oxobject2category set oxtime = oxtime + 10 where oxobjectid = " . $oDb->quote( $soxId );
00217 oxDb::getInstance()->getDb()->Execute($sQ);
00218
00219
00220 $sQ = "update oxobject2category set oxtime = 0 where oxobjectid = " . $oDb->quote( $soxId ) . " and oxcatnid = " . $oDb->quote( $sDefCat ) . " $sShopCheck ";
00221 oxDb::getInstance()->getDb()->Execute($sQ);
00222
00223
00224 oxSeoEncoder::getInstance()->markAsExpired( $soxId, null, 1, null, "oxtype='oxarticle'" );
00225 $this->resetContentCache();
00226 }
00227 }