Path: blob/master/src/applications/calendar/policyrule/PhabricatorCalendarEventInviteesPolicyRule.php
12256 views
<?php12final class PhabricatorCalendarEventInviteesPolicyRule3extends PhabricatorPolicyRule {45private $invited = array();6private $sourcePHIDs = array();78public function getObjectPolicyKey() {9return 'calendar.event.invitees';10}1112public function getObjectPolicyName() {13return pht('Event Invitees');14}1516public function getPolicyExplanation() {17return pht('Users invited to this event can take this action.');18}1920public function getRuleDescription() {21return pht('event invitees');22}2324public function canApplyToObject(PhabricatorPolicyInterface $object) {25return ($object instanceof PhabricatorCalendarEvent);26}2728public function willApplyRules(29PhabricatorUser $viewer,30array $values,31array $objects) {3233$viewer_phid = $viewer->getPHID();34if (!$viewer_phid) {35return;36}3738if (empty($this->invited[$viewer_phid])) {39$this->invited[$viewer_phid] = array();40}4142if (!isset($this->sourcePHIDs[$viewer_phid])) {43$source_phids = PhabricatorEdgeQuery::loadDestinationPHIDs(44$viewer_phid,45PhabricatorProjectMaterializedMemberEdgeType::EDGECONST);46$source_phids[] = $viewer_phid;47$this->sourcePHIDs[$viewer_phid] = $source_phids;48}4950foreach ($objects as $key => $object) {51$cache = $this->getTransactionHint($object);52if ($cache === null) {53// We don't have a hint for this object, so we'll deal with it below.54continue;55}5657// We have a hint, so use that as the source of truth.58unset($objects[$key]);5960foreach ($this->sourcePHIDs[$viewer_phid] as $source_phid) {61if (isset($cache[$source_phid])) {62$this->invited[$viewer_phid][$object->getPHID()] = true;63break;64}65}66}6768$phids = mpull($objects, 'getPHID');69if (!$phids) {70return;71}7273$invited = id(new PhabricatorCalendarEventInvitee())->loadAllWhere(74'eventPHID IN (%Ls)75AND inviteePHID IN (%Ls)76AND status != %s',77$phids,78$this->sourcePHIDs[$viewer_phid],79PhabricatorCalendarEventInvitee::STATUS_UNINVITED);80$invited = mpull($invited, 'getEventPHID');8182$this->invited[$viewer_phid] += array_fill_keys($invited, true);83}8485public function applyRule(86PhabricatorUser $viewer,87$value,88PhabricatorPolicyInterface $object) {8990$viewer_phid = $viewer->getPHID();91if (!$viewer_phid) {92return false;93}9495$invited = idx($this->invited, $viewer_phid);96return isset($invited[$object->getPHID()]);97}9899public function getValueControlType() {100return self::CONTROL_TYPE_NONE;101}102103}104105106