81 lines
2 KiB
PHP
81 lines
2 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Класс сервиса = Упрощенный компонент
|
|
*/
|
|
namespace ctiso\Controller;
|
|
use ctiso\Path,
|
|
ctiso\Model\BaseMapper,
|
|
ctiso\File,
|
|
ctiso\Registry,
|
|
ctiso\Database\PDOStatement;
|
|
|
|
class Service
|
|
{
|
|
public $viewPath = [];
|
|
public $webPath = [];
|
|
public $config/*: Registry*/;
|
|
public $template;
|
|
public $templatePath;
|
|
public $COMPONENTS_WEB;
|
|
|
|
public $db;
|
|
|
|
public function getTemplatePath($name)
|
|
{
|
|
return Path::join($this->viewPath[0], 'templates', 'modern', $name);
|
|
}
|
|
|
|
public function getTemplateWebPath()
|
|
{
|
|
return Path::join($this->webPath[0], strtolower(get_class($this)), 'templates', 'modern');
|
|
}
|
|
|
|
/**
|
|
* @param string $name Имя модели
|
|
*/
|
|
private function getModelPath($name)
|
|
{
|
|
return Path::join ($this->config->get('system', 'path'), "model", $name . ".php");
|
|
}
|
|
|
|
/**
|
|
* Создает модель
|
|
* @param string $name
|
|
* @return BaseMapper
|
|
*/
|
|
public function getModel($name)
|
|
{
|
|
require_once ($this->getModelPath ($name));
|
|
$modelName = $name . "Mapper";
|
|
$model = new $modelName ();
|
|
$model->db = $this->db;
|
|
return $model;
|
|
}
|
|
|
|
public function options($key, $val, $res/*: PDOStatement*/) {
|
|
$result = [];
|
|
while($res->next()) {
|
|
$result[] = ['value' => $res->getInt($key), 'name' => $res->getString($val)];
|
|
}
|
|
return $result;
|
|
}
|
|
|
|
public function optionsPair($list, $selected = false) {
|
|
$result = [];
|
|
foreach ($list as $key => $value) {
|
|
$result [] = ['value' => $key, 'name' => $value, 'selected' => $key == $selected];
|
|
}
|
|
return $result;
|
|
}
|
|
|
|
function getInfo() {
|
|
$filename = Path::join($this->viewPath[0], 'install.json');
|
|
if (file_exists($filename)) {
|
|
$settings = json_decode(File::getContents($filename), true);
|
|
return $settings;
|
|
}
|
|
return [];
|
|
}
|
|
}
|
|
|