westdc-zf1/application/models/EmailText.php

75 lines
1.5 KiB
PHP
Raw 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
2011-10-28 12:52:38 +00:00
$sql = "select * from emailtext where template='".$this->tmpid."'";
$t=$this->db->getFetchMode();
$this->db->setFetchMode(Zend_Db::FETCH_ASSOC);
$rs = $this->db->query($sql);
2011-10-28 12:52:38 +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'];
}
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);
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
}