-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example module and sendout condition rule
- Loading branch information
Showing
9 changed files
with
143 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace modules; | ||
|
||
use Craft; | ||
use craft\base\conditions\BaseCondition; | ||
use craft\events\RegisterConditionRuleTypesEvent; | ||
use modules\conditions\sendouts\LastEntryHasImageConditionRule; | ||
use modules\conditions\sendouts\MondayMorningSendoutConditionRule; | ||
use modules\conditions\sendouts\RecentEntriesPublishedConditionRule; | ||
use putyourlightson\campaign\elements\conditions\sendouts\SendoutScheduleCondition; | ||
use yii\base\Event; | ||
|
||
class Module extends \yii\base\Module | ||
{ | ||
public function init(): void | ||
{ | ||
Craft::setAlias('@modules', __DIR__); | ||
|
||
parent::init(); | ||
|
||
Event::on( | ||
SendoutScheduleCondition::class, | ||
BaseCondition::EVENT_REGISTER_CONDITION_RULE_TYPES, | ||
function(RegisterConditionRuleTypesEvent $event) { | ||
$event->conditionRuleTypes[] = LastEntryHasImageConditionRule::class; | ||
$event->conditionRuleTypes[] = MondayMorningSendoutConditionRule::class; | ||
$event->conditionRuleTypes[] = RecentEntriesPublishedConditionRule::class; | ||
} | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
examples/conditions/sendouts/MondayMorningSendoutConditionRule.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
/** | ||
* @copyright Copyright (c) PutYourLightsOn | ||
*/ | ||
|
||
namespace modules\conditions\sendouts; | ||
|
||
use craft\base\conditions\BaseConditionRule; | ||
use craft\base\ElementInterface; | ||
use craft\elements\conditions\ElementConditionRuleInterface; | ||
use craft\elements\db\ElementQueryInterface; | ||
use DateTime; | ||
|
||
class MondayMorningSendoutConditionRule extends BaseConditionRule implements ElementConditionRuleInterface | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getLabel(): string | ||
{ | ||
return 'Send only between 10:00 and 11:00 on Mondays'; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getExclusiveQueryParams(): array | ||
{ | ||
return [self::class]; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function modifyQuery(ElementQueryInterface $query): void | ||
{ | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function matchElement(ElementInterface $element): bool | ||
{ | ||
$now = new DateTime(); | ||
|
||
// Return whether it is now between 10:00 and 11:00 on Monday. | ||
return $now->format('H') === '10' && $now->format('N') === '1'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
/** | ||
* @link http://craftcms.com/ | ||
* @copyright Copyright (c) Pixel & Tonic, Inc. | ||
* @license http://craftcms.com/license | ||
*/ | ||
|
||
namespace craft\behaviors; | ||
|
||
use craft\elements\Asset; | ||
use craft\elements\db\AssetQuery; | ||
use craft\elements\ElementCollection; | ||
use yii\base\Behavior; | ||
|
||
/** | ||
* Based on https://github.com/craftcms/cms/blob/develop/lib/craft/behaviors/CustomFieldBehavior.php | ||
* | ||
* @internal | ||
*/ | ||
class CustomFieldBehavior extends Behavior | ||
{ | ||
/** | ||
* Custom fields required for PHPStan. | ||
*/ | ||
public AssetQuery|ElementCollection|Asset $images; | ||
|
||
/** | ||
* @var bool Whether the behavior should provide methods based on the field handles. | ||
*/ | ||
public bool $hasMethods = false; | ||
|
||
/** | ||
* @var bool Whether properties on the class should be settable directly. | ||
*/ | ||
public bool $canSetProperties = true; | ||
|
||
/** | ||
* @var string[] List of supported field handles. | ||
*/ | ||
public static $fieldHandles = []; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,7 @@ includes: | |
parameters: | ||
level: 5 | ||
paths: | ||
- examples | ||
- src | ||
scanFiles: | ||
- lib/craft/behaviors/CustomFieldBehavior.php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters