71 lines
1.5 KiB
PHP
71 lines
1.5 KiB
PHP
<?php
|
|
namespace Westdc\Mail;
|
|
|
|
use Zend\ServiceManager\ServiceManager;
|
|
use Zend\ServiceManager\ServiceManagerAwareInterface;
|
|
|
|
class Template implements ServiceManagerAwareInterface
|
|
{
|
|
protected $serviceManager;
|
|
|
|
private $db;
|
|
|
|
public function setServiceManager(ServiceManager $serviceManager)
|
|
{
|
|
$this->serviceManager = $serviceManager;
|
|
|
|
$this->init();
|
|
|
|
return $this;
|
|
}
|
|
|
|
private function init()
|
|
{
|
|
$dbService = $this->serviceManager->get('Db');
|
|
$this->db = $dbService->getPdo();
|
|
|
|
}
|
|
|
|
public function fetchAll()
|
|
{
|
|
$sql='SELECT * FROM emailtext';
|
|
$rs=$this->db->query($sql);
|
|
return $rs->fetchAll(\PDO::FETCH_ASSOC);
|
|
}
|
|
|
|
public function insert($data,$id=0)
|
|
{
|
|
if($this->fetch($data['template']))
|
|
{
|
|
return"该邮件模板已经存在!";
|
|
}
|
|
|
|
$dbhService = $this->serviceManager->get('Db');
|
|
$dbh = $dbhService->getDbh();
|
|
|
|
if(empty($data['subject']))
|
|
{
|
|
$data['subject']='未命名模板';
|
|
}
|
|
|
|
// 替换邮件内容中的'为''
|
|
$data['body']=str_replace("'","''",$data['body']);
|
|
|
|
$rs = $dbh->insert('emailtext',$data,1);
|
|
return $rs;
|
|
}
|
|
|
|
public function fetch($key)
|
|
{
|
|
if(is_numeric($key))
|
|
{
|
|
$sql="SELECT * FROM emailtext WHERE id=$key";
|
|
}else
|
|
{
|
|
$sql="SELECT * FROM emailtext WHERE template='$key'";
|
|
}
|
|
|
|
$rs=$this->db->query($sql);
|
|
return $rs->fetch();
|
|
}
|
|
} |