westdc-zf1/application/models/EmailText.php

81 lines
1.7 KiB
PHP
Raw Permalink Normal View History

2011-10-12 13:03:17 +00:00
<?php
class EmailText{
private $tmpid;
private $db;
private $data;
protected $tmpinfo;
2011-10-12 13:03:17 +00:00
function __construct($db,$id,$replace)
{
$this->db=$db;
$this->tmpid=$id;
$this->data=$replace;
$this->load();
2011-10-12 13:03:17 +00:00
}
protected function getinfo(){
if(is_numeric($this->tmpid))
$sql = "select * from emailtext where id='".$this->tmpid."'";
else
$sql = "select * from emailtext where template='".$this->tmpid."'";
2011-10-27 10:01:18 +00:00
$t=$this->db->getFetchMode();
$this->db->setFetchMode(Zend_Db::FETCH_ASSOC);
$rs = $this->db->query($sql);
2011-10-27 10:01:18 +00:00
$this->db->setFetchMode($t);
$this->tmpinfo = $rs->fetch();
}
2011-10-18 12:26:11 +00:00
public function load($body=''){
2011-10-12 13:03:17 +00:00
if(empty($this->tmpid))
{
return false;
}else{
if (empty($body))
{
$this->getinfo();
$body=$this->tmpinfo['body'];
}
if (empty($this->tmpinfo['subject']))
{
$this->getinfo();
}
2011-10-12 13:03:17 +00:00
if(!empty($body))
2011-10-12 13:03:17 +00:00
{
if(count($this->data)==0)
{
return false;
}
else
{
$patterns = array();
$replacements = array();
foreach($this->data as $k=>$v)
{
$patterns[]='/{'.$k.'}/i';
$replacements[]=$v;
}
ksort($patterns);
ksort($replacements);
$this->tmpinfo['body'] = preg_replace($patterns, $replacements, $body);
$this->tmpinfo['subject'] = preg_replace($patterns, $replacements, $this->tmpinfo['subject']);
return true;
2011-10-12 13:03:17 +00:00
}//count($this->data)
}
else
{
return false;
}
}//empty($this->tmpid)
}//function loadtmp
public function getBody() {
return $this->tmpinfo['body'];
}
public function getSubject() {
return $this->tmpinfo['subject'];
}
2011-10-12 13:03:17 +00:00
}