Skip to content

added setting newsletter subscription via acp. #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions adm/style/event/acp_users_prefs_append.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<fieldset>
<legend>{{ lang('NEWSLETTER') }}</legend>
<dl>
<dt><label for="newsletter1">{{ lang('NEWSLETTER') }}{{ lang('COLON') }}</label><br><span>{{ lang('NEWSLETTER_EXPLAIN') }}</span></dt>
<dd>
<label for="newsletter1"><input type="radio" name="newsletter" id="newsletter1" value="1"{% if NEWSLETTER %} checked="checked"{% endif %} /> {{ lang('YES') }}</label>
<label for="newsletter0"><input type="radio" name="newsletter" id="newsletter0" value="0"{% if not NEWSLETTER %} checked="checked"{% endif %} /> {{ lang('NO') }}</label>
</dd>
</dl>
</fieldset>
54 changes: 51 additions & 3 deletions event/listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,12 @@ static public function getSubscribedEvents()
array('modify_email_template', 0),
array('post_newsletter_archive', 50), // Workaround for event since there is no _after event
),
'core.ucp_prefs_modify_common' => 'modify_ucp_prefs',
'core.ucp_prefs_personal_update_data' => 'update_ucp_newsletter',
'core.permissions' => 'add_permissions',
'core.ucp_prefs_modify_common' => 'modify_ucp_prefs',
'core.ucp_prefs_personal_update_data' => 'update_ucp_newsletter',
'core.permissions' => 'add_permissions',
'core.acp_users_prefs_modify_data' => 'acp_users_newsletter_settings_get',
'core.acp_users_prefs_modify_template_data' => 'acp_profile_newsletter_template',
'core.acp_users_prefs_modify_sql' => 'acp_profile_newsletter_set',
);
}

Expand Down Expand Up @@ -290,4 +293,49 @@ public function update_ucp_newsletter($event)
'user_allow_newsletter' => $this->request->variable('newsletter', (bool) $this->user->data['user_allow_newsletter']),
);
}

public function acp_users_newsletter_settings_get($event)
{
$data = $event['data'];
$user_row = $event['user_row'];
$data = array_merge($data, array(
'user_allow_newsletter' => $this->request->variable('newsletter', (bool) $user_row['user_allow_newsletter']),
));
$event['data'] = $data;
}

/**
* Assign template data in the ACP
*
* @param object $event The event object
* @return null
* @access public
*/
public function acp_profile_newsletter_template($event)
{
$this->user->add_lang_ext('phpbbde/newsletter', 'common');
$data = $event['data'];
$user_prefs_data = $event['user_prefs_data'];
$user_prefs_data = array_merge($user_prefs_data, array(
'NEWSLETTER' => $data['user_allow_newsletter'],
));
$event['user_prefs_data'] = $user_prefs_data;
}

/**
* Add user options' state into the sql_array
*
* @param object $event The event object
* @return null
* @access public
*/
public function acp_profile_newsletter_set($event)
{
$data = $event['data'];
$sql_ary = $event['sql_ary'];
$sql_ary = array_merge($sql_ary, array(
'user_allow_newsletter' => $this->request->variable('newsletter', (bool) $event['data']['user_allow_newsletter']),
));
$event['sql_ary'] = $sql_ary;
}
}