DirectmessageController.php 9.60 KiB
<?php
namespace DTInternet\DtiOnlineconsulting\Controller;
/***************************************************************
 *  Copyright notice
 *  (c) 2022 Stefan Bublies <bublies@dt-internet.de>
 *  All rights reserved
 ***************************************************************/
use \TYPO3\CMS\Core\Utility\GeneralUtility;
use \TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use DTInternet\DtiUsermanagement\Utility\FeuserUtility;
use TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository;
use DTInternet\DtiOnlineconsulting\Utility\RelationUtility;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility as Locallang;
/**
 * (c) 2022 Stefan Bublies bublies@dt-internet.de
class DirectmessageController extends ActionController
    /**
     * @var \TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager
     * @TYPO3\CMS\Extbase\Annotation\Inject
    protected $persistenceManager;
    /**
     * Init the persistenceManager
     * @return void
    public function __construct()
        $this->persistenceManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance("TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager");
        /**
     * topicsRepository
     * @var \DTInternet\DtiOnlineconsulting\Domain\Repository\TopicsRepository
    protected $topicsRepository = null;
    /**
     * @param \DTInternet\DtiOnlineconsulting\Domain\Repository\TopicsRepository $topicsRepository
    public function injectTopicsRepository(\DTInternet\DtiOnlineconsulting\Domain\Repository\TopicsRepository $topicsRepository)
        $this->topicsRepository = $topicsRepository;
    /**
     * topicsRepository
     * @var \DTInternet\DtiOnlineconsulting\Domain\Repository\TopicanswersRepository
    protected $topicanswersRepository = null;
    /**
     * @param \DTInternet\DtiOnlineconsulting\Domain\Repository\TopicanswersRepository $topicanswersRepository
    public function injectTopicanswersRepository(\DTInternet\DtiOnlineconsulting\Domain\Repository\TopicanswersRepository $topicanswersRepository)
        $this->topicanswersRepository = $topicanswersRepository;
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
} /** * FunctionSwitch * @return void */ public function selectionAction() { if($this->settings['function'] == 1) { $this->userlist(); } else { $this->agentlist(); } $this->view->assign('function', $this->settings['function']); } /** * Userlist Action * @return void */ public function userlist() { $feUserData = FeuserUtility::get(); $topics = $this->topicsRepository->findByFeuser($feUserData['uid']); $this->view->assign('topics', $topics); } /** * Agentlist Action * @return void */ public function agentlist() { $topics = $this->topicsRepository->findByClosed(0); $closedtopics = $this->topicsRepository->findByClosed(1); $this->view->assignMultiple([ 'topics' => $topics, 'closedtopics' => $closedtopics ]); } /** * ChatAction * @param $topics * @return void */ public function chatAction(\DTInternet\DtiOnlineconsulting\Domain\Model\Topics $topics) { $arguments = $this->request->getArguments(); $feUserData = FeuserUtility::get(); if ($arguments['directmessage']) { if(!$arguments['directmessage']['bodytext'] == '') { $feUserData = FeuserUtility::get(); $newRequest = new \DTInternet\DtiOnlineconsulting\Domain\Model\Topicanswers(); $newRequest->setAnswertext($arguments['directmessage']['bodytext']); $newRequest->setPid(17); // muss noch per Konstante variabel gemacht werden if($feUserData['usergroup'] > 1) { // muss noch per Konstante variabel gemacht werden $newRequest->setFeuser($feUserData['uid']); $newRequest->setAgent(0); } else { $newRequest->setFeuser(0); $newRequest->setAgent($feUserData['uid']); } $this->topicanswersRepository->add($newRequest); $this->persistenceManager->persistAll();
141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
$answerObjects = $this->topicanswersRepository->findByAnswertext($arguments['directmessage']['bodytext']); $answerObjectsCleaned = []; foreach($answerObjects as $object) { if ($object->getFeuser() == $feUserData['uid'] OR $object->getAgent() == $feUserData['uid']) { $answerObjectsCleaned = $object; } } RelationUtility::setRelation($topics->getUid(), $answerObjectsCleaned->getUid()); // Neue Nachricht Info für User bzw. Agenten setzen if ($feUserData['usergroup'] > 1) { // muss noch per Konstante variabel gemacht werden $topics->setAgentstate(1); $this->topicsRepository->update($topics); $this->persistenceManager->persistAll(); } else { $topics->setUserstate(1); $this->topicsRepository->update($topics); $this->persistenceManager->persistAll(); } $redirectArray = []; $redirectArray['topics'] = $topics; $this->redirect('chat', 'Directmessage', 'dtionlineconsulting', $redirectArray); } else { $this->addFlashMessage( Locallang::translate('tx_dtionlineconsulting.topics.answer.error.body', 'dti_onlineconsulting', NULL), Locallang::translate('tx_dtionlineconsulting.topics.answer.error.header', 'dti_onlineconsulting', NULL), \TYPO3\CMS\Core\Messaging\AbstractMessage::ERROR ); } } // Neue Nachricht Info für User bzw. Agenten zurück setzen bzw. als gelesen markieren if ($feUserData['usergroup'] > 1) { // muss noch per Konstante variabel gemacht werden $topics->setUserstate(0); $this->topicsRepository->update($topics); $this->persistenceManager->persistAll(); } else { $topics->setAgentstate(0); $this->topicsRepository->update($topics); $this->persistenceManager->persistAll(); } $this->view->assignMultiple([ 'topic' => $topics, 'arguments' => $arguments ]); } /** * @return void * @throws \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException */ public function addAction() { $arguments = $this->request->getArguments(); if ($arguments['directmessage']) { if (!$arguments['directmessage']['bodytext'] == '') { $feUserData = FeuserUtility::get(); $newRequest = new \DTInternet\DtiOnlineconsulting\Domain\Model\Topics(); $newRequest->setBodytext($arguments['directmessage']['bodytext']); $newRequest->setPid(17); $newRequest->setFeuser($feUserData['uid']); $newRequest->setAgent(0); $newRequest->setAgentstate(1); $newRequest->setUserstate(0); $this->topicsRepository->add($newRequest);