discount_users_ajax.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class discount_users_ajax extends ajaxListComponent
00007 {
00013     protected $_aColumns = array( 'container1' => array(    // field , table,  visible, multilanguage, ident
00014                                         array( 'oxusername',  'oxuser', 1, 0, 0 ),
00015                                         array( 'oxlname',     'oxuser', 0, 0, 0 ),
00016                                         array( 'oxfname',     'oxuser', 0, 0, 0 ),
00017                                         array( 'oxstreet',    'oxuser', 0, 0, 0 ),
00018                                         array( 'oxstreetnr',  'oxuser', 0, 0, 0 ),
00019                                         array( 'oxcity',      'oxuser', 0, 0, 0 ),
00020                                         array( 'oxzip',       'oxuser', 0, 0, 0 ),
00021                                         array( 'oxfon',       'oxuser', 0, 0, 0 ),
00022                                         array( 'oxbirthdate', 'oxuser', 0, 0, 0 ),
00023                                         array( 'oxid',        'oxuser', 0, 0, 1 ),
00024                                         ),
00025                                     'container2' => array(
00026                                         array( 'oxusername',  'oxuser', 1, 0, 0 ),
00027                                         array( 'oxlname',     'oxuser', 0, 0, 0 ),
00028                                         array( 'oxfname',     'oxuser', 0, 0, 0 ),
00029                                         array( 'oxstreet',    'oxuser', 0, 0, 0 ),
00030                                         array( 'oxstreetnr',  'oxuser', 0, 0, 0 ),
00031                                         array( 'oxcity',      'oxuser', 0, 0, 0 ),
00032                                         array( 'oxzip',       'oxuser', 0, 0, 0 ),
00033                                         array( 'oxfon',       'oxuser', 0, 0, 0 ),
00034                                         array( 'oxbirthdate', 'oxuser', 0, 0, 0 ),
00035                                         array( 'oxid',     'oxobject2discount', 0, 0, 1 ),
00036                                         )
00037                                 );
00038 
00044     protected function _getQuery()
00045     {
00046         $oConfig = $this->getConfig();
00047 
00048         $sUserTable = $this->_getViewName( 'oxuser' );
00049         $oDb = oxDb::getDb();
00050         $sId = $oConfig->getRequestParameter( 'oxid' );
00051         $sSynchId = $oConfig->getRequestParameter( 'synchoxid' );
00052 
00053         // category selected or not ?
00054         if ( !$sId ) {
00055             $sQAdd = " from $sUserTable where 1 ";
00056             if (!$oConfig->getConfigParam( 'blMallUsers' ) )
00057                 $sQAdd .= " and oxshopid = '".$oConfig->getShopId()."' ";
00058         } else {
00059             // selected group ?
00060             if ( $sSynchId && $sSynchId != $sId ) {
00061                 $sQAdd = " from oxobject2group left join $sUserTable on $sUserTable.oxid = oxobject2group.oxobjectid where oxobject2group.oxgroupsid = ".$oDb->quote( $sId );
00062                 if ( !$oConfig->getConfigParam( 'blMallUsers' ) )
00063                     $sQAdd .= " and $sUserTable.oxshopid = '".$oConfig->getShopId()."' ";
00064 
00065             } else {
00066                 $sQAdd  = " from oxobject2discount, $sUserTable where $sUserTable.oxid=oxobject2discount.oxobjectid ";
00067                 $sQAdd .= " and oxobject2discount.oxdiscountid = ".$oDb->quote( $sId )." and oxobject2discount.oxtype = 'oxuser' ";
00068             }
00069         }
00070 
00071         if ( $sSynchId && $sSynchId != $sId ) {
00072             $sQAdd .= " and $sUserTable.oxid not in ( select $sUserTable.oxid from oxobject2discount, $sUserTable where $sUserTable.oxid=oxobject2discount.oxobjectid ";
00073             $sQAdd .= " and oxobject2discount.oxdiscountid = ".$oDb->quote( $sSynchId )." and oxobject2discount.oxtype = 'oxuser' ) ";
00074         }
00075 
00076         return $sQAdd;
00077     }
00078 
00084     public function removeDiscUser()
00085     {
00086         $oConfig = $this->getConfig();
00087 
00088         $aRemoveGroups = $this->_getActionIds( 'oxobject2discount.oxid' );
00089         if ( $oConfig->getRequestParameter( 'all' ) ) {
00090 
00091             $sQ = $this->_addFilter( "delete oxobject2discount.* ".$this->_getQuery() );
00092             oxDb::getDb()->Execute( $sQ );
00093 
00094         } elseif ( $aRemoveGroups && is_array( $aRemoveGroups ) ) {
00095             $sQ = "delete from oxobject2discount where oxobject2discount.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aRemoveGroups ) ) . ") ";
00096             oxDb::getDb()->Execute( $sQ );
00097         }
00098     }
00099 
00105     public function addDiscUser()
00106     {
00107         $oConfig = $this->getConfig();
00108         $aChosenUsr = $this->_getActionIds( 'oxuser.oxid' );
00109         $soxId       = $oConfig->getRequestParameter( 'synchoxid');
00110 
00111 
00112         if ( $oConfig->getRequestParameter( 'all' ) ) {
00113             $sUserTable = $this->_getViewName( 'oxuser' );
00114             $aChosenUsr = $this->_getAll( $this->_addFilter( "select $sUserTable.oxid ".$this->_getQuery() ) );
00115         }
00116         if ( $soxId && $soxId != "-1" && is_array( $aChosenUsr ) ) {
00117             foreach ( $aChosenUsr as $sChosenUsr) {
00118                 $oObject2Discount = oxNew( "oxbase" );
00119                 $oObject2Discount->init( 'oxobject2discount' );
00120                 $oObject2Discount->oxobject2discount__oxdiscountid = new oxField($soxId);
00121                 $oObject2Discount->oxobject2discount__oxobjectid   = new oxField($sChosenUsr);
00122                 $oObject2Discount->oxobject2discount__oxtype       = new oxField("oxuser");
00123                 $oObject2Discount->save();
00124             }
00125         }
00126     }
00127 }