Skip to content

Commit

Permalink
Add ContactIsAttendingConditionRule example
Browse files Browse the repository at this point in the history
  • Loading branch information
bencroker committed Jun 20, 2024
1 parent 60180dd commit 255e712
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
2 changes: 2 additions & 0 deletions examples/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Craft;
use craft\base\conditions\BaseCondition;
use craft\events\RegisterConditionRulesEvent;
use modules\conditions\segments\ContactIsAttendingConditionRule;
use modules\conditions\segments\ContactIsUserConditionRule;
use modules\conditions\sendouts\LastEntryHasImageConditionRule;
use modules\conditions\sendouts\MondayMorningSendoutConditionRule;
Expand All @@ -26,6 +27,7 @@ public function init(): void
BaseCondition::EVENT_REGISTER_CONDITION_RULES,
function(RegisterConditionRulesEvent $event) {
$event->conditionRules[] = ContactIsUserConditionRule::class;
$event->conditionRules[] = ContactIsAttendingConditionRule::class;
}
);

Expand Down
68 changes: 68 additions & 0 deletions examples/conditions/segments/ContactIsAttendingConditionRule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
/**
* @copyright Copyright (c) PutYourLightsOn
*/

namespace modules\conditions\segments;

use craft\base\conditions\BaseConditionRule;
use craft\base\ElementInterface;
use craft\elements\conditions\ElementConditionRuleInterface;
use craft\elements\db\ElementQueryInterface;
use craft\elements\Entry;

class ContactIsAttendingConditionRule extends BaseConditionRule implements ElementConditionRuleInterface
{
/**
* @inheritdoc
*/
public string $operator = '';

/**
* @inheritdoc
*/
public function getLabel(): string
{
return 'Contact is attending.';
}

/**
* @inheritdoc
*/
public function getExclusiveQueryParams(): array
{
return [self::class];
}

/**
* @inheritdoc
*/
public function modifyQuery(ElementQueryInterface $query): void
{
$rsvp = Entry::find()
->section('rsvp')
->one();

$ids = $rsvp->attending->ids();

Check failure on line 46 in examples/conditions/segments/ContactIsAttendingConditionRule.php

View workflow job for this annotation

GitHub Actions / PHPStan

Cannot access property $attending on array|craft\elements\Entry.

$query->andWhere([
'id' => $ids,
]);
}

/**
* @inheritdoc
*/
public function matchElement(ElementInterface $element): bool
{
return true;
}

/**
* @inheritdoc
*/
protected function inputHtml(): string
{
return '';
}
}

0 comments on commit 255e712

Please sign in to comment.