From afa58973aeb8db37476346e162882ead967e88e7 Mon Sep 17 00:00:00 2001
From: Roland Schneider
Date: Fri, 27 May 2016 21:00:23 +0200
Subject: [PATCH 1/3] add subscriber
---
backend/views/newsletter/view.php | 9 +-
common/components/Helper.php | 14 +--
common/config/params.php | 4 +-
common/models/Log.php | 4 +
common/models/Subscriber.php | 85 +++++++++++++++++++
console/controllers/TicketController.php | 57 ++++++++-----
.../m160527_054414_add_table__subscriber.php | 43 ++++++++++
frontend/controllers/SiteController.php | 44 +++-------
frontend/views/site/subscribeform.php | 17 +---
frontend/views/site/unsubscribe.php | 6 ++
10 files changed, 208 insertions(+), 75 deletions(-)
create mode 100644 common/models/Subscriber.php
create mode 100644 console/migrations/m160527_054414_add_table__subscriber.php
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:
From 410e74a61c84fb6b70050792e0de11b3e765e808 Mon Sep 17 00:00:00 2001
From: Roland Schneider
Date: Mon, 30 May 2016 08:18:25 +0200
Subject: [PATCH 2/3] Add unpaid tickets display
Add unpaid tickets display to reception
---
changelog.txt | 2 ++
common/config/params.php | 2 +-
common/models/Ticket.php | 30 ++++++++++++++++++++
frontend/models/ReceptionForm.php | 6 ++++
frontend/views/common/_reception_ticket.php | 31 +++++++++++++++++++++
5 files changed, 70 insertions(+), 1 deletion(-)
diff --git a/changelog.txt b/changelog.txt
index 7719a4a..4eae589 100644
--- a/changelog.txt
+++ b/changelog.txt
@@ -1,3 +1,5 @@
+-0.0.75
+ - add unpaid tickets display
-0.0.74
- add newsletter changes
-0.0.73
diff --git a/common/config/params.php b/common/config/params.php
index 2511c36..a5b82df 100644
--- a/common/config/params.php
+++ b/common/config/params.php
@@ -5,7 +5,7 @@ return [
'supportEmail' => 'rocho02@gmail.com',
'infoEmail' => 'info@rocho-net.hu',
'user.passwordResetTokenExpire' => 3600,
- 'version' => 'v0.0.74',
+ 'version' => 'v0.0.75',
'company' => 'movar',//gyor
'company_name' => "Freimann Kft.",
'product_visiblity' => 'account',// on reception which products to display. account or global
diff --git a/common/models/Ticket.php b/common/models/Ticket.php
index b2250f1..81635f1 100644
--- a/common/models/Ticket.php
+++ b/common/models/Ticket.php
@@ -124,6 +124,11 @@ class Ticket extends \common\models\BaseFitnessActiveRecord
public function getCard(){
return $this->hasOne( Card::className(), ["id_card" =>"id_card" ] );
}
+
+ public function getContract(){
+ return $this->hasOne( Contract::className(), ["id_contract" =>"id_contract" ] );
+ }
+
public function getCardNumber(){
$result = "";
$card = $this->card;
@@ -217,6 +222,31 @@ class Ticket extends \common\models\BaseFitnessActiveRecord
return $result;
}
+ /**
+ * @param common\models\Card $card the card to which we are looking for
+ * */
+ public static function readUnpaid($card){
+
+ if ( $card == null )
+ return [];
+
+ $query = Ticket::find();
+ $query->innerJoin("transfer", "transfer.id_object = ticket.id_ticket ");
+ $today = date('Y-m-d');
+
+ $query->andWhere(['ticket.id_card' => $card->id_card]);
+ $query->andWhere( 'ticket.start <= :today' ,[ 'today' => $today] );
+ $query->andWhere( 'ticket.end >= :today' ,[ 'today' => $today] );
+ $query->andWhere( ['in' ,'ticket.status' ,[ Ticket::STATUS_INACTIVE, Ticket::STATUS_ACTIVE] ]);
+ $query->andWhere( ["transfer.type" => Transfer::TYPE_TICKET] );
+ $query->andWhere( [ "transfer.status" => Transfer::STATUS_NOT_PAID ]);
+ $query->orderBy([ "ticket.created_at" =>SORT_DESC] );
+
+ $result = $query->all();
+
+ return $result;
+
+ }
public static function mkStatisticQuery($start,$end,$id_card = null){
diff --git a/frontend/models/ReceptionForm.php b/frontend/models/ReceptionForm.php
index 1aa7549..30a9f66 100644
--- a/frontend/models/ReceptionForm.php
+++ b/frontend/models/ReceptionForm.php
@@ -26,6 +26,7 @@ class ReceptionForm extends Model
public $card;
public $customer;
public $tickets;
+ public $unpaidTickets;
public $defaultAccount;
public $cardSearchModel;
public $lastCassaState;
@@ -77,6 +78,7 @@ class ReceptionForm extends Model
if ( $this->card != null ){
$this->customer = $this->card->customer;
$this->readValidTickets();
+ $this->readUnpaidTicket();
$this->readAssignedKeys();
$this->readContract();
}
@@ -183,6 +185,10 @@ class ReceptionForm extends Model
$this->tickets = Ticket::readActive($this->card);
}
+ public function readUnpaidTicket(){
+ $this->unpaidTickets = Ticket::readUnpaid($this->card);
+ }
+
/**
* @return true , if card found without customer
* */
diff --git a/frontend/views/common/_reception_ticket.php b/frontend/views/common/_reception_ticket.php
index 4084565..c690c10 100644
--- a/frontend/views/common/_reception_ticket.php
+++ b/frontend/views/common/_reception_ticket.php
@@ -105,4 +105,35 @@ if ( isset($model->contract)){
}
}
+if ( isset( $model->unpaidTickets ) ) {
+ if ( count($model->unpaidTickets) > 0){
+ echo Html::beginTag("div",['class'=>"alert alert-warning", "role"=>"alert"]);
+ echo Html::beginTag("strong",[ ]);
+ echo "Fizetetlen bérletek";
+ echo Html::endTag("strong");
+ echo "";
+ $formatter = \Yii::$app->formatter;
+ foreach ($model->unpaidTickets as $t ){
+ echo Html::beginTag("li",[ ]);
+ $c = $t->contract;
+ if (isset($c)){
+ echo "Szerződéses";
+ }
+ echo $t->getTicketTypeName();
+
+ echo ": ";
+ echo $formatter->asDate($t->start);
+ echo " - " ;
+ echo $formatter->asDate($t->end);
+ echo " (";
+ echo $t->price_brutto;
+ echo " Ft)";
+ echo Html::endTag("li");
+ }
+ echo "
";
+ echo Html::endTag("div");
+ }
+}
+
+
?>
\ No newline at end of file
From 06eca0fe03a47900951137813346b1c1d5256a5c Mon Sep 17 00:00:00 2001
From: Roland Schneider
Date: Wed, 1 Jun 2016 18:26:32 +0200
Subject: [PATCH 3/3] login changes
---
frontend/controllers/SiteController.php | 4 +++-
update_botond.sh | 4 ++++
2 files changed, 7 insertions(+), 1 deletion(-)
create mode 100644 update_botond.sh
diff --git a/frontend/controllers/SiteController.php b/frontend/controllers/SiteController.php
index d3eb93e..6707abc 100644
--- a/frontend/controllers/SiteController.php
+++ b/frontend/controllers/SiteController.php
@@ -101,7 +101,9 @@ class SiteController extends Controller
$message = "";
$user = User::findOne(\Yii::$app->user->id);
if ( isset($geoip)){
- $message = "Bejelentkezés: " .$user->username. " Ip cím:". $geoip->ip . " Város: " . $geoip->city;
+ $ip = isset( $geoip->ip ) ? $geoip->ip : "";
+ $city = isset( $geoip->city ) ? $geoip->city : "";
+ $message = "Bejelentkezés: " .$user->username. " Ip cím:". $ip . " Város: " . $city;
}
Log::log([
diff --git a/update_botond.sh b/update_botond.sh
new file mode 100644
index 0000000..ee360db
--- /dev/null
+++ b/update_botond.sh
@@ -0,0 +1,4 @@
+git pull origin master
+composer install
+php yii migrate
+yii migrate --interactive=0
\ No newline at end of file