Skip to content
This repository was archived by the owner on Jan 21, 2023. It is now read-only.

Commit

Permalink
add old version for typo3 9.5x branches
Browse files Browse the repository at this point in the history
  • Loading branch information
Carsten Walther committed Jun 30, 2020
1 parent 6280c4e commit 9b6dd65
Show file tree
Hide file tree
Showing 662 changed files with 35,445 additions and 2,700 deletions.
67 changes: 30 additions & 37 deletions Classes/Backend/ToolbarItems/ServiceDeskToolbarItem.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
<?php
declare(strict_types = 1);

namespace Walther\JiraServiceDesk\Backend\ToolbarItems;

use TYPO3\CMS\Backend\Toolbar\ToolbarItemInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\View\StandaloneView;
use Walther\JiraServiceDesk\Service\Resource\Request;
use Walther\JiraServiceDesk\Service\Resource\ServiceDesk;
use Walther\JiraServiceDesk\Service\Service;
use Walther\JiraServiceDesk\Utility\AccessUtility;

/**
* Main functionality to render a toolbar at the top bar of the TYPO3 Backend.
*
* @package Walther\JiraServiceDesk\Backend\ToolbarItems
* @author Carsten Walther
* @author Carsten Walther
*/
class ServiceDeskToolbarItem implements ToolbarItemInterface
class ServiceDeskToolbarItem implements \TYPO3\CMS\Backend\Toolbar\ToolbarItemInterface
{
/**
* Checks whether the user has access to this toolbar item.
Expand All @@ -25,7 +18,7 @@ class ServiceDeskToolbarItem implements ToolbarItemInterface
*/
public function checkAccess() : bool
{
return AccessUtility::hasAccess();
return \Walther\JiraServiceDesk\Utility\AccessUtility::hasAccess();
}

/**
Expand All @@ -37,41 +30,21 @@ public function checkAccess() : bool
*/
public function getItem() : string
{
if (AccessUtility::hasAccess()) {
if (\Walther\JiraServiceDesk\Utility\AccessUtility::hasAccess()) {
return $this->getFluidTemplateObject('ToolbarItem.html')->render();
}

return '';
}

/**
* Returns a new standalone view, shorthand function.
*
* @param string $filename
*
* @return \TYPO3\CMS\Fluid\View\StandaloneView The standalone view
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\InvalidExtensionNameException
*/
protected function getFluidTemplateObject(string $filename) : StandaloneView
{
$view = GeneralUtility::makeInstance(StandaloneView::class);
$view->setLayoutRootPaths(['EXT:jira_service_desk/Resources/Private/Layouts']);
$view->setPartialRootPaths(['EXT:jira_service_desk/Resources/Private/Partials']);
$view->setTemplateRootPaths(['EXT:jira_service_desk/Resources/Private/Templates/ToolbarItems']);
$view->setTemplate($filename);
$view->getRequest()->setControllerExtensionName('ServiceDesk');

return $view;
}

/**
* TRUE if this toolbar item has a collapsible drop down.
*
* @return bool TRUE if there is a drop down, FALSE if not
*/
public function hasDropDown() : bool
{
if (AccessUtility::hasAccess()) {
if (\Walther\JiraServiceDesk\Utility\AccessUtility::hasAccess()) {
return true;
}

Expand All @@ -88,13 +61,13 @@ public function hasDropDown() : bool
*/
public function getDropDown() : string
{
if (AccessUtility::hasAccess()) {
if (\Walther\JiraServiceDesk\Utility\AccessUtility::hasAccess()) {
$serviceDeskId = (int)$GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['jira_service_desk']['serviceDeskId'];

$service = GeneralUtility::makeInstance(Service::class)->initialize();
$serviceDesk = GeneralUtility::makeInstance(ServiceDesk::class, $service);
$service = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\Walther\JiraServiceDesk\Service\Service::class)->initialize();
$serviceDesk = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\Walther\JiraServiceDesk\Service\Resource\ServiceDesk::class, $service);

$request = GeneralUtility::makeInstance(Request::class, $service);
$request = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\Walther\JiraServiceDesk\Service\Resource\Request::class, $service);
$customerRequests = $request->getCustomerRequests($serviceDeskId);

$customerRequestCounts = [];
Expand Down Expand Up @@ -160,4 +133,24 @@ public function updateServiceDeskMenuHook(&$params) : void
}
';
}

/**
* Returns a new standalone view, shorthand function.
*
* @param string $filename
*
* @return \TYPO3\CMS\Fluid\View\StandaloneView The standalone view
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\InvalidExtensionNameException
*/
protected function getFluidTemplateObject(string $filename) : \TYPO3\CMS\Fluid\View\StandaloneView
{
$view = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Fluid\View\StandaloneView::class);
$view->setLayoutRootPaths(['EXT:jira_service_desk/Resources/Private/Layouts']);
$view->setPartialRootPaths(['EXT:jira_service_desk/Resources/Private/Partials']);
$view->setTemplateRootPaths(['EXT:jira_service_desk/Resources/Private/Templates/ToolbarItems']);
$view->setTemplate($filename);
$view->getRequest()->setControllerExtensionName('ServiceDesk');

return $view;
}
}
124 changes: 42 additions & 82 deletions Classes/Controller/AjaxController.php
Original file line number Diff line number Diff line change
@@ -1,89 +1,62 @@
<?php
declare(strict_types = 1);

namespace Walther\JiraServiceDesk\Controller;

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface as Cache;
use TYPO3\CMS\Core\Http\HtmlResponse;
use TYPO3\CMS\Core\Http\JsonResponse;
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\View\StandaloneView;
use Walther\JiraServiceDesk\Service\Resource\Knowledgebase;
use Walther\JiraServiceDesk\Service\Resource\Request;
use Walther\JiraServiceDesk\Service\Resource\ServiceDesk;
use Walther\JiraServiceDesk\Service\Service;
use Walther\JiraServiceDesk\Utility\AccessUtility;
use TYPO3\CMS\Extbase\Utility\DebuggerUtility;

/**
* This class implements the required Ajax methods.
*
* @package Walther\JiraServiceDesk\Controller
* @author Carsten Walther
* @author Carsten Walther
*/
class AjaxController implements SingletonInterface
class AjaxController
{
/**
* Service object
*
* @var \Walther\JiraServiceDesk\Service\Service
*/
protected $service;

/**
* ServiceDesk resource object
*
* @var \Walther\JiraServiceDesk\Service\Resource\ServiceDesk
*/
protected $serviceDeskResource;
protected $serviceDesk;

/**
* Request resource object
*
* @var \Walther\JiraServiceDesk\Service\Resource\Request
*/
protected $requestResource;
protected $request;

/**
* Knowledgebase resource object
*
* @var \Walther\JiraServiceDesk\Service\Resource\Knowledgebase
*/
protected $knowledgebaseResource;
/**
* @var Cache
*/
private $cache;
/**
* @var int
*/
private $lifeTime = 60 * 60 * 1;
protected $knowledgebase;

/**
* AjaxController constructor.
*
* @param \TYPO3\CMS\Core\Cache\Frontend\FrontendInterface $cache
* @param \Walther\JiraServiceDesk\Service\Service $service
* @param \Walther\JiraServiceDesk\Service\Resource\ServiceDesk $serviceDeskResource
* @param \Walther\JiraServiceDesk\Service\Resource\Request $requestResource
* @param \Walther\JiraServiceDesk\Service\Resource\Knowledgebase $knowledgebaseResource
* @return void
*/
public function __construct(Cache $cache, Service $service, ServiceDesk $serviceDeskResource, Request $requestResource, Knowledgebase $knowledgebaseResource)
public function __construct()
{
if (AccessUtility::hasAccess()) {
$this->cache = $cache;

$this->service = $service;
$this->service->initialize();
if (\Walther\JiraServiceDesk\Utility\AccessUtility::hasAccess()) {

$this->serviceDeskResource = $serviceDeskResource;
$this->serviceDeskResource->setService($this->service);
$this->service = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\Walther\JiraServiceDesk\Service\Service::class);

$this->requestResource = $requestResource;
$this->requestResource->setService($this->service);

$this->knowledgebaseResource = $knowledgebaseResource;
$this->knowledgebaseResource->setService($this->service);
if ($this->service->initialize()) {
$this->serviceDesk = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\Walther\JiraServiceDesk\Service\Resource\ServiceDesk::class, $this->service);
$this->request = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\Walther\JiraServiceDesk\Service\Resource\Request::class, $this->service);
$this->knowledgebase = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\Walther\JiraServiceDesk\Service\Resource\Knowledgebase::class, $this->service);
}
}
}

