westdc-core/Westdc/Mail/Template.php

87 lines
1.9 KiB
PHP
Raw Normal View History

2014-12-19 06:48:02 +00:00
<?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();
2014-12-19 10:23:38 +00:00
2014-12-19 06:48:02 +00:00
}
public function fetchAll()
{
$sql='SELECT * FROM emailtext';
$rs=$this->db->query($sql);
return $rs->fetchAll(\PDO::FETCH_ASSOC);
}
2014-12-19 10:23:38 +00:00
public function insert($data,$id=0)
{
$dbhService = $this->serviceManager->get('Db');
$dbh = $dbhService->getDbh();
if(empty($data['subject']))
{
$data['subject']='未命名模板';
}
2014-12-19 13:17:03 +00:00
// 替换邮件内容中的 ' 为 ''
2014-12-19 10:23:38 +00:00
$data['body']=str_replace("'","''",$data['body']);
$rs = $dbh->insert('emailtext',$data,1);
return $rs;
}
2014-12-19 13:17:03 +00:00
//删除邮件模板
public function del($id)
{
$sql = "DELETE FROM emailtext WHERE id=$id";
$rs = $this->db->exec($sql);
return $rs;
}
//更新邮件模板
public function update($table,$data,$id)
{
$dbhService = $this->serviceManager->get('Db');
$dbh = $dbhService->getDbh();
// 替换邮件内容中的 ' 为 ''
$data['body']=str_replace("'","''",$data['body']);
$rs = $dbh->update('emailtext',$data,"id=$id",1);
return $rs;
}
2014-12-19 10:23:38 +00:00
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();
}
2014-12-19 06:48:02 +00:00
}