discount_categories_ajax.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class discount_categories_ajax extends ajaxListComponent
00007 {
00008 
00014     protected $_aColumns = array('container1' => array( // field , table,         visible, multilanguage, ident
00015         array('oxtitle', 'oxcategories', 1, 1, 0),
00016         array('oxdesc', 'oxcategories', 1, 1, 0),
00017         array('oxid', 'oxcategories', 0, 0, 0),
00018         array('oxid', 'oxcategories', 0, 0, 1)
00019     ),
00020                                  'container2' => array(
00021                                      array('oxtitle', 'oxcategories', 1, 1, 0),
00022                                      array('oxdesc', 'oxcategories', 1, 1, 0),
00023                                      array('oxid', 'oxcategories', 0, 0, 0),
00024                                      array('oxid', 'oxobject2discount', 0, 0, 1),
00025                                      array('oxid', 'oxcategories', 0, 0, 1)
00026                                  ),
00027     );
00028 
00034     protected function _getQuery()
00035     {
00036         $oDb = oxDb::getDb();
00037         $oConfig = $this->getConfig();
00038         $sId = $oConfig->getRequestParameter('oxid');
00039         $sSynchId = $oConfig->getRequestParameter('synchoxid');
00040 
00041         $sCategoryTable = $this->_getViewName('oxcategories');
00042 
00043         // category selected or not ?
00044         if (!$sId) {
00045             $sQAdd = " from {$sCategoryTable}";
00046         } else {
00047             $sQAdd = " from oxobject2discount, {$sCategoryTable} " .
00048                      "where {$sCategoryTable}.oxid=oxobject2discount.oxobjectid " .
00049                      " and oxobject2discount.oxdiscountid = " . $oDb->quote($sId) .
00050                      " and oxobject2discount.oxtype = 'oxcategories' ";
00051         }
00052 
00053         if ($sSynchId && $sSynchId != $sId) {
00054             // performance
00055             $sSubSelect = " select {$sCategoryTable}.oxid from oxobject2discount, {$sCategoryTable} " .
00056                           "where {$sCategoryTable}.oxid=oxobject2discount.oxobjectid " .
00057                           " and oxobject2discount.oxdiscountid = " . $oDb->quote($sSynchId) .
00058                           " and oxobject2discount.oxtype = 'oxcategories' ";
00059             if (stristr($sQAdd, 'where') === false) {
00060                 $sQAdd .= ' where ';
00061             } else {
00062                 $sQAdd .= ' and ';
00063             }
00064             $sQAdd .= " {$sCategoryTable}.oxid not in ( $sSubSelect ) ";
00065         }
00066 
00067         return $sQAdd;
00068     }
00069 
00073     public function removeDiscCat()
00074     {
00075         $oConfig = $this->getConfig();
00076         $aChosenCat = $this->_getActionIds('oxobject2discount.oxid');
00077 
00078 
00079         if ($oConfig->getRequestParameter('all')) {
00080 
00081             $sQ = $this->_addFilter("delete oxobject2discount.* " . $this->_getQuery());
00082             oxDb::getDb()->Execute($sQ);
00083 
00084         } elseif (is_array($aChosenCat)) {
00085             $sChosenCategories = implode(", ", oxDb::getInstance()->quoteArray($aChosenCat));
00086             $sQ = "delete from oxobject2discount where oxobject2discount.oxid in (" . $sChosenCategories . ") ";
00087             oxDb::getDb()->Execute($sQ);
00088         }
00089     }
00090 
00094     public function addDiscCat()
00095     {
00096         $oConfig = $this->getConfig();
00097         $aChosenCat = $this->_getActionIds('oxcategories.oxid');
00098         $soxId = $oConfig->getRequestParameter('synchoxid');
00099 
00100 
00101         if ($oConfig->getRequestParameter('all')) {
00102             $sCategoryTable = $this->_getViewName('oxcategories');
00103             $aChosenCat = $this->_getAll($this->_addFilter("select $sCategoryTable.oxid " . $this->_getQuery()));
00104         }
00105         if ($soxId && $soxId != "-1" && is_array($aChosenCat)) {
00106             foreach ($aChosenCat as $sChosenCat) {
00107                 $oObject2Discount = oxNew("oxbase");
00108                 $oObject2Discount->init('oxobject2discount');
00109                 $oObject2Discount->oxobject2discount__oxdiscountid = new oxField($soxId);
00110                 $oObject2Discount->oxobject2discount__oxobjectid = new oxField($sChosenCat);
00111                 $oObject2Discount->oxobject2discount__oxtype = new oxField("oxcategories");
00112                 $oObject2Discount->save();
00113             }
00114         }
00115 
00116     }
00117 }