This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
khosb/modules/email/classes/Model/Email/Template/Translate.php

51 lines
1.2 KiB
PHP
Raw Normal View History

2013-10-10 02:44:53 +00:00
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
*
* @package Email
* @category Models
* @author Deon George
* @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class Model_Email_Template_Translate extends ORM {
2013-10-10 02:44:53 +00:00
// This module doesnt keep track of column updates automatically
protected $_created_column = FALSE;
protected $_updated_column = FALSE;
protected $_belongs_to = array(
'template'=>array('model'=>'Email_Template','foreign_key'=>'email_template_id'),
);
2013-11-28 06:41:34 +00:00
protected $_has_one = array(
'language'=>array('foreign_key'=>'id'),
);
protected $_save_message = TRUE;
public function complete($data,$column) {
$output = $this->display($column);
foreach ($this->variables($column) as $k => $v)
$output = str_replace('$'.$v.'$',$data[$v],$output);
return $output;
}
2013-10-10 02:44:53 +00:00
public function variables($field) {
$results = array();
$matches = array();
preg_match_all('/\$([A-Z0-9_]+)\$/U',$this->$field,$matches,PREG_OFFSET_CAPTURE);
2013-10-10 02:44:53 +00:00
foreach ($matches[1] as $k => $v)
$results[$v[1]] = $v[0];
$results = array_unique($results);
asort($results);
return $results;
}
}
?>