rendering of edit subscription form
This commit is contained in:
@ -1,7 +1,13 @@
|
||||
<?php
|
||||
namespace MailPoet\Router;
|
||||
use \MailPoet\Util\Security;
|
||||
|
||||
use \MailPoet\Models\Subscriber;
|
||||
use \MailPoet\Models\CustomField;
|
||||
use \MailPoet\Models\Setting;
|
||||
use \MailPoet\Models\Segment;
|
||||
use \MailPoet\Util\Helpers;
|
||||
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
@ -145,10 +151,124 @@ class Router {
|
||||
);
|
||||
break;
|
||||
case 'edit':
|
||||
$subscriber = $subscriber
|
||||
->withCustomFields()
|
||||
->withSubscriptions();
|
||||
$content = 'TODO';
|
||||
if($subscriber !== false) {
|
||||
$subscriber = $subscriber
|
||||
->withCustomFields()
|
||||
->withSubscriptions();
|
||||
|
||||
$custom_fields = array_map(function($custom_field) use($subscriber) {
|
||||
$custom_field->id = 'cf_'.$custom_field->id;
|
||||
$custom_field = $custom_field->asArray();
|
||||
$custom_field['params']['value'] = $subscriber->{$custom_field['id']};
|
||||
return $custom_field;
|
||||
}, CustomField::findMany());
|
||||
|
||||
$segment_ids = Setting::getValue('subscription.segments', array());
|
||||
if(!empty($segment_ids)) {
|
||||
$segments = Segment::getPublic()
|
||||
->whereIn('id', $segment_ids)
|
||||
->findMany();
|
||||
} else {
|
||||
$segments = Segment::getPublic()->findMany();
|
||||
}
|
||||
|
||||
$subscribed_segment_ids = Helpers::arrayColumn(
|
||||
$subscriber->subscriptions, 'id'
|
||||
);
|
||||
|
||||
$segments = array_map(function($segment) use($subscribed_segment_ids) {
|
||||
return array(
|
||||
'id' => $segment->id,
|
||||
'name' => $segment->name,
|
||||
'is_checked' => in_array($segment->id, $subscribed_segment_ids)
|
||||
);
|
||||
}, $segments);
|
||||
|
||||
$fields = array(
|
||||
array(
|
||||
'id' => 'email',
|
||||
'type' => 'text',
|
||||
'params' => array(
|
||||
'label' => __('Email'),
|
||||
'required' => true,
|
||||
'value' => $subscriber->email
|
||||
)
|
||||
),
|
||||
array(
|
||||
'id' => 'first_name',
|
||||
'type' => 'text',
|
||||
'params' => array(
|
||||
'label' => __('First name'),
|
||||
'value' => $subscriber->first_name
|
||||
)
|
||||
),
|
||||
array(
|
||||
'id' => 'last_name',
|
||||
'type' => 'text',
|
||||
'params' => array(
|
||||
'label' => __('Last name'),
|
||||
'value' => $subscriber->last_name
|
||||
)
|
||||
),
|
||||
array(
|
||||
'id' => 'status',
|
||||
'type' => 'select',
|
||||
'params' => array(
|
||||
'label' => __('Status'),
|
||||
'values' => array(
|
||||
array(
|
||||
'value' => array(
|
||||
Subscriber::STATUS_SUBSCRIBED => __('Subscribed')
|
||||
),
|
||||
'is_checked' => (
|
||||
$subscriber->status === Subscriber::STATUS_SUBSCRIBED
|
||||
)
|
||||
),
|
||||
array(
|
||||
'value' => array(
|
||||
Subscriber::STATUS_UNSUBSCRIBED => __('Unsubscribed')
|
||||
),
|
||||
'is_checked' => (
|
||||
$subscriber->status === Subscriber::STATUS_UNSUBSCRIBED
|
||||
)
|
||||
),
|
||||
array(
|
||||
'value' => array(
|
||||
Subscriber::STATUS_UNCONFIRMED => __('Unconfirmed')
|
||||
),
|
||||
'is_checked' => (
|
||||
$subscriber->status === Subscriber::STATUS_UNCONFIRMED
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$form = array_merge(
|
||||
$fields,
|
||||
$custom_fields,
|
||||
array(
|
||||
array(
|
||||
'id' => 'segment',
|
||||
'type' => 'segment',
|
||||
'params' => array(
|
||||
'label' => __('Your lists'),
|
||||
'values' => $segments
|
||||
)
|
||||
),
|
||||
array(
|
||||
'id' => 'submit',
|
||||
'type' => 'submit',
|
||||
'params' => array(
|
||||
'label' => __('Subscribe!')
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$content = \MailPoet\Form\Renderer::renderBlocks($form);
|
||||
}
|
||||
break;
|
||||
case 'unsubscribe':
|
||||
$content = '<p>'.__("Great, you'll never hear from us again!").'</p>';
|
||||
|
Reference in New Issue
Block a user