newsletter_selection_ajax.php

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