public function saveData($aSubscriberData)
 {
     $oSubscriber = SubscriberQuery::create()->findPk($this->iSubscriberId);
     if ($oSubscriber === null) {
         $oSubscriber = new Subscriber();
         $oSubscriber->setCreatedBy(Session::getSession()->getUserId());
         $oSubscriber->setCreatedAt(date('c'));
     }
     $oSubscriber->setPreferredLanguageId($aSubscriberData['preferred_language_id']);
     $oSubscriber->setName($aSubscriberData['name']);
     $oSubscriber->setEmail($aSubscriberData['email']);
     $this->validate($aSubscriberData, $oSubscriber);
     if (!Flash::noErrors()) {
         throw new ValidationException();
     }
     // Subscriptions
     foreach ($oSubscriber->getSubscriberGroupMemberships() as $oSubscriberGroupMembership) {
         $oSubscriberGroupMembership->delete();
     }
     $aSubscriptions = isset($aSubscriberData['subscriber_group_ids']) ? $aSubscriberData['subscriber_group_ids'] : array();
     foreach ($aSubscriptions as $iSubscriberGroupId) {
         $oSubscriberGroupMembership = new SubscriberGroupMembership();
         $oSubscriberGroupMembership->setSubscriberGroupId($iSubscriberGroupId);
         $oSubscriber->addSubscriberGroupMembership($oSubscriberGroupMembership);
     }
     return $oSubscriber->save();
 }
Exemplo n.º 2
0
 public function addSubscriberGroupMembershipBySubscriberGroupId($iSubscriberGroupId)
 {
     $oSubscriberGroupMembership = new SubscriberGroupMembership();
     $oSubscriberGroupMembership->setSubscriberGroupId($iSubscriberGroupId);
     if (Settings::getSetting('newsletter', 'optin_confirmation_required', true)) {
         $oSubscriberGroupMembership->setOptInHash($this->getOptInChecksum($iSubscriberGroupId));
     }
     return $this->addSubscriberGroupMembership($oSubscriberGroupMembership);
 }
 /** 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);
 }
 /**
  * Filter the query by a related SubscriberGroupMembership object
  *
  * @param   SubscriberGroupMembership|PropelObjectCollection $subscriberGroupMembership  the related object to use as filter
  * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return                 SubscriberQuery The current query, for fluid interface
  * @throws PropelException - if the provided filter is invalid.
  */
 public function filterBySubscriberGroupMembership($subscriberGroupMembership, $comparison = null)
 {
     if ($subscriberGroupMembership instanceof SubscriberGroupMembership) {
         return $this->addUsingAlias(SubscriberPeer::ID, $subscriberGroupMembership->getSubscriberId(), $comparison);
     } elseif ($subscriberGroupMembership instanceof PropelObjectCollection) {
         return $this->useSubscriberGroupMembershipQuery()->filterByPrimaryKeys($subscriberGroupMembership->getPrimaryKeys())->endUse();
     } else {
         throw new PropelException('filterBySubscriberGroupMembership() only accepts arguments of type SubscriberGroupMembership or PropelCollection');
     }
 }
Exemplo n.º 5
0
 /**
  * @param	SubscriberGroupMembership $subscriberGroupMembership The subscriberGroupMembership object to add.
  */
 protected function doAddSubscriberGroupMembership($subscriberGroupMembership)
 {
     $this->collSubscriberGroupMemberships[] = $subscriberGroupMembership;
     $subscriberGroupMembership->setSubscriber($this);
 }
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doSelect*()
  * methods in your stub classes -- you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by doSelect*()
  * and retrieveByPK*() calls.
  *
  * @param SubscriberGroupMembership $obj A SubscriberGroupMembership object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool($obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = serialize(array((string) $obj->getSubscriberId(), (string) $obj->getSubscriberGroupId()));
         }
         // if key === null
         SubscriberGroupMembershipPeer::$instances[$key] = $obj;
     }
 }
 /**
  * Exclude object from result
  *
  * @param   SubscriberGroupMembership $subscriberGroupMembership Object to remove from the list of results
  *
  * @return SubscriberGroupMembershipQuery The current query, for fluid interface
  */
 public function prune($subscriberGroupMembership = null)
 {
     if ($subscriberGroupMembership) {
         $this->addCond('pruneCond0', $this->getAliasedColName(SubscriberGroupMembershipPeer::SUBSCRIBER_ID), $subscriberGroupMembership->getSubscriberId(), Criteria::NOT_EQUAL);
         $this->addCond('pruneCond1', $this->getAliasedColName(SubscriberGroupMembershipPeer::SUBSCRIBER_GROUP_ID), $subscriberGroupMembership->getSubscriberGroupId(), Criteria::NOT_EQUAL);
         $this->combine(array('pruneCond0', 'pruneCond1'), Criteria::LOGICAL_OR);
     }
     return $this;
 }