discount_groups_ajax.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class discount_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', 'oxobject2discount', 0, 0, 1),
00023                                  )
00024     );
00025 
00031     protected function _getQuery()
00032     {
00033         $oConfig = $this->getConfig();
00034         // active AJAX component
00035         $sGroupTable = $this->_getViewName('oxgroups');
00036         $oDb = oxDb::getDb();
00037         $sId = $oConfig->getRequestParameter('oxid');
00038         $sSynchId = $oConfig->getRequestParameter('synchoxid');
00039 
00040         // category selected or not ?
00041         if (!$sId) {
00042             $sQAdd = " from {$sGroupTable} where 1 ";
00043         } else {
00044             $sQAdd .= " from oxobject2discount, {$sGroupTable} where {$sGroupTable}.oxid=oxobject2discount.oxobjectid ";
00045             $sQAdd .= " and oxobject2discount.oxdiscountid = " . $oDb->quote($sId) .
00046                       " and oxobject2discount.oxtype = 'oxgroups' ";
00047         }
00048 
00049         if ($sSynchId && $sSynchId != $sId) {
00050             $sQAdd .= " and {$sGroupTable}.oxid not in ( select {$sGroupTable}.oxid " .
00051                       "from oxobject2discount, {$sGroupTable} where {$sGroupTable}.oxid=oxobject2discount.oxobjectid " .
00052                       " and oxobject2discount.oxdiscountid = " . $oDb->quote($sSynchId) .
00053                       " and oxobject2discount.oxtype = 'oxgroups' ) ";
00054         }
00055 
00056         return $sQAdd;
00057     }
00058 
00062     public function removeDiscGroup()
00063     {
00064         $oConfig = $this->getConfig();
00065 
00066         $aRemoveGroups = $this->_getActionIds('oxobject2discount.oxid');
00067         if ($oConfig->getRequestParameter('all')) {
00068 
00069             $sQ = $this->_addFilter("delete oxobject2discount.* " . $this->_getQuery());
00070             oxDb::getDb()->Execute($sQ);
00071 
00072         } elseif ($aRemoveGroups && is_array($aRemoveGroups)) {
00073             $sRemoveGroups = implode(", ", oxDb::getInstance()->quoteArray($aRemoveGroups));
00074             $sQ = "delete from oxobject2discount where oxobject2discount.oxid in (" . $sRemoveGroups . ") ";
00075             oxDb::getDb()->Execute($sQ);
00076         }
00077     }
00078 
00082     public function addDiscGroup()
00083     {
00084         $oConfig = $this->getConfig();
00085         $aChosenCat = $this->_getActionIds('oxgroups.oxid');
00086         $soxId = $oConfig->getRequestParameter('synchoxid');
00087 
00088 
00089         if ($oConfig->getRequestParameter('all')) {
00090             $sGroupTable = $this->_getViewName('oxgroups');
00091             $aChosenCat = $this->_getAll($this->_addFilter("select $sGroupTable.oxid " . $this->_getQuery()));
00092         }
00093         if ($soxId && $soxId != "-1" && is_array($aChosenCat)) {
00094             foreach ($aChosenCat as $sChosenCat) {
00095                 $oObject2Discount = oxNew("oxbase");
00096                 $oObject2Discount->init('oxobject2discount');
00097                 $oObject2Discount->oxobject2discount__oxdiscountid = new oxField($soxId);
00098                 $oObject2Discount->oxobject2discount__oxobjectid = new oxField($sChosenCat);
00099                 $oObject2Discount->oxobject2discount__oxtype = new oxField("oxgroups");
00100                 $oObject2Discount->save();
00101             }
00102         }
00103     }
00104 }