bug fixes / dbmapper fixes

This commit is contained in:
Dennis Eichhorn 2021-12-19 20:20:39 +01:00
parent 1cb4cdf2be
commit f74e885a53
11 changed files with 91 additions and 92 deletions

View File

@ -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;

View File

@ -143,8 +143,6 @@ final class ApiController extends Controller
*/
public function createQAQuestionFromRequest(RequestAbstract $request, ResponseAbstract $response, $data = null) : QAQuestion
{
$mardkownParser = new Markdown();
$question = new QAQuestion();
$question->name = (string) $request->getData('title');
$question->questionRaw = (string) $request->getData('plain');
@ -442,7 +440,10 @@ final class ApiController extends Controller
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) {
$new = new QAQuestionVote();
@ -505,7 +506,10 @@ final class ApiController extends Controller
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) {
$new = new QAAnswerVote();

View File

@ -77,11 +77,13 @@ final class BackendController extends Controller
->with('createdBy/account')
->with('votes')
->with('answers')
->with('answers/votes')
->with('tags')
->with('tags/title')
->where('tags/title/language', $response->getLanguage())
->where('language', $response->getLanguage())
->limit(50)->execute();
$view->setData('questions', $list);
$apps = QAAppMapper::getAll()->execute();
@ -112,6 +114,7 @@ final class BackendController extends Controller
->with('answers')
->with('answers/createdBy')
->with('answers/createdBy/account')
->with('answers/votes')
->with('createdBy')
->with('createdBy/account')
->with('votes')
@ -121,6 +124,7 @@ final class BackendController extends Controller
->where('id', (int) $request->getData('id'))
->where('tags/title/language', $response->getLanguage())
->execute();
$view->addData('question', $question);
$scores = QAHelperMapper::getAccountScore($question->getAccounts());

View File

@ -198,7 +198,7 @@ class QAAnswer implements \JsonSerializable
/**
* Get all votes
*
* @return QAVnswerVote[]
* @return QAAnswerVote[]
*
* @since 1.0.0
*/

View File

@ -77,21 +77,4 @@ final class QAAnswerVoteMapper extends DataMapperFactory
* @since 1.0.0
*/
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);
}
}

View File

@ -98,7 +98,7 @@ class QAQuestion implements \JsonSerializable
/**
* Tags.
*
* @var array<int, int|Tag>
* @var array<int, Tag>
* @since 1.0.0
*/
private array $tags = [];
@ -343,7 +343,7 @@ class QAQuestion implements \JsonSerializable
/**
* Get all votes
*
* @return QAVnswerVote[]
* @return QAQuestionVote[]
*
* @since 1.0.0
*/

View File

@ -77,21 +77,4 @@ final class QAQuestionVoteMapper extends DataMapperFactory
* @since 1.0.0
*/
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);
}
}

View File

@ -43,6 +43,13 @@ final class QAAnswerVoteMapperTest extends \PHPUnit\Framework\TestCase
self::assertEquals($vote->answer, $voteR->answer);
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()
);
}
}

View File

@ -43,6 +43,12 @@ final class QAQuestionVoteMapperTest extends \PHPUnit\Framework\TestCase
self::assertEquals($vote->question, $voteR->question);
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()
);
}
}