kasifi/newsletter-bundle

Symfony NewsletterBundle

安装: 15

依赖者: 0

建议者: 0

安全: 0

星标: 0

关注者: 1

分支: 11

语言:JavaScript

类型:symfony-bundle

1.0.2 2013-04-10 07:36 UTC

This package is not auto-updated.

Last update: 2024-09-24 03:44:00 UTC


README

一款优秀的Symfony2 Newsletter Bundle

特性

  • 不同模板
  • 处理不同渠道和分组
  • 电子邮件正文富文本编辑器
  • 创建新闻通讯向导
  • 处理正文块
  • 电子邮件消息排队
  • 统计数据
  • 每个新闻通讯都有不同的用户

沙盒

查看我们的沙盒: https://github.com/ibrows/IbrowsNewsletterBundleSandbox 演示安装: http://newsletterbundle.ibrhost.com (用户:demo / 密码:demo)

如何安装

将Bundle添加到您的composer.json文件中

// composer.json

{
    "require": {
        "ibrows/newsletter-bundle": "*"
    }
}

使用composer.phar从控制台安装Bundle

$ php composer.phar update ibrows/newsletter-bundle

在AppKernel.php中启用Bundle

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Stfalcon\Bundle\TinymceBundle\StfalconTinymceBundle(),
        new Ibrows\Bundle\NewsletterBundle\IbrowsNewsletterBundle(),
    );
}

配置

# app/config/ibrows_newsletter.yml

ibrows_newsletter:
  mandants:
    # generate a secure token for each mandant!
    default:    ThisTokenIsNotSoSecretChangeItdefault
    mandantA:   ThisTokenIsNotSoSecretChangeItMandantA
    mandantB:   ThisTokenIsNotSoSecretChangeItMandantB
  classes:
    # needed entities - see next step for creating them
    model:
      # most likely fos user
      user:         Ibrows\YourBundle\Entity\User
      # depends on the namespace you set at
      mandant:      Ibrows\YourBundle\Entity\Newsletter\Mandant
      newsletter:   Ibrows\YourBundle\Entity\Newsletter\Newsletter
      subscriber:   Ibrows\YourBundle\Entity\Newsletter\Subscriber
      design:       Ibrows\YourBundle\Entity\Newsletter\Design
      block:        Ibrows\YourBundle\Entity\Newsletter\Block
      group:        Ibrows\YourBundle\Entity\Newsletter\Group
      readlog:      Ibrows\YourBundle\Entity\Newsletter\Log\ReadLog
      sendlog:      Ibrows\YourBundle\Entity\Newsletter\Log\SendLog
      sendsettings: Ibrows\YourBundle\Entity\Newsletter\SendSettings
      mailjob:      Ibrows\YourBundle\Entity\Newsletter\MailJob

  filesystem:
      block:
        # where to store uploaded files (e.g. image uploads)
        directory:  %kernel.root_dir%/../web/uploads/block
        # absolute path to the uploaded files
        public:     /uploads/block
# app/config/routing.yml

# IbrowsNewsletter
ibrows_newsletter:
    resource: "@IbrowsNewsletterBundle/Controller/"
    type:     annotation
    prefix:   /newsletter
# app/config/stfalcon_tinymce.yml

stfalcon_tinymce:
  include_jquery: false
  tinymce_jquery: true
  textarea_class: "tinymce"
  # create own methods in your own RendererBridge and set here the icons and description for them
  tinymce_buttons:
    unsubscribelink:
      title: "Unsubscribe link"
      image: "http://placehold.it/30x30"
    now:
      title: "Current date"
      image: "http://placehold.it/30x30"
    gendertitle:
      title: "Gender title"
      image: "http://placehold.it/30x30"
    statisticlogreadimage:
      title: "Statistics image"
      image: "http://placehold.it/30x30"
    readonlinelink:
      title: "Read online link"
      image: "http://placehold.it/30x30"
  theme:
    simple:
      mode: "textareas"
      theme: "advanced"
      plugins: "fullscreen,table"
      theme_advanced_buttons2: "unsubscribelink,now,gendertitle,statisticlogreadimage,readonlinelink"
      #theme_advanced_buttons2: "tablecontrols"
# app/config/config.yml

imports:
    # ...
    - { resource: stfalcon_tinymce.yml }
    - { resource: ibrows_newsletter.yml }

添加NoStreamBlob DBAL类型

# app/config/config.yml

# Doctrine Configuration
    doctrine:
        dbal:
            types:
                nostreamblob: Ibrows\Bundle\NewsletterBundle\DBAL\Types\NoStreamBlobType

配置mandants

