Commit 5888ea04 authored by mabolek's avatar mabolek
Browse files

[BUGFIX] Added missing file from commit 93d01f96

parent 4d0f0153
<?php
namespace T3o\Karma\Utility;
use In2code\Femanager\Controller\AbstractController as In2CodeAbstractController;
use T3o\Karma\Domain\Model\KarmaSource;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Domain\Model\FrontendUser as ExtbaseFrontendUser;
use T3o\Karma\Domain\Repository\KarmaSourceRepository;
use T3o\Karma\Service\KarmaService;
use T3o\Karma\Domain\Repository\FrontendUserRepository;
use TYPO3\CMS\Extbase\Object\ObjectManager;
/***************************************************************
* 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 UserProfileChangeKarmaIssuer
{
/**
* @var \T3o\Karma\Service\KarmaService
*/
protected $karmaService;
/**
* @var \T3o\Karma\Domain\Repository\FrontendUserRepository
*/
protected $frontendUserRepository;
/**
* @var \T3o\Karma\Domain\Repository\KarmaSourceRepository
*/
protected $karmaSourceRepository;
/**
* @var \TYPO3\CMS\Extbase\Object\ObjectManager
*/
protected $objectManager;
/**
* @var array
*/
protected $settings;
/**
* UserProfileChangeKarmaIssuer 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
*/
public function injectKarmaService(KarmaService $karmaService)
{
$this->karmaService = $karmaService;
}
/**
* @param \T3o\Karma\Domain\Repository\FrontendUserRepository $frontendUserRepository
*/
public function injectFrontendUserRepository(FrontendUserRepository $frontendUserRepository)
{
$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
*/
public function injectObjectManager(ObjectManager $objectManager) {
$this->objectManager = $objectManager;
}
/**
* @param ExtbaseFrontendUser $frontendUser
* @param string $action
* @param In2CodeAbstractController $object
*/
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);
}
$this->karmaService->addKarmaToUser(
$this->settings['userProfileChangeKarmaIssuer']['newUserWasCreated']['valueEarned'],
$frontendUser,
$karmaSource
);
}
}
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