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
00101
00102 if ( oxConfig::getParameter( 'all' ) ) {
00103
00104 $sQ = $this->_addFilter( "delete $sO2CView.* ".$this->_getQuery() );
00105 oxDb::getDb()->Execute( $sQ );
00106
00107 } elseif ( is_array( $aRemoveCat ) && count( $aRemoveCat ) ) {
00108
00109 $sQ = 'delete from oxobject2category where oxid in ("' . implode( '", "', $aRemoveCat ) . '")';
00110 oxDb::getDb()->Execute( $sQ );
00111
00112 }
00113 }
00114
00120 public function addcat()
00121 {
00122 $myConfig = $this->getConfig();
00123 $aAddCat = $this->_getActionIds( 'oxcategories.oxid' );
00124 $soxId = oxConfig::getParameter( 'synchoxid' );
00125 $sShopID = $myConfig->getShopId();
00126 $sO2CView = getViewName('oxobject2category');
00127
00128
00129 if ( oxConfig::getParameter( 'all' ) ) {
00130 $sCategoriesTable = getViewName( 'oxcategories' );
00131 $aAddCat = $this->_getAll( $this->_addFilter( "select $sCategoriesTable.oxid ".$this->_getQuery() ) );
00132 }
00133
00134 if ( isset( $aAddCat) && is_array($aAddCat)) {
00135
00136
00137 $oNew = oxNew( 'oxbase' );
00138 $oNew->init( 'oxobject2category' );
00139
00140 foreach ( $aAddCat as $sAdd ) {
00141
00142
00143 $sSelect = 'select 1 from ' . $sO2CView . ' as oxobject2category where oxobject2category.oxcatnid="' . $sAdd . '" and oxobject2category.oxobjectid ="' . $soxId . '"';
00144 if ( oxDb::getDb()->getOne( $sSelect ) )
00145 continue;
00146
00147 $oNew->oxobject2category__oxid = new oxField($oNew->setId( oxUtilsObject::getInstance()->generateUID() ));
00148 $oNew->oxobject2category__oxobjectid = new oxField($soxId);
00149 $oNew->oxobject2category__oxcatnid = new oxField($sAdd);
00150 $oNew->oxobject2category__oxtime = new oxField(time());
00151
00152
00153 $oNew->save();
00154 }
00155 }
00156 }
00157
00163 public function setAsDefault()
00164 {
00165 $myConfig = $this->getConfig();
00166 $sDefCat = oxConfig::getParameter( "defcat" );
00167 $soxId = oxConfig::getParameter( "oxid" );
00168 $sShopId = $myConfig->getShopId();
00169
00170 $sShopCheck = "";
00171
00172 $sQ = "update oxobject2category set oxtime = oxtime + 10 where oxobjectid = '$soxId' $sShopCheck ";
00173 oxDb::getInstance()->getDb()->Execute($sQ);
00174 $sQ = "update oxobject2category set oxtime = 0 where oxobjectid = '$soxId' and oxcatnid = '".$sDefCat."' $sShopCheck ";
00175 oxDb::getInstance()->getDb()->Execute($sQ);
00176 }
00177 }