First step of converting legacy ExtraVar class to module

This commit is contained in:
Kijin Sung 2024-04-12 00:23:56 +09:00
parent 267aa9c397
commit dd06193a1d
9 changed files with 164 additions and 0 deletions

View file

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<module version="0.2">
<title xml:lang="ko">확장 변수</title>
<title xml:lang="en">Extra Input Fields</title>
<description xml:lang="ko">회원정보, 문서 등의 사용자 정의 입력 항목을 관리합니다.</description>
<description xml:lang="en">Manage custom input fields in member information, documents, etc.</description>
<version>RX_VERSION</version>
<date>RX_CORE</date>
<category>service</category>
<author link="https://rhymix.org">
<name xml:lang="ko">Rhymix</name>
<name xml:lang="en">Rhymix</name>
</author>
</module>

View file

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<module>
<actions>
<action name="dispExtravarAdminConfig" class="Controllers\Config" menu_name="extravar" menu_index="true" admin_index="true" />
<action name="procExtravarAdminInsertConfig" class="Controllers\Config" standalone="true" />
</actions>
<menus>
<menu name="extravar">
<title xml:lang="ko">확장 변수</title>
<title xml:lang="en">Extra Input Fields</title>
</menu>
</menus>
</module>

View file

@ -0,0 +1,11 @@
<?php
namespace Rhymix\Modules\Extravar\Controllers;
/**
* Base class for Extravar module.
*/
class Base extends \ModuleObject
{
}

View file

@ -0,0 +1,64 @@
<?php
namespace Rhymix\Modules\Extravar\Controllers;
use Context;
use ModuleController;
use ModuleModel;
use Rhymix\Framework\Exceptions\TargetNotFound;
use Rhymix\Framework\Storage;
/**
* Controller for module configuration by administrator.
*/
class Config extends Base
{
/**
* Display the config page.
*/
public function dispExtravarAdminConfig()
{
// Get current module config.
$config = ModuleModel::getModuleConfig($this->module) ?: new \stdClass;
Context::set('config', $config);
// Get the list of installed skins.
$skins = ModuleModel::getSkins($this->module_path);
Context::set('skin_list', $skins);
// Set admin template path.
$this->setTemplatePath($this->module_path . 'views');
$this->setTemplateFile('config.blade.php');
}
/**
* Save module config.
*/
public function procExtravarAdminInsertConfig()
{
// Get current module config.
$config = ModuleModel::getModuleConfig($this->module) ?: new \stdClass;
// Update the config object.
$vars = Context::getRequestVars();
$config->skin = trim($vars->skin ?? '');
if (!Storage::isDirectory(sprintf('%s/skins/%s/', rtrim($this->module_path, '/'), $config->skin)))
{
throw new TargetNotFound;
}
// Save the updated config.
$output = ModuleController::getInstance()->insertModuleConfig($this->module, $config);
if (!$output->toBool())
{
return $output;
}
// Redirect back to the config page.
$this->setMessage('success_updated');
$this->setRedirectUrl(Context::get('success_return_url') ?: getNotEncodedUrl([
'module' => 'admin',
'act' => 'dispExtravarAdminConfig',
]));
}
}

View file

@ -0,0 +1,11 @@
<?php
namespace Rhymix\Modules\Extravar\Controllers;
/**
* Install class for Extravar module.
*/
class Install extends Base
{
}

View file

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<skin version="0.2">
<title xml:lang="ko">기본 스킨</title>
<title xml:lang="en">Default Skin</title>
<description xml:lang="ko">기존 버전과 호환되는 확장변수 입력란 코드를 제공합니다.</description>
<description xml:lang="en">Provides input form codes compatible with older versions.</description>
<version>1.0</version>
<date>2024-04-01</date>
<author link="https://rhymix.org">
<name xml:lang="ko">Rhymix</name>
<name xml:lang="en">Rhymix</name>
</author>
</skin>

View file

@ -0,0 +1,30 @@
@include ('header.blade.php')
<form action="./" class="x_form-horizontal" method="post">
<input type="hidden" name="module" value="member" />
<input type="hidden" name="act" value="procExtravarAdminInsertConfig" />
<input type="hidden" name="success_return_url" value="{{ getUrl(['module' => 'admin', 'act' => $act]) }}" />
<input type="hidden" name="xe_validator_id" value="modules/extravar/views/config/1" />
@if ($XE_VALIDATOR_MESSAGE && $XE_VALIDATOR_ID === 'modules/extravar/views/config/1')
<div class="message {{ $XE_VALIDATOR_MESSAGE_TYPE }}">
<p>{{ $XE_VALIDATOR_MESSAGE }}</p>
</div>
@endif
<div class="x_control-group">
<label class="x_control-label" for="skin">{{ $lang->skin }}</label>
<div class="x_controls">
<select id="skin" name="skin">
@foreach ($skin_list as $key => $val)
<option value="{{ $key }}" @selected(isset($config->skin) && $key === $config->skin)>
{{ $val->title }} ({{ $key }})
</option>
@endforeach
</select>
</div>
</div>
<div class="x_clearfix btnArea">
<span class="x_pull-right">
<button type="submit" class="x_btn x_btn-primary">{{ $lang->cmd_save }}</button>
</span>
</div>
</form>

View file

@ -0,0 +1,8 @@
<div class="x_page-header">
<h1>{{ $lang->extra_vars }}</h1>
</div>
<ul class="x_nav x_nav-tabs">
<li @class(['x_active' => $act === 'dispExtravarAdminConfig'])>
<a href="{{ getUrl(['module' => 'admin', 'act' => 'dispExtravarAdminConfig']) }}">{{ $lang->skin }}</a>
</li>
</ul>