voucherserie_groups_ajax.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class voucherserie_groups_ajax extends ajaxListComponent
00007 {
00008 
00014     protected $_aColumns = array('container1' => array( // field , table,  visible, multilanguage, ident
00015         array('oxtitle', 'oxgroups', 1, 0, 0),
00016         array('oxid', 'oxgroups', 0, 0, 0),
00017         array('oxid', 'oxgroups', 0, 0, 1),
00018     ),
00019                                  'container2' => array(
00020                                      array('oxtitle', 'oxgroups', 1, 0, 0),
00021                                      array('oxid', 'oxgroups', 0, 0, 0),
00022                                      array('oxid', 'oxobject2group', 0, 0, 1),
00023                                  )
00024     );
00025 
00031     protected function _getQuery()
00032     {
00033         // looking for table/view
00034         $sGroupTable = $this->_getViewName('oxgroups');
00035         $oDb = oxDb::getDb();
00036         $oConfig = oxRegistry::getConfig();
00037         $sVoucherId = $oConfig->getRequestParameter('oxid');
00038         $sSynchVoucherId = $oConfig->getRequestParameter('synchoxid');
00039 
00040         // category selected or not ?
00041         if (!$sVoucherId) {
00042             $sQAdd = " from $sGroupTable where 1 ";
00043         } else {
00044             $sQAdd = " from $sGroupTable, oxobject2group where ";
00045             $sQAdd .= " oxobject2group.oxobjectid = " . $oDb->quote($sVoucherId) . " and $sGroupTable.oxid = oxobject2group.oxgroupsid ";
00046         }
00047 
00048         if ($sSynchVoucherId && $sSynchVoucherId != $sVoucherId) {
00049             $sQAdd .= " and $sGroupTable.oxid not in ( select $sGroupTable.oxid from $sGroupTable, oxobject2group where ";
00050             $sQAdd .= " oxobject2group.oxobjectid = " . $oDb->quote($sSynchVoucherId) . " and $sGroupTable.oxid = oxobject2group.oxgroupsid ) ";
00051         }
00052 
00053         return $sQAdd;
00054     }
00055 
00059     public function removeGroupFromVoucher()
00060     {
00061         $aRemoveGroups = $this->_getActionIds('oxobject2group.oxid');
00062         if (oxRegistry::getConfig()->getRequestParameter('all')) {
00063 
00064             $sQ = $this->_addFilter("delete oxobject2group.* " . $this->_getQuery());
00065             oxDb::getDb()->Execute($sQ);
00066 
00067         } elseif ($aRemoveGroups && is_array($aRemoveGroups)) {
00068             $sQ = "delete from oxobject2group where oxobject2group.oxid in (" . implode(", ", oxDb::getInstance()->quoteArray($aRemoveGroups)) . ") ";
00069             oxDb::getDb()->Execute($sQ);
00070         }
00071     }
00072 
00076     public function addGroupToVoucher()
00077     {
00078         $oConfig = oxRegistry::getConfig();
00079         $aChosenCat = $this->_getActionIds('oxgroups.oxid');
00080         $soxId = $oConfig->getRequestParameter('synchoxid');
00081 
00082         if ($oConfig->getRequestParameter('all')) {
00083             $sGroupTable = $this->_getViewName('oxgroups');
00084             $aChosenCat = $this->_getAll($this->_addFilter("select $sGroupTable.oxid " . $this->_getQuery()));
00085         }
00086         if ($soxId && $soxId != "-1" && is_array($aChosenCat)) {
00087             foreach ($aChosenCat as $sChosenCat) {
00088                 $oNewGroup = oxNew("oxobject2group");
00089                 $oNewGroup->oxobject2group__oxobjectid = new oxField($soxId);
00090                 $oNewGroup->oxobject2group__oxgroupsid = new oxField($sChosenCat);
00091                 $oNewGroup->save();
00092             }
00093         }
00094     }
00095 }