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, 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
00031 $sOxid = oxConfig::getParameter( 'oxid' );
00032 $sSynchOxid = oxConfig::getParameter( 'synchoxid' );
00033
00034 if ( $sOxid ) {
00035
00036 $sQAdd = " from $sO2CView left join $sCategoriesTable on $sCategoriesTable.oxid=$sO2CView.oxcatnid ";
00037 $sQAdd .= " where $sO2CView.oxobjectid = '$sOxid' and $sCategoriesTable.oxid is not null ";
00038 } else {
00039 $sQAdd = " from $sCategoriesTable where $sCategoriesTable.oxid not in ( ";
00040 $sQAdd .= " select $sCategoriesTable.oxid from $sO2CView left join $sCategoriesTable on $sCategoriesTable.oxid=$sO2CView.oxcatnid ";
00041 $sQAdd .= " where $sO2CView.oxobjectid = '$sSynchOxid' and $sCategoriesTable.oxid is not null ) ";
00042 }
00043
00044 return $sQAdd;
00045 }
00046
00054 protected function _getDataFields( $sQ )
00055 {
00056 $aDataFields = parent::_getDataFields( $sQ );
00057 if ( oxConfig::getParameter( 'oxid' ) && is_array( $aDataFields ) && count( $aDataFields ) ) {
00058
00059
00060 $iMinPos = null;
00061 $iMinVal = null;
00062 reset( $aDataFields );
00063 while ( list( $iPos, $aField ) = each( $aDataFields ) ) {
00064
00065
00066 if ( $aField['_3'] == '0' ) {
00067 $iMinPos = null;
00068 break;
00069 }
00070
00071 if ( !$iMinVal ) {
00072 $iMinVal = $aField['_3'];
00073 $iMinPos = $iPos;
00074 } elseif ( $iMinVal > $aField['_3'] ) {
00075 $iMinPos = $iPos;
00076 }
00077 }
00078
00079
00080 if ( isset( $iMinPos ) ) {
00081 $aDataFields[$iMinPos]['_3'] = '0';
00082 }
00083 }
00084
00085 return $aDataFields;
00086 }
00087
00093 public function removecat()
00094 {
00095 $myConfig = $this->getConfig();
00096 $aRemoveCat = $this->_getActionIds( 'oxobject2category.oxid' );
00097 $soxId = oxConfig::getParameter( 'oxid' );
00098 $sShopID = $myConfig->getShopId();
00099 $sO2CView = getViewName( 'oxobject2category' );
00100 $oDb = oxDb::getDb();
00101
00102
00103 if ( oxConfig::getParameter( 'all' ) ) {
00104
00105 $sQ = $this->_addFilter( "delete $sO2CView.* ".$this->_getQuery() );
00106 $oDb->Execute( $sQ );
00107
00108 } elseif ( is_array( $aRemoveCat ) && count( $aRemoveCat ) ) {
00109
00110 $sQ = 'delete from oxobject2category where oxid in ("' . implode( '", "', $aRemoveCat ) . '")';
00111 $oDb->Execute( $sQ );
00112
00113 }
00114
00115 $this->resetContentCache();
00116 }
00117
00123 public function addcat()
00124 {
00125 $myConfig = $this->getConfig();
00126 $aAddCat = $this->_getActionIds( 'oxcategories.oxid' );
00127 $soxId = oxConfig::getParameter( 'synchoxid' );
00128 $sShopID = $myConfig->getShopId();
00129 $sO2CView = getViewName('oxobject2category');
00130
00131
00132 if ( oxConfig::getParameter( 'all' ) ) {
00133 $sCategoriesTable = getViewName( 'oxcategories' );
00134 $aAddCat = $this->_getAll( $this->_addFilter( "select $sCategoriesTable.oxid ".$this->_getQuery() ) );
00135 }
00136
00137 if ( isset( $aAddCat) && is_array($aAddCat)) {
00138
00139 $oDb = oxDb::getDb();
00140
00141 $oNew = oxNew( 'oxbase' );
00142 $oNew->init( 'oxobject2category' );
00143 $myUtilsObj = oxUtilsObject::getInstance();
00144
00145 foreach ( $aAddCat as $sAdd ) {
00146
00147
00148 $sSelect = 'select 1 from ' . $sO2CView . ' as oxobject2category where oxobject2category.oxcatnid="' . $sAdd . '" and oxobject2category.oxobjectid ="' . $soxId . '"';
00149 if ( $oDb->getOne( $sSelect ) )
00150 continue;
00151
00152 $oNew->setId( $myUtilsObj->generateUID() );
00153 $oNew->oxobject2category__oxobjectid = new oxField($soxId);
00154 $oNew->oxobject2category__oxcatnid = new oxField($sAdd);
00155 $oNew->oxobject2category__oxtime = new oxField(time());
00156
00157
00158 $oNew->save();
00159 }
00160
00161 $this->resetContentCache();
00162 }
00163 }
00164
00170 public function setAsDefault()
00171 {
00172 $myConfig = $this->getConfig();
00173 $sDefCat = oxConfig::getParameter( "defcat" );
00174 $soxId = oxConfig::getParameter( "oxid" );
00175 $sShopId = $myConfig->getShopId();
00176
00177 $sShopCheck = "";
00178
00179 $sQ = "update oxobject2category set oxtime = oxtime + 10 where oxobjectid = '$soxId' $sShopCheck ";
00180 oxDb::getInstance()->getDb()->Execute($sQ);
00181 $sQ = "update oxobject2category set oxtime = 0 where oxobjectid = '$soxId' and oxcatnid = '".$sDefCat."' $sShopCheck ";
00182 oxDb::getInstance()->getDb()->Execute($sQ);
00183 }
00184 }