允许的mandants已在ibrows_newsletter.mandants下定义在ibrows_newsletter.yml中。可以运行每个mandant在单独的数据库上。为此,我们需要通知doctrine关于不同的连接

# app/config/config.yml

# Doctrine Configuration
doctrine:
    dbal:
        # ...
        connections:
            default:
                driver:   %database_driver%
                host:     %database_host%
                port:     %database_port%
                dbname:   %database_name%
                user:     %database_user%
                password: %database_password%
                charset:  UTF8
            mandantA:
                driver:   %database_driver_mandanta%
                host:     %database_host_mandanta%
                port:     %database_port_mandanta%
                dbname:   %database_name_mandanta%
                user:     %database_user_mandanta%
                password: %database_password_mandanta%
                charset:  UTF8
            mandantB:
                driver:   %database_driver_mandantb%
                host:     %database_host_mandantb%
                port:     %database_port_mandantb%
                dbname:   %database_name_mandantb%
                user:     %database_user_mandantb%
                password: %database_password_mandantb%

    orm:
        # ...
        entity_managers:
            default:
                connection: default
                mappings:
                    YourBundle: ~
                    # FOSUserBundle: ~
                    # ...
            mandantA:
                connection: mandantA
                mappings:
                    ibrows_newsletter:
                        type: annotation
                        prefix: YourBundle\Entity\Newsletter
                        dir: "%kernel.root_dir%/../src/Ibrows/YourBundle/Entity/Newsletter"
                        is_bundle: false
            mandantB:
                connection: mandantB
                mappings:
                    ibrows_newsletter:
                        type: annotation
                        prefix: YourBundle\Entity\Newsletter
                        dir: "%kernel.root_dir%/../src/Ibrows/YourBundle/Entity/Newsletter"
                        is_bundle: false

连接设置

# app/config/parameters.yml

parameters:
    database_driver:   pdo_mysql
    database_host:     127.0.0.1
    database_port:     ~
    database_name:     newslettersandbox
    database_user:     user
    database_password: pass

    database_driver_mandanta:   pdo_mysql
    database_host_mandanta:     127.0.0.1
    database_port_mandanta:     ~
    database_name_mandanta:     newslettersandbox_mandanta
    database_user_mandanta:     user
    database_password_mandanta: pass

    database_driver_mandantb:   pdo_mysql
    database_host_mandantb:     127.0.0.1
    database_port_mandantb:     ~
    database_name_mandantb:     newslettersandbox_mandantb
    database_user_mandantb:     user
    database_password_mandantb: pass

启用已配置的mandants

# create the databases
$ php app/console doctrine:schema:create --em default
$ php app/console doctrine:schema:create --em mandantA
$ php app/console doctrine:schema:create --em mandantB

# enable the mandants (insert them in the defined database - already existings will be ignored)
$ php app/console ibrows:newsletter:mandants:enable

生成所需的实体

$ php app/console ibrows:newsletter:entities:generate Ibrows\\YourBundle\\Entity

增强用户类 - 实现 MandantUserInterface

此概念背后的想法是用户实体通过symfony安全组件进行认证(最有可能始终存储在默认连接 - 数据库中)。现在,该实体需要实现MandantUserInterface,以便IbrowsNewsletterBundle知道应使用哪个mandant。

# YourBundle\Entity\User (e.g. FOSUser implementation)

<?php

namespace YourBundle\Entity;

use FOS\UserBundle\Entity\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;

use Ibrows\Bundle\NewsletterBundle\Model\User\MandantUserInterface;

/**
 * @ORM\Entity
 * @ORM\Table(name="fos_user")
 */
class User extends BaseUser implements MandantUserInterface
{
	/**
	 * @ORM\Id
	 * @ORM\Column(type="integer")
	 * @ORM\GeneratedValue(strategy="AUTO")
	 */
	protected $id;

	/**
	 * @ORM\Column(type="string", nullable=true)
	 */
	protected $mandant;

    /**
     * @return string
     */
    public function getMandant()
	{
		return $this->mandant;
	}
}

将来自默认连接的用户(例如FOSUser)与mandant关联

    UPDATE `fos_user` SET mandant = "default" WHERE username = "YourUsername";
    UPDATE `fos_user` SET mandant = "mandantA" WHERE username = "YourUsernameA";
    UPDATE `fos_user` SET mandant = "mandantB" WHERE username = "YourUsernameB";

启动

  • 在浏览器中打开您的项目
  • 使用具有有效mandant的用户进行认证
  • 打开 /newsletter (app_dev.php/newsletter)
  • 创建设计
  • 创建新闻通讯
  • 享受乐趣

定制

  • 实现自己的GenderTitleStrategy以设置正确的称呼
  • 实现自己的RendererBridge以提供更多方法