diff --git a/backend/controllers/CustomerController.php b/backend/controllers/CustomerController.php index c1482af..53d524a 100644 --- a/backend/controllers/CustomerController.php +++ b/backend/controllers/CustomerController.php @@ -11,6 +11,9 @@ use yii\web\NotFoundHttpException; use yii\filters\VerbFilter; use yii\base\Object; use backend\models\CustomerUpdate; +use backend\models\CustomerNewsLetterModel; +use yii\db\Query; +use yii\data\ActiveDataProvider; /** * CustomerController implements the CRUD actions for Customer model. @@ -18,6 +21,27 @@ use backend\models\CustomerUpdate; class CustomerController extends \backend\controllers\BackendController { + + + public function behaviors() + { + return [ + 'access' => [ + 'class' => \yii\filters\AccessControl::className(), + 'rules' => [ + // allow authenticated users + [ + 'actions' => ['create','index','view','update','mail'], + 'allow' => true, + 'roles' => ['admin','employee','reception'], + ], + // everything else is denied + ], + ], + ]; + } + + /** * Lists all Customer models. * @return mixed @@ -119,4 +143,36 @@ class CustomerController extends \backend\controllers\BackendController throw new NotFoundHttpException('The requested page does not exist.'); } } + + + public function actionMail(){ + $model = new CustomerNewsLetterModel(); + + $query = new Query(); + $query->distinct(); + $query->select([ 'email']); + $query->from("customer"); + $query->andWhere(['newsletter' => 1]); + $query->andWhere(['status' => Customer::STATUS_ACTIVE]); + + + if ($model->load(Yii::$app->request->post()) && $model->validate()) { + + + $message = \Yii::$app->mailer->compose ( ); + + $message + ->setFrom ( "noreply@fitnessadmin.hu" ) + ->setBcc(['rocho02@gmail.com',"rocho02@freemail.hu"]) + //->setTo(['rocho02@gmail.com']) + ->setHtmlBody($model->text ) + ->setSubject ( $model->subject ) + ->send (); + return $this->redirect(['customer/mail']); + } + + + return $this->render('mail', [ 'model' => $model ]); + } + } diff --git a/backend/controllers/NewsletterController.php b/backend/controllers/NewsletterController.php new file mode 100644 index 0000000..41ae1d4 --- /dev/null +++ b/backend/controllers/NewsletterController.php @@ -0,0 +1,146 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['post'], + ], + ], + ]; + } + + /** + * Lists all Newsletter models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new NewsletterSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single Newsletter model. + * @param integer $id + * @return mixed + */ + public function actionView($id) + { + $model = $this->findModel($id); + $testModel = new NewsletterTestForm( + [ + 'newsletter' => $model + ] + ); + + + if ($testModel->load(Yii::$app->request->post()) && $testModel->validate()) { + $testModel->sendEmail(); + Helper::flash("success", "Teszt e-mail elküldve"); + return $this->redirect(['view', 'id' => $model->id_newsletter]); + } + + return $this->render('view', [ + 'model' => $model, + 'testModel' => $testModel + ]); + } + + /** + * Creates a new Newsletter model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new Newsletter(); + + $model->status = Newsletter::$STATUS_ACTIVE; + $model->sent = Newsletter::$SENT_NOT; + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id_newsletter]); + } else { + return $this->render('create', [ + 'model' => $model, + ]); + } + } + + /** + * Updates an existing Newsletter model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param integer $id + * @return mixed + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id_newsletter]); + } else { + return $this->render('update', [ + 'model' => $model, + ]); + } + } + + /** + * Deletes an existing Newsletter model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param integer $id + * @return mixed + */ + public function actionDelete($id) + { + $model = $this->findModel($id); + + $model->status = Newsletter::$STATUS_DELETED; + + $model->save(false); + + return $this->redirect(['index']); + } + + /** + * Finds the Newsletter model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return Newsletter the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = Newsletter::findOne($id)) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } +} diff --git a/backend/models/CustomerNewsLetterModel.php b/backend/models/CustomerNewsLetterModel.php new file mode 100644 index 0000000..13a30f7 --- /dev/null +++ b/backend/models/CustomerNewsLetterModel.php @@ -0,0 +1,32 @@ + $query, + 'sort' =>[ + 'defaultOrder' =>[ 'created_at' => SORT_DESC ] + ] + ]); + + $this->load($params); + + if (!$this->validate()) { + // uncomment the following line if you do not want to return any records when validation fails + // $query->where('0=1'); + return $dataProvider; + } + + $query->andFilterWhere([ + 'id_newsletter' => $this->id_newsletter, + 'status' => $this->status, + 'sent' => $this->sent, + 'sent_at' => $this->sent_at, + 'created_at' => $this->created_at, + 'updated_at' => $this->updated_at, + ]); + + $query->andFilterWhere(['like', 'subject', $this->subject]) + ->andFilterWhere(['like', 'body', $this->body]); + + return $dataProvider; + } +} diff --git a/backend/models/NewsletterTestForm.php b/backend/models/NewsletterTestForm.php new file mode 100644 index 0000000..ddb8c16 --- /dev/null +++ b/backend/models/NewsletterTestForm.php @@ -0,0 +1,75 @@ + "E-mail", + 'customer_name' => "Vendég neve" + ]; + } + + public function validateCustomer( $attribute, $params ) { + + $customer = Customer::find()->andWhere(['like','name',$this->customer_name])->one(); + if ( !isset($customer)){ + $this->addError($attribute,"Vendég nem található"); + }else{ + $this->_customer = $customer; + } + + } + + public function sendEmail(){ + $newsletter = $this->newsletter; + $message = \Yii::$app->mailer->compose ( ); + + $replacePairs = [ + '{vendeg_neve}' => $this->_customer->name + ]; + + $mailBody = $newsletter->body; + $mailBody = strtr($mailBody, $replacePairs ); + $mailSubject = $newsletter->subject; + $mailSubject = strtr($mailSubject, $replacePairs ); + + $message + ->setFrom ( [ \Yii::$app->params['newsletter_from'] => Helper::getCompanyName() ]) + ->setTo ( [ + $this->email ]) + ->setHtmlBody( $mailBody ) + ->setSubject ( $mailSubject ) + ->send (); + } + +} \ No newline at end of file diff --git a/backend/views/customer/mail.php b/backend/views/customer/mail.php new file mode 100644 index 0000000..3092b07 --- /dev/null +++ b/backend/views/customer/mail.php @@ -0,0 +1,63 @@ + + +

Hírlevél küldése

+ +

+Hírlevél küldése minden vendégnek, aki +

+ +
+ + + + field($model,'subject')?> + + field($model, 'text')->widget(TinyMce::className(), [ + 'options' => ['rows' => 12], + // 'language' => 'en', + 'clientOptions' => [ + 'plugins' => [ + "advlist autolink lists link charmap print preview anchor", + "searchreplace visualblocks code fullscreen", + "insertdatetime media table contextmenu paste" + ], + 'toolbar' => "undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image" + ] + ]);?> + + + + + + field($model, 'address')->textInput(['maxlength' => true]) ?> + +
+ 'btn btn-success' ]) ?> +
+ + + +
diff --git a/backend/views/newsletter/_form.php b/backend/views/newsletter/_form.php new file mode 100644 index 0000000..f351a07 --- /dev/null +++ b/backend/views/newsletter/_form.php @@ -0,0 +1,39 @@ + +

+Az új hirlevelek következő nap hajnal 3-kor kerülnek kiküldésre +

+
+ + + + field($model,'subject')?> + + field($model, 'body')->widget(TinyMce::className(), [ + 'options' => ['rows' => 12], + // 'language' => 'en', + 'clientOptions' => [ + 'plugins' => [ + "advlist autolink lists link charmap print preview anchor", + "searchreplace visualblocks code fullscreen", + "insertdatetime media table contextmenu paste" + ], + 'toolbar' => "undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image" + ] + ]);?> + + +
+ isNewRecord ? Yii::t('common/newsletter', 'Mentés') : Yii::t('common/newsletter', 'Módosítás'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> +
+ + + +
diff --git a/backend/views/newsletter/_search.php b/backend/views/newsletter/_search.php new file mode 100644 index 0000000..c4bda09 --- /dev/null +++ b/backend/views/newsletter/_search.php @@ -0,0 +1,41 @@ + + + diff --git a/backend/views/newsletter/create.php b/backend/views/newsletter/create.php new file mode 100644 index 0000000..e4d8885 --- /dev/null +++ b/backend/views/newsletter/create.php @@ -0,0 +1,21 @@ +title = Yii::t('common/newsletter', 'Új hírlevél'); +$this->params['breadcrumbs'][] = ['label' => Yii::t('common/newsletter', 'Hírlevelek'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/backend/views/newsletter/index.php b/backend/views/newsletter/index.php new file mode 100644 index 0000000..af16b9c --- /dev/null +++ b/backend/views/newsletter/index.php @@ -0,0 +1,59 @@ +title = Yii::t('common/newsletter', 'Hírlevelek'); +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ render('_search', ['model' => $searchModel]); ?> + +

+ 'btn btn-success']) ?> +

+ + $dataProvider, + 'columns' => [ + + 'id_newsletter', + 'subject', + [ + 'attribute' => 'status', + 'value' => 'statusName' + ], + [ + 'attribute' => 'sent', + 'value' => 'sentName' + ], + 'sent_at:datetime', + 'created_at:datetime', + // 'updated_at', + + ['class' => 'yii\grid\ActionColumn', + 'buttons' =>[ + 'update' => function ($url, $model, $key) { + return $model->sent === Newsletter::$SENT_NOT + ? Html::a('Módosít', $url,['class' => 'btn btn-xs btn-success']) : ''; + }, + 'view' => function ($url, $model, $key) { + return Html::a('Részletek', $url,['class' => 'btn btn-xs btn-success']) ; + }, + 'delete' => function ($url, $model, $key) { + return $model->sent === Newsletter::$SENT_NOT ? Html::a('Törlés', $url,['class' => 'btn btn-xs btn-success']) : ''; + }, + ], + + ], + ], + ]); ?> + +
diff --git a/backend/views/newsletter/update.php b/backend/views/newsletter/update.php new file mode 100644 index 0000000..5d1a256 --- /dev/null +++ b/backend/views/newsletter/update.php @@ -0,0 +1,21 @@ +title = Yii::t('common/newsletter', 'Hírlevél módosítása'); +$this->params['breadcrumbs'][] = ['label' => Yii::t('common/newsletter', 'Hírlevelek'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = ['label' => $model->id_newsletter, 'url' => ['view', 'id' => $model->id_newsletter]]; +$this->params['breadcrumbs'][] = Yii::t('common/newsletter', 'Update'); +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/backend/views/newsletter/view.php b/backend/views/newsletter/view.php new file mode 100644 index 0000000..8706788 --- /dev/null +++ b/backend/views/newsletter/view.php @@ -0,0 +1,95 @@ +title = $model->id_newsletter; +$this->params['breadcrumbs'][] = ['label' => Yii::t('common/newsletter', 'Hírlevelek'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

Hírlevél részletei

+ + + sent != Newsletter::$SENT_TRUE){?> +

+ $model->id_newsletter], ['class' => 'btn btn-primary']) ?> + $model->id_newsletter], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => Yii::t('common/log', 'Are you sure you want to delete this item?'), + 'method' => 'post', + ], + ]) ?> +

+ + + $model, + 'attributes' => [ + 'id_newsletter', + [ + 'attribute' => 'status', + 'value' => $model->statusName + ], + [ + 'attribute' => 'sent', + 'value' => $model->sent == Newsletter::$SENT_NOT ? "Küldésre vár" : "Elküldve" + ], + 'sent_at:datetime', + 'created_at:datetime', + 'updated_at:datetime', + ], + ]) ?> +
+ +

Tárgy:

+
+

+ subject?> +

+
+

Üzenet

+
+ body ?> +
+ +

+Teszt üzenet küldése +

+

+ A küldés gombra kattintva úgy küldünk ki egy darab e-mailt, +

+

+ +
+ + Url::current()] + ); ?> + + field($testModel, 'customer_name') ?> + field($testModel, 'email') ?> + + +
+ [ 'btn btn-primary' ]]) ?> +
+ + + +
\ No newline at end of file diff --git a/common/config/params.php b/common/config/params.php index aaefd74..f453fef 100644 --- a/common/config/params.php +++ b/common/config/params.php @@ -47,5 +47,6 @@ return [ 'day' => 5, ] ], + 'newsletter_from' => 'noreply@fitnessadmin.hu' ]; diff --git a/common/mail/warn_expire.php b/common/mail/warn_expire.php index a76922b..bd5bced 100644 --- a/common/mail/warn_expire.php +++ b/common/mail/warn_expire.php @@ -1,6 +1,6 @@

Kedves customerName?>!

- Az alábbi bérleted day?> nap múlva lejár: + Tájékoztatjuk, hogy az alábbi bérlete day?> nap múlva lejár:

-Ha ismét egy ilyen bérletet szeretnél vásárolni, akkor legközelebb ne felejts el magaddal vinni ticketTypePriceBrutto?> Ft-ot amikor edzésre mész! -

-

-Üdvözlettel: + Üdvözlettel:

company ?>

+

+ Ez egy automatikus e-mail üzenet, amelyre nem tud válaszolni. +

-Tájékoztatunk, hogy ezen levél a tagsági kártyádat +Ezen levél a tagsági kártyáját kezelő company ?> nyivlántartó rendszerének értesítő üzenete, -így nem minősül hírlevélnek, e-mail címedet a company ?> nyilvántartó rendszerének +így nem minősül hírlevélnek, e-mail címét a company ?> nyilvántartó rendszerének adatbázisából a company ?> engedélyével értük el. -A megadott adatadat az adatvédelmi törvénynek (1992. évi LXIII. törvény) és a reklámtörvénynek (2008. évi XLVIII. törvény) megfelelően kezeljük. +A megadott adatait az adatvédelmi törvénynek (1992. évi LXIII. törvény) és a reklámtörvénynek (2008. évi XLVIII. törvény) megfelelően kezeljük.

\ No newline at end of file diff --git a/common/models/Log.php b/common/models/Log.php index b6a3e6b..1037e07 100644 --- a/common/models/Log.php +++ b/common/models/Log.php @@ -6,6 +6,7 @@ use Yii; use yii\helpers\Url; use yii\helpers\VarDumper; use common\models\BaseFitnessActiveRecord; +use yii\helpers\Console; /** * This is the model class for table "log". @@ -92,6 +93,15 @@ class Log extends BaseFitnessActiveRecord public static function info($message ){ self::log(['type' =>self::$TYPE_INFO, 'message' => $message]); } + + /** + * example + * Log::log([ + 'type' =>Log::$TYPE_LOGIN, + 'message' => $message + ]); + * @param unknown $config + */ public static function log( $config ){ $model = new Log($config); $model->app = \Yii::$app->name; diff --git a/common/models/Newsletter.php b/common/models/Newsletter.php new file mode 100644 index 0000000..162e65a --- /dev/null +++ b/common/models/Newsletter.php @@ -0,0 +1,86 @@ + 255] + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'id_newsletter' => Yii::t('common/newsletter', 'Hírlevél azonosító'), + 'subject' => Yii::t('common/newsletter', 'Tárgy'), + 'body' => Yii::t('common/newsletter', 'Szöveg'), + 'status' => Yii::t('common/newsletter', 'Státusz'), + 'sent' => Yii::t('common/newsletter', 'Elküldve'), + 'sent_at' => Yii::t('common/newsletter', 'Küldés ideje'), + 'created_at' => Yii::t('common/newsletter', 'Létrehozva'), + 'updated_at' => Yii::t('common/newsletter', 'Módosítva'), + ]; + } + + public static function statuses( ) { + return [ + self::$STATUS_ACTIVE => 'Aktív', + self::$STATUS_DELETED=> 'Törölve', + ]; + } + + public function getStatusName(){ + return Helper::getArrayValue(self::statuses(), $this->status, ""); + } + + public function getSentName(){ + if ( $this->sent == self::$SENT_NOT){ + return "Nincs elküldve"; + }else if ( $this->sent == self::$SENT_TRUE){ + return "Elküldve"; + }else{ + return ""; + } + } + +} diff --git a/composer.json b/composer.json index 291f694..31863aa 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,8 @@ "bower-asset/webcamjs": "^1.0", "mpdf/mpdf": "^6.0", "os/php-excel": "^2.1", - "phpoffice/phpexcel": "^1.8" + "phpoffice/phpexcel": "^1.8", + "2amigos/yii2-tinymce-widget": "~1.1" }, "require-dev": { "yiisoft/yii2-codeception": "*", diff --git a/composer.lock b/composer.lock index 858f7f3..6c59e44 100644 --- a/composer.lock +++ b/composer.lock @@ -4,9 +4,69 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "c484600811777b0032034033ae4414b9", - "content-hash": "f44617094989091a2f19c2feb2257d3a", + "hash": "f8904c887de6d8934d7e32a613a802b4", + "content-hash": "b1809c8690ea12eaadb899a9549ef697", "packages": [ + { + "name": "2amigos/yii2-tinymce-widget", + "version": "1.1.1", + "source": { + "type": "git", + "url": "https://github.com/2amigos/yii2-tinymce-widget.git", + "reference": "d58bad3ede450f86acd475fb4ecda982b980132b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/2amigos/yii2-tinymce-widget/zipball/d58bad3ede450f86acd475fb4ecda982b980132b", + "reference": "d58bad3ede450f86acd475fb4ecda982b980132b", + "shasum": "" + }, + "require": { + "tinymce/tinymce": ">=4", + "yiisoft/yii2": "~2.0.0" + }, + "require-dev": { + "phpunit/phpunit": "4.*" + }, + "type": "yii2-extension", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + }, + "asset-installer-paths": { + "bower-asset-library": "vendor/bower" + } + }, + "autoload": { + "psr-4": { + "dosamigos\\tinymce\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "2amigOS! Consulting Group", + "email": "hola@2amigos.us", + "homepage": "http://2amigos.us", + "role": "Developer" + } + ], + "description": "TinyMCE widget for Yii2.", + "homepage": "http://yiiwheels.com/extension/tinymce-widget", + "keywords": [ + "2amigos", + "extension", + "tinymce", + "widget", + "yii", + "yii 2", + "yii2" + ], + "time": "2015-03-28 21:53:43" + }, { "name": "almasaeed2010/adminlte", "version": "v2.3.2", @@ -2044,6 +2104,52 @@ ], "time": "2015-06-06 14:19:39" }, + { + "name": "tinymce/tinymce", + "version": "4.3.12", + "source": { + "type": "git", + "url": "https://github.com/tinymce/tinymce-dist.git", + "reference": "dfa88d1f6868aa80081f35f3bb0b8257181b6fdf" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/tinymce/tinymce-dist/zipball/dfa88d1f6868aa80081f35f3bb0b8257181b6fdf", + "reference": "dfa88d1f6868aa80081f35f3bb0b8257181b6fdf", + "shasum": "" + }, + "type": "component", + "extra": { + "component": { + "scripts": [ + "tinymce.js", + "plugins/*/plugin.js", + "themes/*/theme.js" + ], + "files": [ + "tinymce.min.js", + "plugins/*/plugin.min.js", + "themes/*/theme.min.js", + "skins/**" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-2.1" + ], + "description": "Web based JavaScript HTML WYSIWYG editor control.", + "homepage": "http://www.tinymce.com", + "keywords": [ + "editor", + "html", + "javascript", + "richtext", + "tinymce", + "wysiwyg" + ], + "time": "2016-05-10 11:15:05" + }, { "name": "yiisoft/yii2", "version": "2.0.6", diff --git a/console/controllers/DoorlogController.php b/console/controllers/DoorlogController.php index fa86223..fd58b0e 100644 --- a/console/controllers/DoorlogController.php +++ b/console/controllers/DoorlogController.php @@ -37,7 +37,7 @@ class DoorlogController extends Controller{ $log->id_card = 9719; $log->id_customer = 5559; $log->id_ticket_current = $ticket; - $log->direction = 7; + $log->direction = 3; $log->id_key = 1; $log->type = 0; $log->source_app = DoorLog::$SOURCE_APP_FITNESS_ADMIN; @@ -58,7 +58,7 @@ class DoorlogController extends Controller{ $log->id_card = 9719; $log->id_customer = 5559; $log->id_ticket_current = $ticket; - $log->direction = 5; + $log->direction = 1; $log->id_key = null; $log->type = 0; $log->source_app = DoorLog::$SOURCE_APP_FITNESS_ADMIN; diff --git a/console/controllers/TicketController.php b/console/controllers/TicketController.php index 2cb3b7d..89d1033 100644 --- a/console/controllers/TicketController.php +++ b/console/controllers/TicketController.php @@ -3,7 +3,6 @@ namespace console\controllers; use Yii; -use common\models; use yii\console\Controller; use common\models\Ticket; use common\models\Customer; @@ -11,6 +10,8 @@ use yii\db\Query; use yii\db\Expression; use common\components\WarnMailModel; use common\components\Helper; +use common\models\Newsletter; +use common\models\Log; class TicketController extends Controller { public function actionIndex() { @@ -64,6 +65,10 @@ class TicketController extends Controller { 'ticket.end' => new Expression ( 'DATE_ADD(CURDATE(),INTERVAL ' . $dayCount . ' DAY)' ) ] ); + $query->andWhere([ + ['<','ticket.usage_count' ,'ticket.max_usage_count'] + ]); + $recepients = $query->all (); \Yii::info ( "Bérlet lejár figyelmeztetés küldése: " . $dayCount . " nap múlva " @@ -97,4 +102,89 @@ class TicketController extends Controller { } } } + + + + public function actionDaily(){ + set_time_limit(0); + $this->actionWarnExpire(); + $this->actionNewsletter(); + } + + public function actionNewsletter(){ + set_time_limit(0); + $q1 = Newsletter::find(); + $q1->andWhere(['sent' => Newsletter::$SENT_NOT]); + $q1->andWhere(['status' => Newsletter::$STATUS_ACTIVE]); + + $newsletters = $q1->all(); + + if ( count($newsletters) == 0 ){ + \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']); + $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) )')]); + + + $customers = $q2->all(); + + \Yii::info("Hírlevél küldése " .count($customers) . " vendégnek!" ); + + $i = 0; + + foreach ($newsletters as $newsletter ){ + $i = 0; + foreach ($customers as $customer ){ + + try{ + $log = "Sending Newsletter"; + $log .="[id_newsletter=".$newsletter->id_newsletter ."]"; + $log .="[customer_email=" . $customer['customer_email'] . "]"; + \Yii::info($log); + $message = \Yii::$app->mailer->compose ( ); + + $replacePairs = [ + '{vendeg_neve}' => $customer['customer_name'] + ]; + + $mailBody = $newsletter->body; + $mailBody = strtr($mailBody, $replacePairs ); + $mailSubject = $newsletter->subject; + $mailSubject = strtr($mailSubject, $replacePairs ); + + $message + ->setFrom ( [ \Yii::$app->params['newsletter_from'] => Helper::getCompanyName() ]) + ->setTo ( [ + $customer['customer_email'] + ]) + ->setHtmlBody( $mailBody ) + ->setSubject ( $mailSubject ) + ->send (); + + }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'] ) ; + } + + $i++; + } + $newsletter->sent = Newsletter::$SENT_TRUE; + $newsletter->sent_at = Helper::getDateTimeString(); + $newsletter->save(false); + +// Log::log([ +// 'type' =>Log::$TYPE_LOGIN, +// 'message' => $message +// ]); + } + + } + + } \ No newline at end of file diff --git a/console/migrations/m160516_114454_add__customer_newsletter.php b/console/migrations/m160516_114454_add__customer_newsletter.php new file mode 100644 index 0000000..5cc0245 --- /dev/null +++ b/console/migrations/m160516_114454_add__customer_newsletter.php @@ -0,0 +1,30 @@ +addColumn("customer", "newsletter", "int default 1"); + } + + public function down() + { + echo "m160516_114454_add__customer_newsletter cannot be reverted.\n"; + + return false; + } + + /* + // Use safeUp/safeDown to run migration code within a transaction + public function safeUp() + { + } + + public function safeDown() + { + } + */ +} diff --git a/console/migrations/m160516_122708_add_newsletter.php b/console/migrations/m160516_122708_add_newsletter.php new file mode 100644 index 0000000..f3321d8 --- /dev/null +++ b/console/migrations/m160516_122708_add_newsletter.php @@ -0,0 +1,45 @@ +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('{{%newsletter}}', [ + 'id_newsletter' => $this->primaryKey(), + 'subject' => $this->string(), + 'body' => $this->text(), + 'status' => $this->integer(11), + 'sent' => $this->integer(), + 'sent_at' => $this->dateTime( ), + 'created_at' => $this->dateTime()->notNull(), + 'updated_at' => $this->dateTime()->notNull(), + ], $tableOptions); + } + + public function down() + { + echo "m160516_122708_add_newsletter cannot be reverted.\n"; + + return false; + } + + /* + // Use safeUp/safeDown to run migration code within a transaction + public function safeUp() + { + } + + public function safeDown() + { + } + */ +} diff --git a/frontend/controllers/CustomerController.php b/frontend/controllers/CustomerController.php index b22054d..ec7e635 100644 --- a/frontend/controllers/CustomerController.php +++ b/frontend/controllers/CustomerController.php @@ -114,6 +114,7 @@ class CustomerController extends Controller $model->country = "Magyarország"; $model->id_user = Yii::$app->user->id; $model->warn_mail_ticket_expire_enabled = 1; + $model->newsletter = 1; $receptionForm = new ReceptionForm(); $receptionForm->number = $number; diff --git a/frontend/models/CustomerCreate.php b/frontend/models/CustomerCreate.php index 7447fc0..c480424 100644 --- a/frontend/models/CustomerCreate.php +++ b/frontend/models/CustomerCreate.php @@ -33,6 +33,7 @@ use common\components\Helper; * @property string $updated_at * @property string $cardNumber * @property integer $warn_mail_ticket_expire_enabled + * @property integer $newsletter */ class CustomerCreate extends \common\models\Customer { @@ -109,7 +110,7 @@ class CustomerCreate extends \common\models\Customer [['photo_data'] ,'safe'], [['birth_place'] ,'safe'], [['mother_name'] ,'safe'], - [['warn_mail_ticket_expire_enabled'],'integer'] + [['warn_mail_ticket_expire_enabled','newsletter'],'integer'] // [['email','phone'], 'validateEmailOrPhoneRequired' ], ]; } diff --git a/frontend/models/CustomerUpdate.php b/frontend/models/CustomerUpdate.php index 35e821e..7dbabef 100644 --- a/frontend/models/CustomerUpdate.php +++ b/frontend/models/CustomerUpdate.php @@ -118,7 +118,7 @@ class CustomerUpdate extends \common\models\Customer [['photo_data'] ,'safe'], [['birth_place'] ,'safe'], [['mother_name'] ,'safe'], - [['warn_mail_ticket_expire_enabled'],'integer'] + [['warn_mail_ticket_expire_enabled','newsletter'],'integer'] ]; } diff --git a/frontend/views/customer/_form_create.php b/frontend/views/customer/_form_create.php index 5d5f2b8..ef4c02e 100644 --- a/frontend/views/customer/_form_create.php +++ b/frontend/views/customer/_form_create.php @@ -148,6 +148,11 @@ use kartik\widgets\DatePicker; field($model, 'warn_mail_ticket_expire_enabled')->checkbox([ 'label'=> "Kér értesítést bérlet lejáratáról"]) ?> +
+
+ field($model, 'newsletter')->checkbox([ 'label'=> "Kér hírlevelet"]) ?> +
+
isNewRecord ? Yii::t('common/customer', 'Create') : Yii::t('common/customer', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> diff --git a/frontend/views/customer/_form_update.php b/frontend/views/customer/_form_update.php index 114a2ea..e79e08c 100644 --- a/frontend/views/customer/_form_update.php +++ b/frontend/views/customer/_form_update.php @@ -144,6 +144,11 @@ use yii\base\Widget;
+
+
+ field($model, 'newsletter')->checkbox([ 'label'=> "Kér hírlevelet"]) ?> +
+
isNewRecord ? Yii::t('common/customer', 'Create') : Yii::t('common/customer', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>