add newsletter changes

This commit is contained in:
2016-05-26 08:50:10 +02:00
parent 07d5041126
commit 1fed67a650
16 changed files with 335 additions and 34 deletions

View File

@@ -114,7 +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;
$model->newsletter = 0;
$receptionForm = new ReceptionForm();
$receptionForm->number = $number;

View File

@@ -17,6 +17,7 @@ use common\components\Helper;
use common\models\Log;
use common\models\Customer;
use yii\web\NotFoundHttpException;
use frontend\models\SubscribeForm;
/**
* Site controller
@@ -181,6 +182,8 @@ class SiteController extends Controller
public function actionNewsletterUnsubscribe($id,$token)
{
$this->layout = "main-nologin";
$customer = Customer::find()
->andWhere(['id_customer' => $id ])
@@ -196,8 +199,59 @@ class SiteController extends Controller
$customer->newsletter_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
]);
return $this->render("unsubscribe");
}
public function actionNewsletterSubscribe($id,$token)
{
$this->layout = "main-nologin";
$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() ) {
$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
]);
return $this->redirect(["newsletter-subscribe-success"]);
}
return $this->render("subscribeform",['model' => $model]);
}
public function actionNewsletterSubscribeSuccess( )
{
$this->layout = "main-nologin";
return $this->render("subscribe");
}
/**
* Signs user up.

View File

@@ -110,7 +110,7 @@ class CustomerCreate extends \common\models\Customer
[['photo_data'] ,'safe'],
[['birth_place'] ,'safe'],
[['mother_name'] ,'safe'],
[['warn_mail_ticket_expire_enabled','newsletter'],'integer']
[['warn_mail_ticket_expire_enabled' ],'integer']
// [['email','phone'], 'validateEmailOrPhoneRequired' ],
];
}

View File

@@ -118,7 +118,7 @@ class CustomerUpdate extends \common\models\Customer
[['photo_data'] ,'safe'],
[['birth_place'] ,'safe'],
[['mother_name'] ,'safe'],
[['warn_mail_ticket_expire_enabled','newsletter'],'integer']
[['warn_mail_ticket_expire_enabled' ],'integer']
];
}

View File

@@ -0,0 +1,53 @@
<?php
namespace frontend\models;
use Yii;
use yii\base\Model;
/**
* ContactForm is the model behind the contact form.
*/
class SubscribeForm extends Model
{
public $idCustomer;
public $token;
public $subscribe;
public $customer;//input constructor param
/**
* @inheritdoc
*/
public function rules()
{
return [
// name, email, subject and body are required
[['subscribe', 'token', 'idCustomer' ], 'safe'],
[['subscribe' ], 'required' ],
[['subscribe' ], 'validateSubscribe' ,'skipOnEmpty' => false, 'skipOnError' => false ],
];
}
public function validateSubscribe($attr,$param){
if ( $this->subscribe != '1'){
echo "subscribe failed";
$this->addError( "subscribe", "Feliratkozáshoz be kell jelölnie ezt a mezőt!");
}
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'subscribe' => 'Szeretnék hírlevelet kapni',
];
}
}

View File