Expand All @@ -95,7 +68,7 @@ public function __construct(Cache $cache, Service $service, ServiceDesk $service
* @return \Psr\Http\Message\ResponseInterface
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function dispatch(ServerRequestInterface $request) : ResponseInterface
public function dispatch(\Psr\Http\Message\ServerRequestInterface $request): \Psr\Http\Message\ResponseInterface
{
$serviceDeskId = (int)$GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['jira_service_desk']['serviceDeskId'];

Expand All @@ -108,7 +81,7 @@ public function dispatch(ServerRequestInterface $request) : ResponseInterface
$formData[$requestData['name']][] = [
'id' => $requestData['value']
];
} elseif ($requestData['name'] === 'priority') {
} else if ($requestData['name'] === 'priority') {
$formData[$requestData['name']] = [
'id' => $requestData['value']
];
Expand All @@ -122,87 +95,74 @@ public function dispatch(ServerRequestInterface $request) : ResponseInterface

// this is called by the topbar menu and its hook to update the counts
case 'getServiceDeskMenuData':
$customerRequests = $this->requestResource->getCustomerRequests($serviceDeskId, 0, true);
$customerRequests = $this->request->getCustomerRequests($serviceDeskId, 0, true);
$customerRequestCounts = [];
if (is_array($customerRequests->body->values)) {
foreach ($customerRequests->body->values as $key => $customerRequest) {
$customerRequestCounts[$customerRequest->currentStatus->status]++;
}
}
return new JsonResponse((array)$customerRequestCounts);
return new \TYPO3\CMS\Core\Http\JsonResponse((array)$customerRequestCounts);
break;




// subscribe to an issue
case 'subscribe':
return new JsonResponse((array)$this->requestResource->subscribe($formData['issueId']));
return new \TYPO3\CMS\Core\Http\JsonResponse((array)$this->request->subscribe($formData['issueId']));
break;

// unsubscribe to an issue
case 'unsubscribe':
return new JsonResponse((array)$this->requestResource->unsubscribe($formData['issueId']));
return new \TYPO3\CMS\Core\Http\JsonResponse((array)$this->request->unsubscribe($formData['issueId']));
break;




// this is called by the serviceDesk action on input search strings
case 'getRequestTypes':
// @todo We have to check if we can get access to knowledgebase articles, currently we get 404 errors. Maybe because of experimental api?
$data = $this->getRequestTypes($serviceDeskId);
$data = $this->serviceDesk->getRequestTypes($serviceDeskId);
if ($formData['searchTerm'] !== '') {
foreach ($data->body->values as $key => $value) {
if (stripos(strtolower($value->name), strtolower($formData['searchTerm'])) === false && stripos(strtolower($value->description), strtolower($formData['searchTerm'])) === false) {
unset($data->body->values[$key]);
}
}
}
return new JsonResponse((array)$data);
return new \TYPO3\CMS\Core\Http\JsonResponse((array)$data);
break;




// this is called to perform a request comment
case 'performRequestComment':
BackendUtility::setUpdateSignal('ServiceDeskToolbarItem::updateServiceDeskMenu');
return new JsonResponse((array)$this->requestResource->createRequestComment($formData['requestId'], $formData['comment']));
\TYPO3\CMS\Backend\Utility\BackendUtility::setUpdateSignal('ServiceDeskToolbarItem::updateServiceDeskMenu');
return new \TYPO3\CMS\Core\Http\JsonResponse((array)$this->request->createRequestComment($formData['requestId'], $formData['comment']));
break;




// this is called by the serviceDesk action to load the create request form
case 'getTransitionForm':
$view = GeneralUtility::makeInstance(StandaloneView::class);
$view->setTemplatePathAndFilename(ExtensionManagementUtility::extPath('jira_service_desk') . 'Resources/Private/Partials/Form/Transition.html');
$view = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Fluid\View\StandaloneView::class);
$view->setTemplatePathAndFilename(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('jira_service_desk') . 'Resources/Private/Partials/Form/Transition.html');
$view->assignMultiple([
'requestId' => $formData['requestId'],
'transitionId' => $formData['transitionId']
]);
return new HtmlResponse($view->render());
return new \TYPO3\CMS\Core\Http\HtmlResponse($view->render());
break;

// this is called to perform a customer transition
case 'performCustomerTransition':
BackendUtility::setUpdateSignal('ServiceDeskToolbarItem::updateServiceDeskMenu');
return new JsonResponse((array)$this->requestResource->performCustomerTransition($formData['transition[requestId]'], (int)$formData['transition[transitionId]'], $formData['transition[comment]']));
\TYPO3\CMS\Backend\Utility\BackendUtility::setUpdateSignal('ServiceDeskToolbarItem::updateServiceDeskMenu');
return new \TYPO3\CMS\Core\Http\JsonResponse((array)$this->request->performCustomerTransition($formData['transition[requestId]'], (int)$formData['transition[transitionId]'], $formData['transition[comment]']));
break;
}
}

/**
* @param $serviceDeskId
* @param $expand
*
* @return mixed|\Walther\JiraServiceDesk\Service\Response
* @throws \GuzzleHttp\Exception\GuzzleException
*/
private function getRequestTypes($serviceDeskId, $expand = false)
{
$cacheHash = md5('getRequestTypes');

if ($items = $this->cache->get($cacheHash)) {
return $items;
}

$items = $this->serviceDeskResource->getRequestTypes($serviceDeskId, $expand);
$this->cache->set($cacheHash, $items, ['jira_service_desk'], $this->lifeTime);

return $items;
}
}
Loading

0 comments on commit 9b6dd65

Please sign in to comment.