diff --git a/backend/views/newsletter/view.php b/backend/views/newsletter/view.php
index 8706788..0c666d4 100644
--- a/backend/views/newsletter/view.php
+++ b/backend/views/newsletter/view.php
@@ -60,7 +60,7 @@ $this->params['breadcrumbs'][] = $this->title;
body ?>
-
+
Teszt üzenet küldése
@@ -68,10 +68,10 @@ Teszt üzenet küldése
A küldés gombra kattintva úgy küldünk ki egy darab e-mailt,
-
- mintha a megadott vendég lenne a fogadó
+ mintha a megadott előfizető lenne a fogadó
-
- viszont a vendég e-mail címe helyett a megadott e-mail címre küldjük
+ viszont az előfizető e-mail címe helyett a megadott e-mail címre küldjük
@@ -92,4 +92,5 @@ Teszt üzenet küldése
-
\ No newline at end of file
+
+
\ No newline at end of file
diff --git a/common/components/Helper.php b/common/components/Helper.php
index 6179b56..aee7908 100644
--- a/common/components/Helper.php
+++ b/common/components/Helper.php
@@ -397,12 +397,16 @@ class Helper {
}
public static function getWebUrl(){
- if ( self::isCompanyMovar()){
- return "https://fitnessadmin.hu/fitness-web";
- }else if ( self::isCompanyGyor()){
- return "https://fitnessadmin.hu/cutler";
+ if ( \Yii::$app->params['development'] == true ){
+ return "http://localhost/fitness-web";
}else{
- return "https://localhost/fitness-web";
+ if ( self::isCompanyMovar()){
+ return "https://fitnessadmin.hu/fitness-web";
+ }else if ( self::isCompanyGyor()){
+ return "https://fitnessadmin.hu/cutler";
+ }else{
+ return "https://localhost/fitness-web";
+ }
}
}
diff --git a/common/config/params.php b/common/config/params.php
index 09aad24..2511c36 100644
--- a/common/config/params.php
+++ b/common/config/params.php
@@ -1,5 +1,6 @@
false,
'adminEmail' => 'rocho02@gmail.com',
'supportEmail' => 'rocho02@gmail.com',
'infoEmail' => 'info@rocho-net.hu',
@@ -47,6 +48,7 @@ return [
'day' => 5,
]
],
- 'newsletter_from' => 'noreply@fitnessadmin.hu'
+ 'newsletter_from' => 'noreply@fitnessadmin.hu',
+ 'newsletter_enabled' => false
];
diff --git a/common/models/Log.php b/common/models/Log.php
index d8847f4..6f1cfca 100644
--- a/common/models/Log.php
+++ b/common/models/Log.php
@@ -45,6 +45,10 @@ class Log extends BaseFitnessActiveRecord
public static $TYPE_WASTE = 100;
public static $TYPE_NEWSLETTER_SUBSCRIBE = 110;
public static $TYPE_NEWSLETTER_UNSUBSCRIBE = 120;
+ public static $TYPE_NEWSLETTER_SENT = 130;
+ public static $TYPE_TICKET_EXPIRE_SENT = 140;
+ public static $TYPE_NEWSLETTER_SEND_START = 150;
+ public static $TYPE_NEWSLETTER_SEND_END = 160;
/**
* @inheritdoc
diff --git a/common/models/Subscriber.php b/common/models/Subscriber.php
new file mode 100644
index 0000000..f17b141
--- /dev/null
+++ b/common/models/Subscriber.php
@@ -0,0 +1,85 @@
+ TimestampBehavior::className(),
+ 'value' => function(){ return date('Y-m-d H:i:s' ); }
+ ],
+ ], parent::behaviors());
+ }
+
+
+ /**
+ * @inheritdoc
+ */
+ public function rules()
+ {
+ return [
+ [['email'], 'email'],
+ [['status','email','name'], 'required'],
+ [['status'], 'integer'],
+ [['name'], 'string', 'max' => 255],
+ ['status' ,'validateSubscribe' ,'skipOnEmpty' => false, 'skipOnError' => false ,'on' => 'subscribe']
+ ];
+ }
+
+ public function validateSubscribe($attr,$param){
+ if ( $this->status != '1'){
+ $this->addError( "status", "Feliratkozáshoz be kell jelölnie ezt a mezőt!");
+ }
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function attributeLabels()
+ {
+ return [
+ 'id_subscriber' => Yii::t('common/subscriber', 'Id Subscriber'),
+ 'name' => Yii::t('common/subscriber', 'Név'),
+ 'email' => Yii::t('common/subscriber', 'Email'),
+ 'status' => Yii::t('common/subscriber', 'Szeretnék hírlevelet kapni'),
+ 'token' => Yii::t('common/subscriber', 'Token'),
+ 'created_at' => Yii::t('common/subscriber', 'Created At'),
+ 'updated_at' => Yii::t('common/subscriber', 'Updated At'),
+ ];
+ }
+
+ public function beforeSave($insert){
+ if ( parent::beforeSave($insert)){
+ $this->token = Yii::$app->security->generateRandomString() . '_' . time();
+ }
+ return true;
+ }
+
+}
diff --git a/console/controllers/TicketController.php b/console/controllers/TicketController.php
index 5e930b1..d9ef266 100644
--- a/console/controllers/TicketController.php
+++ b/console/controllers/TicketController.php
@@ -13,6 +13,7 @@ use common\components\Helper;
use common\models\Newsletter;
use common\models\Log;
use yii\helpers\Html;
+use common\models\Subscriber;
class TicketController extends Controller {
public function actionIndex() {
@@ -110,6 +111,12 @@ class TicketController extends Controller {
->setTo ( $recepientEmail )
->setSubject ( "Értesítés - " . Helper::getCompanyName()." - Bérleted ".$dayCount." nap múlva lejár" )
->send ();
+
+ Log::logC([
+ 'type' => Log::$TYPE_TICKET_EXPIRE_SENT,
+ 'message' => "Bérlet lejár üzenet: " . $recepient['customer_name']." [id_customer=". $recepient['customer_id_customer'] ."]",
+ 'id_customer' => $recepient['customer_id_customer']
+ ]);
}
}
}
@@ -129,6 +136,12 @@ class TicketController extends Controller {
public function actionNewsletter(){
set_time_limit(0);
+
+ if ( \Yii::$app->params['newsletter_enabled'] != true ){
+ return;
+ }
+
+
$q1 = Newsletter::find();
$q1->andWhere(['sent' => Newsletter::$SENT_NOT]);
$q1->andWhere(['status' => Newsletter::$STATUS_ACTIVE]);
@@ -139,38 +152,32 @@ class TicketController extends Controller {
\Yii::info("Nincs elküldendő hírlevél");
}
- $q2 = new Query();
- $q2->distinct();
- $q2->select(['customer.email as customer_email','customer.name as customer_name'
- ,'customer.id_customer as customer_id_customer'
- ,'customer.newsletter_token as customer_newsletter_token'
- ]);
- $q2->from("customer");
- $q2->innerJoin("ticket","ticket.id_card = customer.id_customer_card");
-// $q2->andWhere(['status' => Customer::STATUS_ACTIVE ]);
- $q2->andWhere(['newsletter' => Customer::$ENABLED ]);
- $q2->andWhere(['>=' ,'ticket.end',new Expression('DATE( DATE_ADD(NOW(),INTERVAL -3 MONTH) )')]);
+ $subscribers = Subscriber::find()->andWhere(['status' => 1])->all();
+
- $customers = $q2->all();
-
- \Yii::info("Hírlevél küldése " .count($customers) . " vendégnek!" );
+ \Yii::info("Hírlevél küldése " .count($subscribers) . " előfizetőnek!" );
$i = 0;
foreach ($newsletters as $newsletter ){
$i = 0;
- foreach ($customers as $customer ){
+ Log::logC([
+ 'type' => Log::$TYPE_NEWSLETTER_SEND_START,
+ 'message' => "Hírlevél küldés indítása[id_newsletter=" . $newsletter->id_newsletter ."]"
+ ]);
+ foreach ($subscribers as $subscriber ){
try{
$log = "Sending Newsletter";
$log .="[id_newsletter=".$newsletter->id_newsletter ."]";
- $log .="[customer_email=" . $customer['customer_email'] . "]";
+ $log .="[subscriber_email=" . $subscriber->email . "]";
+ $log .="[subscriber_id=" . $subscriber->id_subscriber . "]";
\Yii::info($log);
$message = \Yii::$app->mailer->compose ( );
$replacePairs = [
- '{vendeg_neve}' => $customer['customer_name']
+ '{vendeg_neve}' => $subscriber->name
];
$mailBody = $newsletter->body;
@@ -178,7 +185,7 @@ class TicketController extends Controller {
$mailBody .="
";
$mailBody .="Leiratkozás hírlevélről:";
- $mailBody .= Html::a("Leiratkozom",Helper::getWebUrl() ."/frontend/web/index.php?r=site/newsletter-unsubscribe&id=".$customer['customer_id_customer']."&token=".$customer['customer_newsletter_token']);
+ $mailBody .= Html::a("Leiratkozom",Helper::getWebUrl() ."/frontend/web/index.php?r=site/newsletter-unsubscribe&id=".$subscriber->id_subscriber."&token=". $subscriber->token );
$mailSubject = $newsletter->subject;
$mailSubject = strtr($mailSubject, $replacePairs );
@@ -186,14 +193,19 @@ class TicketController extends Controller {
$message
->setFrom ( [ \Yii::$app->params['newsletter_from'] => Helper::getCompanyName() ])
->setTo ( [
- $customer['customer_email']
+ $subscriber->email => $subscriber->name
])
->setHtmlBody( $mailBody )
->setSubject ( $mailSubject )
->send ();
+ Log::logC([
+ 'type' => Log::$TYPE_NEWSLETTER_SENT,
+ 'message' => "Hírlevél küldés[id_newsletter=" . $newsletter->id_newsletter ."][id_subscriber=" . $subscriber->id_subscriber ."]"
+ ]);
+
}catch (\Exception $ex){
- \Yii::error("Nem sikerült hírlevelet kikülden: Hírlevél azonosító=" .$newsletter->id_newsletter. ";Vendég azonosító ". $customer['customer_name'] ) ;
+ \Yii::error("Nem sikerült hírlevelet kikülden: Hírlevél azonosító=" .$newsletter->id_newsletter. ";Előfizető azonosító ". $subscriber->id_subscriber ) ;
}
$i++;
@@ -202,6 +214,11 @@ class TicketController extends Controller {
$newsletter->sent_at = Helper::getDateTimeString();
$newsletter->save(false);
+ Log::logC([
+ 'type' => Log::$TYPE_NEWSLETTER_SEND_END,
+ 'message' => "Hírlevél küldés befejezése[id_newsletter=" . $newsletter->id_newsletter ."]"
+ ]);
+
// Log::log([
// 'type' =>Log::$TYPE_LOGIN,
// 'message' => $message
diff --git a/console/migrations/m160527_054414_add_table__subscriber.php b/console/migrations/m160527_054414_add_table__subscriber.php
new file mode 100644
index 0000000..ce40ecc
--- /dev/null
+++ b/console/migrations/m160527_054414_add_table__subscriber.php
@@ -0,0 +1,43 @@
+db->driverName === 'mysql') {
+ // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
+ $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
+ }
+
+ $this->createTable('{{%subscriber}}', [
+ 'id_subscriber' => $this->primaryKey(),
+ 'name' => $this->string(),
+ 'email' => $this->text(),
+ 'status' => $this->integer(11),
+ 'token' => $this->string(),
+ 'created_at' => $this->dateTime()->notNull(),
+ 'updated_at' => $this->dateTime()->notNull(),
+ ], $tableOptions);
+ }
+
+ public function down()
+ {
+
+ return true;
+ }
+
+ /*
+ // Use safeUp/safeDown to run migration code within a transaction
+ public function safeUp()
+ {
+ }
+
+ public function safeDown()
+ {
+ }
+ */
+}
diff --git a/frontend/controllers/SiteController.php b/frontend/controllers/SiteController.php
index 28291c7..d3eb93e 100644
--- a/frontend/controllers/SiteController.php
+++ b/frontend/controllers/SiteController.php
@@ -18,6 +18,7 @@ use common\models\Log;
use common\models\Customer;
use yii\web\NotFoundHttpException;
use frontend\models\SubscribeForm;
+use common\models\Subscriber;
/**
* Site controller
@@ -185,9 +186,9 @@ class SiteController extends Controller
$this->layout = "main-nologin";
- $customer = Customer::find()
- ->andWhere(['id_customer' => $id ])
- ->andWhere(['newsletter_token' => $token])
+ $customer = Subscriber::find()
+ ->andWhere(['id_subscriber' => $id ])
+ ->andWhere(['token' => $token])
->one();
@@ -195,51 +196,32 @@ class SiteController extends Controller
throw new NotFoundHttpException("Az oldal nem található");
}
- $customer->newsletter = 0;
- $customer->newsletter_token = Yii::$app->security->generateRandomString() . '_' . time();
+ $customer->status = 0;
+ $customer->token = Yii::$app->security->generateRandomString() . '_' . time();
$customer->save();
Log::logC([
- 'id_customer' => $customer->id_customer,
'type' => Log::$TYPE_NEWSLETTER_UNSUBSCRIBE,
- "message" => "Hírlevél feliratkozás: ". $customer->name
+ "message" => "Hírlevél leiratkozás: ". $customer->name
]);
- return $this->render("unsubscribe");
+ return $this->render("unsubscribe",['subscriber' => $customer]);
}
- public function actionNewsletterSubscribe($id,$token)
+ public function actionNewsletterSubscribe()
{
$this->layout = "main-nologin";
+ $model = new Subscriber(['scenario' => 'subscribe']);
+
-
- $customer = Customer::find()
- ->andWhere(['id_customer' => $id ])
- ->andWhere(['newsletter_token' => $token])
- ->one();
-
- if ( !isset($customer)){
- throw new NotFoundHttpException("Az oldal nem található");
- }
- $model = new SubscribeForm([
- 'customer' => $customer
- ]);
-
- if ($model->load(Yii::$app->request->post()) && $model->validate() ) {
-
-
+ if ($model->load(Yii::$app->request->post()) && $model->save() ) {
- $customer->newsletter = 1;
- $customer->newsletter_token = Yii::$app->security->generateRandomString() . '_' . time();
- $customer->save();
-
Log::logC([
- 'id_customer' => $customer->id_customer,
'type' => Log::$TYPE_NEWSLETTER_SUBSCRIBE,
- "message" => "Hírlevél feliratkozás: ". $customer->name ." - " . $customer->email
+ "message" => "Hírlevél feliratkozás: ". $model->name ." - " . $model->email
]);
return $this->redirect(["newsletter-subscribe-success"]);
diff --git a/frontend/views/site/subscribeform.php b/frontend/views/site/subscribeform.php
index 99190ee..55e8c11 100644
--- a/frontend/views/site/subscribeform.php
+++ b/frontend/views/site/subscribeform.php
@@ -4,18 +4,6 @@ use yii\helpers\Html;
use common\components\Helper;
?>
-
diff --git a/frontend/views/site/unsubscribe.php b/frontend/views/site/unsubscribe.php
index 48ff169..349d53e 100644
--- a/frontend/views/site/unsubscribe.php
+++ b/frontend/views/site/unsubscribe.php
@@ -1,7 +1,13 @@
+
+ Kedves name ?>!
+
+
Ön sikeresen leiratkozott a hírlevelünkről!
+A leiratkozott e-mail cím : email?>
+
Köszönettel: