Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Open
LU NAS
Commits
86c8f8be
Commit
86c8f8be
authored
Apr 28, 2021
by
Dainis Abols
Browse files
Inital composer package
parents
Pipeline
#170
failed with stages
Changes
56
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
.gitignore
0 → 100644
View file @
86c8f8be
.idea/
Classes/Controller/DocumentController.php
0 → 100644
View file @
86c8f8be
<?php
namespace
Lu\LuNas\Controller
;
use
Lu\LuApi\DataSources\SolrRegulations
;
use
Lu\LuNas\Domain\Model\Document
;
use
Lu\LuNas\Domain\Model\Status
;
use
Lu\LuNas\Domain\Repository\DocumentRepository
;
use
Lu\LuNas\Domain\Session\BackendSessionHandler
;
use
Lu\LuNas\Domain\Session\FrontendSessionHandler
;
use
Lu\LuNas\Filter
;
use
Lu\LuNas\Helpers\DataHelper
;
use
Lu\LuNas\Sort
;
use
TYPO3\CMS\Backend\Routing\UriBuilder
as
BackendUriBuilder
;
use
TYPO3\CMS\Backend\Template\Components\ButtonBar
;
use
TYPO3\CMS\Backend\View\BackendTemplateView
;
use
TYPO3\CMS\Core\FormProtection\FormProtectionFactory
;
use
TYPO3\CMS\Core\Imaging\Icon
;
use
TYPO3\CMS\Core\Imaging\IconFactory
;
use
TYPO3\CMS\Core\Localization\LanguageService
;
use
TYPO3\CMS\Core\Page\PageRenderer
;
use
TYPO3\CMS\Core\Utility\GeneralUtility
;
use
TYPO3\CMS\Core\Utility\HttpUtility
;
use
TYPO3\CMS\Extbase\Mvc\Controller\ActionController
;
use
TYPO3\CMS\Extbase\Mvc\View\ViewInterface
;
use
TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder
;
/**
* Class DocumentController
*
* @author Dainis Abols <dainis.abols@lu.lv>
* @owner University of Latvia
* @version 3.0.0
* @since 19.02.2018
*
* @package Lu\LuNas\Controller
*/
class
DocumentController
extends
ActionController
{
/**
* @var DocumentRepository
*/
private
$documentRepository
;
/**
* Backend Template Container
*
* @var string
*/
protected
$defaultViewObjectName
=
\
TYPO3\CMS\Backend\View\BackendTemplateView
::
class
;
/**
* Backend-Session
*
* @var \Lu\LuNas\Domain\Session\BackendSessionHandler
*/
protected
$backendSession
;
/**
* Frontend-Session
*
* @var \Lu\LuNas\Domain\Session\FrontendSessionHandler
*/
protected
$frontendSession
;
/**
* Frontend- or Backend-Session
* The type of session is set automatically in initializeAction().
*
* @var \Lu\LuNas\Domain\Session\SessionHandler
*/
protected
$session
;
/**
* DocumentController constructor.
* Injects frontend and backend sessions.
*
* @param \Lu\LuNas\Domain\Session\FrontendSessionHandler $frontendSession
* @param \Lu\LuNas\Domain\Session\BackendSessionHandler $backendSession
*/
public
function
__construct
(
FrontendSessionHandler
$frontendSession
,
BackendSessionHandler
$backendSession
)
{
$this
->
frontendSession
=
$frontendSession
;
$this
->
backendSession
=
$backendSession
;
}
/**
* Set up the doc header properly here
*
* @param ViewInterface $view
*
* @return void
*/
protected
function
initializeView
(
ViewInterface
$view
)
{
parent
::
initializeView
(
$view
);
if
(
$view
instanceof
BackendTemplateView
)
{
$view
->
getModuleTemplate
()
->
getPageRenderer
()
->
loadRequireJsModule
(
'TYPO3/CMS/Backend/Modal'
);
}
// Add datepicker
if
(
$this
->
view
->
getModuleTemplate
())
{
$pageRenderer
=
$this
->
view
->
getModuleTemplate
()
->
getPageRenderer
();
$pageRenderer
->
loadRequireJsModule
(
'TYPO3/CMS/Backend/DateTimePicker'
);
$dateFormat
=
[
'YYYY-MM-DD'
,
'YYYY-MM-DD HH:mm'
];
$pageRenderer
->
addInlineSetting
(
'DateTimePicker'
,
'DateFormat'
,
$dateFormat
);
}
}
/**
* Inject the entry repository
*
* @param \Lu\LuNas\Domain\Repository\DocumentRepository $documentRepository
*/
public
function
injectEntryRepository
(
DocumentRepository
$documentRepository
)
{
$this
->
documentRepository
=
$documentRepository
;
}
/**
* List Action
*
* @return void
*/
public
function
listAction
()
{
// Preset used variables
$request
=
$this
->
request
->
getArguments
();
$sortModel
=
new
Sort
();
$documentsModel
=
new
Document
();
$statusModel
=
new
Status
();
$entriesPerPage
=
DocumentRepository
::
ITEMS_PER_PAGE
;
$maximumNumberOfLinks
=
DocumentRepository
::
MAX_PAGE_SHOWN
;
$filterModel
=
new
Filter
(
$request
,
$this
->
backendSession
);
$dataHelper
=
new
DataHelper
();
// Get current page @FIXME There has to be a better way!
$currentPage
=
!
empty
(
$request
[
'@widget_0'
][
'currentPage'
])
?
(
int
)
$request
[
'@widget_0'
][
'currentPage'
]
:
1
;
// Get filters
$filters
=
$filterModel
->
getFilters
(
$request
);
if
(
$filters
)
{
// Fetch status data
if
(
$filters
[
'status'
])
{
$statusModel
->
loadAll
();
$status
=
$statusModel
->
getStatusById
(
$filters
[
'status'
]);
$filters
[
'statusName'
]
=
$status
[
'title'
]
??
''
;
}
$solrRegulations
=
new
SolrRegulations
();
$solrRegulations
->
setFilters
(
$filters
);
unset
(
$filters
[
'statusName'
]);
$jsonData
=
$solrRegulations
->
fetch
();
$idFilter
=
$dataHelper
->
APIDecode
(
$jsonData
);
$idFilter
=
empty
(
$idFilter
)
?
[[
'id'
=>
0
]]
:
$idFilter
;
$documentsModel
->
setFilter
(
$idFilter
);
}
// Get sort options
$sort
=
$sortModel
->
getSort
(
$request
);
// Set order
$order
=
$sortModel
->
getSortOrder
();
if
(
!
empty
(
$order
))
{
$expl
=
explode
(
" "
,
$order
);
$order
=
[];
$order
[
reset
(
$expl
)]
=
end
(
$expl
);
}
else
{
$order
=
[
'date_accepted'
=>
'desc'
,
'uid'
=>
'desc'
,
];
}
// Get records
$recordCount
=
$documentsModel
->
getCount
();
$documents
=
$documentsModel
->
getAll
(
$entriesPerPage
,
$currentPage
,
$order
);
$statusList
=
$statusModel
->
getStatus
();
$uriBuilder
=
GeneralUtility
::
makeInstance
(
BackendUriBuilder
::
class
);
// Add edit url
$routeBuilder
=
GeneralUtility
::
makeInstance
(
BackendUriBuilder
::
class
);
$returnUrl
=
(
string
)
$routeBuilder
->
buildUriFromRoutePath
(
'/web/LuNasDocuments/'
,
[
'id'
=>
$this
->
pageUid
,
'token'
=>
$this
->
getToken
(
true
),
]
);
foreach
(
$documents
as
&
$doc
)
{
$url
=
$uriBuilder
->
buildUriFromRoute
(
'record_edit'
,
[
'edit[tx_lunas_domain_model_document]['
.
$doc
[
'uid'
]
.
']'
=>
'edit'
,
'returnUrl'
=>
$returnUrl
,
]
);
$doc
[
'onClick'
]
=
"window.location.href='
{
$url
}
'; return false;"
;
}
// Prepare data for view
$data
=
[
'documents'
=>
$documents
,
'filter'
=>
$filters
,
'recordsCount'
=>
$recordCount
,
'range'
=>
range
(
1
,
$recordCount
),
'showPager'
=>
$recordCount
>
$entriesPerPage
?
true
:
false
,
'itemsPerPage'
=>
$entriesPerPage
,
'maximumNumberOfLinks'
=>
$maximumNumberOfLinks
,
'status'
=>
[
""
=>
""
]
+
$statusList
,
'self'
=>
basename
(
$_SERVER
[
'REQUEST_URI'
]),
'sort'
=>
$sort
,
'currentSort'
=>
explode
(
" "
,
$sortModel
->
getSortOrder
()),
'form'
=>
'post'
,
];
// Add header buttons
$this
->
createButtons
();
// Add custom JS
$pageRenderer
=
GeneralUtility
::
makeInstance
(
PageRenderer
::
class
);
$pageRenderer
->
loadRequireJsModule
(
'TYPO3/CMS/LuNas/LuNas'
);
$syncResult
=
$this
->
backendSession
->
pull
(
'lu_nas_syn_result'
);
// Assign data to view
$this
->
view
->
assign
(
'syncResult'
,
$syncResult
);
$this
->
view
->
assign
(
'data'
,
$data
);
}
/**
* Redirects to native content create window
*/
public
function
addAction
()
{
$config
=
GeneralUtility
::
makeInstance
(
\
TYPO3\CMS\Core\Configuration\ExtensionConfiguration
::
class
)
->
get
(
'lu_nas'
);
// Predefine values/models
$documentModel
=
new
Document
();
$table
=
$documentModel
->
getTableName
();
$uriBuilder
=
GeneralUtility
::
makeInstance
(
BackendUriBuilder
::
class
);
// Create redirect url
$returnUrl
=
$uriBuilder
->
buildUriFromRoutePath
(
'/web/LuNasDocuments/'
,
[
'id'
=>
$this
->
pageUid
,
'token'
=>
$this
->
getToken
(
true
),
]
);
$pid
=
$config
[
'storage_page_id'
];
$url
=
$uriBuilder
->
buildUriFromRoute
(
'record_edit'
,
[
'edit['
.
$table
.
']['
.
$pid
.
']'
=>
'new'
,
'returnUrl'
=>
(
string
)
$returnUrl
,
]
);
// Redirect
HttpUtility
::
redirect
(
$url
);
}
/**
* Adds header buttons
*/
protected
function
createButtons
()
{
// Preset used variables
$buttonBar
=
$this
->
view
->
getModuleTemplate
()
->
getDocHeaderComponent
()
->
getButtonBar
();
$iconFactory
=
GeneralUtility
::
makeInstance
(
IconFactory
::
class
);
$uriBuilder
=
$this
->
objectManager
->
get
(
UriBuilder
::
class
);
// Set basic uri
$uriBuilder
->
setRequest
(
$this
->
request
);
// Create filter button
$title
=
$this
->
getLanguageService
()
->
sL
(
'LLL:EXT:lu_nas/Resources/Private/Language/locallang.xlf:buttons.filter'
);
$toggleButton
=
$buttonBar
->
makeLinkButton
()
->
setHref
(
'#'
)
->
setClasses
(
'toggle'
)
->
setDataAttributes
(
[
'togglelink'
=>
'1'
,
'toggle'
=>
'filterMenu'
,
]
)
->
setTitle
(
$title
)
->
setIcon
(
$iconFactory
->
getIcon
(
'actions-filter'
,
Icon
::
SIZE_SMALL
));
$buttonBar
->
addButton
(
$toggleButton
,
ButtonBar
::
BUTTON_POSITION_LEFT
,
1
);
// Create additional buttons
$buttons
=
[
[
'group'
=>
2
,
'table'
=>
'tx_lunas_domain_model_document'
,
'label'
=>
'buttons.add'
,
'action'
=>
'add'
,
'icon'
=>
'actions-document-new'
,
],
];
foreach
(
$buttons
as
$key
=>
$tableConfiguration
)
{
$title
=
$this
->
getLanguageService
()
->
sL
(
'LLL:EXT:lu_nas/Resources/Private/Language/locallang.xlf:'
.
$tableConfiguration
[
'label'
]);
$viewButton
=
$buttonBar
->
makeLinkButton
()
->
setHref
(
$uriBuilder
->
reset
()
->
setRequest
(
$this
->
request
)
->
uriFor
(
$tableConfiguration
[
'action'
],
[],
'Document'
))
->
setTitle
(
$title
)
->
setIcon
(
$iconFactory
->
getIcon
(
$tableConfiguration
[
'icon'
],
Icon
::
SIZE_SMALL
));
$buttonBar
->
addButton
(
$viewButton
,
ButtonBar
::
BUTTON_POSITION_LEFT
,
$tableConfiguration
[
'group'
]);
}
}
/**
* Returns the LanguageService
*
* @return LanguageService
*/
protected
function
getLanguageService
()
{
return
$GLOBALS
[
'LANG'
];
}
/**
* Get a CSRF token
*
* @param bool $tokenOnly Set it to TRUE to get only the token, otherwise including the &token= as prefix
*
* @return string
*/
protected
function
getToken
(
$tokenOnly
=
false
)
{
$token
=
FormProtectionFactory
::
get
(
'backend'
)
->
generateToken
(
'route'
,
'web_LuNasDocuments'
);
if
(
$tokenOnly
)
{
return
$token
;
}
else
{
return
'&token='
.
$token
;
}
}
}
Classes/Controller/FrontController.php
0 → 100644
View file @
86c8f8be
<?php
namespace
Lu\LuNas\Controller
;
use
Lu\LuApi\DataSources\SolrRegulations
;
use
Lu\LuNas\Domain\Model\Document
;
use
Lu\LuNas\Domain\Model\Issuer
;
use
Lu\LuNas\Domain\Model\OrderType
;
use
Lu\LuNas\Domain\Model\Status
;
use
Lu\LuNas\Domain\Model\Type
;
use
Lu\LuNas\Domain\Repository\DocumentRepository
;
use
Lu\LuNas\Domain\Session\BackendSessionHandler
;
use
Lu\LuNas\Domain\Session\FrontendSessionHandler
;
use
Lu\LuNas\Filter
;
use
Lu\LuNas\Helpers\DataHelper
;
use
Lu\LuNas\Sort
;
//use TYPO3\CMS\Backend\View\BackendTemplateView;
use
TYPO3\CMS\Core\FormProtection\FormProtectionFactory
;
use
TYPO3\CMS\Core\Page\PageRenderer
;
use
TYPO3\CMS\Core\Utility\GeneralUtility
;
use
TYPO3\CMS\Extbase\Mvc\Controller\ActionController
;
use
TYPO3\CMS\Extbase\Mvc\View\ViewInterface
;
/**
* Class FrontController
*
* @author Dainis Abols <dainis.abols@lu.lv>
* @owner University of Latvia
* @version 3.0.1
* @since 02.11.2018
*
* @package Lu\LuNas\Controller
*/
class
FrontController
extends
ActionController
{
/**
* @var DocumentRepository
*/
private
$documentRepository
;
/**
* Backend Template Container
*
* @var string
*/
// protected $defaultViewObjectName = \TYPO3\CMS\Backend\View\BackendTemplateView::class;
/**
* Backend-Session
*
* @var \Lu\LuNas\Domain\Session\BackendSessionHandler
*/
protected
$backendSession
;
/**
* Frontend-Session
*
* @var \Lu\LuNas\Domain\Session\FrontendSessionHandler
*/
protected
$frontendSession
;
/**
* Frontend- or Backend-Session
* The type of session is set automatically in initializeAction().
*
* @var \Lu\LuNas\Domain\Session\SessionHandler
*/
protected
$session
;
/**
* FrontController constructor.
* Injects frontend and backend sessions.
*
* @param \Lu\LuNas\Domain\Session\FrontendSessionHandler $frontendSession
* @param \Lu\LuNas\Domain\Session\BackendSessionHandler $backendSession
*/
public
function
__construct
(
FrontendSessionHandler
$frontendSession
,
BackendSessionHandler
$backendSession
)
{
$this
->
frontendSession
=
$frontendSession
;
$this
->
backendSession
=
$backendSession
;
}
/**
* Set up the doc header properly here
*
* @param ViewInterface $view
*
* @return void
*/
protected
function
initializeView
(
ViewInterface
$view
)
{
parent
::
initializeView
(
$view
);
// if ($view instanceof BackendTe) {
// $view->getModuleTemplate()->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/Modal');
// }
//
// // Add datepicker
// $pageRenderer = $this->view->getModuleTemplate()->getPageRenderer();
// $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/DateTimePicker');
// $dateFormat = ['YYYY-MM-DD', 'YYYY-MM-DD HH:mm'];
// $pageRenderer->addInlineSetting('DateTimePicker', 'DateFormat', $dateFormat);
}
/**
* Inject the entry repository
*
* @param \Lu\LuNas\Domain\Repository\DocumentRepository $documentRepository
*/
public
function
injectEntryRepository
(
DocumentRepository
$documentRepository
)
{
$this
->
documentRepository
=
$documentRepository
;
}
/**
* List Action
*
* @return void
*/
public
function
listAction
()
{
// Preset used variables
$request
=
$this
->
request
->
getArguments
();
$sortModel
=
new
Sort
();
$documentsModel
=
new
Document
();
$statusModel
=
new
Status
(
'public'
);
$entriesPerPage
=
!
empty
(
$this
->
settings
[
'ItemsPerPage'
])
?
$this
->
settings
[
'ItemsPerPage'
]
:
DocumentRepository
::
ITEMS_PER_PAGE
;
$maximumNumberOfLinks
=
!
empty
(
$this
->
settings
[
'MaxPageShown'
])
?
$this
->
settings
[
'MaxPageShown'
]
:
DocumentRepository
::
MAX_PAGE_SHOWN
;
$filterModel
=
new
Filter
(
$request
,
$this
->
frontendSession
);
$dataHelper
=
new
DataHelper
();
// Set to always show active documents, if no filters provided
if
(
empty
(
$filterModel
->
getFilters
(
$request
)))
{
$filter
[
'status'
]
=
1
;
$filterModel
->
setFilters
(
$filter
);
}
// Set to public access
$documentsModel
->
setPublic
(
true
);
// Get current page
$currentPage
=
!
empty
(
$request
[
'@widget_0'
][
'currentPage'
])
?
(
int
)
$request
[
'@widget_0'
][
'currentPage'
]
:
1
;
// Get filters
$facet_filters
=
$filters
=
$filterModel
->
getFilters
(
$request
);
// Check facet call
if
(
!
empty
(
$request
[
'facet_field'
]))
{
$filters
[
'facet_field'
]
=
$request
[
'facet_field'
];
}
// Check filter options
if
(
$request
[
'view_count'
]
==
1
)
{
$documentsModel
->
setFilter
([
'view_count'
=>
'desc'
]);
}
else
if
(
$filters
)
{
// Fetch status data
if
(
$filters
[
'status'
])
{
$statusModel
->
loadAll
();
$status
=
$statusModel
->
getStatusById
(
$filters
[
'status'
]);
$filters
[
'statusName'
]
=
$status
[
'title'
]
??
''
;
}
$facet_filters
=
$filters
;
$solrRegulations
=
new
SolrRegulations
();
// Add hidden status name, if applicable
$fullStatusModel
=
new
Status
();
$hiddenStatusId
=
$fullStatusModel
->
getHiddenId
();
if
(
$hiddenStatusId
)
{
$hiddenStatus
=
$fullStatusModel
->
getStatusById
(
$hiddenStatusId
);
if
(
!
empty
(
$hiddenStatus
[
'title'
]))
{
$solrRegulations
->
hideStatus
(
$hiddenStatus
[
'title'
]);
}
}
$solrRegulations
->
setFilters
(
$filters
);
unset
(
$filters
[
'statusName'
]);
$jsonData
=
$solrRegulations
->
fetch
();
$idFilter
=
$dataHelper
->
APIDecode
(
$jsonData
);
$idFilter
=
empty
(
$idFilter
)
?
[[
'id'
=>
0
]]
:
$idFilter
;
$documentsModel
->
setFilter
(
$idFilter
);
}
// Get sort options
$sort
=
$sortModel
->
getSort
(
$request
);
// Set order
$order
=
$sortModel
->
getSortOrder
();
if
(
!
empty
(
$order
))
{
$expl
=
explode
(
" "
,
$order
);
$order
=
[];
$order
[
reset
(
$expl
)]
=
end
(
$expl
);
}
else
{
$order
=
[
'date_accepted'
=>
'desc'
,
'uid'
=>
'desc'
,
];
}
// Get records
$recordCount
=
$documentsModel
->
getCount
();
$documents
=
$documentsModel
->
getAll
(
$entriesPerPage
,
$currentPage
,
$order
);
$documentsModel
->
setFilter
(
$facet_filters
);
// <-- Warning, returned with original IDs
$facets
=
$documentsModel
->
getFacets
();
$statusList
=
$statusModel
->
getStatus
();
// Add status name
foreach
(
$documents
as
&
$doc
)
{
$status
=
$statusModel
->
getStatusById
(
$doc
[
'status_id'
]);
$doc
[
'statusName'
]
=
$status
[
'title'
];
}
$showPager
=
$recordCount
>
$entriesPerPage
?
true
:
false
;
if
(
$request
[
'view_count'
]
==
1
)
{
$showPager
=
false
;
}
// Prepare data for view
$data
=
[
'documents'
=>
$documents
,
'facets'
=>
$facets
,
'filter'
=>
$filters
,
'recordsCount'
=>
$recordCount
,
'range'
=>
range
(
1
,
$recordCount
),
'showPager'
=>
$showPager
,
'itemsPerPage'
=>
$entriesPerPage
,
'maximumNumberOfLinks'
=>
$maximumNumberOfLinks
,
'status'
=>
[
""
=>
""
]
+
$statusList
,
'self'
=>
$this
->
uriBuilder
->
setArguments
([
'tx_lunas_pi1[controller]'
=>
'Front'
])
->
setAddQueryString
(
true
)
->
build
(),
'sort'
=>
$sort
,
'currentSort'
=>
explode
(
" "
,
$sortModel
->
getSortOrder
()),
'form'
=>
'get'
,
];
// Add custom JS
$pageRenderer
=
GeneralUtility
::
makeInstance
(
PageRenderer
::
class
);
$pageRenderer
->
loadRequireJsModule
(
'TYPO3/CMS/LuNas/LuNas'
);
$syncResult
=
$this
->
frontendSession
->
pull
(
'lu_nas_syn_result'
);
// Assign data to view
$this
->
view
->
assign
(
'syncResult'
,
$syncResult
);
$this
->
view
->
assign
(
'data'
,
$data
);
}
/**
* Detailed document view
*/
public
function
detailAction
()
{
// Preset used variables
$request
=
$this
->
request
->
getArguments
();
$typeModel
=
new
Type
();
$statusModel
=
new
Status
();
$issuerModel
=
new
Issuer
();
$documentsModel
=
new
Document
();
$orderTypeModel
=
new
OrderType
();
// Redirect to list, if invalid UID
if
(
empty
(
$request
[
'uid'
]))
{
$this
->
redirect
(
'list'
,
'Front'
);
}