Move non-member voting, vote canceling, and report canceling options from Board module to Document & Comment modules

This commit is contained in:
Kijin Sung 2023-07-05 22:27:17 +09:00
parent 103f5ce884
commit 3215631dfc
13 changed files with 454 additions and 192 deletions

View file

@ -11,34 +11,19 @@
*/
class CommentController extends Comment
{
/**
* Initialization
* @return void
*/
function init()
{
}
/**
* Action to handle recommendation votes on comments (Up)
* @return Object
*/
function procCommentVoteUp()
{
if($this->module_info->non_login_vote !== 'Y')
{
if(!Context::get('is_logged'))
{
throw new Rhymix\Framework\Exceptions\NotPermitted;
}
}
$comment_srl = Context::get('target_srl');
if(!$comment_srl)
{
throw new Rhymix\Framework\Exceptions\InvalidRequest;
}
// Check target comment.
$oComment = CommentModel::getComment($comment_srl);
if(!$oComment->isExists())
{
@ -48,11 +33,31 @@ class CommentController extends Comment
{
throw new Rhymix\Framework\Exceptions\NotPermitted;
}
// Check if voting is enabled.
$comment_config = ModuleModel::getModulePartConfig('comment', $oComment->get('module_srl'));
if($comment_config->use_vote_up === 'N')
{
throw new Rhymix\Framework\Exceptions\FeatureDisabled;
}
if(!Context::get('is_logged'))
{
if (isset($comment_config->allow_vote_non_member))
{
if ($comment_config->allow_vote_non_member !== 'Y')
{
throw new Rhymix\Framework\Exceptions\MustLogin;
}
}
else
{
$module_info = $this->module_info ?: ModuleModel::getModuleInfoByModuleSrl($oComment->get('module_srl'));
if (($module_info->non_login_vote ?? 'N') !== 'Y')
{
throw new Rhymix\Framework\Exceptions\MustLogin;
}
}
}
$point = 1;
$allow_same_ip = ($comment_config->allow_vote_from_same_ip ?? 'N') === 'Y';
@ -63,19 +68,13 @@ class CommentController extends Comment
function procCommentVoteUpCancel()
{
if($this->module_info->non_login_vote !== 'Y')
{
if(!Context::get('is_logged'))
{
throw new Rhymix\Framework\Exceptions\NotPermitted;
}
}
$comment_srl = Context::get('target_srl');
if(!$comment_srl)
{
throw new Rhymix\Framework\Exceptions\InvalidRequest;
}
// Check target comment.
$oComment = CommentModel::getComment($comment_srl);
if(!$oComment->isExists())
{
@ -90,8 +89,47 @@ class CommentController extends Comment
throw new Rhymix\Framework\Exception('failed_voted_canceled');
}
// Check if voting and canceling are enabled.
$comment_config = ModuleModel::getModulePartConfig('comment', $oComment->get('module_srl'));
$module_info = $this->module_info ?: ModuleModel::getModuleInfoByModuleSrl($oComment->get('module_srl'));
if (isset($comment_config->allow_vote_cancel))
{
if ($comment_config->allow_vote_cancel !== 'Y')
{
throw new Rhymix\Framework\Exceptions\FeatureDisabled;
}
}
else
{
if (($module_info->cancel_vote ?? 'N') !== 'Y')
{
throw new Rhymix\Framework\Exceptions\FeatureDisabled;
}
}
if(!Context::get('is_logged'))
{
if (isset($comment_config->allow_vote_non_member))
{
if ($comment_config->allow_vote_non_member !== 'Y')
{
throw new Rhymix\Framework\Exceptions\MustLogin;
}
}
else
{
if (($module_info->non_login_vote ?? 'N') !== 'Y')
{
throw new Rhymix\Framework\Exceptions\MustLogin;
}
}
}
$point = 1;
$output = $this->updateVotedCountCancel($comment_srl, $oComment, $point);
if(!$output->toBool())
{
return $output;
}
$output = new BaseObject();
$output->setMessage('success_voted_canceled');
@ -106,19 +144,13 @@ class CommentController extends Comment
*/
function procCommentVoteDown()
{
if($this->module_info->non_login_vote !== 'Y')
{
if(!Context::get('is_logged'))
{
throw new Rhymix\Framework\Exceptions\NotPermitted;
}
}
$comment_srl = Context::get('target_srl');
if(!$comment_srl)
{
throw new Rhymix\Framework\Exceptions\InvalidRequest;
}
// Check target comment.
$oComment = CommentModel::getComment($comment_srl);
if(!$oComment->isExists())
{
@ -128,11 +160,31 @@ class CommentController extends Comment
{
throw new Rhymix\Framework\Exceptions\NotPermitted;
}
// Check if voting is enabled.
$comment_config = ModuleModel::getModulePartConfig('comment', $oComment->get('module_srl'));
if($comment_config->use_vote_down === 'N')
{
throw new Rhymix\Framework\Exceptions\FeatureDisabled;
}
if(!Context::get('is_logged'))
{
if (isset($comment_config->allow_vote_non_member))
{
if ($comment_config->allow_vote_non_member !== 'Y')
{
throw new Rhymix\Framework\Exceptions\MustLogin;
}
}
else
{
$module_info = $this->module_info ?: ModuleModel::getModuleInfoByModuleSrl($oComment->get('module_srl'));
if (($module_info->non_login_vote ?? 'N') !== 'Y')
{
throw new Rhymix\Framework\Exceptions\MustLogin;
}
}
}
$point = -1;
$allow_same_ip = ($comment_config->allow_vote_from_same_ip ?? 'N') === 'Y';
@ -143,19 +195,13 @@ class CommentController extends Comment
function procCommentVoteDownCancel()
{
if($this->module_info->non_login_vote !== 'Y')
{
if(!Context::get('is_logged'))
{
throw new Rhymix\Framework\Exceptions\NotPermitted;
}
}
$comment_srl = Context::get('target_srl');
if(!$comment_srl)
{
throw new Rhymix\Framework\Exceptions\InvalidRequest;
}
// Check target comment.
$oComment = CommentModel::getComment($comment_srl);
if(!$oComment->isExists())
{
@ -170,8 +216,47 @@ class CommentController extends Comment
throw new Rhymix\Framework\Exception('failed_blamed_canceled');
}
// Check if voting and canceling are enabled.
$comment_config = ModuleModel::getModulePartConfig('comment', $oComment->get('module_srl'));
$module_info = $this->module_info ?: ModuleModel::getModuleInfoByModuleSrl($oComment->get('module_srl'));
if (isset($comment_config->allow_vote_cancel))
{
if ($comment_config->allow_vote_cancel !== 'Y')
{
throw new Rhymix\Framework\Exceptions\FeatureDisabled;
}
}
else
{
if (($module_info->cancel_vote ?? 'N') !== 'Y')
{
throw new Rhymix\Framework\Exceptions\FeatureDisabled;
}
}
if(!Context::get('is_logged'))
{
if (isset($comment_config->allow_vote_non_member))
{
if ($comment_config->allow_vote_non_member !== 'Y')
{
throw new Rhymix\Framework\Exceptions\MustLogin;
}
}
else
{
if (($module_info->non_login_vote ?? 'N') !== 'Y')
{
throw new Rhymix\Framework\Exceptions\MustLogin;
}
}
}
$point = -1;
$output = $this->updateVotedCountCancel($comment_srl, $oComment, $point);
if(!$output->toBool())
{
return $output;
}
$output = new BaseObject();
$output->setMessage('success_blamed_canceled');
@ -305,6 +390,7 @@ class CommentController extends Comment
throw new Rhymix\Framework\Exceptions\MustLogin;
}
// Check if the comment exists and is accessible to the current user.
$comment_srl = Context::get('target_srl');
if (!$comment_srl)
{
@ -319,10 +405,23 @@ class CommentController extends Comment
{
throw new Rhymix\Framework\Exceptions\NotPermitted;
}
$module_info = ModuleModel::getModuleInfoByModuleSrl($oComment->get('module_srl'));
if ($module_info->cancel_vote !== 'Y')
// Check if canceling is allowed.
$comment_config = ModuleModel::getModulePartConfig('comment', $oComment->get('module_srl'));
if (isset($comment_config->allow_declare_cancel))
{
throw new Rhymix\Framework\Exception('failed_declared_cancel');
if ($comment_config->allow_declare_cancel !== 'Y')
{
throw new Rhymix\Framework\Exception('failed_declared_cancel');
}
}
else
{
$module_info = ModuleModel::getModuleInfoByModuleSrl($oComment->get('module_srl'));
if (($module_info->cancel_vote ?? 'N') !== 'Y')
{
throw new Rhymix\Framework\Exception('failed_declared_cancel');
}
}
if (Context::get('success_return_url'))
@ -1949,9 +2048,18 @@ class CommentController extends Comment
$comment_config->allow_vote_from_same_ip = Context::get('allow_vote_from_same_ip');
if(!$comment_config->allow_vote_from_same_ip) $comment_config->allow_vote_from_same_ip = 'N';
$comment_config->allow_vote_cancel = Context::get('allow_vote_cancel');
if(!$comment_config->allow_vote_cancel) $comment_config->allow_vote_cancel = 'N';
$comment_config->allow_vote_non_member = Context::get('allow_vote_non_member');
if(!$comment_config->allow_vote_non_member) $comment_config->allow_vote_non_member = 'N';
$comment_config->allow_declare_from_same_ip = Context::get('allow_declare_from_same_ip');
if(!$comment_config->allow_declare_from_same_ip) $comment_config->allow_declare_from_same_ip = 'N';
$comment_config->allow_declare_cancel = Context::get('allow_declare_cancel');
if(!$comment_config->allow_declare_cancel) $comment_config->allow_declare_cancel = 'N';
$comment_config->declared_message = Context::get('declared_message');
if(!is_array($comment_config->declared_message)) $comment_config->declared_message = array();
$comment_config->declared_message = array_values($comment_config->declared_message);

View file

@ -44,6 +44,48 @@ class CommentView extends Comment
// get the comment configuration
$comment_config = CommentModel::getCommentConfig($current_module_srl);
if(!$comment_config)
{
$comment_config = new stdClass();
}
if(!isset($comment_config->cmd_comment_validation))
{
$comment_config->cmd_comment_validation = 'N';
}
if(!isset($comment_config->use_vote_up))
{
$comment_config->use_vote_up = 'Y';
}
if(!isset($comment_config->use_vote_down))
{
$comment_config->use_vote_down = 'Y';
}
if(!isset($comment_config->allow_vote_from_same_ip))
{
$comment_config->allow_vote_from_same_ip = 'N';
}
if(!isset($comment_config->allow_declare_from_same_ip))
{
$comment_config->allow_declare_from_same_ip = 'N';
}
if ($current_module_srl)
{
$module_info = ModuleModel::getModuleInfoByModuleSrl($current_module_srl);
if (!isset($comment_config->allow_vote_cancel))
{
$comment_config->allow_vote_cancel = (($module_info->cancel_vote ?? 'N') === 'Y') ? 'Y' : 'N';
}
if (!isset($comment_config->allow_vote_non_member))
{
$comment_config->allow_vote_non_member = (($module_info->non_login_vote ?? 'N') === 'Y') ? 'Y' : 'N';
}
if (!isset($comment_config->allow_declare_cancel))
{
$comment_config->allow_declare_cancel = (($module_info->cancel_vote ?? 'N') === 'Y') ? 'Y' : 'N';
}
}
Context::set('comment_config', $comment_config);
// get a group list

View file

@ -28,6 +28,20 @@
</select>
</div>
</div>
<div class="x_control-group">
<label for="use_comment_validation" class="x_control-label">{$lang->cmd_comment_validation}</label>
<div class="x_controls">
<label for="use_comment_validation_Y" class="x_inline">
<input type="radio" id="use_comment_validation_Y" name="use_comment_validation" value="Y" checked="checked"|cond="$comment_config->use_comment_validation === 'Y'">
{$lang->cmd_yes}
</label>
<label for="use_comment_validation_N" class="x_inline">
<input type="radio" id="use_comment_validation_N" name="use_comment_validation" value="N" checked="checked"|cond="$comment_config->use_comment_validation !== 'Y'">
{$lang->cmd_no}
</label>
<p class="x_help-inline">{$lang->about_comment_validation}</p>
</div>
</div>
<div class="x_control-group">
<label for="c_use_vote_up" class="x_control-label">{$lang->cmd_vote}</label>
<div class="x_controls">
@ -49,45 +63,35 @@
</div>
</div>
<div class="x_control-group">
<label class="x_control-label">{lang('document.allow_vote_from_same_ip')}</label>
<label class="x_control-label">{$lang->cmd_vote_config}</label>
<div class="x_controls">
<label for="c_allow_vote_from_same_ip_Y" class="x_inline">
<input type="radio" id="c_allow_vote_from_same_ip_Y" name="allow_vote_from_same_ip" value="Y" checked="checked"|cond="$comment_config->allow_vote_from_same_ip === 'Y'">
{$lang->cmd_yes}
<label for="c_allow_vote_from_same_ip" class="x_inline">
<input type="checkbox" id="c_allow_vote_from_same_ip" name="allow_vote_from_same_ip" value="Y" checked="checked"|cond="$comment_config->allow_vote_from_same_ip === 'Y'">
{lang('document.allow_vote_from_same_ip')}
</label>
<label for="c_allow_vote_from_same_ip_N" class="x_inline">
<input type="radio" id="c_allow_vote_from_same_ip_N" name="allow_vote_from_same_ip" value="N" checked="checked"|cond="$comment_config->allow_vote_from_same_ip !== 'Y'">
{$lang->cmd_no}
<label for="c_allow_vote_cancel" class="x_inline">
<input type="checkbox" id="c_allow_vote_cancel" name="allow_vote_cancel" value="Y" checked="checked"|cond="$comment_config->allow_vote_cancel === 'Y'">
{lang('document.allow_vote_cancel')}
</label>
<label for="c_allow_vote_non_member" class="x_inline">
<input type="checkbox" id="c_allow_vote_non_member" name="allow_vote_non_member" value="Y" checked="checked"|cond="$comment_config->allow_vote_non_member === 'Y'">
{lang('document.allow_vote_non_member')}
</label>
</div>
</div>
<div class="x_control-group">
<label for="use_vote_down" class="x_control-label">{lang('document.allow_declare_from_same_ip')}</label>
<label class="x_control-label">{$lang->cmd_declare_config}</label>
<div class="x_controls">
<label for="c_allow_declare_from_same_ip_Y" class="x_inline">
<input type="radio" id="c_allow_declare_from_same_ip_Y" name="allow_declare_from_same_ip" value="Y" checked="checked"|cond="$comment_config->allow_declare_from_same_ip === 'Y'">
{$lang->cmd_yes}
<label for="c_allow_declare_from_same_ip" class="x_inline">
<input type="checkbox" id="c_allow_declare_from_same_ip" name="allow_declare_from_same_ip" value="Y" checked="checked"|cond="$comment_config->allow_declare_from_same_ip === 'Y'">
{lang('document.allow_declare_from_same_ip')}
</label>
<label for="c_allow_declare_from_same_ip_N" class="x_inline">
<input type="radio" id="c_allow_declare_from_same_ip_N" name="allow_declare_from_same_ip" value="N" checked="checked"|cond="$comment_config->allow_declare_from_same_ip !== 'Y'">
{$lang->cmd_no}
<label for="c_allow_declare_cancel" class="x_inline">
<input type="checkbox" id="c_allow_declare_cancel" name="allow_declare_cancel" value="Y" checked="checked"|cond="$comment_config->allow_declare_cancel === 'Y'">
{lang('document.allow_declare_cancel')}
</label>
</div>
</div>
<div class="x_control-group">
<label for="use_comment_validation" class="x_control-label">{$lang->cmd_comment_validation}</label>
<div class="x_controls">
<label for="use_comment_validation_Y" class="x_inline">
<input type="radio" id="use_comment_validation_Y" name="use_comment_validation" value="Y" checked="checked"|cond="$comment_config->use_comment_validation === 'Y'">
{$lang->cmd_yes}
</label>
<label for="use_comment_validation_N" class="x_inline">
<input type="radio" id="use_comment_validation_N" name="use_comment_validation" value="N" checked="checked"|cond="$comment_config->use_comment_validation !== 'Y'">
{$lang->cmd_no}
</label>
<p class="x_help-inline">{$lang->about_comment_validation}</p>
</div>
</div>
<div class="x_control-group">
<label class="x_control-label">{lang('document.cmd_declared_message')}</label>
<div class="x_controls">