add newsletter
This commit is contained in:
@@ -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 ]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
146
backend/controllers/NewsletterController.php
Normal file
146
backend/controllers/NewsletterController.php
Normal file
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
|
||||
namespace backend\controllers;
|
||||
|
||||
use Yii;
|
||||
use common\models\Newsletter;
|
||||
use backend\models\NewsletterSearch;
|
||||
use yii\web\Controller;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use yii\filters\VerbFilter;
|
||||
use common\models\Customer;
|
||||
use backend\models\NewsletterTestForm;
|
||||
use common\components\Helper;
|
||||
|
||||
/**
|
||||
* NewsletterController implements the CRUD actions for Newsletter model.
|
||||
*/
|
||||
class NewsletterController extends Controller
|
||||
{
|
||||
public function behaviors()
|
||||
{
|
||||
return [
|
||||
'verbs' => [
|
||||
'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.');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user