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                     $aColumns = array();
00036                     include_once 'inc/'.strtolower(__CLASS__).'.inc.php';
00037                     $this->_aViewData['oxajax'] = $aColumns;
00038                     return "popups/newsletter_selection.tpl";
00039                 }
00040             }
00041         }
00042 
00043         return "newsletter_selection.tpl";
00044     }
00045 
00051     public function getUserCount()
00052     {
00053         if ( $this->_iUserCount === null ) {
00054             $this->_iUserCount = 0;
00055 
00056             // load object
00057             $oNewsletter = oxNew( "oxnewsletter" );
00058             if ( $oNewsletter->load( $this->getEditObjectId() ) ) {
00059                 // get nr. of users in these groups
00060                 // we do not use lists here as we dont need this overhead right now
00061                 $oDB = oxDb::getDb();
00062                 $blSep = false;
00063                 $sSelectGroups = " ( oxobject2group.oxgroupsid in ( ";
00064 
00065                 // remove already added groups
00066                 foreach ( $oNewsletter->getGroups() as $oInGroup ) {
00067                     if ( $blSep ) {
00068                         $sSelectGroups .= ",";
00069                     }
00070                     $sSelectGroups .= $oDB->quote( $oInGroup->oxgroups__oxid->value );
00071                     $blSep = true;
00072                 }
00073 
00074                 $sSelectGroups .= " ) ) ";
00075 
00076                 // no group selected
00077                 if ( !$blSep ) {
00078                     $sSelectGroups = " oxobject2group.oxobjectid is null ";
00079                 }
00080 
00081                 $sQ = "select count(*) from ( select oxnewssubscribed.oxemail as _icnt from oxnewssubscribed left join
00082                        oxobject2group on oxobject2group.oxobjectid = oxnewssubscribed.oxuserid
00083                        where ( oxobject2group.oxshopid = '".$this->getConfig()->getShopID()."'
00084                        or oxobject2group.oxshopid is null ) and {$sSelectGroups} and
00085                        oxnewssubscribed.oxdboptin = 1 and ( not ( oxnewssubscribed.oxemailfailed = '1') )
00086                        and (not(oxnewssubscribed.oxemailfailed = '1')) group by oxnewssubscribed.oxemail ) as _tmp";
00087 
00088                 $this->_iUserCount = $oDB->getOne( $sQ );
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 }