Commit 58292401 authored by mabolek's avatar mabolek

[TASK] Removed KarmaSource domain model because it was unnecessary

parent 617e2212
<?php
namespace T3o\Karma\Domain\Model;
/***************************************************************
* Copyright notice
*
* (c) 2018
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
class KarmaSource extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
{
/**
* The title of the karma source
*
* @var string
*/
protected $title;
/**
* The alphanumeric code of the karma source
*
* Used for API calls etc.
*
* @var string
*/
protected $code;
/**
* Get the title of the karma source
*
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Set the title of the karma source
*
* @param string $title
*/
public function setTitle(string $title)
{
$this->title = $title;
}
/**
* Get the karma source code
*
* Alphanumeric code for use in APIs etc.
*
* @return string
*/
public function getCode()
{
return $this->code;
}
/**
* Set the karma code
*
* Set the alphanumeric code for use in APIs etc.
*
* @param string $code
*/
public function setCode(string $code)
{
$this->code = $code;
}
}
<?php
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
*
* (c) 2018
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
class KarmaSourceRepository extends \TYPO3\CMS\Extbase\Persistence\Repository
{
/**
* @var KarmaService
*/
public $karmaService;
public function injectKarmaService(KarmaService $karmaService)
{
$this->karmaService = $karmaService;
}
/**
* Calculates the immutable karma total for a user
*
* @param \TYPO3\CMS\Extbase\Domain\Model\FrontendUser $frontendUser
* @return int
*/
public function calculateImmutableKarmaTotalForUser(\TYPO3\CMS\Extbase\Domain\Model\FrontendUser $frontendUser)
{
$frontendUser = $this->karmaService->ensureCorrectFrontendUserSubclass($frontendUser);
$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;
}
/**
* Calculates the mutable karma total for a user
*
* @param \TYPO3\CMS\Extbase\Domain\Model\FrontendUser $frontendUser
*/
public function calculateMutableKarmaTotalForUser(\TYPO3\CMS\Extbase\Domain\Model\FrontendUser $frontendUser)
{
$frontendUser = $this->karmaService->ensureCorrectFrontendUserSubclass($frontendUser);
$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());
}
}
......@@ -20,23 +20,6 @@ CREATE TABLE tx_karma_domain_model_ledgerentry (
PRIMARY KEY (uid)
);
#
# Table structure for table 'tx_karma_domain_model_karmasource'
#
CREATE TABLE tx_karma_domain_model_karmasource (
uid int(11) NOT NULL auto_increment,
pid int(11) DEFAULT '0' NOT NULL,
deleted smallint(6) DEFAULT '0' NOT NULL,
hidden tinyint(4) DEFAULT '0' NOT NULL,
tstamp int(11) DEFAULT '0' NOT NULL,
crdate int(11) DEFAULT '0' NOT NULL,
title tinytext,
code varchar(30) DEFAULT '' NOT NULL,
PRIMARY KEY (uid)
);
#
# Table structure for table 'tx_karma_campaign'
#
......
Markdown is supported
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