Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
services
Archive
t3o
my.typo3.org
Commits
8274de7d
Commit
8274de7d
authored
Feb 12, 2019
by
mabolek
Committed by
Sebastian Kotte
Feb 12, 2019
Browse files
[TASK] Simplified trigger action API for adding karma
parent
3229b5e3
Changes
2
Hide whitespace changes
Inline
Side-by-side
extensions/karma/Classes/Service/KarmaService.php
View file @
8274de7d
...
...
@@ -6,6 +6,7 @@ use T3o\Karma\Domain\Model\FrontendUser;
use
T3o\Karma\Domain\Model\LedgerEntry
;
use
T3o\Karma\Domain\Repository\FrontendUserRepository
;
use
T3o\Karma\Domain\Repository\LedgerEntryRepository
;
use
TYPO3\CMS\Core\Utility\GeneralUtility
;
use
TYPO3\CMS\Extbase\Domain\Model\FrontendUser
as
ExtbaseFrontendUser
;
/***************************************************************
...
...
@@ -43,6 +44,25 @@ class KarmaService implements \TYPO3\CMS\Core\SingletonInterface
*/
protected
$frontendUserRepository
;
/**
* @var array
*/
protected
$settings
;
/**
* UserProfileChangeKarmaIssuerUtility constructor.
*/
public
function
__construct
()
{
$objectManager
=
GeneralUtility
::
makeInstance
(
\
TYPO3\CMS\Extbase\Object\ObjectManager
::
class
);
/** @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManager $configurationManager */
$configurationManager
=
$objectManager
->
get
(
\
TYPO3\CMS\Extbase\Configuration\ConfigurationManager
::
class
);
$this
->
settings
=
$configuration
=
$configurationManager
->
getConfiguration
(
\
TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
::
CONFIGURATION_TYPE_SETTINGS
,
'karma'
);
}
/**
* @param LedgerEntryRepository $ledgerEntryRepository
*/
...
...
@@ -185,6 +205,44 @@ class KarmaService implements \TYPO3\CMS\Core\SingletonInterface
$this
->
frontendUserRepository
->
update
(
$frontendUser
);
}
/**
* Trigger a karma-earning action for a user
*
* @param $issuerCode The issuer code for the karma
* @param $issuerActionCode The issuer action code for the karma
* @param ExtbaseFrontendUser $frontendUser The frontend user earning the karma
* @throws \Exception If the $issuerCode, $issuerActionCode, or karma source code is not defined in TypoScript.
*/
public
function
triggerKarmaIssuerActionForUser
(
$issuerCode
,
$issuerActionCode
,
ExtbaseFrontendUser
$frontendUser
)
{
if
(
!
key_exists
(
$issuerCode
,
$this
->
settings
[
'issuers'
]))
{
throw
new
\
Exception
(
'Issuer code "'
.
$issuerCode
.
'" does not exist.'
,
1549968187
);
}
if
(
!
key_exists
(
$issuerActionCode
,
$this
->
settings
[
'issuers'
][
$issuerCode
]))
{
throw
new
\
Exception
(
'Issuer action code "'
.
$issuerActionCode
.
'" does not exist.'
,
1549968249
);
}
$issuerActionSettings
=
$this
->
settings
[
'issuers'
][
$issuerCode
][
$issuerActionCode
];
$karmaSourceCode
=
$issuerActionSettings
[
'sourceCode'
];
if
(
$karmaSourceCode
===
''
)
{
throw
new
\
Exception
(
'Empty karma source code supplied. Please configure it in TypoScript.'
,
1541508560
);
}
if
(
!
key_exists
(
$karmaSourceCode
,
$this
->
settings
[
'sourceCodes'
]))
{
throw
new
\
Exception
(
'Karma source code "'
.
$karmaSourceCode
.
'" does not exist.'
,
1549968362
);
}
$this
->
addKarmaToUser
(
$issuerActionSettings
[
'valueEarned'
],
$frontendUser
,
$karmaSourceCode
,
$issuerCode
,
$issuerActionCode
);
}
/**
* 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 @
8274de7d
...
...
@@ -3,11 +3,8 @@
namespace
T3o\Karma\Utility
;
use
In2code\Femanager\Controller\AbstractController
as
In2CodeAbstractController
;
use
T3o\Karma\Domain\Repository\FrontendUserRepository
;
use
T3o\Karma\Service\KarmaService
;
use
TYPO3\CMS\Core\Utility\GeneralUtility
;
use
TYPO3\CMS\Extbase\Domain\Model\FrontendUser
as
ExtbaseFrontendUser
;
use
TYPO3\CMS\Extbase\Object\ObjectManager
;
/***************************************************************
* Copyright notice
...
...
@@ -41,35 +38,6 @@ class UserProfileChangeKarmaIssuerUtility
*/
protected
$karmaService
;
/**
* @var \T3o\Karma\Domain\Repository\FrontendUserRepository
*/
protected
$frontendUserRepository
;
/**
* @var \TYPO3\CMS\Extbase\Object\ObjectManager
*/
protected
$objectManager
;
/**
* @var array
*/
protected
$settings
;
/**
* UserProfileChangeKarmaIssuerUtility constructor.
*/
public
function
__construct
()
{
$objectManager
=
GeneralUtility
::
makeInstance
(
\
TYPO3\CMS\Extbase\Object\ObjectManager
::
class
);
/** @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManager $configurationManager */
$configurationManager
=
$objectManager
->
get
(
\
TYPO3\CMS\Extbase\Configuration\ConfigurationManager
::
class
);
$this
->
settings
=
$configuration
=
$configurationManager
->
getConfiguration
(
\
TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
::
CONFIGURATION_TYPE_SETTINGS
,
'karma'
);
}
/**
* @param \T3o\Karma\Service\KarmaService $karmaService
*/
...
...
@@ -79,41 +47,18 @@ class UserProfileChangeKarmaIssuerUtility
}
/**
* @param \T3o\Karma\Domain\Repository\FrontendUserRepository $frontendUserRepository
*/
public
function
injectFrontendUserRepository
(
FrontendUserRepository
$frontendUserRepository
)
{
$this
->
frontendUserRepository
=
$frontendUserRepository
;
}
/**
* @param \TYPO3\CMS\Extbase\Object\ObjectManager $objectManager
*/
public
function
injectObjectManager
(
ObjectManager
$objectManager
)
{
$this
->
objectManager
=
$objectManager
;
}
/**
* Triggered when a new user is created
*
* @param ExtbaseFrontendUser $frontendUser
* @param string $action
* @param In2CodeAbstractController $object
*/
public
function
newUserWasCreated
(
ExtbaseFrontendUser
$frontendUser
)
{
$issuerActionSettings
=
$this
->
settings
[
'issuers'
][
self
::
ISSUER_CODE
][
__FUNCTION__
];
$karmaSourceCode
=
$issuerActionSettings
[
'sourceCode'
];
if
(
$karmaSourceCode
===
''
)
{
throw
new
\
Exception
(
'Empty karma source code supplied. Please configure it in TypoScript.'
,
1541508560
);
}
$this
->
karmaService
->
addKarmaToUser
(
$issuerActionSettings
[
'valueEarned'
],
$frontendUser
,
$issuerActionSettings
[
'sourceCode'
],
$this
->
karmaService
->
triggerKarmaIssuerActionForUser
(
self
::
ISSUER_CODE
,
__FUNCTION__
__FUNCTION__
,
$frontendUser
);
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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