<?php defined('SYSPATH') or die('No direct access allowed.');

/**
 *
 * @package    OSB
 * @subpackage EmailTemplate
 * @category   Models
 * @author     Deon George
 * @copyright  (c) 2010 Deon George
 * @license    http://dev.leenooks.net/license.html
 */
class Model_Email_Template_Translate extends ORMOSB {
	// This module doesnt keep track of column updates automatically
	protected $_created_column = FALSE;
	protected $_updated_column = FALSE;

	public function variables($field) {
		$results = array();
		$matches = array();

		preg_match_all('/%([A-Z0-9_]+)%/U',$this->$field,$matches,PREG_OFFSET_CAPTURE);

		foreach ($matches[1] as $k => $v)
			$results[$v[1]] = $v[0];

		$results = array_unique($results);
		asort($results);

		return $results;
	}

	public function resolve($data,$column) {
		$output = $this->display($column);

		foreach ($this->variables($column) as $k => $v)
			$output = str_replace('%'.$v.'%',$data[$v],$output);

		return $output;
	}
}
?>
