newsletter_selection.php

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