OXID eShop CE  4.8.12
 All Classes Files Functions Variables Pages
newsletter_selection.php
Go to the documentation of this file.
1 <?php
2 
9 {
14  protected $_iUserCount = null;
15 
23  public function render()
24  {
26 
27  $soxId = $this->_aViewData["oxid"] = $this->getEditObjectId();
28  if ( $soxId != "-1" && isset( $soxId ) ) {
29  // load object
30  $oNewsletter = oxNew( "oxnewsletter" );
31  if ( $oNewsletter->load( $soxId ) ) {
32  $this->_aViewData["edit"] = $oNewsletter;
33 
34  if ( oxConfig::getParameter("aoc") ) {
35  $oNewsletterSelectionAjax = oxNew( 'newsletter_selection_ajax' );
36  $this->_aViewData['oxajax'] = $oNewsletterSelectionAjax->getColumns();
37  return "popups/newsletter_selection.tpl";
38  }
39  }
40  }
41 
42  return "newsletter_selection.tpl";
43  }
44 
50  public function getUserCount()
51  {
52  if ( $this->_iUserCount === null ) {
53  $this->_iUserCount = 0;
54 
55  // load object
56  $oNewsletter = oxNew( "oxnewsletter" );
57  if ( $oNewsletter->load( $this->getEditObjectId() ) ) {
58  // get nr. of users in these groups
59  // we do not use lists here as we dont need this overhead right now
60  $oDB = oxDb::getDb();
61  $blSep = false;
62  $sSelectGroups = " ( oxobject2group.oxgroupsid in ( ";
63 
64  // remove already added groups
65  foreach ( $oNewsletter->getGroups() as $oInGroup ) {
66  if ( $blSep ) {
67  $sSelectGroups .= ",";
68  }
69  $sSelectGroups .= $oDB->quote( $oInGroup->oxgroups__oxid->value );
70  $blSep = true;
71  }
72 
73  $sSelectGroups .= " ) ) ";
74 
75  // no group selected
76  if ( !$blSep ) {
77  $sSelectGroups = " oxobject2group.oxobjectid is null ";
78  }
79  $sShopId = $this->getConfig()->getShopID();
80  $sQ = "select count(*) from ( select oxnewssubscribed.oxemail as _icnt from oxnewssubscribed left join
81  oxobject2group on oxobject2group.oxobjectid = oxnewssubscribed.oxuserid
82  where ( oxobject2group.oxshopid = '{$sShopId}'
83  or oxobject2group.oxshopid is null ) and {$sSelectGroups} and
84  oxnewssubscribed.oxdboptin = 1 and ( not ( oxnewssubscribed.oxemailfailed = '1') )
85  and (not(oxnewssubscribed.oxemailfailed = '1')) and oxnewssubscribed.oxshopid = '{$sShopId}'
86  group by oxnewssubscribed.oxemail ) as _tmp";
87 
88  $this->_iUserCount = $oDB->getOne( $sQ, false, false );
89  }
90  }
91  return $this->_iUserCount;
92  }
93 
99  public function save()
100  {
101  $soxId = $this->getEditObjectId();
102  $aParams = oxConfig::getParameter( "editval");
103  $aParams['oxnewsletter__oxshopid'] = $this->getConfig()->getShopId();
104 
105  $oNewsletter = oxNew( "oxNewsLetter" );
106  if ( $soxId != "-1" ) {
107  $oNewsletter->load( $soxId );
108  } else {
109  $aParams['oxnewsletter__oxid'] = null;
110  }
111 
112  $oNewsletter->assign( $aParams );
113  $oNewsletter->save();
114 
115  // set oxid if inserted
116  $this->setEditObjectId( $oNewsletter->getId() );
117  }
118 }