newsletter_selection.php

Go to the documentation of this file.
00001 <?php
00002 
00008 class Newsletter_Selection extends oxAdminDetails
00009 {
00014     protected $_iUserCount = null;
00015 
00023     public function render()
00024     {
00025         parent::render();
00026 
00027         $soxId = $this->_aViewData["oxid"] = $this->getEditObjectId();
00028         if ( $soxId != "-1" && isset( $soxId ) ) {
00029             // load object
00030             $oNewsletter = oxNew( "oxnewsletter" );
00031             if ( $oNewsletter->load( $soxId ) ) {
00032                 $this->_aViewData["edit"] = $oNewsletter;
00033 
00034                 if ( oxConfig::getParameter("aoc") ) {
00035                     $oNewsletterSelectionAjax = oxNew( 'newsletter_selection_ajax' );
00036                     $this->_aViewData['oxajax'] = $oNewsletterSelectionAjax->getColumns();
00037                     return "popups/newsletter_selection.tpl";
00038                 }
00039             }
00040         }
00041 
00042         return "newsletter_selection.tpl";
00043     }
00044 
00050     public function getUserCount()
00051     {
00052         if ( $this->_iUserCount === null ) {
00053             $this->_iUserCount = 0;
00054 
00055             // load object
00056             $oNewsletter = oxNew( "oxnewsletter" );
00057             if ( $oNewsletter->load( $this->getEditObjectId() ) ) {
00058                 // get nr. of users in these groups
00059                 // we do not use lists here as we dont need this overhead right now
00060                 $oDB = oxDb::getDb();
00061                 $blSep = false;
00062                 $sSelectGroups = " ( oxobject2group.oxgroupsid in ( ";
00063 
00064                 // remove already added groups
00065                 foreach ( $oNewsletter->getGroups() as $oInGroup ) {
00066                     if ( $blSep ) {
00067                         $sSelectGroups .= ",";
00068                     }
00069                     $sSelectGroups .= $oDB->quote( $oInGroup->oxgroups__oxid->value );
00070                     $blSep = true;
00071                 }
00072 
00073                 $sSelectGroups .= " ) ) ";
00074 
00075                 // no group selected
00076                 if ( !$blSep ) {
00077                     $sSelectGroups = " oxobject2group.oxobjectid is null ";
00078                 }
00079 
00080                 $sQ = "select count(*) from ( select oxnewssubscribed.oxemail as _icnt from oxnewssubscribed left join
00081                        oxobject2group on oxobject2group.oxobjectid = oxnewssubscribed.oxuserid
00082                        where ( oxobject2group.oxshopid = '".$this->getConfig()->getShopID()."'
00083                        or oxobject2group.oxshopid is null ) and {$sSelectGroups} and
00084                        oxnewssubscribed.oxdboptin = 1 and ( not ( oxnewssubscribed.oxemailfailed = '1') )
00085                        and (not(oxnewssubscribed.oxemailfailed = '1')) group by oxnewssubscribed.oxemail ) as _tmp";
00086 
00087                 $this->_iUserCount = $oDB->getOne( $sQ, false, false );
00088             }
00089         }
00090         return $this->_iUserCount;
00091     }
00092 
00098     public function save()
00099     {
00100         $soxId = $this->getEditObjectId();
00101         $aParams = oxConfig::getParameter( "editval");
00102         $aParams['oxnewsletter__oxshopid'] = $this->getConfig()->getShopId();
00103 
00104         $oNewsletter = oxNew( "oxNewsLetter" );
00105         if ( $soxId != "-1" ) {
00106             $oNewsletter->load( $soxId );
00107         } else {
00108             $aParams['oxnewsletter__oxid'] = null;
00109         }
00110 
00111         $oNewsletter->assign( $aParams );
00112         $oNewsletter->save();
00113 
00114         // set oxid if inserted
00115         $this->setEditObjectId( $oNewsletter->getId() );
00116     }
00117 }