Migrate v3 data; WIP on journal items
This commit is contained in:
@@ -22,6 +22,16 @@ class Auth
|
||||
return self::$auth0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the logged on user information
|
||||
*
|
||||
* @return array|null The user information (null if no user is logged on)
|
||||
*/
|
||||
public static function user(): ?array
|
||||
{
|
||||
return self::client()->getUser();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initiate a log on with Auth0
|
||||
*
|
||||
@@ -50,4 +60,20 @@ class Auth
|
||||
header('Location: ' . self::client()->logout($_ENV['AUTH0_BASE_URL']));
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Require a user be logged on
|
||||
*
|
||||
* @param bool $redirect Whether to redirect to log on if there is not a user logged on
|
||||
* @return void If it returns, there is a user logged on; if not, we will be redirected to log on
|
||||
* @throws ConfigurationException If the Auth0 client is not configured correctly
|
||||
*/
|
||||
public static function requireUser(bool $redirect = true): void
|
||||
{
|
||||
if (is_null(self::user())) {
|
||||
if ($redirect) self::logOn();
|
||||
http_response_code(403);
|
||||
die('Not Authorized');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,12 @@
|
||||
|
||||
namespace MyPrayerJournal;
|
||||
|
||||
use JsonSerializable;
|
||||
|
||||
/**
|
||||
* A record of an action taken on a request
|
||||
*/
|
||||
class History
|
||||
class History implements JsonSerializable
|
||||
{
|
||||
/**
|
||||
* @param string $asOf The date/time this entry was made
|
||||
@@ -13,4 +15,11 @@ class History
|
||||
* @param string|null $text The text for this history entry (optional)
|
||||
*/
|
||||
public function __construct(public string $asOf, public RequestAction $action, public ?string $text = null) { }
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
$values = ['asOf' => $this->asOf, 'action' => $this->action->value];
|
||||
if (!is_null($this->text)) $values['text'] = $this->text;
|
||||
return $values;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,4 +114,15 @@ class Layout
|
||||
</footer><?php
|
||||
}
|
||||
|
||||
/// Create a card when there are no results found
|
||||
public static function noResults(string $heading, string $link, string $buttonText, string $text): void
|
||||
{ ?>
|
||||
<div class=card>
|
||||
<h5 class=card-header><?=$heading?></h5>
|
||||
<div class="card-body text-center">
|
||||
<p class=card-text><?=$text?></p><?php
|
||||
page_link($link, $buttonText, ['class' => 'btn btn-primary']); ?>
|
||||
</div>
|
||||
</div><?php
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,14 +2,23 @@
|
||||
|
||||
namespace MyPrayerJournal;
|
||||
|
||||
use JsonSerializable;
|
||||
|
||||
/**
|
||||
* The recurrence for a prayer request
|
||||
*/
|
||||
class Recurrence
|
||||
class Recurrence implements JsonSerializable
|
||||
{
|
||||
/**
|
||||
* @param RecurrencePeriod $period The recurrence period
|
||||
* @param int|null $interval How many of the periods will pass before the request is visible again
|
||||
*/
|
||||
public function __construct(public RecurrencePeriod $period, public ?int $interval = null) { }
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
$values = ['period' => $this->period->value];
|
||||
if (!is_null($this->interval)) $values['interval'] = $this->interval;
|
||||
return $values;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,17 +5,17 @@ namespace MyPrayerJournal;
|
||||
/**
|
||||
* The type of recurrence a request can have
|
||||
*/
|
||||
enum RecurrencePeriod
|
||||
enum RecurrencePeriod: string
|
||||
{
|
||||
/** Requests, once prayed, are available again immediately */
|
||||
case Immediate;
|
||||
case Immediate = 'Immediate';
|
||||
|
||||
/** Requests, once prayed, appear again in a number of hours */
|
||||
case Hours;
|
||||
case Hours = 'Hours';
|
||||
|
||||
/** Requests, once prayed, appear again in a number of days */
|
||||
case Days;
|
||||
case Days = 'Days';
|
||||
|
||||
/** Requests, once prayed, appear again in a number of weeks */
|
||||
case Weeks;
|
||||
case Weeks = 'Weeks';
|
||||
}
|
||||
|
||||
@@ -4,12 +4,13 @@ namespace MyPrayerJournal;
|
||||
|
||||
use BitBadger\PDODocument\{DocumentException, Find};
|
||||
use Exception;
|
||||
use JsonSerializable;
|
||||
use Visus\Cuid2\Cuid2;
|
||||
|
||||
/**
|
||||
* A prayer request
|
||||
*/
|
||||
class Request
|
||||
class Request implements JsonSerializable
|
||||
{
|
||||
/**
|
||||
* @param string $id The ID for the request
|
||||
@@ -18,8 +19,8 @@ class Request
|
||||
* @param string|null $snoozedUntil The date/time the snooze expires for this request (null = not snoozed)
|
||||
* @param string|null $showAfter The date/time the current recurrence period is over (null = immediate)
|
||||
* @param Recurrence $recurrence The recurrence for this request
|
||||
* @param array|History[] $history The history of this request
|
||||
* @param array|Note[] $notes Notes regarding this request
|
||||
* @param History[] $history The history of this request
|
||||
* @param Note[] $notes Notes regarding this request
|
||||
* @throws Exception If the ID generation fails
|
||||
*/
|
||||
public function __construct(public string $id = '', public string $enteredOn = '', public string $userId = '',
|
||||
@@ -44,4 +45,19 @@ class Request
|
||||
$req = Find::byId(Table::REQUEST, $id, self::class);
|
||||
return ($req && $req->userId == $_SESSION['user_id']) ? $req : false;
|
||||
}
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
$values = [
|
||||
'id' => $this->id,
|
||||
'enteredOn' => $this->enteredOn,
|
||||
'userId' => $this->userId,
|
||||
'recurrence' => $this->recurrence,
|
||||
'history' => $this->history,
|
||||
'notes' => $this->notes
|
||||
];
|
||||
if (!is_null($this->snoozedUntil)) $values['snoozedUntil'] = $this->snoozedUntil;
|
||||
if (!is_null($this->showAfter)) $values['showAfter'] = $this->showAfter;
|
||||
return $values;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,17 +5,17 @@ namespace MyPrayerJournal;
|
||||
/**
|
||||
* An action taken on a prayer request
|
||||
*/
|
||||
enum RequestAction
|
||||
enum RequestAction: string
|
||||
{
|
||||
/** The request was created */
|
||||
case Created;
|
||||
case Created = 'Created';
|
||||
|
||||
/** The request was marked as having been prayed for */
|
||||
case Prayed;
|
||||
case Prayed = 'Prayed';
|
||||
|
||||
/** The request was updated */
|
||||
case Updated;
|
||||
case Updated = 'Updated';
|
||||
|
||||
/** The request was marked as answered */
|
||||
case Answered;
|
||||
case Answered = 'Answered';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user