news_main_ajax.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class news_main_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         // active AJAX component
00034         $sGroupTable = $this->_getViewName('oxgroups');
00035         $oDb = oxDb::getDb();
00036         $sDiscountId = $this->getConfig()->getRequestParameter('oxid');
00037         $sSynchDiscountId = $this->getConfig()->getRequestParameter('synchoxid');
00038 
00039         // category selected or not ?
00040         if (!$sDiscountId) {
00041             $sQAdd = " from $sGroupTable where 1 ";
00042         } else {
00043             $sQAdd = " from oxobject2group left join $sGroupTable on oxobject2group.oxgroupsid=$sGroupTable.oxid ";
00044             $sQAdd .= " where oxobject2group.oxobjectid = " . $oDb->quote($sDiscountId);
00045         }
00046 
00047         if ($sSynchDiscountId && $sSynchDiscountId != $sDiscountId) {
00048             $sQAdd .= ' and ' . $sGroupTable . '.oxid not in ( select ' . $sGroupTable . '.oxid from oxobject2group left join ' . $sGroupTable . ' on oxobject2group.oxgroupsid=' . $sGroupTable . '.oxid ';
00049             $sQAdd .= " where oxobject2group.oxobjectid = " . $oDb->quote($sSynchDiscountId) . " ) ";
00050         }
00051 
00052         return $sQAdd;
00053     }
00054 
00058     public function removeGroupFromNews()
00059     {
00060         $aRemoveGroups = $this->_getActionIds('oxobject2group.oxid');
00061         if ($this->getConfig()->getRequestParameter('all')) {
00062 
00063             $sQ = $this->_addFilter("delete oxobject2group.* " . $this->_getQuery());
00064             oxDb::getDb()->Execute($sQ);
00065 
00066         } elseif ($aRemoveGroups && is_array($aRemoveGroups)) {
00067             $sQ = "delete from oxobject2group where oxobject2group.oxid in (" . implode(", ", oxDb::getInstance()->quoteArray($aRemoveGroups)) . ") ";
00068             oxDb::getDb()->Execute($sQ);
00069         }
00070     }
00071 
00075     public function addGroupToNews()
00076     {
00077         $aAddGroups = $this->_getActionIds('oxgroups.oxid');
00078         $soxId = $this->getConfig()->getRequestParameter('synchoxid');
00079 
00080         if ($this->getConfig()->getRequestParameter('all')) {
00081             $sGroupTable = $this->_getViewName('oxgroups');
00082             $aAddGroups = $this->_getAll($this->_addFilter("select $sGroupTable.oxid " . $this->_getQuery()));
00083         }
00084         if ($soxId && $soxId != "-1" && is_array($aAddGroups)) {
00085             foreach ($aAddGroups as $sAddgroup) {
00086                 $oNewGroup = oxNew("oxobject2group");
00087                 $oNewGroup->oxobject2group__oxobjectid = new oxField($soxId);
00088                 $oNewGroup->oxobject2group__oxgroupsid = new oxField($sAddgroup);
00089                 $oNewGroup->save();
00090             }
00091         }
00092     }
00093 }