mirror of
https://github.com/standardebooks/web.git
synced 2025-07-15 02:46:46 -04:00
Add automatic donation drives
This commit is contained in:
parent
d8ed44e20e
commit
19cf14c1aa
10 changed files with 396 additions and 296 deletions
|
@ -74,15 +74,26 @@ const ARTWORK_UPLOADS_LOG_FILE_PATH = '/var/log/local/artwork-uploads.log'; // M
|
|||
define('PD_YEAR', intval((new DateTimeImmutable('now', new DateTimeZone('America/Juneau')))->format('Y')) - 96); // Latest continental US time zone.
|
||||
define('PD_STRING', 'January 1, ' . (PD_YEAR + 1));
|
||||
|
||||
define('DONATION_HOLIDAY_ALERT_ON', NOW > new DateTimeImmutable('November 15, ' . NOW->format('Y')) || NOW < new DateTimeImmutable('January 7, ' . NOW->add(new DateInterval('P1Y'))->format('Y')));
|
||||
define('DONATION_ALERT_ON', DONATION_HOLIDAY_ALERT_ON || rand(1, 4) == 2);
|
||||
// Controls the progress bar donation dialog.
|
||||
const DONATION_DRIVES_ENABLED = true; // **`TRUE`** to enable automatic donation drives; **`FALSE`** to disable all donation drives.
|
||||
const DONATION_DRIVE_DATES = [
|
||||
new DonationDrive(
|
||||
'Spring drive',
|
||||
new DateTimeImmutable('Second Monday of May'),
|
||||
new DateTimeImmutable('Second Monday of May +2 weeks'),
|
||||
50,
|
||||
20
|
||||
),
|
||||
new DonationDrive(
|
||||
'Holiday drive',
|
||||
NOW < new DateTimeImmutable('November 15') ? new DateTimeImmutable('November 15') : new DateTimeImmutable('November 15 -1 year'),
|
||||
NOW < new DateTimeImmutable('January 7') ? new DateTimeImmutable('January 7') : new DateTimeImmutable('January 7 +1 year'),
|
||||
50,
|
||||
20
|
||||
)
|
||||
];
|
||||
|
||||
// Controls the progress bar donation dialog
|
||||
const DONATION_DRIVE_ON = true;
|
||||
const DONATION_DRIVE_START = new DateTimeImmutable('May 20, 2024 00:00:00 America/New_York');
|
||||
const DONATION_DRIVE_END = new DateTimeImmutable('June 3, 2024 23:59:00 America/New_York');
|
||||
|
||||
// Controls the countdown donation dialog
|
||||
const DONATION_DRIVE_COUNTER_ON = false;
|
||||
// Controls the countdown donation dialog, basically unused right now.
|
||||
const DONATION_DRIVE_COUNTER_ENABLED = false;
|
||||
const DONATION_DRIVE_COUNTER_START = new DateTimeImmutable('May 2, 2022 00:00:00 America/New_York');
|
||||
const DONATION_DRIVE_COUNTER_END = new DateTimeImmutable('May 8, 2022 23:59:00 America/New_York');
|
||||
|
|
95
lib/DonationDrive.php
Normal file
95
lib/DonationDrive.php
Normal file
|
@ -0,0 +1,95 @@
|
|||
<?
|
||||
use Safe\DateTimeImmutable;
|
||||
|
||||
/**
|
||||
* @property int $DonationCount
|
||||
* @property int $StretchDonationCount
|
||||
* @property bool $IsStretchEnabled
|
||||
* @property int $TargetDonationCount
|
||||
*/
|
||||
class DonationDrive{
|
||||
use Traits\Accessor;
|
||||
|
||||
protected int $_DonationCount;
|
||||
protected int $_StretchDonationCount;
|
||||
protected bool $_IsStretchEnabled;
|
||||
protected int $_TargetDonationCount;
|
||||
|
||||
public function __construct(public string $Name, public DateTimeImmutable $Start, public DateTimeImmutable $End, public int $BaseTargetDonationCount, public int $StretchTargetDonationCount){
|
||||
}
|
||||
|
||||
public static function GetByIsRunning(): ?DonationDrive{
|
||||
foreach(DONATION_DRIVE_DATES as $donationDrive){
|
||||
if(NOW > $donationDrive->Start && NOW < $donationDrive->End){
|
||||
return $donationDrive;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected function GetDonationCount(): int{
|
||||
if(!isset($this->_DonationCount)){
|
||||
$this->_DonationCount = Db::QueryInt('
|
||||
SELECT sum(cnt)
|
||||
from
|
||||
(
|
||||
(
|
||||
# Anonymous patrons, i.e. from AOGF
|
||||
select count(*) cnt from Payments
|
||||
where
|
||||
UserId is null
|
||||
and
|
||||
(
|
||||
(IsRecurring = true and Amount >= 10 and Created >= ?)
|
||||
or
|
||||
(IsRecurring = false and Amount >= 100 and Created >= ?)
|
||||
)
|
||||
)
|
||||
union all
|
||||
(
|
||||
# All non-anonymous patrons
|
||||
select count(*) as cnt from Patrons
|
||||
where Created >= ?
|
||||
)
|
||||
) x
|
||||
', [$this->Start, $this->Start, $this->Start]);
|
||||
}
|
||||
return $this->_DonationCount;
|
||||
}
|
||||
|
||||
protected function GetTargetDonationCount(): int{
|
||||
if(!isset($this->_TargetDonationCount)){
|
||||
$this->_TargetDonationCount = $this->BaseTargetDonationCount;
|
||||
|
||||
if($this->DonationCount > $this->BaseTargetDonationCount){
|
||||
$this->_TargetDonationCount = $this->_TargetDonationCount + $this->StretchTargetDonationCount;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_TargetDonationCount;
|
||||
}
|
||||
|
||||
protected function GetStretchDonationCount(): int{
|
||||
if(!isset($this->_StretchDonationCount)){
|
||||
$this->_StretchDonationCount = $this->DonationCount - $this->BaseTargetDonationCount;
|
||||
if($this->_StretchDonationCount < 0){
|
||||
$this->_StretchDonationCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_StretchDonationCount;
|
||||
}
|
||||
|
||||
protected function GetIsStretchEnabled(): bool{
|
||||
if(!isset($this->_IsStretchEnabled)){
|
||||
$this->_IsStretchEnabled = false;
|
||||
|
||||
if($this->StretchTargetDonationCount > 0 && $this->DonationCount >= $this->BaseTargetDonationCount){
|
||||
$this->_IsStretchEnabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_IsStretchEnabled;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue