first commit
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: ondra
|
||||
* Date: 25.10.17
|
||||
* Time: 8:56.
|
||||
*/
|
||||
|
||||
namespace KupShop\ContentBundle\View;
|
||||
|
||||
use KupShop\KupShopBundle\Views\Traits\RequestTrait;
|
||||
use KupShop\KupShopBundle\Views\View;
|
||||
use KupShop\UserBundle\Util\UserConsent;
|
||||
use Query\Operator;
|
||||
|
||||
class NewsletterUnsubscribeView extends View
|
||||
{
|
||||
use RequestTrait;
|
||||
|
||||
protected $template = 'newsletter.unsubscribe.tpl';
|
||||
|
||||
private $userConsent;
|
||||
|
||||
public function __construct(UserConsent $userConsent)
|
||||
{
|
||||
$this->userConsent = $userConsent;
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return translate('unsubscribeTitle', 'newsletter');
|
||||
}
|
||||
|
||||
public function getBreadcrumbs()
|
||||
{
|
||||
return getReturnNavigation(-1, 'NO_TYPE', ['Newsletter']);
|
||||
}
|
||||
|
||||
public function getBodyVariables()
|
||||
{
|
||||
$vars = parent::getBodyVariables();
|
||||
|
||||
$return = $this->unsubscribe();
|
||||
if (is_string($return)) {
|
||||
$vars['unsubscribed'] = $return;
|
||||
}
|
||||
$vars['act'] = 'unsubscribe';
|
||||
|
||||
return $vars;
|
||||
}
|
||||
|
||||
public function unsubscribe()
|
||||
{
|
||||
$param = strtr($this->request->get('unsubscribe'), ' ', '+');
|
||||
$mails = explode(';', gzinflate(base64_decode($param)));
|
||||
wpj_debug(gzinflate(base64_decode($param)));
|
||||
|
||||
if (empty($mails) || !is_array($mails)) {
|
||||
addUserMessage(translate('errorInvalidLink', 'newsletter'));
|
||||
} else {
|
||||
$email = trim($this->request->get('email'));
|
||||
if (!empty($email)) {
|
||||
if (array_search($email, $mails) === false) {
|
||||
addUserMessage(translate('errorInvalidLink', 'newsletter'));
|
||||
} else {
|
||||
$user = sqlQueryBuilder()->select('id')->from('users')
|
||||
->where("get_news = 'Y'")
|
||||
->andWhere(Operator::equals(['email' => $email]))
|
||||
->execute()->fetch();
|
||||
if ($user) {
|
||||
$user_id = $user['id'];
|
||||
$this->userConsent->updateNewsletter($user_id, 'N', false);
|
||||
|
||||
return $email;
|
||||
} else {
|
||||
addUserMessage(replacePlaceholders(translate('errorNotSubscribed', 'newsletter'), ['EMAIL' => $email]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user