mirror of
https://github.com/Karaka-Management/oms-QA.git
synced 2026-01-11 15:48:42 +00:00
new datamapper mostly implemented
This commit is contained in:
parent
5531392420
commit
1cb4cdf2be
|
|
@ -27,7 +27,7 @@ use phpOMS\DataStorage\Cookie\CookieJar;
|
|||
use phpOMS\DataStorage\Database\Connection\ConnectionAbstract;
|
||||
use phpOMS\DataStorage\Database\DatabasePool;
|
||||
use phpOMS\DataStorage\Database\DatabaseStatus;
|
||||
use phpOMS\DataStorage\Database\DataMapperAbstract;
|
||||
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
|
||||
use phpOMS\DataStorage\Session\HttpSession;
|
||||
use phpOMS\Dispatcher\Dispatcher;
|
||||
use phpOMS\Event\EventManager;
|
||||
|
|
@ -136,13 +136,13 @@ final class Application
|
|||
|
||||
/** @var ConnectionAbstract $con */
|
||||
$con = $this->app->dbPool->get();
|
||||
DataMapperAbstract::setConnection($con);
|
||||
DataMapperFactory::db($con);
|
||||
|
||||
$this->app->cachePool = new CachePool();
|
||||
$this->app->appSettings = new CoreSettings();
|
||||
$this->app->eventManager = new EventManager($this->app->dispatcher);
|
||||
$this->app->accountManager = new AccountManager($this->app->sessionManager);
|
||||
$this->app->l11nServer = LocalizationMapper::get(1);
|
||||
$this->app->l11nServer = LocalizationMapper::get()->where('id', 1)->execute();
|
||||
$this->app->orgId = $this->getApplicationOrganization($request, $this->config['app']);
|
||||
|
||||
$aid = Auth::authenticate($this->app->sessionManager);
|
||||
|
|
|
|||
|
|
@ -49,6 +49,6 @@ final class Installer extends InstallerAbstract
|
|||
$app = new QAApp();
|
||||
$app->name = 'Backend';
|
||||
|
||||
$id = QAAppMapper::create($app);
|
||||
$id = QAAppMapper::create()->execute($app);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -333,7 +333,7 @@ final class ApiController extends Controller
|
|||
*/
|
||||
public function apiChangeAnsweredStatus(RequestAbstract $request, ResponseAbstract $response, $data = null) : void
|
||||
{
|
||||
$old = clone QAAnswerMapper::get((int) $request->getData('id'));
|
||||
$old = clone QAAnswerMapper::get()->where('id', (int) $request->getData('id'))->execute();
|
||||
$new = $this->updateAnsweredStatusFromRequest($request);
|
||||
$this->updateModel($request->header->account, $old, $new, QAAnswerMapper::class, 'answer', $request->getOrigin());
|
||||
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Answer', 'Answer successfully updated.', $new);
|
||||
|
|
@ -350,7 +350,7 @@ final class ApiController extends Controller
|
|||
*/
|
||||
public function updateAnsweredStatusFromRequest(RequestAbstract $request) : QAAnswer
|
||||
{
|
||||
$answer = QAAnswerMapper::get((int) $request->getData('id'));
|
||||
$answer = QAAnswerMapper::get()->where('id', (int) $request->getData('id'))->execute();
|
||||
$answer->isAccepted = $request->getData('accepted', 'bool') ?? false;
|
||||
|
||||
return $answer;
|
||||
|
|
|
|||
|
|
@ -72,10 +72,19 @@ final class BackendController extends Controller
|
|||
$view->setTemplate('/Modules/QA/Theme/Backend/qa-dashboard');
|
||||
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1006001001, $request, $response));
|
||||
|
||||
$list = QAQuestionMapper::with('language', $response->getLanguage())::getNewest(50);
|
||||
$list = QAQuestionMapper::getAll()
|
||||
->with('createdBy')
|
||||
->with('createdBy/account')
|
||||
->with('votes')
|
||||
->with('answers')
|
||||
->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();
|
||||
$apps = QAAppMapper::getAll()->execute();
|
||||
$view->setData('apps', $apps);
|
||||
|
||||
return $view;
|
||||
|
|
@ -99,7 +108,19 @@ final class BackendController extends Controller
|
|||
$view->setTemplate('/Modules/QA/Theme/Backend/qa-question');
|
||||
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1006001001, $request, $response));
|
||||
|
||||
$question = QAQuestionMapper::get((int) $request->getData('id'));
|
||||
$question = QAQuestionMapper::get()
|
||||
->with('answers')
|
||||
->with('answers/createdBy')
|
||||
->with('answers/createdBy/account')
|
||||
->with('createdBy')
|
||||
->with('createdBy/account')
|
||||
->with('votes')
|
||||
->with('tags')
|
||||
->with('tags/title')
|
||||
->with('media')
|
||||
->where('id', (int) $request->getData('id'))
|
||||
->where('tags/title/language', $response->getLanguage())
|
||||
->execute();
|
||||
$view->addData('question', $question);
|
||||
|
||||
$scores = QAHelperMapper::getAccountScore($question->getAccounts());
|
||||
|
|
@ -126,7 +147,7 @@ final class BackendController extends Controller
|
|||
$view->setTemplate('/Modules/QA/Theme/Backend/qa-question-create');
|
||||
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1006001001, $request, $response));
|
||||
|
||||
$question = QAQuestionMapper::get((int) $request->getData('id'));
|
||||
$question = QAQuestionMapper::get()->where('id', (int) $request->getData('id'))->execute();
|
||||
$view->addData('question', $question);
|
||||
|
||||
return $view;
|
||||
|
|
@ -150,12 +171,12 @@ final class BackendController extends Controller
|
|||
|
||||
$id = $request->getData('id') ?? '';
|
||||
|
||||
$settings = SettingMapper::getFor($id, 'module');
|
||||
$settings = SettingMapper::getAll()->where('module', $id)->execute();
|
||||
if (!($settings instanceof NullSetting)) {
|
||||
$view->setData('settings', !\is_array($settings) ? [$settings] : $settings);
|
||||
}
|
||||
|
||||
$apps = QAAppMapper::getAll();
|
||||
$apps = QAAppMapper::getAll()->execute();
|
||||
$view->setData('apps', $apps);
|
||||
|
||||
if (\is_file(__DIR__ . '/../Admin/Settings/Theme/Backend/settings.tpl.php')) {
|
||||
|
|
@ -184,7 +205,7 @@ final class BackendController extends Controller
|
|||
$view->setTemplate('/Modules/' . static::NAME . '/Admin/Settings/Theme/Backend/settings-app');
|
||||
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1000105001, $request, $response));
|
||||
|
||||
$view->addData('app', QAAppMapper::get((int) $request->getData('app')));
|
||||
$view->addData('app', QAAppMapper::get()->where('id', (int) $request->getData('app'))->execute());
|
||||
|
||||
return $view;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ namespace Modules\QA\Models;
|
|||
|
||||
use Modules\Media\Models\MediaMapper;
|
||||
use Modules\Profile\Models\ProfileMapper;
|
||||
use phpOMS\DataStorage\Database\DataMapperAbstract;
|
||||
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
|
||||
|
||||
/**
|
||||
* Mapper class.
|
||||
|
|
@ -26,7 +26,7 @@ use phpOMS\DataStorage\Database\DataMapperAbstract;
|
|||
* @link https://orange-management.org
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class QAAnswerMapper extends DataMapperAbstract
|
||||
final class QAAnswerMapper extends DataMapperFactory
|
||||
{
|
||||
/**
|
||||
* Columns.
|
||||
|
|
@ -34,7 +34,7 @@ final class QAAnswerMapper extends DataMapperAbstract
|
|||
* @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static array $columns = [
|
||||
public const COLUMNS = [
|
||||
'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' => ['name' => 'qa_answer_answer', 'type' => 'string', 'internal' => 'answer'],
|
||||
|
|
@ -51,7 +51,7 @@ final class QAAnswerMapper extends DataMapperAbstract
|
|||
* @var array<string, array{mapper:string, external:string}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static array $belongsTo = [
|
||||
public const BELONGS_TO = [
|
||||
'createdBy' => [
|
||||
'mapper' => ProfileMapper::class,
|
||||
'external' => 'qa_answer_created_by',
|
||||
|
|
@ -69,7 +69,7 @@ final class QAAnswerMapper extends DataMapperAbstract
|
|||
* @var array<string, array{mapper:string, table:string, self?:?string, external?:?string, column?:string}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static array $hasMany = [
|
||||
public const HAS_MANY = [
|
||||
'votes' => [
|
||||
'mapper' => QAAnswerVoteMapper::class,
|
||||
'table' => 'qa_answer_vote',
|
||||
|
|
@ -90,7 +90,7 @@ final class QAAnswerMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $table = 'qa_answer';
|
||||
public const TABLE = 'qa_answer';
|
||||
|
||||
/**
|
||||
* Created at.
|
||||
|
|
@ -98,7 +98,7 @@ final class QAAnswerMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $createdAt = 'qa_answer_created_at';
|
||||
public const CREATED_AT = 'qa_answer_created_at';
|
||||
|
||||
/**
|
||||
* Primary field name.
|
||||
|
|
@ -106,5 +106,5 @@ final class QAAnswerMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $primaryField = 'qa_answer_id';
|
||||
public const PRIMARYFIELD ='qa_answer_id';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ declare(strict_types=1);
|
|||
namespace Modules\QA\Models;
|
||||
|
||||
use Modules\Admin\Models\AccountMapper;
|
||||
use phpOMS\DataStorage\Database\DataMapperAbstract;
|
||||
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
|
||||
|
||||
/**
|
||||
* Mapper class.
|
||||
|
|
@ -25,7 +25,7 @@ use phpOMS\DataStorage\Database\DataMapperAbstract;
|
|||
* @link https://orange-management.org
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class QAAnswerVoteMapper extends DataMapperAbstract
|
||||
final class QAAnswerVoteMapper extends DataMapperFactory
|
||||
{
|
||||
/**
|
||||
* Columns.
|
||||
|
|
@ -33,7 +33,7 @@ final class QAAnswerVoteMapper extends DataMapperAbstract
|
|||
* @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static array $columns = [
|
||||
public const COLUMNS = [
|
||||
'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_answer' => ['name' => 'qa_answer_vote_answer', 'type' => 'int', 'internal' => 'answer', 'readonly' => true],
|
||||
|
|
@ -47,7 +47,7 @@ final class QAAnswerVoteMapper extends DataMapperAbstract
|
|||
* @var array<string, array{mapper:string, external:string}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static array $belongsTo = [
|
||||
public const BELONGS_TO = [
|
||||
'createdBy' => [
|
||||
'mapper' => AccountMapper::class,
|
||||
'external' => 'qa_answer_vote_created_by',
|
||||
|
|
@ -60,7 +60,7 @@ final class QAAnswerVoteMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $table = 'qa_answer_vote';
|
||||
public const TABLE = 'qa_answer_vote';
|
||||
|
||||
/**
|
||||
* Created at.
|
||||
|
|
@ -68,7 +68,7 @@ final class QAAnswerVoteMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $createdAt = 'qa_answer_vote_created_at';
|
||||
public const CREATED_AT = 'qa_answer_vote_created_at';
|
||||
|
||||
/**
|
||||
* Primary field name.
|
||||
|
|
@ -76,7 +76,7 @@ final class QAAnswerVoteMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $primaryField = 'qa_answer_vote_id';
|
||||
public const PRIMARYFIELD ='qa_answer_vote_id';
|
||||
|
||||
/**
|
||||
* Find vote for answer from user
|
||||
|
|
@ -90,13 +90,8 @@ final class QAAnswerVoteMapper extends DataMapperAbstract
|
|||
*/
|
||||
public static function findVote(int $answer, int $account) : bool | QAAnswerVote
|
||||
{
|
||||
$depth = 3;
|
||||
$query = self::getQuery();
|
||||
$query->where(self::$table . '_d' . $depth . '.qa_answer_vote_created_by', '=', $account)
|
||||
->andWhere(self::$table . '_d' . $depth . '.qa_answer_vote_answer', '=', $answer);
|
||||
$results = self::getAll()->where('comment', $answer)->where('createdBy', $account)->execute();
|
||||
|
||||
$results = self::getAllByQuery($query);
|
||||
|
||||
return \reset($results);
|
||||
return empty($results) ? new NullQAAnswerVote() : \reset($results);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace Modules\QA\Models;
|
||||
|
||||
use phpOMS\DataStorage\Database\DataMapperAbstract;
|
||||
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
|
||||
|
||||
/**
|
||||
* Mapper class.
|
||||
|
|
@ -24,7 +24,7 @@ use phpOMS\DataStorage\Database\DataMapperAbstract;
|
|||
* @link https://orange-management.org
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class QAAppMapper extends DataMapperAbstract
|
||||
final class QAAppMapper extends DataMapperFactory
|
||||
{
|
||||
/**
|
||||
* Columns.
|
||||
|
|
@ -32,7 +32,7 @@ final class QAAppMapper extends DataMapperAbstract
|
|||
* @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static array $columns = [
|
||||
public const COLUMNS = [
|
||||
'qa_app_id' => ['name' => 'qa_app_id', 'type' => 'int', 'internal' => 'id'],
|
||||
'qa_app_name' => ['name' => 'qa_app_name', 'type' => 'string', 'internal' => 'name'],
|
||||
];
|
||||
|
|
@ -43,7 +43,7 @@ final class QAAppMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $table = 'qa_app';
|
||||
public const TABLE = 'qa_app';
|
||||
|
||||
/**
|
||||
* Primary field name.
|
||||
|
|
@ -51,5 +51,5 @@ final class QAAppMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $primaryField = 'qa_app_id';
|
||||
public const PRIMARYFIELD ='qa_app_id';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace Modules\QA\Models;
|
||||
|
||||
use phpOMS\DataStorage\Database\DataMapperAbstract;
|
||||
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
|
||||
use phpOMS\DataStorage\Database\Query\Builder;
|
||||
|
||||
/**
|
||||
|
|
@ -25,7 +25,7 @@ use phpOMS\DataStorage\Database\Query\Builder;
|
|||
* @link https://orange-management.org
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class QAHelperMapper extends DataMapperAbstract
|
||||
final class QAHelperMapper extends DataMapperFactory
|
||||
{
|
||||
/**
|
||||
* Get total score of account
|
||||
|
|
@ -41,10 +41,10 @@ final class QAHelperMapper extends DataMapperAbstract
|
|||
$query = new Builder(self::$db);
|
||||
$questionScore = $query->select('qa_question_created_by')
|
||||
->selectAs('SUM(qa_question_vote_score)', 'score')
|
||||
->from(QAQuestionVoteMapper::getTable())
|
||||
->leftJoin(QAQuestionMapper::getTable())
|
||||
->on(QAQuestionVoteMapper::getTable() . '.qa_question_vote_question', '=', QAQuestionMapper::getTable() . '.qa_question_id')
|
||||
->where(QAQuestionMapper::getTable() . '.qa_question_created_by', 'in', $accounts)
|
||||
->from(QAQuestionVoteMapper::TABLE)
|
||||
->leftJoin(QAQuestionMapper::TABLE)
|
||||
->on(QAQuestionVoteMapper::TABLE . '.qa_question_vote_question', '=', QAQuestionMapper::TABLE . '.qa_question_id')
|
||||
->where(QAQuestionMapper::TABLE . '.qa_question_created_by', 'in', $accounts)
|
||||
->groupBy('qa_question_created_by')
|
||||
->execute()
|
||||
->fetchAll();
|
||||
|
|
@ -56,10 +56,10 @@ final class QAHelperMapper extends DataMapperAbstract
|
|||
$query = new Builder(self::$db);
|
||||
$answerScore = $query->select('qa_answer_created_by')
|
||||
->selectAs('SUM(qa_answer_vote_score)', 'score')
|
||||
->from(QAAnswerVoteMapper::getTable())
|
||||
->leftJoin(QAAnswerMapper::getTable())
|
||||
->on(QAAnswerVoteMapper::getTable() . '.qa_answer_vote_answer', '=', QAAnswerMapper::getTable() . '.qa_answer_id')
|
||||
->where(QAAnswerMapper::getTable() . '.qa_answer_created_by', 'in', $accounts)
|
||||
->from(QAAnswerVoteMapper::TABLE)
|
||||
->leftJoin(QAAnswerMapper::TABLE)
|
||||
->on(QAAnswerVoteMapper::TABLE . '.qa_answer_vote_answer', '=', QAAnswerMapper::TABLE . '.qa_answer_id')
|
||||
->where(QAAnswerMapper::TABLE . '.qa_answer_created_by', 'in', $accounts)
|
||||
->groupBy('qa_answer_created_by')
|
||||
->execute()
|
||||
->fetchAll();
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ namespace Modules\QA\Models;
|
|||
use Modules\Media\Models\MediaMapper;
|
||||
use Modules\Profile\Models\ProfileMapper;
|
||||
use Modules\Tag\Models\TagMapper;
|
||||
use phpOMS\DataStorage\Database\DataMapperAbstract;
|
||||
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
|
||||
|
||||
/**
|
||||
* Mapper class.
|
||||
|
|
@ -27,7 +27,7 @@ use phpOMS\DataStorage\Database\DataMapperAbstract;
|
|||
* @link https://orange-management.org
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class QAQuestionMapper extends DataMapperAbstract
|
||||
final class QAQuestionMapper extends DataMapperFactory
|
||||
{
|
||||
/**
|
||||
* Columns.
|
||||
|
|
@ -35,7 +35,7 @@ final class QAQuestionMapper extends DataMapperAbstract
|
|||
* @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static array $columns = [
|
||||
public const COLUMNS = [
|
||||
'qa_question_id' => ['name' => 'qa_question_id', 'type' => 'int', 'internal' => 'id'],
|
||||
'qa_question_title' => ['name' => 'qa_question_title', 'type' => 'string', 'internal' => 'name'],
|
||||
'qa_question_language' => ['name' => 'qa_question_language', 'type' => 'string', 'internal' => 'language'],
|
||||
|
|
@ -53,7 +53,13 @@ final class QAQuestionMapper extends DataMapperAbstract
|
|||
* @var array<string, array{mapper:string, table:string, self?:?string, external?:?string, column?:string}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static array $hasMany = [
|
||||
public const HAS_MANY = [
|
||||
'tags' => [
|
||||
'mapper' => TagMapper::class,
|
||||
'table' => 'qa_tag',
|
||||
'self' => 'qa_tag_dst',
|
||||
'external' => 'qa_tag_src',
|
||||
],
|
||||
'answers' => [
|
||||
'mapper' => QAAnswerMapper::class,
|
||||
'table' => 'qa_answer',
|
||||
|
|
@ -66,12 +72,6 @@ final class QAQuestionMapper extends DataMapperAbstract
|
|||
'self' => 'qa_question_vote_question',
|
||||
'external' => null,
|
||||
],
|
||||
'tags' => [
|
||||
'mapper' => TagMapper::class,
|
||||
'table' => 'qa_tag',
|
||||
'self' => 'qa_tag_dst',
|
||||
'external' => 'qa_tag_src',
|
||||
],
|
||||
'media' => [
|
||||
'mapper' => MediaMapper::class,
|
||||
'table' => 'qa_question_media',
|
||||
|
|
@ -86,7 +86,7 @@ final class QAQuestionMapper extends DataMapperAbstract
|
|||
* @var array<string, array{mapper:string, external:string}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static array $belongsTo = [
|
||||
public const BELONGS_TO = [
|
||||
'createdBy' => [
|
||||
'mapper' => ProfileMapper::class,
|
||||
'external' => 'qa_question_created_by',
|
||||
|
|
@ -104,7 +104,7 @@ final class QAQuestionMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $table = 'qa_question';
|
||||
public const TABLE = 'qa_question';
|
||||
|
||||
/**
|
||||
* Created at.
|
||||
|
|
@ -112,7 +112,7 @@ final class QAQuestionMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $createdAt = 'qa_question_created_at';
|
||||
public const CREATED_AT = 'qa_question_created_at';
|
||||
|
||||
/**
|
||||
* Primary field name.
|
||||
|
|
@ -120,5 +120,5 @@ final class QAQuestionMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $primaryField = 'qa_question_id';
|
||||
public const PRIMARYFIELD ='qa_question_id';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ declare(strict_types=1);
|
|||
namespace Modules\QA\Models;
|
||||
|
||||
use Modules\Admin\Models\AccountMapper;
|
||||
use phpOMS\DataStorage\Database\DataMapperAbstract;
|
||||
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
|
||||
|
||||
/**
|
||||
* Mapper class.
|
||||
|
|
@ -25,7 +25,7 @@ use phpOMS\DataStorage\Database\DataMapperAbstract;
|
|||
* @link https://orange-management.org
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class QAQuestionVoteMapper extends DataMapperAbstract
|
||||
final class QAQuestionVoteMapper extends DataMapperFactory
|
||||
{
|
||||
/**
|
||||
* Columns.
|
||||
|
|
@ -33,7 +33,7 @@ final class QAQuestionVoteMapper extends DataMapperAbstract
|
|||
* @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static array $columns = [
|
||||
public const COLUMNS = [
|
||||
'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_question' => ['name' => 'qa_question_vote_question', 'type' => 'int', 'internal' => 'question', 'readonly' => true],
|
||||
|
|
@ -47,7 +47,7 @@ final class QAQuestionVoteMapper extends DataMapperAbstract
|
|||
* @var array<string, array{mapper:string, external:string}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static array $belongsTo = [
|
||||
public const BELONGS_TO = [
|
||||
'createdBy' => [
|
||||
'mapper' => AccountMapper::class,
|
||||
'external' => 'qa_question_vote_created_by',
|
||||
|
|
@ -60,7 +60,7 @@ final class QAQuestionVoteMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $table = 'qa_question_vote';
|
||||
public const TABLE = 'qa_question_vote';
|
||||
|
||||
/**
|
||||
* Created at.
|
||||
|
|
@ -68,7 +68,7 @@ final class QAQuestionVoteMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $createdAt = 'qa_question_vote_created_at';
|
||||
public const CREATED_AT = 'qa_question_vote_created_at';
|
||||
|
||||
/**
|
||||
* Primary field name.
|
||||
|
|
@ -76,7 +76,7 @@ final class QAQuestionVoteMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $primaryField = 'qa_question_vote_id';
|
||||
public const PRIMARYFIELD ='qa_question_vote_id';
|
||||
|
||||
/**
|
||||
* Find vote for question from user
|
||||
|
|
@ -90,13 +90,8 @@ final class QAQuestionVoteMapper extends DataMapperAbstract
|
|||
*/
|
||||
public static function findVote(int $question, int $account) : bool | QAQuestionVote
|
||||
{
|
||||
$depth = 3;
|
||||
$query = self::getQuery();
|
||||
$query->where(self::$table . '_d' . $depth . '.qa_question_vote_created_by', '=', $account)
|
||||
->andWhere(self::$table . '_d' . $depth . '.qa_question_vote_question', '=', $question);
|
||||
$results = self::getAll()->where('comment', $question)->where('createdBy', $account)->execute();
|
||||
|
||||
$results = self::getAllByQuery($query);
|
||||
|
||||
return \reset($results);
|
||||
return empty($results) ? new NullQAQuestionVote() : \reset($results);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ require_once __DIR__ . '/../vendor/autoload.php';
|
|||
require_once __DIR__ . '/Autoloader.php';
|
||||
|
||||
use phpOMS\DataStorage\Database\DatabasePool;
|
||||
use phpOMS\DataStorage\Database\DataMapperAbstract;
|
||||
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
|
||||
use phpOMS\DataStorage\Session\HttpSession;
|
||||
|
||||
$CONFIG = [
|
||||
|
|
@ -329,7 +329,7 @@ $GLOBALS['dbpool']->create('delete', $CONFIG['db']['core']['masters']['delete'])
|
|||
$GLOBALS['dbpool']->create('insert', $CONFIG['db']['core']['masters']['insert']);
|
||||
$GLOBALS['dbpool']->create('schema', $CONFIG['db']['core']['masters']['schema']);
|
||||
|
||||
DataMapperAbstract::setConnection($GLOBALS['dbpool']->get());
|
||||
DataMapperFactory::db($GLOBALS['dbpool']->get());
|
||||
|
||||
$GLOBALS['frameworkpath'] = '/phpOMS/';
|
||||
|
||||
|
|
|
|||
|
|
@ -41,11 +41,11 @@ final class QAAnswerMapperTest extends \PHPUnit\Framework\TestCase
|
|||
$answer->question = new NullQAQuestion(1);
|
||||
$answer->isAccepted = true;
|
||||
|
||||
$id = QAAnswerMapper::create($answer);
|
||||
$id = QAAnswerMapper::create()->execute($answer);
|
||||
self::assertGreaterThan(0, $answer->getId());
|
||||
self::assertEquals($id, $answer->getId());
|
||||
|
||||
$answerR = QAAnswerMapper::get($answer->getId());
|
||||
$answerR = QAAnswerMapper::get()->with('createdBy')->with('account')->where('id', $answer->getId())->execute();
|
||||
self::assertEquals($answer->answer, $answerR->answer);
|
||||
self::assertEquals($answer->question->getId(), $answerR->question->getId());
|
||||
self::assertEquals($answer->getStatus(), $answerR->getStatus());
|
||||
|
|
|
|||
|
|
@ -35,11 +35,11 @@ final class QAAnswerVoteMapperTest extends \PHPUnit\Framework\TestCase
|
|||
$vote->score = 1;
|
||||
$vote->createdBy = new NullAccount(1);
|
||||
|
||||
$id = QAAnswerVoteMapper::create($vote);
|
||||
$id = QAAnswerVoteMapper::create()->execute($vote);
|
||||
self::assertGreaterThan(0, $vote->getId());
|
||||
self::assertEquals($id, $vote->getId());
|
||||
|
||||
$voteR = QAAnswerVoteMapper::get($vote->getId());
|
||||
$voteR = QAAnswerVoteMapper::get()->where('id', $vote->getId())->execute();
|
||||
self::assertEquals($vote->answer, $voteR->answer);
|
||||
self::assertEquals($vote->score, $voteR->score);
|
||||
|
||||
|
|
|
|||
|
|
@ -39,11 +39,11 @@ final class QAQuestionMapperTest extends \PHPUnit\Framework\TestCase
|
|||
$question->createdBy = new Profile(new NullAccount(1));
|
||||
$question->setLanguage('en');
|
||||
|
||||
$id = QAQuestionMapper::create($question);
|
||||
$id = QAQuestionMapper::create()->execute($question);
|
||||
self::assertGreaterThan(0, $question->getId());
|
||||
self::assertEquals($id, $question->getId());
|
||||
|
||||
$questionR = QAQuestionMapper::get($question->getId());
|
||||
$questionR = QAQuestionMapper::get()->with('createdBy')->with('createdBy/account')->where('id', $question->getId())->execute();
|
||||
self::assertEquals($question->name, $questionR->name);
|
||||
self::assertEquals($question->question, $questionR->question);
|
||||
self::assertEquals($question->getStatus(), $questionR->getStatus());
|
||||
|
|
|
|||
|
|
@ -35,11 +35,11 @@ final class QAQuestionVoteMapperTest extends \PHPUnit\Framework\TestCase
|
|||
$vote->score = 1;
|
||||
$vote->createdBy = new NullAccount(1);
|
||||
|
||||
$id = QAQuestionVoteMapper::create($vote);
|
||||
$id = QAQuestionVoteMapper::create()->execute($vote);
|
||||
self::assertGreaterThan(0, $vote->getId());
|
||||
self::assertEquals($id, $vote->getId());
|
||||
|
||||
$voteR = QAQuestionVoteMapper::get($vote->getId());
|
||||
$voteR = QAQuestionVoteMapper::get()->where('id', $vote->getId())->execute();
|
||||
self::assertEquals($vote->question, $voteR->question);
|
||||
self::assertEquals($vote->score, $voteR->score);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user