public function getSubscriberGroups()
 {
     if (SubscriberGroupQuery::create()->count() === 0) {
         $oSubscriberGroup = new SubscriberGroup();
         $oSubscriberGroup->setName(TranslationPeer::getString('wns.subscriber_group.default.name'));
         $oSubscriberGroup->setDisplayName(TranslationPeer::getString('wns.subscriber_group.default.display_name'));
         $oSubscriberGroup->save();
     }
     return SubscriberGroupQuery::create()->select(array('Id', 'Name'))->orderByName()->find()->toKeyValue('Id', 'Name');
 }
 /** 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);
 }
 public function saveData($aSubscriberGroupData)
 {
     if ($this->iSubscriberGroupId) {
         $oSubscriberGroup = SubscriberGroupQuery::create()->findPk($this->iSubscriberGroupId);
     } else {
         $oSubscriberGroup = new SubscriberGroup();
         $oSubscriberGroup->setCreatedBy(Session::getSession()->getUserId());
         $oSubscriberGroup->setCreatedAt(date('c'));
     }
     $oSubscriberGroup->setName($aSubscriberGroupData['name']);
     $oSubscriberGroup->setDisplayName($aSubscriberGroupData['display_name'] == null ? null : $aSubscriberGroupData['display_name']);
     $this->validate($aSubscriberGroupData);
     if (!Flash::noErrors()) {
         throw new ValidationException();
     }
     $oSubscriberGroup->save();
     $oResult = new stdClass();
     $oResult->id = $oSubscriberGroup->getId();
     if ($this->iSubscriberGroupId === null) {
         $oResult->inserted = true;
     } else {
         $oResult->updated = true;
     }
     $this->iSubscriberGroupId = $oResult->id;
     return $oResult;
 }
Example #4
0
 public function actionSynchronize()
 {
     set_time_limit(7200);
     $idNameGroup = array();
     $criteria = new CDbCriteria();
     $mSubG = SubscriberGroup::model()->findAll($criteria);
     if (count($mSubG) > 0) {
         foreach ($mSubG as $i) {
             $idNameGroup[$i->id] = $i->name;
         }
     }
     $criteria = new CDbCriteria();
     $criteria->addCondition('subscriber_group_id = 1 OR subscriber_group_id = 2');
     $mSubscriber = Subscriber::model()->findAll($criteria);
     //var_dump($mSubscriber);
     $test = array();
     if (count($mSubscriber) > 0) {
         Yii::import('ext.MailChimp.MailChimp', true);
         foreach ($mSubscriber as $item) {
             $mailChimp = new MailChimp();
             //                    $mailChimp->removeSubscriber('*****@*****.**');
             //                    die;
             $sGroupName = Yii::app()->params['mailchimp_title_groups'];
             $sGroup = strtolower($idNameGroup[$item->subscriber_group_id]);
             $merge_vars = array('GROUPINGS' => array(array('name' => $sGroupName, 'groups' => $sGroup)));
             if ($item->status == 1) {
                 //                        echo '<pre>';
                 //echo print_r($merge_vars);
                 //echo '</pre>';
                 //echo $item->email;
                 //die();
                 $test[] = $mailChimp->addSubscriber($item->email, $merge_vars);
             } else {
                 $mailChimp->removeSubscriber($item->email);
             }
         }
     }
     Yii::app()->user->setFlash('mailchimp', "Synchronize Mailling list successfully!");
     $this->redirect(Yii::app()->createAbsoluteUrl("admin/setting/mailchimp"));
 }
 /**
  * Resets all references to other model objects or collections of model objects.
  *
  * This method is a user-space workaround for PHP's inability to garbage collect
  * objects with circular references (even in PHP 5.3). This is currently necessary
  * when using Propel in certain daemon or large-volume/high-memory operations.
  *
  * @param boolean $deep Whether to also clear the references on all referrer objects.
  */
 public function clearAllReferences($deep = false)
 {
     if ($deep && !$this->alreadyInClearAllReferencesDeep) {
         $this->alreadyInClearAllReferencesDeep = true;
         if ($this->aSubscriberGroup instanceof Persistent) {
             $this->aSubscriberGroup->clearAllReferences($deep);
         }
         if ($this->aNewsletter instanceof Persistent) {
             $this->aNewsletter->clearAllReferences($deep);
         }
         if ($this->aUserRelatedByCreatedBy instanceof Persistent) {
             $this->aUserRelatedByCreatedBy->clearAllReferences($deep);
         }
         if ($this->aUserRelatedByUpdatedBy instanceof Persistent) {
             $this->aUserRelatedByUpdatedBy->clearAllReferences($deep);
         }
         $this->alreadyInClearAllReferencesDeep = false;
     }
     // if ($deep)
     $this->aSubscriberGroup = null;
     $this->aNewsletter = null;
     $this->aUserRelatedByCreatedBy = null;
     $this->aUserRelatedByUpdatedBy = null;
 }
 /**
  * Filter the query by a related SubscriberGroup object
  *
  * @param   SubscriberGroup|PropelObjectCollection $subscriberGroup The related object(s) to use as filter
  * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return                 NewsletterMailingQuery The current query, for fluid interface
  * @throws PropelException - if the provided filter is invalid.
  */
 public function filterBySubscriberGroup($subscriberGroup, $comparison = null)
 {
     if ($subscriberGroup instanceof SubscriberGroup) {
         return $this->addUsingAlias(NewsletterMailingPeer::SUBSCRIBER_GROUP_ID, $subscriberGroup->getId(), $comparison);
     } elseif ($subscriberGroup instanceof PropelObjectCollection) {
         if (null === $comparison) {
             $comparison = Criteria::IN;
         }
         return $this->addUsingAlias(NewsletterMailingPeer::SUBSCRIBER_GROUP_ID, $subscriberGroup->toKeyValue('PrimaryKey', 'Id'), $comparison);
     } else {
         throw new PropelException('filterBySubscriberGroup() only accepts arguments of type SubscriberGroup or PropelCollection');
     }
 }
Example #7
0
Yii::import('application.extensions.CJuiDateTimePicker.CJuiDateTimePicker');
$this->widget('CJuiDateTimePicker', array('model' => $model, 'attribute' => 'send_time', 'mode' => 'datetime', 'language' => 'en-GB', 'options' => array('showAnim' => 'fold', 'showButtonPanel' => true, 'autoSize' => true, 'dateFormat' => 'dd/mm/yy', 'timeFormat' => 'hh:mm:ss', 'width' => '120', 'separator' => ' '), 'htmlOptions' => array('style' => 'width:180px;')));
?>
        <span>(dd/mm/yyyy)</span>
        <?php 
echo $form->error($model, 'send_time');
?>
    </div>

    <div class="row group_subscriber">
            <?php 
echo $form->labelEx($model, 'newsletter_group_subscriber');
?>
			<div class="fix-label">
            <?php 
$this->widget('ext.multiselect.JMultiSelect', array('model' => $model, 'attribute' => 'newsletter_group_subscriber', 'data' => SubscriberGroup::loadItems(), 'options' => array(), 'htmlOptions' => array('style' => 'width: 350px;')));
?>
		   </div>
        <?php 
if (isset($get_error) && $get_error != "") {
    echo $get_error;
}
?>
            <?php 
echo $form->error($model, 'newsletter_group_subscriber');
?>
    </div>
    
    <div class="row">
        <?php 
echo $form->labelEx($model, 'content');
Example #8
0
echo $model->email;
?>
)</h5>
		<div class="widget-toolbar">
			<a data-action="settings" href="#"><i class="icon-cog"></i></a> <a
				data-action="reload" href="#"><i class="icon-refresh"></i></a> <a
				data-action="collapse" href="#"><i class="icon-chevron-up"></i></a>
			<a data-action="close" href="#"><i class="icon-remove"></i></a>
		</div>
		<div class="widget-toolbar">
            <?php 
echo CHtml::link('<i class="icon-pencil"></i>', array('update', 'id' => $model->id), array('data-rel' => 'tooltip', 'title' => 'Edit', 'data-placement' => 'bottom'));
?>
        </div>
		<div class="widget-toolbar">
            <?php 
echo CHtml::link('<i class="icon-plus"></i>', array('create'), array('data-rel' => 'tooltip', 'title' => 'Add', 'data-placement' => 'bottom'));
?>
        </div>
	</div>
	<!--/.widget-header -->
	<div class="widget-body">
		<div class="widget-main">
            <?php 
$this->widget('bootstrap.widgets.TbDetailView', array('data' => $model, 'attributes' => array('id', array('name' => 'groups', 'type' => 'raw', 'value' => SubscriberGroup::get_groups($model->id)), 'full_name', 'email', array('name' => 'created_on', 'type' => 'raw', 'value' => date("F j, Y, g:i A", strtotime($model->created_on))), array('name' => 'confirmed', 'value' => $model->confirmed ? "Yes" : "No"), array('name' => 'enabled', 'value' => $model->enabled ? "Yes" : "No"))));
?>
        </div>
	</div>
	<!--/.widget-body -->
</div>
<!--/.widget-box -->
Example #9
0
 public function mailchimp()
 {
     set_time_limit(7200);
     $idNameGroup = array();
     $criteria = new CDbCriteria();
     //            $criteria->compare('t.status',1);
     $mSubG = SubscriberGroup::model()->findAll($criteria);
     if (count($mSubG) > 0) {
         foreach ($mSubG as $i) {
             $idNameGroup[$i->id] = $i->name;
         }
     }
     $criteria = new CDbCriteria();
     $mSubscriber = Subscriber::model()->findAll($criteria);
     $test = array();
     if (count($mSubscriber) > 0) {
         Yii::import('ext.MailChimp.MailChimp', true);
         foreach ($mSubscriber as $item) {
             $mailChimp = new MailChimp();
             //                    $mailChimp->removeSubscriber('*****@*****.**');
             //                    die;
             $sGroupName = Yii::app()->params['mailchimp_title_groups'];
             $sGroup = strtolower($idNameGroup[$item->subscriber_group_id]);
             $merge_vars = array('GROUPINGS' => array(array('name' => $sGroupName, 'groups' => $sGroup)));
             if ($item->status == 1) {
                 $test[] = $mailChimp->addSubscriber($item->email, $merge_vars);
             } else {
                 $mailChimp->removeSubscriber($item->email);
             }
         }
     }
 }
Example #10
0
<?php

$form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array('id' => 'subscriber-form', 'enableAjaxValidation' => false));
?>
<p class="help-block">Fields with <span class="required">*</span> are required.</p>
<?php 
echo $form->errorSummary($model);
echo $form->dropDownListControlGroup($model, 'groups', CHtml::listData(SubscriberGroup::model()->findAll(array('condition' => 'status=1', 'order' => 'title')), 'id', 'title'), array('multiple' => true, 'class' => 'chosen-select span4', 'data-placeholder' => 'Choose group...'));
echo $form->textFieldControlGroup($model, 'full_name', array('class' => 'span5', 'maxlength' => 250));
echo $form->textFieldControlGroup($model, 'email', array('class' => 'span5', 'maxlength' => 200));
echo $form->dropDownListControlGroup($model, 'confirmed', array('1' => 'Yes', '0' => 'No'), array('class' => 'span5'));
echo $form->dropDownListControlGroup($model, 'enabled', array('1' => 'Yes', '0' => 'No'), array('class' => 'span5'));
?>
<div class="form-actions">
    <?php 
echo TbHtml::submitButton($model->isNewRecord ? 'Create' : 'Save', array('color' => TbHtml::BUTTON_COLOR_PRIMARY, 'icon' => TbHtml::ICON_PLUS));
?>
    <?php 
echo TbHtml::resetButton('Reset', array('color' => TbHtml::BUTTON_COLOR_INFO));
?>
</div>
<?php 
$this->endWidget();
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  * @return SubscriberGroup the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = SubscriberGroup::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Example #12
0
            <a data-action="close" href="#"><i class="icon-remove"></i></a>
        </div>
    </div><!--/.widget-header -->
    <div class="widget-body">
        <div class="widget-main">
            <?php 
$form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array('id' => 'massmail-form', 'enableAjaxValidation' => false));
?>
            <?php 
echo $form->errorSummary($model);
?>
            <?php 
//echo $form->dropDownListControlGroup($model, 'groups', CHtml::listData(SubscriberGroup::model()->findAll(array('condition' => 'status=1', 'order' => 'title')), 'id', 'title'), array('multiple' => true, 'class' => 'chosen-select span9', 'data-placeholder' => 'All groups'));
?>
            <?php 
