deliveryset_users_ajax.php

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