当前位置: 首页>>代码示例>>PHP>>正文


PHP Subscriber::addSubscriberGroupMembership方法代码示例

本文整理汇总了PHP中Subscriber::addSubscriberGroupMembership方法的典型用法代码示例。如果您正苦于以下问题:PHP Subscriber::addSubscriberGroupMembership方法的具体用法?PHP Subscriber::addSubscriberGroupMembership怎么用?PHP Subscriber::addSubscriberGroupMembership使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Subscriber的用法示例。


在下文中一共展示了Subscriber::addSubscriberGroupMembership方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: addSubscibers

 /** addSubscibers()
  * @param array of email addresses to be added, if they don't exist
  * @param string number of target subscriber group
  * description:
  * • subscribers are added if they don't exist
  * • subscriber_group_membership is added if it does'nt exist
  *
  * @return array of integer received all / actually added
  */
 public function addSubscibers($aSubscribers, $mTargetSubscriberGroup)
 {
     $sSubscribers = '';
     $aTargetSubscriberGroups = is_array($mTargetSubscriberGroup) ? $mTargetSubscriberGroup : array($mTargetSubscriberGroup);
     // If is string the addresses have not been processed and validated by js
     if (is_string($aSubscribers)) {
         // preg_match_all, use
         $sSubscribers = trim($aSubscribers);
         $aSubscribers = array();
         $sSubscribers = preg_replace_callback('/' . Flash::$EMAIL_CHECK_PATTERN . '/', function ($aMatches) use(&$aSubscribers) {
             $aSubscribers[] = $aMatches[0];
             return '';
         }, $sSubscribers);
     }
     $aSubscribers = array_unique($aSubscribers);
     $iCountAll = count($aSubscribers);
     $iMembershipsAdded = 0;
     // Always create temporary groups with all imported subscribers
     $oSubscriberGroup = new SubscriberGroup();
     $oSubscriberGroup->setName(self::GENERATED_PREFIX . date('Ymd-Hs'));
     $oSubscriberGroup->save();
     array_push($aTargetSubscriberGroups, $oSubscriberGroup->getId());
     foreach ($aSubscribers as $sEmail) {
         $oSubscriber = SubscriberQuery::create()->filterByEmail($sEmail)->findOne();
         // Create new if subscriber does not exist and email is correct
         if ($oSubscriber === null) {
             $oSubscriber = new Subscriber();
             $oSubscriber->setEmail($sEmail);
             $oSubscriber->setName($sEmail);
         }
         // Add subscriber_group_membership if it does not exists
         // @todo check change jm > handle multiple groups including generated one
         // Please check meaning and function of counting new subscriptions, only one is counted per subsriber $iMembershipsAdded
         $bHasMemberShip = false;
         foreach ($aTargetSubscriberGroups as $iSubscriberGroupId) {
             if (!$oSubscriber->hasSubscriberGroupMembership($iSubscriberGroupId)) {
                 $bHasMemberShip = true;
                 $oSubscriberGroupMembership = new SubscriberGroupMembership();
                 $oSubscriberGroupMembership->setSubscriberGroupId($iSubscriberGroupId);
                 $oSubscriber->addSubscriberGroupMembership($oSubscriberGroupMembership);
             }
         }
         if ($bHasMemberShip) {
             $iMembershipsAdded++;
         }
         $oSubscriber->save();
     }
     return array('all' => $iCountAll, 'added' => $iMembershipsAdded, 'text' => $sSubscribers);
 }
开发者ID:rapila,项目名称:plugin-newsletter,代码行数:58,代码来源:SubscriberImportWidgetModule.php

示例2: setSubscriber

 /**
  * Declares an association between this object and a Subscriber object.
  *
  * @param                  Subscriber $v
  * @return SubscriberGroupMembership The current object (for fluent API support)
  * @throws PropelException
  */
 public function setSubscriber(Subscriber $v = null)
 {
     if ($v === null) {
         $this->setSubscriberId(NULL);
     } else {
         $this->setSubscriberId($v->getId());
     }
     $this->aSubscriber = $v;
     // Add binding for other direction of this n:n relationship.
     // If this object has already been added to the Subscriber object, it will not be re-added.
     if ($v !== null) {
         $v->addSubscriberGroupMembership($this);
     }
     return $this;
 }
开发者ID:rapila,项目名称:plugin-newsletter,代码行数:22,代码来源:BaseSubscriberGroupMembership.php


注:本文中的Subscriber::addSubscriberGroupMembership方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。