discount_users.inc.php

Go to the documentation of this file.
00001 <?php
00002 
00003 $aColumns = array( 'container1' => array(    // field , table,  visible, multilanguage, ident
00004                                         array( 'oxusername',  'oxuser', 1, 0, 0 ),
00005                                         array( 'oxlname',     'oxuser', 0, 0, 0 ),
00006                                         array( 'oxfname',     'oxuser', 0, 0, 0 ),
00007                                         array( 'oxstreet',    'oxuser', 0, 0, 0 ),
00008                                         array( 'oxstreetnr',  'oxuser', 0, 0, 0 ),
00009                                         array( 'oxcity',      'oxuser', 0, 0, 0 ),
00010                                         array( 'oxzip',       'oxuser', 0, 0, 0 ),
00011                                         array( 'oxfon',       'oxuser', 0, 0, 0 ),
00012                                         array( 'oxbirthdate', 'oxuser', 0, 0, 0 ),
00013                                         array( 'oxid',        'oxuser', 0, 0, 1 ),
00014                                         ),
00015                      'container2' => array(
00016                                         array( 'oxusername',  'oxuser', 1, 0, 0 ),
00017                                         array( 'oxlname',     'oxuser', 0, 0, 0 ),
00018                                         array( 'oxfname',     'oxuser', 0, 0, 0 ),
00019                                         array( 'oxstreet',    'oxuser', 0, 0, 0 ),
00020                                         array( 'oxstreetnr',  'oxuser', 0, 0, 0 ),
00021                                         array( 'oxcity',      'oxuser', 0, 0, 0 ),
00022                                         array( 'oxzip',       'oxuser', 0, 0, 0 ),
00023                                         array( 'oxfon',       'oxuser', 0, 0, 0 ),
00024                                         array( 'oxbirthdate', 'oxuser', 0, 0, 0 ),
00025                                         array( 'oxid',     'oxobject2discount', 0, 0, 1 ),
00026                                         )
00027                     );
00031 class ajaxComponent extends ajaxListComponent
00032 {
00038     protected function _getQuery()
00039     {
00040         $myConfig = $this->getConfig();
00041 
00042         $sUserTable = $this->_getViewName( 'oxuser' );
00043         $oDb = oxDb::getDb();
00044         $sId = oxConfig::getParameter( 'oxid' );
00045         $sSynchId = oxConfig::getParameter( 'synchoxid' );
00046 
00047         // category selected or not ?
00048         if ( !$sId ) {
00049             $sQAdd = " from $sUserTable where 1 ";
00050             if (!$myConfig->getConfigParam( 'blMallUsers' ) )
00051                 $sQAdd .= " and oxshopid = '".$myConfig->getShopId()."' ";
00052         } else {
00053             // selected group ?
00054             if ( $sSynchId && $sSynchId != $sId ) {
00055                 $sQAdd = " from oxobject2group left join $sUserTable on $sUserTable.oxid = oxobject2group.oxobjectid where oxobject2group.oxgroupsid = ".$oDb->quote( $sId );
00056                 if ( !$myConfig->getConfigParam( 'blMallUsers' ) )
00057                     $sQAdd .= "and $sUserTable.oxshopid = '".$myConfig->getShopId()."' ";
00058 
00059             } else {
00060                 $sQAdd  = " from oxobject2discount, $sUserTable where $sUserTable.oxid=oxobject2discount.oxobjectid ";
00061                 $sQAdd .= " and oxobject2discount.oxdiscountid = ".$oDb->quote( $sId )." and oxobject2discount.oxtype = 'oxuser' ";
00062             }
00063         }
00064 
00065         if ( $sSynchId && $sSynchId != $sId ) {
00066             $sQAdd .= " and $sUserTable.oxid not in ( select $sUserTable.oxid from oxobject2discount, $sUserTable where $sUserTable.oxid=oxobject2discount.oxobjectid ";
00067             $sQAdd .= " and oxobject2discount.oxdiscountid = ".$oDb->quote( $sSynchId )." and oxobject2discount.oxtype = 'oxuser' ) ";
00068         }
00069 
00070         return $sQAdd;
00071     }
00072 
00078     public function removediscuser()
00079     {
00080         $aRemoveGroups = $this->_getActionIds( 'oxobject2discount.oxid' );
00081         if ( oxConfig::getParameter( 'all' ) ) {
00082 
00083             $sQ = $this->_addFilter( "delete oxobject2discount.* ".$this->_getQuery() );
00084             oxDb::getDb()->Execute( $sQ );
00085 
00086         } elseif ( $aRemoveGroups && is_array( $aRemoveGroups ) ) {
00087             $sQ = "delete from oxobject2discount where oxobject2discount.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aRemoveGroups ) ) . ") ";
00088             oxDb::getDb()->Execute( $sQ );
00089         }
00090     }
00091 
00097     public function adddiscuser()
00098     {
00099         $aChosenUsr = $this->_getActionIds( 'oxuser.oxid' );
00100         $soxId       = oxConfig::getParameter( 'synchoxid');
00101 
00102         if ( oxConfig::getParameter( 'all' ) ) {
00103             $sUserTable = $this->_getViewName( 'oxuser' );
00104             $aChosenUsr = $this->_getAll( $this->_addFilter( "select $sUserTable.oxid ".$this->_getQuery() ) );
00105         }
00106         if ( $soxId && $soxId != "-1" && is_array( $aChosenUsr ) ) {
00107             foreach ( $aChosenUsr as $sChosenUsr) {
00108                 $oObject2Discount = oxNew( "oxbase" );
00109                 $oObject2Discount->init( 'oxobject2discount' );
00110                 $oObject2Discount->oxobject2discount__oxdiscountid = new oxField($soxId);
00111                 $oObject2Discount->oxobject2discount__oxobjectid   = new oxField($sChosenUsr);
00112                 $oObject2Discount->oxobject2discount__oxtype       = new oxField("oxuser");
00113                 $oObject2Discount->save();
00114             }
00115         }
00116     }
00117 }