Skip to content

Commit

Permalink
Merge pull request #1 from pixelant/typo9
Browse files Browse the repository at this point in the history
Typo3 9 support
  • Loading branch information
Andriy Oprysko authored Feb 3, 2020
2 parents d9bf325 + 1a3f5de commit 85c8e03
Show file tree
Hide file tree
Showing 56 changed files with 404 additions and 2,006 deletions.
143 changes: 76 additions & 67 deletions Classes/Controller/MessageController.php
Original file line number Diff line number Diff line change
@@ -1,97 +1,106 @@
<?php
namespace Resultify\ResultifyMessageBox\Controller;

/***
*
* This file is part of the "Message Box" Extension for TYPO3 CMS.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* (c) 2017 Alex <[email protected]>, Resultify
*
***/
namespace Pixelant\PxaMessageBox\Controller;

use Resultify\ResultifyMessageBox\Utility\DatabaseUtility;
use Pixelant\PxaMessageBox\Domain\Model\Message;
use Pixelant\PxaMessageBox\Domain\Repository\MessageRepository;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Domain\Model\FrontendUser;
use TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;

/**
* MessageController
*/
class MessageController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController
class MessageController extends ActionController
{
/**
* @var \Resultify\ResultifyMessageBox\Domain\Repository\MessageRepository
* @inject
* @var MessageRepository
*/
protected $messageRepository;

/**
* @var FrontendUserRepository
*/
protected $frontendUserRepository = null;

/**
* Loggen in user ID
*
* @var int
*/
protected $userId = null;

/**
* @param MessageRepository $messageRepository
*/
public function injectMessageRepository(MessageRepository $messageRepository)
{
$this->messageRepository = $messageRepository;
}

/**
* @param FrontendUserRepository $frontendUserRepository
*/
public function injectFrontendUserRepository(FrontendUserRepository $frontendUserRepository)
{
$this->frontendUserRepository = $frontendUserRepository;
}

/**
* Init
*/
protected function initializeAction()
{
$userAspect = GeneralUtility::makeInstance(Context::class)->getAspect('frontend.user');
if ($userAspect->isLoggedIn()) {
$this->userId = $userAspect->get('id');
}
}

/**
* action list
*
* @return void
*/
public function listAction()
{
// get user
$user = $GLOBALS['TSFE']->fe_user->user;

// get storage uid
$data = $this->configurationManager->getContentObject()->data;
$storagePids = explode(',',$data['pages']);

if($user['uid'] != NULL && $data['pages'] != '')
{
// get ids of messages already seen by user
$userData = DatabaseUtility::getUserData($user['uid']);
$messagesUids = explode(',',$userData);

// Set sorting
$this->messageRepository->setInvertSorting(boolval($this->settings['invertSorting']));

// get appropriate messages
$messages = $this->messageRepository->findByUidRespectStorage($storagePids, $messagesUids);

$this->view->assign('messages', $messages);
if (!$this->userId) {
return;
}

// Get appropriate messages
$messages = $this->messageRepository->findByNotSeen($this->userId);
if ($this->settings['invertSorting']) {
$messages = array_reverse($messages->toArray());
}

$this->view->assign('messages', $messages);
}

/**
* action ajax
* Close action
*
* @param Message $message
* @return void
*/
public function ajaxAction()
public function closeAction(Message $message)
{
// get user
$user = $GLOBALS['TSFE']->fe_user->user;

// get uid of message that was clicked
$messageUid = $this->request->getArgument('uid');

if($messageUid && $user['uid'] != NULL){
// get ids of messages already seen by this user
$userData = DatabaseUtility::getUserData($user['uid']);
$messagesUids = explode(',',$userData);

// build correct array of uids to update
if($userData == ''){
$messagesUidsToUpdate = $messageUid;
}else{
if (!in_array($messageUid, $messagesUids)) {
array_push($messagesUids, $messageUid);
$messagesUidsToUpdate = implode(",", $messagesUids);
}else{
$messagesUidsToUpdate = implode(",", $messagesUids);
}
}

if(DatabaseUtility::updateUser($user['uid'], $messagesUidsToUpdate)){
echo json_encode(array("result" => "updateOK"));
}else{
echo json_encode(array("result" => "updateError"));
}
}else{
echo json_encode(array("result" => "updateError"));
if (!$this->userId) {
return;
}

/** @var FrontendUser $frontendUser */
$frontendUser = $this->frontendUserRepository->findByUid($this->userId);

$message->addSeenBy($frontendUser);
$this->messageRepository->update($message);

if (GeneralUtility::_GET('type')) {
return json_encode(['success' => true]);
}

$this->redirect('list');
}
}
69 changes: 52 additions & 17 deletions Classes/Domain/Model/Message.php
Original file line number Diff line number Diff line change
@@ -1,54 +1,57 @@
<?php
namespace Resultify\ResultifyMessageBox\Domain\Model;

/***
*
* This file is part of the "Message Box" Extension for TYPO3 CMS.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* (c) 2017 Alex <[email protected]>, Resultify
*
***/

namespace Pixelant\PxaMessageBox\Domain\Model;

use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;

/**
* Message
*/
class Message extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
class Message extends AbstractEntity
{
/**
* date
*
* @var \DateTime
* @validate NotEmpty
*/
protected $date = null;

/**
* author
*
* @var string
* @validate NotEmpty
*/
protected $author = '';

/**
* headline
*
* @var string
* @validate NotEmpty
*/
protected $headline = '';

/**
* text
*
* @var string
* @validate NotEmpty
*/
protected $text = '';

/**
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\FrontendUser>
* @TYPO3\CMS\Extbase\Annotation\ORM\Lazy
*/
protected $seenBy = null;

/**
*/
public function __construct()
{
$this->seenBy = new ObjectStorage();
}


/**
* Returns the date
*
Expand Down Expand Up @@ -132,4 +135,36 @@ public function setText($text)
{
$this->text = $text;
}

/**
* @return ObjectStorage
*/
public function getSeenBy(): ObjectStorage
{
return $this->seenBy;
}

/**
* @param ObjectStorage $seenBy
*/
public function setSeenBy(ObjectStorage $seenBy): void
{
$this->seenBy = $seenBy;
}

/**
* @param \TYPO3\CMS\Extbase\Domain\Model\FrontendUser $frontendUser
*/
public function addSeenBy(\TYPO3\CMS\Extbase\Domain\Model\FrontendUser $frontendUser)
{
$this->seenBy->attach($frontendUser);
}

/**
* @param \TYPO3\CMS\Extbase\Domain\Model\FrontendUser $frontendUser
*/
public function removeSeenBy(\TYPO3\CMS\Extbase\Domain\Model\FrontendUser $frontendUser)
{
$this->seenBy->detach($frontendUser);
}
}
47 changes: 0 additions & 47 deletions Classes/Domain/Model/User.php

This file was deleted.

Loading

0 comments on commit 85c8e03

Please sign in to comment.