Commit 79ac36ab authored by Dainis Abols's avatar Dainis Abols
Browse files

Inital public version

parents
Pipeline #155 failed with stages
in 0 seconds
# Default ignored files
/shelf/
/workspace.xml
# Datasource local storage ignored files
/../../../../../../:\data\www\open\lu_notices\.idea/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/Classes" isTestSource="false" packagePrefix="Lu\LuNotices\" />
<sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/lu_notices.iml" filepath="$PROJECT_DIR$/.idea/lu_notices.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="PhpProjectSharedConfiguration" php_language_level="7">
<option name="suggestChangeDefaultLanguageLevel" value="false" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
<?php
namespace Lu\LuNotices\Controller;
use Lu\LuNotices\Domain\Model\Notices;
use Lu\LuNotices\Domain\Model\Topics;
use Lu\LuNotices\Domain\Repository\NoticesRepository;
use Lu\LuNotices\Domain\Repository\TopicsRepository;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\DataHandling\DataHandler;
use TYPO3\CMS\Core\Resource\ResourceFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
/**
* Class NoticesController
*
* @owner University of Latvia
* @author Maija Zviedre <maija.zviedre@lu.lv>
* @author Dainis Abols <dainis.abols@lu.lv>
* @version 3.0.4
* @since 30.07.2018
*
* @package Lu\LuNotices\Controller
*/
class NoticesController extends ActionController
{
/**
* Topics repository
*
* @var \Lu\LuNotices\Domain\Repository\TopicsRepository
*/
private $topicsRepository;
/**
* Notices repository
*
* @var \Lu\LuNotices\Domain\Repository\NoticesRepository
*/
private $noticesRepository;
/**
* Current page
*
* @var int
*/
public $currentPage;
/**
* Inject the notices repository
*
* @param \Lu\LuNotices\Domain\Repository\NoticesRepository
*/
public function injectNoticesRepository(NoticesRepository $noticesRepository)
{
$this->noticesRepository = $noticesRepository;
}
/**
* Inject the topics repository
*
* @param \Lu\LuNotices\Domain\Repository\TopicsRepository
*/
public function injectTopicsRepository(TopicsRepository $topicsRepository)
{
$this->topicsRepository = $topicsRepository;
}
/**
* List Action
* See all active topics with optional limited notices width summaries.
*/
public function listAction()
{
// Pre-set data
$data = [];
$allTopics = [0];
$dateFrom = null;
$dateTill = null;
$UriBuilder = $this->controllerContext->getUriBuilder()->reset()->setCreateAbsoluteUri(true);
$user = $GLOBALS['TSFE']->fe_user;
$groupBy = $this->settings['GroupBy'];
$currentDate = $this->request->hasArgument('currentDate') ? $this->request->getArgument('currentDate') : null;
// Fetch topics
$topics = $this->topicsRepository->findAll();
$setLimit = (int)$this->settings['NoticesPerTopic'];
// Add filter options, if date set
if ($groupBy == 'date') {
$dateFrom = $dateTill = $currentDate;
}
// Filter topics for frontend user groups
foreach ($topics as $topic) {
if (in_array($topic->getFeGroup(), $user->groupData['uid'])) {
$allTopics[] = $topicId = $topic->getId();
$data[$topicId]['topic'] = $topic;
$data[$topicId]['url'] = $UriBuilder->uriFor('single', ['topic_id' => $topicId, 'currentDate' => $currentDate]);
}
}
// Get dates
if ($groupBy == 'date') {
$dates = Notices::getNoticeDates($allTopics, $currentDate);
// Check if current date is provided
if (!$currentDate) {
$dateFrom = $dateTill = $currentDate = $dates[0]['date_formatted'];
$dates[0]['selected'] = true;
}
$this->view->assign('dates', $dates);
}
// Fill topics with notices
foreach ($topics as $topic) {
if (in_array($topic->getFeGroup(), $user->groupData['uid'])) {
$allTopics[] = $topicId = $topic->getId();
$data[$topicId]['topic'] = $topic;
$data[$topicId]['url'] = $UriBuilder->uriFor('single', ['topic_id' => $topicId, 'currentDate' => $currentDate]);
$topicNotices = $this->noticesRepository->findTopicNotices($topic->getId(), $setLimit, 0, $groupBy, $dateFrom, $dateTill);
$data[$topicId]['notices'] = $topicNotices;
// Get files for each notice
foreach ($data[$topicId]['notices'] as $key => $item) {
$files = $this->cleanNoticeFileResponse($this->getFilesByNotice($item->getUid()));
if ($files) {
$data[$topicId]['notices'][$key]->fileArray = $files;
}
}
}
}
$this->view->assign('data', $data);
}
/**
* Single Action
* See all notices per topic with notices summaries
*/
public function singleAction()
{
// Pre-set variables
$data = [];
$groupBy = $this->settings['GroupBy'];
$currentDate = $this->request->hasArgument('currentDate') ? $this->request->getArgument('currentDate') : null;
// Fetch request
$request = $this->request->getArguments();
$topicId = $this->request->hasArgument('topic_id') ? $this->request->getArgument('topic_id') : 0;
// Add filter options, if date set
if ($groupBy == 'date') {
$dateFrom = $dateTill = $currentDate;
}
// Fetch topic and its notices
$topic = $this->topicsRepository->findByUid($topicId);
$getNotices = $this->noticesRepository->findTopicNotices($topicId, 0, 0, $groupBy, $dateFrom, $dateTill)->count();
// NoticesPerTopicSingle - set Notices per page for TopicSingeView
$setLimit = (int)$this->settings['NoticesPerTopicSingle'];
$currentPage = isset($request['@widget_0']['currentPage']) ? $request['@widget_0']['currentPage'] * $setLimit - 2 : 0;
$topicNotices = $this->noticesRepository->findTopicNotices($topic->getId(), $setLimit, $currentPage, $groupBy, $dateFrom, $dateTill);
// Set data values
$data['range'] = range(1, $getNotices);
$data['itemsPerPage'] = $setLimit;
$data['maximumNumberOfLinks'] = 10;
// Don't show pagination if only one page
if (count($data['range']) < $data['itemsPerPage']) {
$data['hidePagination'] = true;
}
$this->view->assign('data', $data);
$this->view->assign('language', $this->language);
$this->view->assign('notices', $topicNotices);
$this->view->assign('topic', $topic);
}
/**
* Details Action
* See content details
*
* @return void
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\NoSuchArgumentException
*/
public function detailsAction()
{
// Fetch request
$noticeId = $this->request->hasArgument('uid') ? $this->request->getArgument('uid') : 0;
$notice = $this->noticesRepository->findByUid($noticeId);
$files = $this->getFilesByNotice($noticeId);
$this->view->assign('topic', $this->topicsRepository->findByUid($notice->getTopicId()));
$this->view->assign('language', $this->language);
$this->view->assign('notice', $notice);
$this->view->assign('files', $files);
}
/**
* Retrieve files by notice ID
*
* @param $noticeId
*
* @return array
*/
private function getFilesByNotice($noticeId)
{
// Pre-set values
$files = [];
$notice = $this->noticesRepository->findByUid($noticeId);
// Check if files found
if (!empty($notice->getFiles())) {
$noticesFiles = explode(',', $notice->getFiles());
// Removes storage folder name
if (!empty($noticesFiles)) {
foreach ($noticesFiles as $filePath) {
if (!empty($filePath) && file_exists(Environment::getPublicPath().'/'.$filePath)) {
$resourceFactory = ResourceFactory::getInstance();
$filePath = str_replace('fileadmin/', '', $filePath);
$f = $resourceFactory->getFileObjectByStorageAndIdentifier(1, $filePath);
$f->getProperties();
$files[] = $f;
}
}
}
}
return $files;
}
/**
* Strips excess info about files
*
* @param array $files
*
* @return array
*/
private function cleanNoticeFileResponse(array $files): array
{
$data = [];
foreach ($files as $item) {
$storageConf = $item->getStorage()->getConfiguration();
$data[] = [
'name' => end(explode("/", $item->getIdentifier())),
'path' => $storageConf['basePath'].$item->getIdentifier(),
'type' => substr($item->getExtension(), 0, 3), // Use only first 3 letters (docx, xlsx hack while no other icons available, might change in v8)!
];
}
return $data;
}
/**
* Retrieves user category mounts
*
* @param $fields
*
* @return array
*/
public function renderTopicFields(&$fields)
{
$row = $fields['row'];
$pid = $row['pid'];
$dataHandler = new DataHandler();
$resolvedPid = $dataHandler->resolvePid('tx_lunotices_domain_model_notices', $pid);
$userMount = self::getBeUserCatMounts($resolvedPid);
$fields['items'] = Topics::getAllowedTopics($userMount, $resolvedPid);
return $fields;
}
/**
* @param int $pid
*
* @return array
*/
public function getBeUserCatMounts($pid = 0)
{
global $BE_USER;
$catMounts = [];
if ($BE_USER->user['admin']) {
$catMounts = Topics::getTopicIds($pid);
} else {
if (is_array($BE_USER->userGroups)) {
foreach ($BE_USER->userGroups as $group) {
if ($group['lu_notices_topicmounts']) {
$catMounts[] = $group['lu_notices_topicmounts'];
}
}
}
if ($BE_USER->user['lu_notices_topicmounts']) {
$catMounts[] = $BE_USER->user['lu_notices_topicmounts'];
}
}
return $catMounts;
}
}
<?php
namespace Lu\LuNotices\Domain\Model;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
/**
* Class Notices
*
* @owner University of Latvia
* @author Maija Zviedre <maija.zviedre@lu.lv>
* @version 3.0.0
* @since 30.07.2018
*
* @package Lu\LuNotices\Domain\Model
*/
class Notices extends AbstractEntity
{
/**
* @var string
*/
private static $tableName = 'tx_lunotices_domain_model_notices';
/**
* The field uid
*
* @var string
**/
protected $uid = '';
/**
* The field topic_id
*
* @var string
**/
protected $topicId = '';
/**
* The field title
*
* @var string
**/
protected $title = '';
/**
* The field summary
*
* @var string
**/
protected $summary = '';
/**
* The field body
*
* @var string
**/
protected $body = '';
/**
* The field starttime
*
* @var int
**/
protected $starttime = 0;
/**
* The field endtime
*
* @var int
**/
protected $endtime = 0;
/**
* The field hidden
*
* @var int
**/
protected $hidden = 0;
/**
* The field files
*
* @var string
**/
protected $files = '';
/**
* The field url
*
* @var string
**/
protected $url = '';
/**
* Gets the field uid
*
* @return string
*/
public function getId()
{
return $this->uid;
}
/**
* Gets the field title
*
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Gets the field topic_id
*
* @return string
*/
public function getTopicId()
{
return $this->topicId;
}
/**
* Gets the field summary
*
* @return string
*/
public function getSummary()
{
return $this->summary;
}
/**
* Gets the field body
*
* @return string
*/
public function getBody()
{
return $this->body;
}
/**
* Gets the field starttime
*
* @return int
*/
public function getStartTime()
{
return $this->starttime;
}
/**
* Gets the field endtime
*
* @return int
*/
public function getEndTime()
{
return $this->endtime;
}
/**
* Gets the field hidden
*
* @return int
*/
public function getHidden()
{
return $this->hidden;
}
/**
* Gets the field files
*
* @return string
*/
public function getFiles()
{
return $this->files;
}
/**
* Gets the field files
*
* @return string
*/
public function getUrl()
{
return $this->url;
}
/**
* @param array $allTopics
* @param $currentDate
*
* @return array
*/
public static function getNoticeDates(array $allTopics, $currentDate): array
{
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable(self::$tableName);
$dates = [];
// Get data
$response = $queryBuilder->selectLiteral("DATE_FORMAT(FROM_UNIXTIME(`starttime`), '%Y-%m-%d') AS date_formatted", "COUNT(uid) AS count")
->from(self::$tableName)
->where(
$queryBuilder->expr()->in(
'topic_id',
GeneralUtility::intExplode(',', implode(',', $allTopics), true),
Connection::PARAM_INT
)
)
->andWhere(
$queryBuilder->expr()->eq('deleted', $queryBuilder->createNamedParameter(0))
)
->andWhere(
$queryBuilder->expr()->gt('starttime', $queryBuilder->createNamedParameter(1))
)
->groupBy('date_formatted')
->orderBy('date_formatted', 'DESC')
->execute();
// Read and load groups
while ($row = $response->fetch()) {
if ($row['date_formatted'] == $currentDate) {
$row['selected'] = true;
}
$tmp = new \DateTime($row['date_formatted']);
if ($tmp->format('Y') != date("Y")) {
$row['archive'] = true;
}
$dates[] = $row;
}
return $dates;
}
}
<?php
namespace Lu\LuNotices\Domain\Model;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
/**
* Class Topics
*