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 ]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user