mirror of
https://github.com/openvk/openvk
synced 2024-11-11 01:19:53 +03:00
Support: Fix answers evaluating
Now it works
This commit is contained in:
parent
26ddfada05
commit
e00e3b9097
3 changed files with 35 additions and 31 deletions
|
@ -2,7 +2,7 @@
|
|||
namespace openvk\Web\Models\Entities;
|
||||
use openvk\Web\Util\DateTime;
|
||||
use openvk\Web\Models\RowModel;
|
||||
use openvk\Web\Models\Repositories\{Users, SupportAliases};
|
||||
use openvk\Web\Models\Repositories\{Users, SupportAliases, Tickets};
|
||||
|
||||
class TicketComment extends RowModel
|
||||
{
|
||||
|
@ -30,6 +30,11 @@ class TicketComment extends RowModel
|
|||
return (new Users)->get($this->getRecord()->user_id);
|
||||
}
|
||||
|
||||
function getTicket(): Ticket
|
||||
{
|
||||
return (new Tickets)->get($this->getRecord()->ticket_id);
|
||||
}
|
||||
|
||||
function getAuthorName(): string
|
||||
{
|
||||
if($this->getUType() === 0)
|
||||
|
@ -116,17 +121,10 @@ class TicketComment extends RowModel
|
|||
function isLikedByUser(): ?bool
|
||||
{
|
||||
$mark = $this->getMark();
|
||||
switch ($mark) {
|
||||
case 0:
|
||||
return false;
|
||||
break;
|
||||
case 1:
|
||||
return true;
|
||||
break;
|
||||
default:
|
||||
if(is_null($mark))
|
||||
return NULL;
|
||||
break;
|
||||
}
|
||||
else
|
||||
return $mark === 1;
|
||||
}
|
||||
|
||||
use Traits\TRichText;
|
||||
|
|
|
@ -31,7 +31,6 @@ final class SupportPresenter extends OpenVKPresenter
|
|||
$tickets = $this->tickets->getTicketsByuId($this->user->id);
|
||||
if($tickets)
|
||||
$this->template->tickets = $tickets;
|
||||
|
||||
if($_SERVER["REQUEST_METHOD"] === "POST") {
|
||||
if(!empty($this->postParam("name")) && !empty($this->postParam("text"))) {
|
||||
$this->assertNoCSRF();
|
||||
|
@ -230,18 +229,19 @@ final class SupportPresenter extends OpenVKPresenter
|
|||
{
|
||||
$this->willExecuteWriteAction();
|
||||
$this->assertUserLoggedIn();
|
||||
$this->assertNoCSRF();
|
||||
|
||||
$comment = $this->comments->get($id);
|
||||
|
||||
if($this->user->id !== $this->tickets->get($comment->getTicketId())->getUser()->getId())
|
||||
if($this->user->id !== $comment->getTicket()->getUser()->getId())
|
||||
exit(header("HTTP/1.1 403 Forbidden"));
|
||||
|
||||
if($mark === 1 || $mark === 2)
|
||||
header("HTTP/1.1 200 OK");
|
||||
else
|
||||
if($mark !== 1 && $mark !== 2)
|
||||
exit(header("HTTP/1.1 400 Bad Request"));
|
||||
|
||||
$comment->setMark($mark);
|
||||
$comment->save();
|
||||
|
||||
exit(header("HTTP/1.1 200 OK"));
|
||||
}
|
||||
}
|
|
@ -8,7 +8,7 @@
|
|||
{block content}
|
||||
<script>
|
||||
function markAnswer(id, mark) {
|
||||
let url = "/support/comment/" + id + "/rate/" + mark;
|
||||
let url = "/support/comment/" + id + "/rate/" + mark + "?hash=" + {urlencode($csrfToken)};
|
||||
$.ajax(url, {
|
||||
error: errorHandler,
|
||||
success: success(id, mark)
|
||||
|
@ -16,11 +16,12 @@
|
|||
}
|
||||
|
||||
function success(id, mark) {
|
||||
if(mark == 1) {
|
||||
if(mark == 1)
|
||||
document.getElementById("markText-" + id).innerHTML = {_support_good_answer_user};
|
||||
} else {
|
||||
else
|
||||
document.getElementById("markText-" + id).innerHTML = {_support_bad_answer_user};
|
||||
}
|
||||
|
||||
document.getElementById("markLinks-" + id).remove();
|
||||
}
|
||||
|
||||
function errorHandler(id, mark) {
|
||||
|
@ -120,18 +121,23 @@
|
|||
|
||||
{if $comment->getUType() === 1}
|
||||
<div class="post-menu">
|
||||
{var isLikedByUser = $comment->isLikedByUser()}
|
||||
<strong id="markText-{$comment->getId()}">
|
||||
{if !is_null($isLikedByUser)}
|
||||
{if $comment->isLikedByUser()}
|
||||
{_support_good_answer_user}
|
||||
{else}
|
||||
{_support_bad_answer_user}
|
||||
{/if}
|
||||
{/if}
|
||||
</strong>
|
||||
{if $comment->isLikedByUser() === null}
|
||||
<div id="markLinks-{$comment->getId()}">
|
||||
{if is_null($isLikedByUser)}
|
||||
<a onClick="markAnswer({$comment->getId()}, 1)">{_support_rate_good_answer}</a>
|
||||
|
|
||||
<a onClick="markAnswer({$comment->getId()}, 2)">{_support_rate_bad_answer}</a>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue