Skip to content

Commit

Permalink
Merge pull request #18 from docmcfly/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
docmcfly authored Oct 11, 2023
2 parents 957fa7e + 6463850 commit 90b4b98
Show file tree
Hide file tree
Showing 21 changed files with 181 additions and 298 deletions.
13 changes: 6 additions & 7 deletions Classes/Controller/DutyRosterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class DutyRosterController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionContr

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

Expand All @@ -55,7 +55,7 @@ private function prepareEvents(array $events)

/** @var Event $firstEvent */
$lastEvent = $events[count($events) - 1];
if ($lastEvent->getBeginTimeStamp() < $now) {
if ($lastEvent->getDateTime()->getTimestamp() < $now) {
$afterNow = count($events) * (-1);
} else {
$afterNow = -1;
Expand All @@ -66,7 +66,7 @@ private function prepareEvents(array $events)
* @var Event $e
*/
foreach ($events as $e) {
if ($afterNow == -1 && $e->getBeginTimeStamp() > $now) {
if ($afterNow == -1 && $e->getDateTime()->getTimestamp() > $now) {
$afterNow = $c;
}
$c++;
Expand Down Expand Up @@ -175,7 +175,7 @@ public function reasonsForPreventionAction(string $id): string
$visibility = $this->getEventVisiblity($parsedBody);

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

Expand Down Expand Up @@ -208,16 +208,15 @@ private function getEventVisiblity($parsedBody): int
}


private function getValidDate(string $rawDate): string
private function getValidDate(string $rawDate): ?\DateTime
{
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 $dt;
}
}
return null;
Expand Down
9 changes: 5 additions & 4 deletions Classes/Domain/Model/Commitment.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ public function __construct()
* @return void
*/
protected function initStorageObjects()
{
}
{}

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



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

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

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

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

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

}

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




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

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

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

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

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

/**
*
* @return int
* @return \DateTime
*/
public function getBeginTimestamp(): int
public function getDateTime(): \DateTime
{
return $this->getFullDay() ? $this->getBeginDate() : $this->getBeginDate() + $this->getBeginTime();
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 void
Expand Down
31 changes: 16 additions & 15 deletions Classes/Domain/Model/FrontendUserGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,6 @@ class FrontendUserGroup extends AbstractEntity
*/
protected $subgroup;


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

/**
* Constructs a new Frontend User Group
*/
Expand All @@ -45,6 +38,13 @@ public function __construct()
$this->subgroup = new ObjectStorage();
}

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


/**
* Sets the title value
*
Expand Down Expand Up @@ -110,11 +110,12 @@ public function getSubgroup()
return $this->subgroup;
}

/**
*
* @return string
*/
public function getAccronym() {
return $this->accronym;
}
}
/**
*
* @return string
*/
public function getAccronym()
{
return $this->accronym;
}
}
9 changes: 4 additions & 5 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.begin_date', $qb->createNamedParameter($startMoment->getTimestamp())), $qb->expr()
->gte('tx_participants_domain_model_event.date', $qb->createNamedParameter($startMoment->format('Y-m-d'))), $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.begin_date', 'ASC')
->addOrderby('tx_participants_domain_model_event.begin_time', 'ASC')
->orderby('tx_participants_domain_model_event.date', 'ASC')
->addOrderby('tx_participants_domain_model_event.time', 'ASC')
->groupBy('tx_participants_domain_model_commitment.uid');

if (! $withCanceledEvents) {
Expand Down Expand Up @@ -141,7 +141,6 @@ 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 @@ -156,7 +155,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.begin_date', $yesterday->getTimestamp()));
->gt('tx_participants_domain_model_event.date', $yesterday->format('y-m-d')));

// debug($qb->getSQL());
$s = $qb->execute();
Expand Down
29 changes: 15 additions & 14 deletions Classes/Domain/Repository/EventRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function findTomorrowsEvents(): array
$s = $qb->execute();
$return = array();

while ($row = $s->fetchAssociative()) {
while ($row = $s->fetch()) {
$return[] = $this->findByUid($row['uid']);
}
// debug($return);
Expand All @@ -84,8 +84,8 @@ public function findPublicEvents(int $limit = EventRepository::UNLIMITED, array
->andX($qb->expr()
->eq('tx_participants_domain_model_event.public', PublicOption::INHERITED), $qb->expr()
->eq('tx_participants_domain_model_eventtype.public', PublicOption::PUBLIC ))))
->orderBy('begin_date', QueryInterface::ORDER_ASCENDING)
->addOrderBy('begin_time', QueryInterface::ORDER_ASCENDING);
->orderBy('date', QueryInterface::ORDER_ASCENDING)
->addOrderBy('time', QueryInterface::ORDER_ASCENDING);

if ($storageUids == null) {
$qb->andWhere($qb->expr()
Expand All @@ -107,20 +107,21 @@ public function findPublicEvents(int $limit = EventRepository::UNLIMITED, array
}
if ($startWithToday) {
$qb->andWhere($qb->expr()
->gte('tx_participants_domain_model_event.begin_date', time()));
->gte('tx_participants_domain_model_event.date', $qb->createNamedParameter(date('Y-m-d'))));
}
// debug($qb->getSql());
$s = $qb->execute();
$return = array();

while ($row = $s->fetchAssociative()) {
while ($row = $s->fetch()) {
$return[] = $this->findByUid($row['uid']);
}
return $return;
}


public function findEventsAt(array $storageUids, int $from, int $until, int $visibility, int $limit = EventRepository::UNLIMITED, bool $inclusiveCanceledEvents = false): array

public function findEventsAt(array $storageUids, \DateTime $from, \DateTime $until, int $visibility, int $limit = EventRepository::UNLIMITED, bool $inclusiveCanceledEvents = false): array
{
$qb = $this->getQueryBuilder('tx_participants_domain_model_event');

Expand All @@ -146,8 +147,8 @@ public function findEventsAt(array $storageUids, int $from, int $until, int $vis
->eq('tx_participants_domain_model_event.event_type', $qb->quoteIdentifier('tx_participants_domain_model_eventtype.uid')))
->where(
$qb->expr()->andX(
$qb->expr()->gte('begin_date', $qb->createNamedParameter($from)),
$qb->expr()->lt('begin_date', $qb->createNamedParameter($until))
$qb->expr()->gte('date', $qb->createNamedParameter($from->format('Y-m-d'))),
$qb->expr()->lte('date', $qb->createNamedParameter($until->format('Y-m-d')))
)
)
->orderBy('date', QueryInterface::ORDER_ASCENDING)
Expand Down Expand Up @@ -178,20 +179,20 @@ public function findEventsAt(array $storageUids, int $from, int $until, int $vis
$s = $qb->execute();
$return = [];
if (1 == 0) { // add debug infos
$debug = [];
$debug = [];
$debug['sql'] = $qb->getSql();
$debug['from'] = $from;
$debug['until'] = $until;
$debug['from'] = $from->format('Y-m-d');
$debug['until'] = $until->format('Y-m-d');
$return['debug'] = $debug;
}
$data = [];
while ($row = $s->fetchAssociative()) {
/** @var Event $e */
$e = $this->findByUid($row['uid']);
$tmp = [];
$tmp['description'] = htmlspecialchars($e->getEventType()->getTitle() .' ('.date('d.m.Y', $e->getBeginDate()).')');
$tmp['title'] = htmlspecialchars($e->getEventType()->getTitle());
$tmp['date'] = htmlspecialchars(date('d.m.Y', $e->getBeginDate()));
$tmp['description'] = htmlspecialchars($e->getEventType()->getTitle() . ' (' . $e->getDate()->format('d.m.Y') . ')');
$tmp['title'] = htmlspecialchars($e->getEventType()->getTitle());
$tmp['begin_date'] = htmlspecialchars($e->getDate()->format('d.m.Y'));
$data[] = $tmp;
}
$return['data'] = $data;
Expand Down
Loading

0 comments on commit 90b4b98

Please sign in to comment.