actions_groups_ajax.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class actions_groups_ajax extends ajaxListComponent
00007 {
00013     protected $_aColumns = array( 'container1' => array(    // field , table,  visible, multilanguage, ident
00014                                         array( 'oxtitle',  'oxgroups', 1, 0, 0 ),
00015                                         array( 'oxid',     'oxgroups', 0, 0, 0 ),
00016                                         array( 'oxid',     'oxgroups', 0, 0, 1 ),
00017                                         ),
00018                                 'container2' => array(
00019                                         array( 'oxtitle',  'oxgroups', 1, 0, 0 ),
00020                                         array( 'oxid',     'oxgroups', 0, 0, 0 ),
00021                                         array( 'oxid',     'oxobject2action', 0, 0, 1 ),
00022                                         )
00023                                 );
00024 
00030     protected function _getQuery()
00031     {
00032         // active AJAX component
00033         $sGroupTable = $this->_getViewName( 'oxgroups' );
00034         $oDb = oxDb::getDb();
00035 
00036         $sId      = oxConfig::getParameter( 'oxid' );
00037         $sSynchId = oxConfig::getParameter( 'synchoxid' );
00038 
00039         // category selected or not ?
00040         if ( !$sId ) {
00041             $sQAdd  = " from $sGroupTable where 1 ";
00042         } else {
00043             $sQAdd .= " from oxobject2action, $sGroupTable where $sGroupTable.oxid=oxobject2action.oxobjectid ";
00044             $sQAdd .= " and oxobject2action.oxactionid = ".$oDb->quote( $sId )." and oxobject2action.oxclass = 'oxgroups' ";
00045         }
00046 
00047         if ( $sSynchId && $sSynchId != $sId) {
00048             $sQAdd .= " and $sGroupTable.oxid not in ( select $sGroupTable.oxid from oxobject2action, $sGroupTable where $sGroupTable.oxid=oxobject2action.oxobjectid ";
00049             $sQAdd .= " and oxobject2action.oxactionid = ".$oDb->quote( $sSynchId )." and oxobject2action.oxclass = 'oxgroups' ) ";
00050         }
00051 
00052         return $sQAdd;
00053     }
00054 
00060     public function removePromotionGroup()
00061     {
00062         $aRemoveGroups = $this->_getActionIds( 'oxobject2action.oxid' );
00063         if ( oxConfig::getParameter( 'all' ) ) {
00064             $sQ = $this->_addFilter( "delete oxobject2action.* ".$this->_getQuery() );
00065             oxDb::getDb()->Execute( $sQ );
00066         } elseif ( $aRemoveGroups && is_array( $aRemoveGroups ) ) {
00067             $sQ = "delete from oxobject2action where oxobject2action.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aRemoveGroups ) ) . ") ";
00068             oxDb::getDb()->Execute( $sQ );
00069         }
00070     }
00071 
00077     public function addPromotionGroup()
00078     {
00079         $aChosenGroup = $this->_getActionIds( 'oxgroups.oxid' );
00080         $soxId        = oxConfig::getParameter( 'synchoxid' );
00081 
00082         if ( oxConfig::getParameter( 'all' ) ) {
00083             $sGroupTable  = $this->_getViewName('oxgroups');
00084             $aChosenGroup = $this->_getAll( $this->_addFilter( "select $sGroupTable.oxid ".$this->_getQuery() ) );
00085         }
00086         if ( $soxId && $soxId != "-1" && is_array( $aChosenGroup ) ) {
00087             foreach ( $aChosenGroup as $sChosenGroup) {
00088                 $oObject2Promotion = oxNew( "oxbase" );
00089                 $oObject2Promotion->init( 'oxobject2action' );
00090                 $oObject2Promotion->oxobject2action__oxactionid = new oxField( $soxId );
00091                 $oObject2Promotion->oxobject2action__oxobjectid = new oxField( $sChosenGroup );
00092                 $oObject2Promotion->oxobject2action__oxclass    = new oxField( "oxgroups" );
00093                 $oObject2Promotion->save();
00094             }
00095         }
00096     }
00097 }