Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
t3o
my.typo3.org
Commits
bd57edf8
Commit
bd57edf8
authored
Feb 11, 2019
by
mabolek
Committed by
Sebastian Kotte
Feb 12, 2019
Browse files
[TASK] Changed karma source references to code string
parent
b2723be3
Changes
9
Hide whitespace changes
Inline
Side-by-side
extensions/karma/Classes/Controller/AbstractController.php
View file @
bd57edf8
...
...
@@ -3,7 +3,6 @@
namespace
T3o\Karma\Controller
;
use
T3o\Karma\Domain\Repository\FrontendUserRepository
;
use
T3o\Karma\Domain\Repository\KarmaSourceRepository
;
use
T3o\Karma\Domain\Repository\LedgerEntryRepository
;
use
T3o\Karma\Service\KarmaService
;
...
...
@@ -42,11 +41,6 @@ class AbstractController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionControl
*/
protected
$frontendUserRepository
;
/**
* @var KarmaSourceRepository
*/
protected
$karmaSourceRepository
;
/**
* @var LedgerEntryRepository
*/
...
...
@@ -69,18 +63,17 @@ class AbstractController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionControl
}
/**
* @param
KarmaSource
Repository $
karmaSource
Repository
* @param
LedgerEntry
Repository $
ledgerEntry
Repository
*/
public
function
inject
KarmaSourceRepository
(
KarmaSource
Repository
$
karmaSource
Repository
)
public
function
inject
LedgerEntryRepository
(
LedgerEntry
Repository
$
ledgerEntry
Repository
)
{
$this
->
karmaSource
Repository
=
$
karmaSource
Repository
;
$this
->
ledgerEntry
Repository
=
$
ledgerEntry
Repository
;
}
/**
* @
param LedgerEntryRepository $ledgerEntryRepository
* @
return array The source codes for karma
*/
public
function
injectLedgerEntryRepository
(
LedgerEntryRepository
$ledgerEntryRepository
)
{
$this
->
ledgerEntryRepository
=
$ledgerEntryRepository
;
public
function
getKarmaSourceCodes
()
{
return
array_keys
(
$this
->
settings
[
'sourceCodes'
]);
}
}
extensions/karma/Classes/Controller/UserDisplayController.php
View file @
bd57edf8
...
...
@@ -48,6 +48,11 @@ class UserDisplayController extends AbstractController
$immutableValue
=
$this
->
karmaService
->
getImmutableKarmaForUser
(
$frontendUser
);
$mutableValue
=
$this
->
karmaService
->
getMutableKarmaForUser
(
$frontendUser
);
foreach
(
$this
->
getKarmaSourceCodes
()
as
$sourceCode
)
{
}
$this
->
view
->
assign
(
'immutableValue'
,
$immutableValue
);
$this
->
view
->
assign
(
'mutableValue'
,
$mutableValue
);
$this
->
view
->
assign
(
'hasKarma'
,
(
$immutableValue
>
0
||
$mutableValue
>
0
));
...
...
extensions/karma/Classes/Domain/Model/LedgerEntry.php
View file @
bd57edf8
...
...
@@ -64,7 +64,7 @@ class LedgerEntry extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
/**
* The entry karma source
*
* @var
\T3o\Karma\Domain\Model\KarmaSource
* @var
string
*/
protected
$karmaSource
;
...
...
@@ -197,7 +197,7 @@ class LedgerEntry extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
/**
* Get the entry karma source
*
* @return
\T3o\Karma\Domain\Model\KarmaSource
* @return
string
*/
public
function
getKarmaSource
()
{
...
...
@@ -207,9 +207,9 @@ class LedgerEntry extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
/**
* Set the entry karma source
*
* @param
\T3o\Karma\Domain\Model\KarmaSource
$karmaSource
* @param
string
$karmaSource
*/
public
function
setKarmaSource
(
KarmaSource
$karmaSource
)
public
function
setKarmaSource
(
string
$karmaSource
)
{
$this
->
karmaSource
=
$karmaSource
;
}
...
...
extensions/karma/Classes/Domain/Repository/LedgerEntryRepository.php
View file @
bd57edf8
...
...
@@ -94,6 +94,36 @@ class LedgerEntryRepository extends \TYPO3\CMS\Extbase\Persistence\Repository
return
$sum
;
}
/**
* Calculates the immutable karma from a specific source for a specific user
*
* REGARDING MUTABLE VERSION: The mutable version of this function does not
* exist on purpose, because the mutable karma is intended to be source-independent
* so that e.g. writers and developers have the same usage right for their karma.
*
* @param string $source The Karma SourceCode
* @param \TYPO3\CMS\Extbase\Domain\Model\FrontendUser $frontendUser
* @return bool|string
*/
public
function
calculateImmutableKarmaSourceTotalForUser
(
string
$source
,
\
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
),
$queryBuilder
->
expr
()
->
eq
(
'karma_source'
,
$source
)
)
->
execute
();
$sum
=
$result
->
fetchColumn
(
0
);
return
$sum
;
}
/**
* Get the table name for this class
*
...
...
extensions/karma/Classes/Service/KarmaService.php
View file @
bd57edf8
...
...
@@ -4,7 +4,6 @@ namespace T3o\Karma\Service;
use
T3o\Karma\Domain\Model\Campaign
;
use
T3o\Karma\Domain\Model\FrontendUser
;
use
T3o\Karma\Domain\Model\KarmaSource
;
use
T3o\Karma\Domain\Model\LedgerEntry
;
use
T3o\Karma\Domain\Repository\FrontendUserRepository
;
use
T3o\Karma\Domain\Repository\KarmaSourceRepository
;
...
...
@@ -46,11 +45,6 @@ class KarmaService implements \TYPO3\CMS\Core\SingletonInterface
*/
protected
$frontendUserRepository
;
/**
* @var \T3o\Karma\Domain\Repository\KarmaSourceRepository
*/
protected
$karmaSourceRepository
;
/**
* @param LedgerEntryRepository $ledgerEntryRepository
*/
...
...
@@ -67,14 +61,6 @@ class KarmaService implements \TYPO3\CMS\Core\SingletonInterface
$this
->
frontendUserRepository
=
$frontendUserRepository
;
}
/**
* @param KarmaSourceRepository $karmaSourceRepository
*/
public
function
injectKarmaSourceRepository
(
KarmaSourceRepository
$karmaSourceRepository
)
{
$this
->
karmaSourceRepository
=
$karmaSourceRepository
;
}
/**
* Get the imimmutable karma total from the user
*
...
...
@@ -142,10 +128,10 @@ class KarmaService implements \TYPO3\CMS\Core\SingletonInterface
*
* @param int $karmaValue to add to the user
* @param ExtbaseFrontendUser $frontendUser to add the value to
* @param
KarmaSource
$karmaSource for the karma value
* @param
string
$karmaSource for the karma value
* @param Campaign $campaign for the value (optional)
*/
public
function
addKarmaToUser
(
int
$karmaValue
,
ExtbaseFrontendUser
$frontendUser
,
KarmaSource
$karmaSource
,
Campaign
$campaign
=
null
)
public
function
addKarmaToUser
(
int
$karmaValue
,
ExtbaseFrontendUser
$frontendUser
,
string
$karmaSource
,
Campaign
$campaign
=
null
)
{
$frontendUser
=
$this
->
ensureCorrectFrontendUserSubclass
(
$frontendUser
);
...
...
@@ -167,34 +153,6 @@ class KarmaService implements \TYPO3\CMS\Core\SingletonInterface
$this
->
frontendUserRepository
->
update
(
$frontendUser
);
}
/**
* Get a Karma Source object. Will generate a new object with code and label if none exists.
*
* @param string $sourceCode
* @param string $defaultLabel
* @return KarmaSource
* @throws \Exception when $sourceCode is an empty string
*/
public
function
getKarmaSourceByCode
(
string
$sourceCode
,
$defaultLabel
=
'[No Label Set]'
)
{
if
(
$sourceCode
===
''
)
{
throw
new
\
Exception
(
'Empty karma source code supplied.'
,
1541508560
);
}
$karmaSource
=
$this
->
karmaSourceRepository
->
findByCode
(
$sourceCode
)
->
getFirst
();
if
(
$karmaSource
===
null
)
{
/** @var KarmaSource $karmaSource */
$karmaSource
=
new
KarmaSource
();
$karmaSource
->
setCode
(
$sourceCode
);
$karmaSource
->
setTitle
(
$defaultLabel
);
$this
->
karmaSourceRepository
->
add
(
$karmaSource
);
}
return
$karmaSource
;
}
/**
* Will take any FrontendUser object and return a karma extension FrontendUser subclass with the data we need
*
...
...
extensions/karma/Classes/Utility/UserProfileChangeKarmaIssuerUtility.php
View file @
bd57edf8
...
...
@@ -3,7 +3,6 @@
namespace
T3o\Karma\Utility
;
use
In2code\Femanager\Controller\AbstractController
as
In2CodeAbstractController
;
use
T3o\Karma\Domain\Model\KarmaSource
;
use
T3o\Karma\Domain\Repository\FrontendUserRepository
;
use
T3o\Karma\Domain\Repository\KarmaSourceRepository
;
use
T3o\Karma\Service\KarmaService
;
...
...
@@ -46,11 +45,6 @@ class UserProfileChangeKarmaIssuerUtility
*/
protected
$frontendUserRepository
;
/**
* @var \T3o\Karma\Domain\Repository\KarmaSourceRepository
*/
protected
$karmaSourceRepository
;
/**
* @var \TYPO3\CMS\Extbase\Object\ObjectManager
*/
...
...
@@ -91,14 +85,6 @@ class UserProfileChangeKarmaIssuerUtility
$this
->
frontendUserRepository
=
$frontendUserRepository
;
}
/**
* @param \T3o\Karma\Domain\Repository\KarmaSourceRepository $karmaSourceRepository
*/
public
function
injectKarmaSourceRepository
(
KarmaSourceRepository
$karmaSourceRepository
)
{
$this
->
karmaSourceRepository
=
$karmaSourceRepository
;
}
/**
* @param \TYPO3\CMS\Extbase\Object\ObjectManager $objectManager
*/
...
...
@@ -114,27 +100,17 @@ class UserProfileChangeKarmaIssuerUtility
*/
public
function
newUserWasCreated
(
ExtbaseFrontendUser
$frontendUser
)
{
$karmaSourceCode
=
$this
->
settings
[
'userProfileChangeKarmaIssuer'
][
'newUserWasCreated'
][
'sourceCode'
];
$issuerActionSettings
=
$this
->
settings
[
'issuers'
][
'userProfileChange'
][
'newUserWasCreated'
];
$karmaSourceCode
=
$issuerActionSettings
[
'sourceCode'
];
if
(
$karmaSourceCode
===
''
)
{
throw
new
\
Exception
(
'Empty karma source code supplied. Please configure it in TypoScript.'
,
1541508560
);
}
$karmaSource
=
$this
->
karmaSourceRepository
->
findByCode
(
$karmaSourceCode
)
->
getFirst
();
if
(
$karmaSource
===
null
)
{
/** @var KarmaSource $karmaSource */
$karmaSource
=
new
KarmaSource
();
$karmaSource
->
setCode
(
$karmaSourceCode
);
$karmaSource
->
setTitle
(
$this
->
settings
[
'userProfileChangeKarmaIssuer'
][
'newUserWasCreated'
][
'defaultSourceLabel'
]);
$this
->
karmaSourceRepository
->
add
(
$karmaSource
);
}
$this
->
karmaService
->
addKarmaToUser
(
$
this
->
settings
[
'userProfileChangeKarmaIssuer'
][
'newUserWasCreated'
]
[
'valueEarned'
],
$
issuerActionSettings
[
'valueEarned'
],
$frontendUser
,
$
karmaSource
$
issuerActionSettings
[
'sourceCode'
]
);
}
}
extensions/karma/Configuration/TCA/tx_karma_domain_model_ledgerentry.php
View file @
bd57edf8
...
...
@@ -81,13 +81,11 @@ $tx_karma_domain_model_ledgerentry = [
'exclude'
=>
true
,
'label'
=>
$ll
.
'tx_karma_domain_model_ledgerentry.karma_source'
,
'config'
=>
[
'type'
=>
'group'
,
'internal_type'
=>
'db'
,
'foreign_table'
=>
'tx_karma_domain_model_karmasource'
,
'allowed'
=>
'tx_karma_domain_model_karmasource'
,
'size'
=>
1
,
'minitems'
=>
1
,
'maxitems'
=>
1
,
'type'
=>
'input'
,
'size'
=>
16
,
'max'
=>
16
,
'eval'
=>
'trim'
,
'default'
=>
0
,
]
],
'campaign'
=>
[
...
...
extensions/karma/Configuration/TypoScript/setup.txt
View file @
bd57edf8
...
...
@@ -14,11 +14,19 @@ plugin.tx_karma {
}
settings {
userProfileChangeKarmaIssuer {
newUserWasCreated {
sourceCode = usercreated
defaultSourceLabel = Created my.typo3.org User
valueEarned = 10
issuers {
userProfileChange {
newUserWasCreated {
sourceCode = useraction
label = Created my.typo3.org User
valueEarned = 10
}
}
}
sourceCodes {
useraction {
label = my.typo3.org User Action
}
}
}
...
...
extensions/karma/ext_tables.sql
View file @
bd57edf8
...
...
@@ -13,7 +13,7 @@ CREATE TABLE tx_karma_domain_model_ledgerentry (
immutable_value
int
(
11
)
DEFAULT
'0'
,
mutable_value
int
(
11
)
DEFAULT
'0'
,
karma_source
int
(
1
1
)
unsigned
DEFAULT
'
0
'
,
karma_source
varchar
(
1
6
)
DEFAULT
''
,
campaign
int
(
11
)
unsigned
DEFAULT
'0'
,
user
int
(
11
)
unsigned
DEFAULT
'0'
,
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment