Skip to content

Commit

Permalink
Merge pull request #17 from docmcfly/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
docmcfly authored Oct 4, 2023
2 parents e0314f9 + 110a961 commit 957fa7e
Show file tree
Hide file tree
Showing 24 changed files with 526 additions and 133 deletions.
95 changes: 83 additions & 12 deletions Classes/Controller/DutyRosterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace Cylancer\Participants\Controller;

use Cylancer\Participants\Domain\Model\Event;
use Cylancer\Participants\Domain\PublicOption;
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Database\ConnectionPool;
Expand All @@ -23,9 +24,11 @@ class DutyRosterController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionContr

const LIST_TYPE = 'participants_dutyroster';

const DATE_PATTERN = '/^\d{4}-(((0[13578]|1[02])-(([012]\d)|3[01]))|((0[469]|11)-(([012]\d)|30))|02-[012]\d)$/m';

/**
*
* @var EventRepository
* @var EventRepository eventRepository
*/
private $eventRepository;

Expand All @@ -39,44 +42,44 @@ public function __construct(EventRepository $eventRepository)
* @var \TYPO3\CMS\Extbase\Persistence\QueryResultInterface|array $events
* @return array
*/
private function prepareEvents(Array $events)
private function prepareEvents(array $events)
{
$now = time();
$c = count($events);

if ($c == 0) {
$afterNow = - 1;
$afterNow = -1;
} else {
/** @var Event $firstEvent */
$firstEvent = $events[0];

/** @var Event $firstEvent */
$lastEvent = $events[count($events) - 1];
if ($lastEvent->getDateTime()->getTimestamp() < $now) {
$afterNow = count($events) * (- 1);
if ($lastEvent->getBeginTimeStamp() < $now) {
$afterNow = count($events) * (-1);
} else {
$afterNow = - 1;
$afterNow = -1;
$c = 0;

/**
*
* @var Event $e
*/
foreach ($events as $e) {
if ($afterNow == - 1 && $e->getDateTime()->getTimestamp() > $now) {
if ($afterNow == -1 && $e->getBeginTimeStamp() > $now) {
$afterNow = $c;
}
$c ++;
$c++;
}
$afterNow = $afterNow * (- 1);
$afterNow = $afterNow * (-1);
}
}
/**
*
* @var Event $e
*/
foreach ($events as $e) {
$e->setCurrent($afterNow ++);
$e->setCurrent($afterNow++);
// debug($e);
}
return $events;
Expand Down Expand Up @@ -104,7 +107,7 @@ private function getStorageUid(string $id): array
$s = $qb->select('list_type', 'pages', 'pi_flexform')
->from('tt_content')
->where($qb->expr()
->eq('uid', $qb->createNamedParameter($id)))
->eq('uid', $qb->createNamedParameter($id)))
->execute();
if ($row = $s->fetchAssociative()) {
$contentElement = $row;
Expand Down Expand Up @@ -153,4 +156,72 @@ public function downloadIcsAction(string $id)
$this->view->assign('domain', parse_url($baseUri, PHP_URL_HOST));
$this->view->assign('events', $this->prepareEvents($this->eventRepository->findPublicEvents(EventRepository::UNLIMITED, $this->getStorageUid($id), false)));
}
}



/**
* @param string $id
*/
public function reasonsForPreventionAction(string $id): string
{

$parsedBody = $this->request->getParsedBody();

if (is_array($parsedBody)) {


$from = $this->getValidDate($parsedBody['from']);
$until = $this->getValidDate($parsedBody['until']);
$visibility = $this->getEventVisiblity($parsedBody);

if ($from != null && $until != null) {
return json_encode($this->eventRepository->findEventsAt($this->getStorageUid($id), $from, $until + (24 * 3600), $visibility));
}
}

$tmp = date_parse_from_format('Y-m-d', $parsedBody['from']);
return json_encode([
'parsedBody' => $parsedBody,

'isArray' => is_array($parsedBody),

'from' => $from,
'preg' => preg_match(DutyRosterController::DATE_PATTERN, $parsedBody['from']) > 0,
'fd' => $tmp,
'e' => isset($tmp['errors']),
'ec' => count($tmp['errors'])
]);

}

private function getEventVisiblity($parsedBody): int
{
if (!isset($parsedBody['visibility'])) {
return PublicOption::PUBLIC;
} else if (strtoupper($parsedBody['visibility']) === 'ALL') {
return PublicOption::ALL;
} else if (strtoupper($parsedBody['visibility']) === 'INTERNAL') {
return PublicOption::INTERNAL;
} else {
return PublicOption::PUBLIC;
}
}


private function getValidDate(string $rawDate): string
{
if (preg_match(DutyRosterController::DATE_PATTERN, $rawDate)) {
$date = date_parse_from_format('Y-m-d', $rawDate);
if (!isset($date['errors']) || count($date['errors']) == 0) {
$dt = new \DateTime();
$dt->setTimezone(new \DateTimeZone('Europe/Berlin'));
$dt->setTime(0, 0, 0, 0);
$dt->setDate($date['year'], $date['month'], $date['day']);
return $dt->getTimestamp();
}
}
return null;
}


}
9 changes: 4 additions & 5 deletions Classes/Domain/Model/Commitment.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public function __construct()
* @return void
*/
protected function initStorageObjects()
{}
{
}

/**
* Returns the user
Expand Down Expand Up @@ -169,8 +170,6 @@ public function setEvent($event): void
*/
public function getIsNotChangable(): bool
{
return $this->getEvent()
->getDateTime()
->getTimestamp() < time();
return $this->getEvent()->getBeginTimeStamp() < time();
}
}
}
73 changes: 52 additions & 21 deletions Classes/Domain/Model/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* (c) 2022 C. Gogolin <[email protected]>
* (c) 2023 C. Gogolin <[email protected]>
*/
class Event extends AbstractEntity
{



/**
*
* @var ObjectStorage<FrontendUserGroup>
Expand Down Expand Up @@ -73,15 +74,15 @@ class Event extends AbstractEntity

/**
*
* @var string
* @var int
*/
protected $date = '0000-00-00';
protected $beginDate = 0 ;

/**
*
* @var string
* @var int
*/
protected $time = '00:00';
protected $beginTime = 68400; // 19:00

/**
*
Expand Down Expand Up @@ -145,6 +146,7 @@ public function __construct()

// Do not remove the next line: It would break the functionality
$this->initStorageObjects();

}

/**
Expand Down Expand Up @@ -325,42 +327,70 @@ public function setFullDay($fullDay): void
$this->fullDay = $fullDay;
}




/**
*
* @return \DateTime
* @return int
*/
public function getDate(): \DateTime
public function getBeginDate(): int
{
return \DateTime::createFromFormat('Y-m-d', $this->date);
return $this->beginDate;
}

/**
*
* @param \DateTime $date
* @param int $beginDate
* @return void
*/
public function setDate(\DateTime $date): void
public function setBeginDate(\DateTime $beginDate): void
{
$this->date = $date->format('Y-m-d');
$this->beginDate = $beginDate;
}

/**
*
* @return \DateTime
*/
public function getBeginDateUTC(): \DateTime
{
$return = new \DateTime();
$return->setTimestamp($this->beginDate);
$return->setTimezone(new \DateTimeZone ('UTC'));
return $return;
}


/**
*
* @return int
*/
public function getBeginTime(): int
{
return $this->beginTime;
}

/**
*
* @return \DateTime
*/
public function getTime(): \DateTime
{
return \DateTime::createFromFormat('H:i:s', $this->time);
public function getBeginTimeUTC(): \DateTime
{
$return = new \DateTime();
$return->setTimestamp($this->beginTime);
$return->setTimezone(new \DateTimeZone ('UTC'));
return $return;
}

/**
*
* @param \DateTime $time
* @param int $time
* @return void
*/
public function setTime(\DateTime $time): void
public function setTime(int $beginTime): void
{
$this->time = $time->format('H:i:s');
$this->beginTime = $beginTime;
}

/**
Expand All @@ -384,13 +414,14 @@ public function setDuration($duration): void

/**
*
* @return \DateTime
* @return int
*/
public function getDateTime(): \DateTime
public function getBeginTimestamp(): int
{
return $this->getFullDay() ? \DateTime::createFromFormat('Y-m-d', $this->date)->setTime(0, 0) : \DateTime::createFromFormat('Y-m-d H:i:s', $this->date . ' ' . $this->time);
return $this->getFullDay() ? $this->getBeginDate() : $this->getBeginDate() + $this->getBeginTime();
}


/**
*
* @return void
Expand Down
15 changes: 15 additions & 0 deletions Classes/Domain/Model/FrontendUserGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ class FrontendUserGroup extends AbstractEntity
*/
protected $subgroup;


/**
*
* @var string
*/
protected $accronym = '';

/**
* Constructs a new Frontend User Group
*/
Expand Down Expand Up @@ -102,4 +109,12 @@ public function getSubgroup()
{
return $this->subgroup;
}

/**
*
* @return string
*/
public function getAccronym() {
return $this->accronym;
}
}
4 changes: 3 additions & 1 deletion Classes/Domain/PublicOption.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* (c) 2022 C. Gogolin <[email protected]>
* (c) 2023 C. Gogolin <[email protected]>
*/
abstract class PublicOption
{

const ALL = -1;

const INTERNAL = 0;

const PUBLIC = 1;
Expand Down
9 changes: 5 additions & 4 deletions Classes/Domain/Repository/CommitmentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ public function findCurrentEventCommitments(FrontendUser $user, array $dutyRoste
->in('tx_participants_domain_model_event.pid', $dutyRosterStrorageUids)))
->where($qb->expr()
->andX($qb->expr()
->gte('tx_participants_domain_model_event.date', $qb->createNamedParameter($startMoment->format('Y-m-d'))), $qb->expr()
->gte('tx_participants_domain_model_event.begin_date', $qb->createNamedParameter($startMoment->getTimestamp())), $qb->expr()
->eq('tx_participants_domain_model_commitment.user', $qb->createNamedParameter($user->getUid())), $qb->expr()
->eq('tx_participants_domain_model_commitment.pid', $planningStorageUid)))
->orderby('tx_participants_domain_model_event.date', 'ASC')
->addOrderby('tx_participants_domain_model_event.time', 'ASC')
->orderby('tx_participants_domain_model_event.begin_date', 'ASC')
->addOrderby('tx_participants_domain_model_event.begin_time', 'ASC')
->groupBy('tx_participants_domain_model_commitment.uid');

if (! $withCanceledEvents) {
Expand Down Expand Up @@ -141,6 +141,7 @@ public function findMissingCommitmentsOf(int $userUid, int $commitmentStorageUid
{
$yesterday = new \DateTime();
$yesterday->sub(new \DateInterval('P1D'));
$yesterday->setTimezone(new \DateTimeZone('UTC'));

$qb = $this->getQueryBuilder('tx_participants_domain_model_event');
$qb->select('tx_participants_domain_model_event.uid', 'tx_participants_domain_model_commitment.pid')
Expand All @@ -155,7 +156,7 @@ public function findMissingCommitmentsOf(int $userUid, int $commitmentStorageUid
->andWhere($qb->expr()
->in('tx_participants_domain_model_event.pid', $eventStorageUids))
->andWhere($qb->expr()
->gt('tx_participants_domain_model_event.date', $yesterday->format('y-m-d')));
->gt('tx_participants_domain_model_event.begin_date', $yesterday->getTimestamp()));

// debug($qb->getSQL());
$s = $qb->execute();
Expand Down
Loading

0 comments on commit 957fa7e

Please sign in to comment.