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                 $sShopId = $this->getConfig()->getShopID();
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 = '{$sShopId}'
00083                        or oxobject2group.oxshopid is null ) and {$sSelectGroups} and
00084                        oxnewssubscribed.oxdboptin = 1 and ( not ( oxnewssubscribed.oxemailfailed = '1') )
00085                        and (not(oxnewssubscribed.oxemailfailed = '1')) and oxnewssubscribed.oxshopid = '{$sShopId}'
00086                        group by oxnewssubscribed.oxemail ) as _tmp";
00087 
00088                 $this->_iUserCount = $oDB->getOne( $sQ, false, false );
00089             }
00090         }
00091         return $this->_iUserCount;
00092     }
00093 
00099     public function save()
00100     {
00101         $soxId = $this->getEditObjectId();
00102         $aParams = oxConfig::getParameter( "editval");
00103         $aParams['oxnewsletter__oxshopid'] = $this->getConfig()->getShopId();
00104 
00105         $oNewsletter = oxNew( "oxNewsLetter" );
00106         if ( $soxId != "-1" ) {
00107             $oNewsletter->load( $soxId );
00108         } else {
00109             $aParams['oxnewsletter__oxid'] = null;
00110         }
00111 
00112         $oNewsletter->assign( $aParams );
00113         $oNewsletter->save();
00114 
00115         // set oxid if inserted
00116         $this->setEditObjectId( $oNewsletter->getId() );
00117     }
00118 }