00001 <?php
00002
00006 class delivery_categories_ajax extends ajaxListComponent
00007 {
00008
00014 protected $_aColumns = array('container1' => array(
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', 'oxobject2delivery', 0, 0, 1),
00025 array('oxid', 'oxcategories', 0, 0, 1)
00026 ),
00027 );
00028
00034 protected function _getQuery()
00035 {
00036
00037 $sCatTable = $this->_getViewName('oxcategories');
00038 $oDb = oxDb::getDb();
00039 $sDelId = $this->getConfig()->getRequestParameter('oxid');
00040 $sSynchDelId = $this->getConfig()->getRequestParameter('synchoxid');
00041
00042
00043 if (!$sDelId) {
00044 $sQAdd = " from {$sCatTable} ";
00045 } else {
00046 $sQAdd = " from oxobject2delivery left join {$sCatTable} " .
00047 "on {$sCatTable}.oxid=oxobject2delivery.oxobjectid " .
00048 " where oxobject2delivery.oxdeliveryid = " . $oDb->quote($sDelId) .
00049 " and oxobject2delivery.oxtype = 'oxcategories' ";
00050 }
00051
00052 if ($sSynchDelId && $sSynchDelId != $sDelId) {
00053
00054 $sSubSelect = " select {$sCatTable}.oxid from oxobject2delivery left join {$sCatTable} " .
00055 "on {$sCatTable}.oxid=oxobject2delivery.oxobjectid " .
00056 " where oxobject2delivery.oxdeliveryid = " . $oDb->quote($sSynchDelId) .
00057 " and oxobject2delivery.oxtype = 'oxcategories' ";
00058 if (stristr($sQAdd, 'where') === false) {
00059 $sQAdd .= ' where ';
00060 } else {
00061 $sQAdd .= ' and ';
00062 }
00063 $sQAdd .= " {$sCatTable}.oxid not in ( $sSubSelect ) ";
00064 }
00065
00066 return $sQAdd;
00067 }
00068
00072 public function removeCatFromDel()
00073 {
00074 $aChosenCat = $this->_getActionIds('oxobject2delivery.oxid');
00075
00076
00077 if ($this->getConfig()->getRequestParameter('all')) {
00078
00079 $sQ = $this->_addFilter("delete oxobject2delivery.* " . $this->_getQuery());
00080 oxDb::getDb()->Execute($sQ);
00081
00082 } elseif (is_array($aChosenCat)) {
00083 $sChosenCategoriess = implode(", ", oxDb::getInstance()->quoteArray($aChosenCat));
00084 $sQ = "delete from oxobject2delivery where oxobject2delivery.oxid in (" . $sChosenCategoriess . ") ";
00085 oxDb::getDb()->Execute($sQ);
00086 }
00087 }
00088
00092 public function addCatToDel()
00093 {
00094 $aChosenCat = $this->_getActionIds('oxcategories.oxid');
00095 $soxId = $this->getConfig()->getRequestParameter('synchoxid');
00096
00097
00098 if ($this->getConfig()->getRequestParameter('all')) {
00099 $sCatTable = $this->_getViewName('oxcategories');
00100 $aChosenCat = $this->_getAll($this->_addFilter("select $sCatTable.oxid " . $this->_getQuery()));
00101 }
00102
00103 if (isset($soxId) && $soxId != "-1" && isset($aChosenCat) && $aChosenCat) {
00104 foreach ($aChosenCat as $sChosenCat) {
00105 $oObject2Delivery = oxNew('oxbase');
00106 $oObject2Delivery->init('oxobject2delivery');
00107 $oObject2Delivery->oxobject2delivery__oxdeliveryid = new oxField($soxId);
00108 $oObject2Delivery->oxobject2delivery__oxobjectid = new oxField($sChosenCat);
00109 $oObject2Delivery->oxobject2delivery__oxtype = new oxField("oxcategories");
00110 $oObject2Delivery->save();
00111 }
00112 }
00113 }
00114 }