mirror of
https://github.com/Karaka-Management/oms-QA.git
synced 2026-02-14 14:58:41 +00:00
bug fixes / dbmapper fixes
This commit is contained in:
parent
1cb4cdf2be
commit
f74e885a53
|
|
@ -1,4 +1,16 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
/**
|
||||||
|
* Orange Management
|
||||||
|
*
|
||||||
|
* PHP Version 8.0
|
||||||
|
*
|
||||||
|
* @package Template
|
||||||
|
* @copyright Dennis Eichhorn
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @version 1.0.0
|
||||||
|
* @link https://orange-management.org
|
||||||
|
*/
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
use phpOMS\Uri\UriFactory;
|
use phpOMS\Uri\UriFactory;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -143,8 +143,6 @@ final class ApiController extends Controller
|
||||||
*/
|
*/
|
||||||
public function createQAQuestionFromRequest(RequestAbstract $request, ResponseAbstract $response, $data = null) : QAQuestion
|
public function createQAQuestionFromRequest(RequestAbstract $request, ResponseAbstract $response, $data = null) : QAQuestion
|
||||||
{
|
{
|
||||||
$mardkownParser = new Markdown();
|
|
||||||
|
|
||||||
$question = new QAQuestion();
|
$question = new QAQuestion();
|
||||||
$question->name = (string) $request->getData('title');
|
$question->name = (string) $request->getData('title');
|
||||||
$question->questionRaw = (string) $request->getData('plain');
|
$question->questionRaw = (string) $request->getData('plain');
|
||||||
|
|
@ -442,7 +440,10 @@ final class ApiController extends Controller
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$questionVote = QAQuestionVoteMapper::findVote((int) $request->getData('id'), $request->header->account);
|
$questionVote = QAQuestionVoteMapper::get()
|
||||||
|
->where('question', (int) $request->getData('id'))
|
||||||
|
->where('createdBy', $request->header->account)
|
||||||
|
->execute();
|
||||||
|
|
||||||
if ($questionVote === false || $questionVote instanceof NullQAQuestionVote || $questionVote === null) {
|
if ($questionVote === false || $questionVote instanceof NullQAQuestionVote || $questionVote === null) {
|
||||||
$new = new QAQuestionVote();
|
$new = new QAQuestionVote();
|
||||||
|
|
@ -505,7 +506,10 @@ final class ApiController extends Controller
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$answerVote = QAAnswerVoteMapper::findVote((int) $request->getData('id'), $request->header->account);
|
$answerVote = QAAnswerVoteMapper::get()
|
||||||
|
->where('answer', (int) $request->getData('id'))
|
||||||
|
->where('createdBy', $request->header->account)
|
||||||
|
->execute();
|
||||||
|
|
||||||
if ($answerVote === false || $answerVote instanceof NullQAAnswerVote || $answerVote === null) {
|
if ($answerVote === false || $answerVote instanceof NullQAAnswerVote || $answerVote === null) {
|
||||||
$new = new QAAnswerVote();
|
$new = new QAAnswerVote();
|
||||||
|
|
|
||||||
|
|
@ -77,11 +77,13 @@ final class BackendController extends Controller
|
||||||
->with('createdBy/account')
|
->with('createdBy/account')
|
||||||
->with('votes')
|
->with('votes')
|
||||||
->with('answers')
|
->with('answers')
|
||||||
|
->with('answers/votes')
|
||||||
->with('tags')
|
->with('tags')
|
||||||
->with('tags/title')
|
->with('tags/title')
|
||||||
->where('tags/title/language', $response->getLanguage())
|
->where('tags/title/language', $response->getLanguage())
|
||||||
->where('language', $response->getLanguage())
|
->where('language', $response->getLanguage())
|
||||||
->limit(50)->execute();
|
->limit(50)->execute();
|
||||||
|
|
||||||
$view->setData('questions', $list);
|
$view->setData('questions', $list);
|
||||||
|
|
||||||
$apps = QAAppMapper::getAll()->execute();
|
$apps = QAAppMapper::getAll()->execute();
|
||||||
|
|
@ -112,6 +114,7 @@ final class BackendController extends Controller
|
||||||
->with('answers')
|
->with('answers')
|
||||||
->with('answers/createdBy')
|
->with('answers/createdBy')
|
||||||
->with('answers/createdBy/account')
|
->with('answers/createdBy/account')
|
||||||
|
->with('answers/votes')
|
||||||
->with('createdBy')
|
->with('createdBy')
|
||||||
->with('createdBy/account')
|
->with('createdBy/account')
|
||||||
->with('votes')
|
->with('votes')
|
||||||
|
|
@ -121,6 +124,7 @@ final class BackendController extends Controller
|
||||||
->where('id', (int) $request->getData('id'))
|
->where('id', (int) $request->getData('id'))
|
||||||
->where('tags/title/language', $response->getLanguage())
|
->where('tags/title/language', $response->getLanguage())
|
||||||
->execute();
|
->execute();
|
||||||
|
|
||||||
$view->addData('question', $question);
|
$view->addData('question', $question);
|
||||||
|
|
||||||
$scores = QAHelperMapper::getAccountScore($question->getAccounts());
|
$scores = QAHelperMapper::getAccountScore($question->getAccounts());
|
||||||
|
|
|
||||||
|
|
@ -198,7 +198,7 @@ class QAAnswer implements \JsonSerializable
|
||||||
/**
|
/**
|
||||||
* Get all votes
|
* Get all votes
|
||||||
*
|
*
|
||||||
* @return QAVnswerVote[]
|
* @return QAAnswerVote[]
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -35,14 +35,14 @@ final class QAAnswerMapper extends DataMapperFactory
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public const COLUMNS = [
|
public const COLUMNS = [
|
||||||
'qa_answer_id' => ['name' => 'qa_answer_id', 'type' => 'int', 'internal' => 'id'],
|
'qa_answer_id' => ['name' => 'qa_answer_id', 'type' => 'int', 'internal' => 'id'],
|
||||||
'qa_answer_answer_raw' => ['name' => 'qa_answer_answer_raw', 'type' => 'string', 'internal' => 'answerRaw'],
|
'qa_answer_answer_raw' => ['name' => 'qa_answer_answer_raw', 'type' => 'string', 'internal' => 'answerRaw'],
|
||||||
'qa_answer_answer' => ['name' => 'qa_answer_answer', 'type' => 'string', 'internal' => 'answer'],
|
'qa_answer_answer' => ['name' => 'qa_answer_answer', 'type' => 'string', 'internal' => 'answer'],
|
||||||
'qa_answer_question' => ['name' => 'qa_answer_question', 'type' => 'int', 'internal' => 'question'],
|
'qa_answer_question' => ['name' => 'qa_answer_question', 'type' => 'int', 'internal' => 'question'],
|
||||||
'qa_answer_status' => ['name' => 'qa_answer_status', 'type' => 'int', 'internal' => 'status'],
|
'qa_answer_status' => ['name' => 'qa_answer_status', 'type' => 'int', 'internal' => 'status'],
|
||||||
'qa_answer_accepted' => ['name' => 'qa_answer_accepted', 'type' => 'bool', 'internal' => 'isAccepted'],
|
'qa_answer_accepted' => ['name' => 'qa_answer_accepted', 'type' => 'bool', 'internal' => 'isAccepted'],
|
||||||
'qa_answer_created_by' => ['name' => 'qa_answer_created_by', 'type' => 'int', 'internal' => 'createdBy', 'readonly' => true],
|
'qa_answer_created_by' => ['name' => 'qa_answer_created_by', 'type' => 'int', 'internal' => 'createdBy', 'readonly' => true],
|
||||||
'qa_answer_created_at' => ['name' => 'qa_answer_created_at', 'type' => 'DateTimeImmutable', 'internal' => 'createdAt', 'readonly' => true],
|
'qa_answer_created_at' => ['name' => 'qa_answer_created_at', 'type' => 'DateTimeImmutable', 'internal' => 'createdAt', 'readonly' => true],
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -53,13 +53,13 @@ final class QAAnswerMapper extends DataMapperFactory
|
||||||
*/
|
*/
|
||||||
public const BELONGS_TO = [
|
public const BELONGS_TO = [
|
||||||
'createdBy' => [
|
'createdBy' => [
|
||||||
'mapper' => ProfileMapper::class,
|
'mapper' => ProfileMapper::class,
|
||||||
'external' => 'qa_answer_created_by',
|
'external' => 'qa_answer_created_by',
|
||||||
'by' => 'account',
|
'by' => 'account',
|
||||||
],
|
],
|
||||||
'question' => [
|
'question' => [
|
||||||
'mapper' => QAQuestionMapper::class,
|
'mapper' => QAQuestionMapper::class,
|
||||||
'external' => 'qa_answer_question',
|
'external' => 'qa_answer_question',
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
@ -71,10 +71,10 @@ final class QAAnswerMapper extends DataMapperFactory
|
||||||
*/
|
*/
|
||||||
public const HAS_MANY = [
|
public const HAS_MANY = [
|
||||||
'votes' => [
|
'votes' => [
|
||||||
'mapper' => QAAnswerVoteMapper::class,
|
'mapper' => QAAnswerVoteMapper::class,
|
||||||
'table' => 'qa_answer_vote',
|
'table' => 'qa_answer_vote',
|
||||||
'self' => 'qa_answer_vote_answer',
|
'self' => 'qa_answer_vote_answer',
|
||||||
'external' => null,
|
'external' => null,
|
||||||
],
|
],
|
||||||
'media' => [
|
'media' => [
|
||||||
'mapper' => MediaMapper::class,
|
'mapper' => MediaMapper::class,
|
||||||
|
|
|
||||||
|
|
@ -34,11 +34,11 @@ final class QAAnswerVoteMapper extends DataMapperFactory
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public const COLUMNS = [
|
public const COLUMNS = [
|
||||||
'qa_answer_vote_id' => ['name' => 'qa_answer_vote_id', 'type' => 'int', 'internal' => 'id'],
|
'qa_answer_vote_id' => ['name' => 'qa_answer_vote_id', 'type' => 'int', 'internal' => 'id'],
|
||||||
'qa_answer_vote_score' => ['name' => 'qa_answer_vote_score', 'type' => 'int', 'internal' => 'score'],
|
'qa_answer_vote_score' => ['name' => 'qa_answer_vote_score', 'type' => 'int', 'internal' => 'score'],
|
||||||
'qa_answer_vote_answer' => ['name' => 'qa_answer_vote_answer', 'type' => 'int', 'internal' => 'answer', 'readonly' => true],
|
'qa_answer_vote_answer' => ['name' => 'qa_answer_vote_answer', 'type' => 'int', 'internal' => 'answer', 'readonly' => true],
|
||||||
'qa_answer_vote_created_by' => ['name' => 'qa_answer_vote_created_by', 'type' => 'int', 'internal' => 'createdBy', 'readonly' => true],
|
'qa_answer_vote_created_by' => ['name' => 'qa_answer_vote_created_by', 'type' => 'int', 'internal' => 'createdBy', 'readonly' => true],
|
||||||
'qa_answer_vote_created_at' => ['name' => 'qa_answer_vote_created_at', 'type' => 'DateTimeImmutable', 'internal' => 'createdAt', 'readonly' => true],
|
'qa_answer_vote_created_at' => ['name' => 'qa_answer_vote_created_at', 'type' => 'DateTimeImmutable', 'internal' => 'createdAt', 'readonly' => true],
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -49,8 +49,8 @@ final class QAAnswerVoteMapper extends DataMapperFactory
|
||||||
*/
|
*/
|
||||||
public const BELONGS_TO = [
|
public const BELONGS_TO = [
|
||||||
'createdBy' => [
|
'createdBy' => [
|
||||||
'mapper' => AccountMapper::class,
|
'mapper' => AccountMapper::class,
|
||||||
'external' => 'qa_answer_vote_created_by',
|
'external' => 'qa_answer_vote_created_by',
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
@ -77,21 +77,4 @@ final class QAAnswerVoteMapper extends DataMapperFactory
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public const PRIMARYFIELD ='qa_answer_vote_id';
|
public const PRIMARYFIELD ='qa_answer_vote_id';
|
||||||
|
|
||||||
/**
|
|
||||||
* Find vote for answer from user
|
|
||||||
*
|
|
||||||
* @param int $answer Answer id
|
|
||||||
* @param int $account Account id
|
|
||||||
*
|
|
||||||
* @return bool|QAAnswerVote
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public static function findVote(int $answer, int $account) : bool | QAAnswerVote
|
|
||||||
{
|
|
||||||
$results = self::getAll()->where('comment', $answer)->where('createdBy', $account)->execute();
|
|
||||||
|
|
||||||
return empty($results) ? new NullQAAnswerVote() : \reset($results);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -98,7 +98,7 @@ class QAQuestion implements \JsonSerializable
|
||||||
/**
|
/**
|
||||||
* Tags.
|
* Tags.
|
||||||
*
|
*
|
||||||
* @var array<int, int|Tag>
|
* @var array<int, Tag>
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
private array $tags = [];
|
private array $tags = [];
|
||||||
|
|
@ -343,7 +343,7 @@ class QAQuestion implements \JsonSerializable
|
||||||
/**
|
/**
|
||||||
* Get all votes
|
* Get all votes
|
||||||
*
|
*
|
||||||
* @return QAVnswerVote[]
|
* @return QAQuestionVote[]
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -36,15 +36,15 @@ final class QAQuestionMapper extends DataMapperFactory
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public const COLUMNS = [
|
public const COLUMNS = [
|
||||||
'qa_question_id' => ['name' => 'qa_question_id', 'type' => 'int', 'internal' => 'id'],
|
'qa_question_id' => ['name' => 'qa_question_id', 'type' => 'int', 'internal' => 'id'],
|
||||||
'qa_question_title' => ['name' => 'qa_question_title', 'type' => 'string', 'internal' => 'name'],
|
'qa_question_title' => ['name' => 'qa_question_title', 'type' => 'string', 'internal' => 'name'],
|
||||||
'qa_question_language' => ['name' => 'qa_question_language', 'type' => 'string', 'internal' => 'language'],
|
'qa_question_language' => ['name' => 'qa_question_language', 'type' => 'string', 'internal' => 'language'],
|
||||||
'qa_question_question' => ['name' => 'qa_question_question', 'type' => 'string', 'internal' => 'question'],
|
'qa_question_question' => ['name' => 'qa_question_question', 'type' => 'string', 'internal' => 'question'],
|
||||||
'qa_question_question_raw' => ['name' => 'qa_question_question_raw', 'type' => 'string', 'internal' => 'questionRaw'],
|
'qa_question_question_raw' => ['name' => 'qa_question_question_raw', 'type' => 'string', 'internal' => 'questionRaw'],
|
||||||
'qa_question_status' => ['name' => 'qa_question_status', 'type' => 'int', 'internal' => 'status'],
|
'qa_question_status' => ['name' => 'qa_question_status', 'type' => 'int', 'internal' => 'status'],
|
||||||
'qa_question_created_by' => ['name' => 'qa_question_created_by', 'type' => 'int', 'internal' => 'createdBy', 'readonly' => true],
|
'qa_question_created_by' => ['name' => 'qa_question_created_by', 'type' => 'int', 'internal' => 'createdBy', 'readonly' => true],
|
||||||
'qa_question_created_at' => ['name' => 'qa_question_created_at', 'type' => 'DateTimeImmutable', 'internal' => 'createdAt', 'readonly' => true],
|
'qa_question_created_at' => ['name' => 'qa_question_created_at', 'type' => 'DateTimeImmutable', 'internal' => 'createdAt', 'readonly' => true],
|
||||||
'qa_question_app' => ['name' => 'qa_question_app', 'type' => 'int', 'internal' => 'app'],
|
'qa_question_app' => ['name' => 'qa_question_app', 'type' => 'int', 'internal' => 'app'],
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -61,16 +61,16 @@ final class QAQuestionMapper extends DataMapperFactory
|
||||||
'external' => 'qa_tag_src',
|
'external' => 'qa_tag_src',
|
||||||
],
|
],
|
||||||
'answers' => [
|
'answers' => [
|
||||||
'mapper' => QAAnswerMapper::class,
|
'mapper' => QAAnswerMapper::class,
|
||||||
'table' => 'qa_answer',
|
'table' => 'qa_answer',
|
||||||
'self' => 'qa_answer_question',
|
'self' => 'qa_answer_question',
|
||||||
'external' => null,
|
'external' => null,
|
||||||
],
|
],
|
||||||
'votes' => [
|
'votes' => [
|
||||||
'mapper' => QAQuestionVoteMapper::class,
|
'mapper' => QAQuestionVoteMapper::class,
|
||||||
'table' => 'qa_question_vote',
|
'table' => 'qa_question_vote',
|
||||||
'self' => 'qa_question_vote_question',
|
'self' => 'qa_question_vote_question',
|
||||||
'external' => null,
|
'external' => null,
|
||||||
],
|
],
|
||||||
'media' => [
|
'media' => [
|
||||||
'mapper' => MediaMapper::class,
|
'mapper' => MediaMapper::class,
|
||||||
|
|
|
||||||
|
|
@ -34,11 +34,11 @@ final class QAQuestionVoteMapper extends DataMapperFactory
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public const COLUMNS = [
|
public const COLUMNS = [
|
||||||
'qa_question_vote_id' => ['name' => 'qa_question_vote_id', 'type' => 'int', 'internal' => 'id'],
|
'qa_question_vote_id' => ['name' => 'qa_question_vote_id', 'type' => 'int', 'internal' => 'id'],
|
||||||
'qa_question_vote_score' => ['name' => 'qa_question_vote_score', 'type' => 'int', 'internal' => 'score'],
|
'qa_question_vote_score' => ['name' => 'qa_question_vote_score', 'type' => 'int', 'internal' => 'score'],
|
||||||
'qa_question_vote_question' => ['name' => 'qa_question_vote_question', 'type' => 'int', 'internal' => 'question', 'readonly' => true],
|
'qa_question_vote_question' => ['name' => 'qa_question_vote_question', 'type' => 'int', 'internal' => 'question', 'readonly' => true],
|
||||||
'qa_question_vote_created_by' => ['name' => 'qa_question_vote_created_by', 'type' => 'int', 'internal' => 'createdBy', 'readonly' => true],
|
'qa_question_vote_created_by' => ['name' => 'qa_question_vote_created_by', 'type' => 'int', 'internal' => 'createdBy', 'readonly' => true],
|
||||||
'qa_question_vote_created_at' => ['name' => 'qa_question_vote_created_at', 'type' => 'DateTimeImmutable', 'internal' => 'createdAt', 'readonly' => true],
|
'qa_question_vote_created_at' => ['name' => 'qa_question_vote_created_at', 'type' => 'DateTimeImmutable', 'internal' => 'createdAt', 'readonly' => true],
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -49,8 +49,8 @@ final class QAQuestionVoteMapper extends DataMapperFactory
|
||||||
*/
|
*/
|
||||||
public const BELONGS_TO = [
|
public const BELONGS_TO = [
|
||||||
'createdBy' => [
|
'createdBy' => [
|
||||||
'mapper' => AccountMapper::class,
|
'mapper' => AccountMapper::class,
|
||||||
'external' => 'qa_question_vote_created_by',
|
'external' => 'qa_question_vote_created_by',
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
@ -77,21 +77,4 @@ final class QAQuestionVoteMapper extends DataMapperFactory
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public const PRIMARYFIELD ='qa_question_vote_id';
|
public const PRIMARYFIELD ='qa_question_vote_id';
|
||||||
|
|
||||||
/**
|
|
||||||
* Find vote for question from user
|
|
||||||
*
|
|
||||||
* @param int $question Question id
|
|
||||||
* @param int $account Account id
|
|
||||||
*
|
|
||||||
* @return bool|QAQuestionVote
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public static function findVote(int $question, int $account) : bool | QAQuestionVote
|
|
||||||
{
|
|
||||||
$results = self::getAll()->where('comment', $question)->where('createdBy', $account)->execute();
|
|
||||||
|
|
||||||
return empty($results) ? new NullQAQuestionVote() : \reset($results);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,13 @@ final class QAAnswerVoteMapperTest extends \PHPUnit\Framework\TestCase
|
||||||
self::assertEquals($vote->answer, $voteR->answer);
|
self::assertEquals($vote->answer, $voteR->answer);
|
||||||
self::assertEquals($vote->score, $voteR->score);
|
self::assertEquals($vote->score, $voteR->score);
|
||||||
|
|
||||||
self::assertEquals(1, QAAnswerVoteMapper::findVote(1, 1)->getId());
|
self::assertEquals(1,
|
||||||
|
QAAnswerVoteMapper::get()
|
||||||
|
->where('answer', 1)
|
||||||
|
->where('createdBy', 1)
|
||||||
|
->limit(1)
|
||||||
|
->execute()
|
||||||
|
->getId()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,12 @@ final class QAQuestionVoteMapperTest extends \PHPUnit\Framework\TestCase
|
||||||
self::assertEquals($vote->question, $voteR->question);
|
self::assertEquals($vote->question, $voteR->question);
|
||||||
self::assertEquals($vote->score, $voteR->score);
|
self::assertEquals($vote->score, $voteR->score);
|
||||||
|
|
||||||
self::assertEquals(1, QAQuestionVoteMapper::findVote(1, 1)->getId());
|
self::assertEquals(1,
|
||||||
|
QAQuestionVoteMapper::get()
|
||||||
|
->where('question', 1)
|
||||||
|
->where('createdBy', 1)
|
||||||
|
->limit(1)
|
||||||
|
->execute()->getId()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user