usergroup_main_ajax.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class usergroup_main_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',     'oxobject2group', 0, 0, 1 ),
00036                                         )
00037                                 );
00038 
00044     protected function _getQuery()
00045     {
00046         $myConfig = $this->getConfig();
00047 
00048         // looking for table/view
00049         $sUserTable = $this->_getViewName( 'oxuser' );
00050         $oDb = oxDb::getDb();
00051         $sRoleId      = oxConfig::getParameter( 'oxid' );
00052         $sSynchRoleId = oxConfig::getParameter( 'synchoxid' );
00053 
00054         // category selected or not ?
00055         if ( !$sRoleId ) {
00056             $sQAdd  = " from $sUserTable where 1 ";
00057         } else {
00058             $sQAdd  = " from $sUserTable, oxobject2group where $sUserTable.oxid=oxobject2group.oxobjectid and ";
00059             $sQAdd .= " oxobject2group.oxgroupsid = ".$oDb->quote( $sRoleId );
00060         }
00061 
00062         if ( $sSynchRoleId && $sSynchRoleId != $sRoleId) {
00063             $sQAdd .= " and $sUserTable.oxid not in ( select $sUserTable.oxid from $sUserTable, oxobject2group where $sUserTable.oxid=oxobject2group.oxobjectid and ";
00064             $sQAdd .= " oxobject2group.oxgroupsid = ".$oDb->quote( $sSynchRoleId );
00065             if (!$myConfig->getConfigParam( 'blMallUsers' ) )
00066                 $sQAdd .= " and $sUserTable.oxshopid = '".$myConfig->getShopId()."' ";
00067             $sQAdd .= " ) ";
00068         }
00069 
00070         if ( !$myConfig->getConfigParam( 'blMallUsers' ) )
00071             $sQAdd .= " and $sUserTable.oxshopid = '".$myConfig->getShopId()."' ";
00072 
00073         return $sQAdd;
00074     }
00075 
00081     public function removeUserFromUGroup()
00082     {
00083         $aRemoveGroups = $this->_getActionIds( 'oxobject2group.oxid' );
00084 
00085         if ( oxConfig::getParameter( 'all' ) ) {
00086 
00087             $sQ = $this->_addFilter( "delete oxobject2group.* ".$this->_getQuery() );
00088             oxDb::getDb()->Execute( $sQ );
00089 
00090         } elseif ( $aRemoveGroups && is_array( $aRemoveGroups ) ) {
00091             $sQ = "delete from oxobject2group where oxobject2group.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aRemoveGroups ) ) . ") ";
00092             oxDb::getDb()->Execute( $sQ );
00093         }
00094     }
00095 
00101     public function addUserToUGroup()
00102     {
00103         $aAddUsers = $this->_getActionIds( 'oxuser.oxid' );
00104         $soxId     = oxConfig::getParameter( 'synchoxid' );
00105 
00106         if ( oxConfig::getParameter( 'all' ) ) {
00107             $sUserTable = $this->_getViewName( 'oxuser' );
00108             $aAddUsers = $this->_getAll( $this->_addFilter( "select $sUserTable.oxid ".$this->_getQuery() ) );
00109         }
00110         if ( $soxId && $soxId != "-1" && is_array( $aAddUsers ) ) {
00111             foreach ($aAddUsers as $sAdduser) {
00112                 $oNewGroup = oxNew( "oxobject2group" );
00113                 $oNewGroup->oxobject2group__oxobjectid = new oxField($sAdduser);
00114                 $oNewGroup->oxobject2group__oxgroupsid = new oxField($soxId);
00115                 $oNewGroup->save();
00116             }
00117         }
00118     }
00119 }