00001 <?php
00002
00006 class article_extend_ajax extends ajaxListComponent
00007 {
00013 protected $_aColumns = array( 'container1' => array(
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
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
00069 $iMinPos = null;
00070 $iMinVal = null;
00071 reset( $aDataFields );
00072 while ( list( $iPos, $aField ) = each( $aDataFields ) ) {
00073
00074
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
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
00112 if ( oxConfig::getParameter( 'all' ) ) {
00113 $sCategoriesTable = $this->_getViewName( 'oxcategories' );
00114 $aRemoveCat = $this->_getAll( $this->_addFilter( "select {$sCategoriesTable}.oxid ".$this->_getQuery() ) );
00115
00116 }
00117
00118
00119 if ( is_array( $aRemoveCat ) && count( $aRemoveCat ) ) {
00120
00121 $sQ = "delete from oxobject2category where oxobject2category.oxobjectid= " . oxDb::getDb()->quote( $soxId ) . " and ";
00122 $sQ .= " oxcatnid in (" . implode( ', ', oxDb::getInstance()->quoteArray( $aRemoveCat ) ) . ')';
00123 $oDb->Execute( $sQ );
00124
00125
00126
00127
00128 $this->_updateOxTime( $soxId );
00129 }
00130
00131 $this->resetArtSeoUrl( $soxId, $aRemoveCat );
00132 $this->resetContentCache();
00133
00134 }
00135
00141 public function addCat()
00142 {
00143 $myConfig = $this->getConfig();
00144 $oDb = oxDb::getDb();
00145 $aAddCat = $this->_getActionIds( 'oxcategories.oxid' );
00146 $soxId = oxConfig::getParameter( 'synchoxid' );
00147 $sShopID = $myConfig->getShopId();
00148 $sO2CView = $this->_getViewName('oxobject2category');
00149
00150
00151 if ( oxConfig::getParameter( 'all' ) ) {
00152 $sCategoriesTable = $this->_getViewName( 'oxcategories' );
00153 $aAddCat = $this->_getAll( $this->_addFilter( "select $sCategoriesTable.oxid ".$this->_getQuery() ) );
00154 }
00155
00156 if ( isset( $aAddCat) && is_array($aAddCat)) {
00157
00158 $oDb = oxDb::getDb();
00159
00160 $oNew = oxNew( 'oxbase' );
00161 $oNew->init( 'oxobject2category' );
00162 $myUtilsObj = oxUtilsObject::getInstance();
00163
00164 foreach ( $aAddCat as $sAdd ) {
00165
00166
00167 $sSelect = "select 1 from " . $sO2CView . " as oxobject2category where oxobject2category.oxcatnid= " . $oDb->quote( $sAdd ) . " and oxobject2category.oxobjectid = " . $oDb->quote( $soxId ) . " ";
00168 if ( $oDb->getOne( $sSelect, false, false ) )
00169 continue;
00170
00171 $oNew->setId( $myUtilsObj->generateUID() );
00172 $oNew->oxobject2category__oxobjectid = new oxField( $soxId );
00173 $oNew->oxobject2category__oxcatnid = new oxField( $sAdd );
00174 $oNew->oxobject2category__oxtime = new oxField( time() );
00175
00176
00177 $oNew->save();
00178 }
00179
00180 $this->_updateOxTime( $soxId );
00181
00182 $this->resetArtSeoUrl( $soxId );
00183 $this->resetContentCache();
00184
00185
00186 }
00187 }
00188
00196 protected function _updateOxTime( $soxId )
00197 {
00198 $oDb = oxDb::getDb();
00199 $sO2CView = $this->_getViewName('oxobject2category');
00200 $soxId = $oDb->quote( $soxId );
00201
00202
00203 $sQ = "update oxobject2category set oxtime = 0 where oxobjectid = {$soxId} and oxid = (
00204 select oxid from (
00205 select oxid from {$sO2CView} where oxobjectid = {$soxId} order by oxtime limit 1
00206 ) as _tmp
00207 )";
00208 $oDb->execute( $sQ );
00209 }
00210
00216 public function setAsDefault()
00217 {
00218 $myConfig = $this->getConfig();
00219 $sDefCat = oxConfig::getParameter( "defcat" );
00220 $soxId = oxConfig::getParameter( "oxid" );
00221 $sShopId = $myConfig->getShopId();
00222 $oDb = oxDb::getDb();
00223
00224 $sShopCheck = "";
00225
00226
00227 $sQ = "update oxobject2category set oxtime = oxtime + 10 where oxobjectid = " . $oDb->quote( $soxId );
00228 oxDb::getInstance()->getDb()->Execute($sQ);
00229
00230
00231 $sQ = "update oxobject2category set oxtime = 0 where oxobjectid = " . $oDb->quote( $soxId ) . " and oxcatnid = " . $oDb->quote( $sDefCat ) . " $sShopCheck ";
00232 oxDb::getInstance()->getDb()->Execute($sQ);
00233
00234
00235
00236 oxRegistry::get("oxSeoEncoder")->markAsExpired( $soxId, null, 1, null, "oxtype='oxarticle'" );
00237 $this->resetContentCache();
00238 }
00239 }