echo $form->dropDownListControlGroup($model, 'groups', CHtml::listData(SubscriberGroup::model()->findAll(array('condition' => 'status=1', 'order' => 'title')), 'id', 'title'), array('empty' => 'All', 'class' => 'span5'));
?>
            <?php 
echo $form->textFieldControlGroup($model, 'subject', array('span' => 12, 'maxlength' => 250));
?>
            <?php 
echo $form->labelEx($model, 'message_body');
?>
            <?php 
$this->widget('application.extensions.yii-ckeditor.CKEditorWidget', array('model' => $model, 'attribute' => 'message_body', 'config' => array('language' => 'en')));
?>
            <div class="form-actions">
                <?php 
echo TbHtml::submitButton('Send', array('color' => TbHtml::BUTTON_COLOR_PRIMARY, 'size' => TbHtml::BUTTON_SIZE_LARGE));
?>
            </div>
 public static function get_groups($id)
 {
     $model = Subscriber::model()->findByAttributes(array('id' => $id));
     $exval = explode(',', $model->groups);
     $groups = '';
     $total = count($exval);
     for ($i = 0; $i < $total; $i++) {
         if ($i == $total - 1) {
             $groups .= SubscriberGroup::get_title(trim($exval[$i])) . ' ';
         } else {
             $groups .= SubscriberGroup::get_title(trim($exval[$i])) . ', ';
         }
     }
     return $groups;
 }
 /**
  * Exclude object from result
  *
  * @param   SubscriberGroup $subscriberGroup Object to remove from the list of results
  *
  * @return SubscriberGroupQuery The current query, for fluid interface
  */
 public function prune($subscriberGroup = null)
 {
     if ($subscriberGroup) {
         $this->addUsingAlias(SubscriberGroupPeer::ID, $subscriberGroup->getId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }
Example #15
0
 public static function getDedicateByStr($str)
 {
     if (empty($str)) {
         return '';
     }
     $str = explode(',', $str);
     $res = '';
     foreach ($str as $key => $item) {
         if ($key == 0) {
             $res .= SubscriberGroup::model()->findByPk($item)->name;
         } else {
             $res .= '<br />' . SubscriberGroup::model()->findByPk($item)->name;
         }
     }
     return $res;
 }
 /**
  * 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 SubscriberGroup $obj A SubscriberGroup 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 = (string) $obj->getId();
         }
         // if key === null
         SubscriberGroupPeer::$instances[$key] = $obj;
     }
 }
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     try {
         $model = SubscriberGroup::model()->findByPk($id);
         if ($model === null) {
             Yii::log("The requested page does not exist.");
             throw new CHttpException(404, 'The requested page does not exist.');
         }
         return $model;
     } catch (Exception $e) {
         Yii::log("Exception " . print_r($e, true), 'error');
         throw new CHttpException("Exception " . print_r($e, true));
     }
 }
Example #18
0
<div class="widget-box">
    <div class="widget-header">
        <h5>Details Subscriber Group (<?php 
echo $model->title;
?>
)</h5>
        <div class="widget-toolbar">
            <a data-action="settings" href="#"><i class="icon-cog"></i></a>
            <a data-action="reload" href="#"><i class="icon-refresh"></i></a>
            <a data-action="collapse" href="#"><i class="icon-chevron-up"></i></a>
            <a data-action="close" href="#"><i class="icon-remove"></i></a>
        </div>
        <div class="widget-toolbar">
            <?php 
echo CHtml::link('<i class="icon-pencil"></i>', array('update', 'id' => $model->id), array('data-rel' => 'tooltip', 'title' => 'Edit', 'data-placement' => 'bottom'));
?>
        </div>
        <div class="widget-toolbar">
            <?php 
echo CHtml::link('<i class="icon-plus"></i>', array('create'), array('data-rel' => 'tooltip', 'title' => 'Add', 'data-placement' => 'bottom'));
?>
        </div>
    </div><!--/.widget-header -->
    <div class="widget-body">
        <div class="widget-main">
            <?php 
$this->widget('bootstrap.widgets.TbDetailView', array('data' => $model, 'attributes' => array('id', array('name' => 'parent', 'type' => 'raw', 'value' => SubscriberGroup::get_title($model->parent)), 'title', 'details', array('name' => 'status', 'value' => $model->status ? "Active" : "Inactive"))));
?>
        </div>
    </div><!--/.widget-body -->
</div><!--/.widget-box -->