@@ -148,11 +148,7 @@ use kartik\widgets\DatePicker;
<?= $form->field($model, 'warn_mail_ticket_expire_enabled')->checkbox([ 'label'=> "Kér értesítést bérlet lejáratáról"]) ?>
</div>
</div>
<div class='row'>
<div class='col-md-6'>
<?= $form->field($model, 'newsletter')->checkbox([ 'label'=> "Kér hírlevelet"]) ?>
</div>
</div>
<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? Yii::t('common/customer', 'Create') : Yii::t('common/customer', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>

View File

@@ -144,11 +144,7 @@ use yii\base\Widget;
</div>
</div>
<div class='row'>
<div class='col-md-6'>
<?= $form->field($model, 'newsletter')->checkbox([ 'label'=> "Kér hírlevelet"]) ?>
</div>
</div>
<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? Yii::t('common/customer', 'Create') : Yii::t('common/customer', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>

View File

@@ -0,0 +1,83 @@
<?php
/* @var $this \yii\web\View */
/* @var $content string */
use yii\helpers\Html;
use yii\bootstrap\Nav;
use yii\bootstrap\NavBar;
use yii\widgets\Breadcrumbs;
use frontend\assets\AppAsset;
use common\widgets\Alert;
use common\components\FrotnendMenuStructure;
use frontend\components\FrontendMenuStructure;
use kartik\widgets\AlertBlock;
use yii\helpers\Url;
use common\components\Helper;
AppAsset::register($this);
?>
<?php $this->beginPage() ?>
<!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>">
<head>
<meta charset="<?= Yii::$app->charset ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
<?= Html::csrfMetaTags() ?>
<title><?= Html::encode($this->title) ?></title>
<script>
var reception_card_url = '<?php echo Url::toRoute('customer/reception');?>';
</script>
<?php $this->head() ?>
</head>
<body>
<?php $this->beginBody() ?>
<div class="wrap">
<?php
NavBar::begin([
'brandLabel' => Helper::getCompanyName(),
'brandUrl' => Yii::$app->homeUrl,
'options' => [
'class' => 'navbar-inverse navbar-fixed-top',
],
]);
NavBar::end();
?>
<div class="container">
<?= Breadcrumbs::widget([
'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
]) ?>
<?= Alert::widget() ?>
<?= $content ?>
</div>
</div>
<footer class="footer" style="min-height: 60px; height: auto;">
<div class="container">
<div class="row">
<div class="col-md-12">
<p class="pull-left">&copy; <?= Yii::$app->name ?> <?= Yii::$app->params['version'] ?> Fitness - WebAdmin <?= date('Y') ?></p>
</div>
</div>
<div class="row">
<div class="col-md-12">
Ingyenesen használható alkalmazás.
Az oldalon szereplő adatok csak tájékoztató jellegűek.<br>
Az adatok helyességéért és igazságtartalmáért felelősséget nem vállalunk.<br>
Az oldal nem használható hivatalos adatforrásként.<br>
</div>
</div>
</div>
</footer>
<?php $this->endBody() ?>
</body>
</html>
<?php $this->endPage() ?>

View File

@@ -0,0 +1,12 @@
<?php
use common\components\Helper;
?>
<p>
Ön sikeresen feliratkozott a hírlevelünkre!
</p>
<p>
Köszönettel:
</p>
<p>
<b> <?php echo Helper::getCompanyName() ?></b>
</p>

View File

@@ -0,0 +1,40 @@
<?php
use yii\widgets\ActiveForm;
use yii\helpers\Html;
use common\components\Helper;
?>
<div class="key-form">
<p>
Kedves <?php echo $model->customer->name ?>!
</p>
<?php if ( empty($model->customer->email)) {?>
<p>
Ön nem adott meg e-mail címet. Ha szeretne feliratkozni a hírlevelünkre,
kérjük keressen bennünket személyesen valamilyik termünkben.
</p>
<p>
Köszönettel: <?php echo Helper::getCompanyName()?>
</p>
<?php }else{?>
<p>
Ha Ön is szeretné megkapni a <?php echo Helper::getCompanyName() ?> hírleveleit,
kérjük jelölje be az alább látható jelölőnégyzetett, és kattintson a feliratkozás gombra.
</p>
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'subscribe')->checkbox([])?>
<div class="form-group">
<?= Html::submitButton( Yii::t('frontend/key', 'Feliratkozás'), ['class' => 'btn btn-primary'])?>
</div>
<?php ActiveForm::end(); ?>
<?php }?>
</div>

View File

@@ -1 +1,10 @@
<?php
use common\components\Helper;
?>
Ön sikeresen leiratkozott a hírlevelünkről!
<p>
Köszönettel:
</p>
<p>
<b> <?php echo Helper::getCompanyName() ?></b>
</p>