cethyworks / zopim-chat-bundle
此包已废弃且不再维护。未建议替代包。
将zopim聊天添加到您的symfony2应用程序
dev-master
2014-05-16 14:58 UTC
Requires
- php: >=5.3.2
- symfony/framework-bundle: ~2.0
This package is not auto-updated.
Last update: 2017-08-02 07:16:28 UTC
README
此扩展包可以在不修改模板的情况下,将zopim聊天 https://www.zopim.com/ 添加到您的symfony2应用程序。
功能
- 通过处理器启用聊天(明确设置条件以启用聊天)
- 发送zopim参数(明确设置发送给zopim的参数)
- 可选:当聊天未启用时注入“演示”模板
待办事项
- travis CI配置
- 配置测试
1. 安装
- 带依赖项
[ZopimChat]
git=https://github.com/Cethy/CethyworksZopimChatBundle.git
target=/bundles/Cethyworks/ZopimChatBundle
- 使用composer
[...]
2. 启用扩展包
在内核中启用扩展包
<?php // app/autoload.php $loader->registerNamespaces(array( // ... 'Cethyworks' => __DIR__.'/../vendor/bundles', ));
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new Cethyworks\ZopimChatBundle\CethyworksZopimChatBundle(), ); }
3. 配置(在app/config/config.yml中)
- 基本配置
cethyworks_zopim_chat:
account_id: {your_zopim_account_id}
- 高级配置
cethyworks_zopim_chat:
account_id: {your_zopim_account_id}
chat_handler: {your_service_name}
demo_template: 'fooBundle:bar:foobar.html.twig'
注意
您的zopim账户ID可以在"小部件定制"选项卡中找到
<!--Start of Zopim Live Chat Script--> <script type="text/javascript"> window.$zopim||(function(d,s){var z=$zopim=function(c){z._.push(c)},$=z.s= d.createElement(s),e=d.getElementsByTagName(s)[0];z.set=function(o){z.set. _.push(o)};z._=[];z.set._=[];$.async=!0;$.setAttribute('charset','utf-8'); $.src='//cdn.zopim.com/?{your_zopim_account_id}';z.t=+new Date;$. type='text/javascript';e.parentNode.insertBefore($,e)})(document,'script'); </script> <!--End of Zopim Live Chat Script-->
4. 进一步操作(处理器)
在“高级”配置下,您可以构建自己的ChatHandler,它必须实现Cethyworks\ZopimChatBundle\Handler\ChatHandlerInterface接口及其两个方法,isEnabled & getParameters。以下是一个示例
namespace foo\BarBundle\Handler; use Cethyworks\ZopimChatBundle\Handler\ChatHandlerInterface; use Symfony\Component\Security\Core\SecurityContext; class ChatHandler implements ChatHandlerInterface { /** * @var type SecurityContext */ protected $securityContext; public function __construct(SecurityContext $securityContext) { $this->securityContext = $securityContext; } public function isEnabled() { return 'premium' == $this->getUser()->getType(); } public function getParameters() { $user = $this->getUser(); return array( 'firstname' => $user->getFirstname(), 'email' => $user->getEmail(), 'notes' => $this->generateNotes($user) ); } /** * @return Foo/UserBundle/User */ protected function getUser() { if(null === $token = $this->securityContext->getToken()) { return null; } return $token->getUser(); } }
5. 当聊天禁用时显示演示模板()
如果您填写了demo_template
选项,则当聊天禁用时,扩展包将自动将其注入到html标签的末尾。模板必须是“twigable”,这是唯一的限制。