Commit 84f2f0a6 authored by mabolek's avatar mabolek Committed by Thomas Löffler
Browse files

[TASK] Calculation functions for karma sum

parent a7392fc4
......@@ -2,7 +2,13 @@
namespace T3o\Karma\Domain\Repository;
use T3o\Karma\Domain\Model\LedgerEntry;
use T3o\Karma\Service\KarmaService;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMap;
use TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper;
/***************************************************************
* Copyright notice
......@@ -49,8 +55,19 @@ class CampaignRepository extends \TYPO3\CMS\Extbase\Persistence\Repository
{
$frontendUser = $this->karmaService->ensureCorrectFrontendUserSubclass($frontendUser);
//@TODO: Implement calculation
return 7;
$queryBuilder = $this->getQueryBuilder();
$result = $queryBuilder
->addSelectLiteral($queryBuilder->expr()->sum('immutable_value'))
->from($this->getTableName())
->where(
$queryBuilder->expr()->eq('user', $frontendUser->getUid()),
$queryBuilder->expr()->eq('expired', 0)
)
->execute();
$sum = $result->fetchColumn(0);
return $sum;
}
/**
......@@ -62,7 +79,42 @@ class CampaignRepository extends \TYPO3\CMS\Extbase\Persistence\Repository
{
$frontendUser = $this->karmaService->ensureCorrectFrontendUserSubclass($frontendUser);
//@TODO: Implement calculation
return 8;
$queryBuilder = $this->getQueryBuilder();
$result = $queryBuilder
->addSelectLiteral($queryBuilder->expr()->sum('mutable_value'))
->from($this->getTableName())
->where(
$queryBuilder->expr()->eq('user', $frontendUser->getUid()),
$queryBuilder->expr()->eq('expired', 0)
)
->execute();
$sum = $result->fetchColumn(0);
return $sum;
}
/**
* Get the table name for this class
*
* @return string
* @internal
*/
protected function getTableName() {
/** @var DataMapper $dataMapper */
$dataMapper = GeneralUtility::makeInstance(DataMapper::class);
/** @var DataMap $dataMap */
$dataMap = $dataMapper->getDataMap(LedgerEntry::class);
return $dataMap->getTableName();
}
/**
* Get a QueryBuilder object
*
* @return QueryBuilder
*/
protected function getQueryBuilder() {
return GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->getTableName());
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment