Commit 67361e58 authored by Олег Гиммельшпах's avatar Олег Гиммельшпах

Merge branch 'master' of git.task-on.com:ktask/task-on.com

parents d370708d f9f8aad5
<?php
namespace common\modules\messageTemplate\components;
use common\modules\messageTemplate\models\MessageTemplate;
use yii\web\NotFoundHttpException;
/**
* Class Templates
* @package common\modules\messageTemplate\components
*
* @property MessageTemplate $template
*/
class Templates {
protected $template;
/**
* @param $id
* @param array $values
* @throws \yii\web\NotFoundHttpException
*/
public function __construct($id, $values=array()){
/** @var MessageTemplate $model */
$model = MessageTemplate::findOne($id);
if ($model===null)
throw new NotFoundHttpException('The requested page does not exist.');
$this->template = $model->template;
$this->setValues($values);
}
protected function setValues($values) {
$pattern = '/\{(.*?)\}/';
preg_match_all($pattern, $this->template, $result, PREG_PATTERN_ORDER);
$pseudo_vars = $result[1];
foreach($pseudo_vars as $key) {
if (array_key_exists($key, $values)) {
$this->template = str_replace('{'.$key.'}', $values[$key], $this->template);
}
if (array_key_exists(mb_strtolower($key), $values)) {
$this->template = str_replace('{'.$key.'}', $values[mb_strtolower($key)], $this->template);
}
}
}
/**
* @return MessageTemplate
*/
public function getTemplate(){
return $this->template;
}
}
\ No newline at end of file
......@@ -25,16 +25,10 @@ class TemplateAdminController extends AdminController {
'Manage' => 'Управление шаблонами',
'Create' => 'Добавление шаблона',
'Update' => 'Редактирование шаблона',
'Delete' => 'Удаление шаблона',
'Testing' => 'Test'
'Delete' => 'Удаление шаблона'
];
}
public function actionTesting(){
$object=new Templates(2);
echo $object->getTemplate();
}
/**
* @return string
*/
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment