예제 #1
0
 public function getWelcomeTemplateOptions()
 {
     $codes = array_keys(MailTemplate::listAllTemplates());
     $result = ['' => '- ' . Lang::get('rainlab.user::lang.settings.no_mail_template') . ' -'];
     $result += array_combine($codes, $codes);
     return $result;
 }
예제 #2
0
 /**
  * Sets mail blocking preferences for a user. Eg:
  *
  * MailBlocker::setPreferences($user, [acme.blog::post.new_reply => 0])
  *
  * MailBlocker::setPreferences($user, [acme.blog::post.new_reply => 0], [fillable => [acme.blog::post.new_reply]])
  *
  * MailBlocker::setPreferences($user, [template_alias => 0], [aliases => [template_alias => acme.blog::post.new_reply]])
  *
  * Supported options:
  * - aliases: Alias definitions, with alias as key and template as value.
  * - fillable: An array of expected templates, undefined templates are ignored.
  * - verify: Only allow mail templates that are registered in the system.
  *
  * @param  array $templates Template name as key and boolean as value. If false, template is blocked. 
  * @param  RainLab\User\Models\User $user
  * @param  array $options
  * @return void
  */
 public static function setPreferences($user, $templates, $options = [])
 {
     $templates = (array) $templates;
     if (!$user) {
         throw new Exception('A user must be provided for MailBlocker::setPreferences');
     }
     extract(array_merge(['aliases' => [], 'fillable' => [], 'verify' => false], $options));
     if ($aliases) {
         $fillable = array_merge($fillable, array_values($aliases));
         $templates = array_build($templates, function ($key, $value) use($aliases) {
             return [array_get($aliases, $key, $key), $value];
         });
     }
     if ($fillable) {
         $templates = array_intersect_key($templates, array_flip($fillable));
     }
     if ($verify) {
         $existing = MailTemplate::listAllTemplates();
         $templates = array_intersect_key($templates, $existing);
     }
     $currentBlocks = array_flip(static::checkAllForUser($user));
     foreach ($templates as $template => $value) {
         // User wants to receive mail and is blocking
         if ($value && isset($currentBlocks[$template])) {
             static::removeBlock($template, $user);
         } elseif (!$value && !isset($currentBlocks[$template])) {
             static::addBlock($template, $user);
         }
     }
 }