deliveryset_users_ajax.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class deliveryset_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',     'oxobject2delivery', 0, 0, 1 ),
00036                                         )
00037                                 );
00038 
00044     protected function _getQuery()
00045     {
00046         $myConfig = $this->getConfig();
00047         $oDb = oxDb::getDb();
00048         $sId      = $myConfig->getRequestParameter( 'oxid' );
00049         $sSynchId = $myConfig->getRequestParameter( 'synchoxid' );
00050 
00051         $sUserTable = $this->_getViewName('oxuser');
00052 
00053         // category selected or not ?
00054         if ( !$sId) {
00055             $sQAdd  = " from $sUserTable where 1 ";
00056             if (!$myConfig->getConfigParam( 'blMallUsers' ) )
00057                 $sQAdd .= "and $sUserTable.oxshopid = '".$myConfig->getShopId()."' ";
00058         } elseif ( $sSynchId && $sSynchId != $sId ) {
00059             // selected group ?
00060             $sQAdd  = " from oxobject2group left join $sUserTable on $sUserTable.oxid = oxobject2group.oxobjectid ";
00061             $sQAdd .= " where oxobject2group.oxgroupsid = ".$oDb->quote( $sId );
00062             if (!$myConfig->getConfigParam( 'blMallUsers' ) )
00063                 $sQAdd .= "and $sUserTable.oxshopid = '".$myConfig->getShopId()."' ";
00064 
00065             // resetting
00066             $sId = null;
00067         } else {
00068             $sQAdd  = " from oxobject2delivery, $sUserTable where oxobject2delivery.oxdeliveryid = ".$oDb->quote( $sId );
00069             $sQAdd .= "and oxobject2delivery.oxobjectid = $sUserTable.oxid and oxobject2delivery.oxtype = 'oxdelsetu' ";
00070         }
00071 
00072         if ( $sSynchId && $sSynchId != $sId) {
00073             $sQAdd .= "and $sUserTable.oxid not in ( select $sUserTable.oxid from oxobject2delivery, $sUserTable where oxobject2delivery.oxdeliveryid = ".$oDb->quote( $sSynchId );
00074             $sQAdd .= "and oxobject2delivery.oxobjectid = $sUserTable.oxid and oxobject2delivery.oxtype = 'oxdelsetu' ) ";
00075         }
00076 
00077         return $sQAdd;
00078     }
00079 
00085     public function removeUserFromSet()
00086     {
00087         $aRemoveGroups = $this->_getActionIds( 'oxobject2delivery.oxid' );
00088         if ( $this->getConfig()->getRequestParameter( 'all' ) ) {
00089 
00090             $sQ = $this->_addFilter( "delete oxobject2delivery.* ".$this->_getQuery() );
00091             oxDb::getDb()->Execute( $sQ );
00092 
00093         } elseif ( $aRemoveGroups && is_array( $aRemoveGroups ) ) {
00094             $sQ = "delete from oxobject2delivery where oxobject2delivery.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aRemoveGroups ) ) . ") ";
00095             oxDb::getDb()->Execute( $sQ );
00096         }
00097     }
00098 
00104     public function addUserToSet()
00105     {
00106         $aChosenUsr = $this->_getActionIds( 'oxuser.oxid' );
00107         $soxId      = $this->getConfig()->getRequestParameter( 'synchoxid' );
00108 
00109         // adding
00110         if ( $this->getConfig()->getRequestParameter( 'all' ) ) {
00111             $sUserTable = $this->_getViewName('oxuser');
00112             $aChosenUsr = $this->_getAll( $this->_addFilter( "select $sUserTable.oxid ".$this->_getQuery() ) );
00113         }
00114         if ( $soxId && $soxId != "-1" && is_array( $aChosenUsr ) ) {
00115             foreach ( $aChosenUsr as $sChosenUsr) {
00116                 $oObject2Delivery = oxNew( 'oxbase' );
00117                 $oObject2Delivery->init( 'oxobject2delivery' );
00118                 $oObject2Delivery->oxobject2delivery__oxdeliveryid = new oxField($soxId);
00119                 $oObject2Delivery->oxobject2delivery__oxobjectid   = new oxField($sChosenUsr);
00120                 $oObject2Delivery->oxobject2delivery__oxtype       = new oxField("oxdelsetu");
00121                 $oObject2Delivery->save();
00122             }
00123         }
00124     }
00125 
00126 }