- 변경한 GeneralQueryMode에 따라 Lite가 불가능 - Lite여도 된다면 GeneralLite 클래스로 변경 - 그렇지 않다면 General 클래스로 변경 - 내부에서 어떠한 연산을 할 지 알 수 없는데, 구현 시점에서 편의에 따라 column 여부가 차이나면 이후에 문제가 될 수 있음 - 엔진이 살짝 무거워 질 것으로 보임
70 lines
1.6 KiB
PHP
70 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace sammo\API\Vote;
|
|
|
|
use DateTimeInterface;
|
|
use sammo\DB;
|
|
use sammo\DTO\VoteComment;
|
|
use sammo\Enums\APIRecoveryType;
|
|
use sammo\Enums\GeneralLiteQueryMode;
|
|
use sammo\Enums\GeneralQueryMode;
|
|
use sammo\General;
|
|
use sammo\GeneralLite;
|
|
use sammo\Session;
|
|
use sammo\TimeUtil;
|
|
use sammo\Validator;
|
|
|
|
class AddComment extends \sammo\BaseAPI
|
|
{
|
|
function getRequiredSessionMode(): int
|
|
{
|
|
return static::REQ_GAME_LOGIN | static::REQ_READ_ONLY;
|
|
}
|
|
|
|
function validateArgs(): ?string
|
|
{
|
|
$v = new Validator($this->args);
|
|
$v->rule('required', [
|
|
'voteID',
|
|
'text',
|
|
])->rule('lengthMin', 'text', 1)
|
|
->rule('int', 'voteID');
|
|
|
|
if (!$v->validate()) {
|
|
return $v->errorStr();
|
|
}
|
|
$this->args['voteID'] = (int)$this->args['voteID'];
|
|
return null;
|
|
}
|
|
|
|
function launch(Session $session, ?DateTimeInterface $modifiedSince, ?string $reqEtag): null | string | array | APIRecoveryType
|
|
{
|
|
$voteID = $this->args['voteID'];
|
|
$text = mb_substr($this->args['text'], 0, 200);
|
|
|
|
$generalID = $session->generalID;
|
|
$general = GeneralLite::createObjFromDB($generalID, null, GeneralLiteQueryMode::Core);
|
|
$generalName = $general->getName();
|
|
$nationID = $general->getNationID();
|
|
$nationName = $general->getStaticNation()['name'];
|
|
$date = TimeUtil::now();
|
|
|
|
|
|
$comment = new VoteComment(
|
|
id: null,
|
|
voteID: $voteID,
|
|
generalID: $generalID,
|
|
nationID: $nationID,
|
|
nationName: $nationName,
|
|
generalName: $generalName,
|
|
text: $text,
|
|
date: $date
|
|
);
|
|
|
|
$db = DB::db();
|
|
$db->insert('vote_comment', $comment->toArray());
|
|
|
|
return null;
|
|
}
|
|
}
|