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
00360fe9
Commit
00360fe9
authored
Nov 06, 2018
by
mabolek
Committed by
Thomas Löffler
Feb 11, 2019
Browse files
[TASK] Moved karma source fetch into KarmaService
parent
93d01f96
Changes
2
Hide whitespace changes
Inline
Side-by-side
extensions/karma/Classes/Service/KarmaService.php
View file @
00360fe9
...
...
@@ -7,6 +7,7 @@ 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
;
use
T3o\Karma\Domain\Repository\LedgerEntryRepository
;
use
TYPO3\CMS\Extbase\Domain\Model\FrontendUser
as
ExtbaseFrontendUser
;
...
...
@@ -45,6 +46,11 @@ class KarmaService implements \TYPO3\CMS\Core\SingletonInterface
*/
protected
$frontendUserRepository
;
/**
* @var \T3o\Karma\Domain\Repository\KarmaSourceRepository
*/
protected
$karmaSourceRepository
;
/**
* @param LedgerEntryRepository $ledgerEntryRepository
*/
...
...
@@ -61,6 +67,13 @@ 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
*
...
...
@@ -153,6 +166,34 @@ 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
(
$karmaSourceCode
);
$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
*
...
...
html/typo3conf/ext/karma/Classes/Utility/UserProfileChangeKarmaIssuer.php
View file @
00360fe9
...
...
@@ -46,11 +46,6 @@ class UserProfileChangeKarmaIssuer
*/
protected
$frontendUserRepository
;
/**
* @var \T3o\Karma\Domain\Repository\KarmaSourceRepository
*/
protected
$karmaSourceRepository
;
/**
* @var \TYPO3\CMS\Extbase\Object\ObjectManager
*/
...
...
@@ -91,14 +86,6 @@ class UserProfileChangeKarmaIssuer
$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
*/
...
...
@@ -113,22 +100,10 @@ class UserProfileChangeKarmaIssuer
*/
public
function
newUserWasCreated
(
ExtbaseFrontendUser
$frontendUser
)
{
$karmaSourceCode
=
$this
->
settings
[
'userProfileChangeKarmaIssuer'
][
'newUserWasCreated'
][
'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
);
}
$karmaSource
=
$this
->
karmaService
->
getKarmaSourceByCode
(
$this
->
settings
[
'userProfileChangeKarmaIssuer'
][
'newUserWasCreated'
][
'sourceCode'
],
$this
->
settings
[
'userProfileChangeKarmaIssuer'
][
'newUserWasCreated'
][
'defaultSourceLabel'
]
);
$this
->
karmaService
->
addKarmaToUser
(
$this
->
settings
[
'userProfileChangeKarmaIssuer'
][
'newUserWasCreated'
][
'valueEarned'
],
...
...
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