/** * Triggers a system event. * * This will create a SystemEventInstance instance and notify any remote * systems if they have active SystemEventSubscription objects. * * Each subscriber will be sent a unique SystemEventInstanceMessage. * * eg. * * $message = new stdClass(); * $message->user_id = 54; * $message->city = 'Vancouver'; * \SystemEventPeer::triggerEvent( 'new_user_signed_up', $message ); * * * * @param string $event_unique_key * @param stdClass $message * @param integer $user_id * * @throws \Exception if system event is not known * @throws \Exception if $message is not a stdClass (if not null) * @throws \Exception if $user_id is provided (not null) but not found * * @return SystemEventInstance */ public static function triggerEvent($event_unique_key, $message = null, $user_id = null) { //validate the arguments $system_event = \SystemEventPeer::retrieveByUniqueKey($event_unique_key); if (!$system_event) { throw new \Exception('Unknown System Event: ' . $event_unique_key); } if (!is_null($message)) { if (!$message instanceof \stdClass) { throw new \Exception('Message must be a stdClass.'); } } else { $message = new \stdClass(); } if (!is_null($user_id)) { $user = \UserPeer::retrieveByPK($user_id); if (!$user) { throw new \Exception('Unknown User.'); } } else { $user = \sfContext::getInstance()->getUser()->getProfile(); if (!$user) { throw new \Exception('User must be logged in or you must provide a user_id to triggerError()'); } $user_id = $user->getId(); } //record the event $system_event_instance = new \SystemEventInstance(); $system_event_instance->setMessage(json_encode($message)); if (isset($user)) { $system_event_instance->setUser($user); } $system_event_instance->setSystemEvent($system_event); $system_event_instance->save(); //get the subscribers for this event $system_event_subscriptions = \SystemEventSubscriptionPeer::getSubscriptionsForEvent($system_event->getId(), $user_id); //notify each of the subscribers foreach ($system_event_subscriptions as $system_event_subscription) { $system_event_subscription->saveSystemEventNotification($system_event_instance); } }
/** * Adds an object to the instance pool. * * Propel keeps cached copies of objects in an instance pool when they are retrieved * from the database. In some cases -- especially when you override doSelect*() * methods in your stub classes -- you may need to explicitly add objects * to the cache in order to ensure that the same objects are always returned by doSelect*() * and retrieveByPK*() calls. * * @param SystemEventInstance $obj A SystemEventInstance object. * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). */ public static function addInstanceToPool($obj, $key = null) { if (Propel::isInstancePoolingEnabled()) { if ($key === null) { $key = (string) $obj->getId(); } // if key === null self::$instances[$key] = $obj; } }
/** * Filter the query by a related SystemEventInstance object * * @param SystemEventInstance|PropelObjectCollection $systemEventInstance The related object(s) to use as filter * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return SystemEventInstanceMessageQuery The current query, for fluid interface * @throws PropelException - if the provided filter is invalid. */ public function filterBySystemEventInstance($systemEventInstance, $comparison = null) { if ($systemEventInstance instanceof SystemEventInstance) { return $this->addUsingAlias(SystemEventInstanceMessagePeer::SYSTEM_EVENT_INSTANCE_ID, $systemEventInstance->getId(), $comparison); } elseif ($systemEventInstance instanceof PropelObjectCollection) { if (null === $comparison) { $comparison = Criteria::IN; } return $this->addUsingAlias(SystemEventInstanceMessagePeer::SYSTEM_EVENT_INSTANCE_ID, $systemEventInstance->toKeyValue('PrimaryKey', 'Id'), $comparison); } else { throw new PropelException('filterBySystemEventInstance() only accepts arguments of type SystemEventInstance or PropelCollection'); } }
/** * Exclude object from result * * @param SystemEventInstance $systemEventInstance Object to remove from the list of results * * @return SystemEventInstanceQuery The current query, for fluid interface */ public function prune($systemEventInstance = null) { if ($systemEventInstance) { $this->addUsingAlias(SystemEventInstancePeer::ID, $systemEventInstance->getId(), Criteria::NOT_EQUAL); } return $this; }
/** * Declares an association between this object and a SystemEventInstance object. * * @param SystemEventInstance $v * @return SystemEventInstanceMessage The current object (for fluent API support) * @throws PropelException */ public function setSystemEventInstance(SystemEventInstance $v = null) { if ($v === null) { $this->setSystemEventInstanceId(NULL); } else { $this->setSystemEventInstanceId($v->getId()); } $this->aSystemEventInstance = $v; // Add binding for other direction of this n:n relationship. // If this object has already been added to the SystemEventInstance object, it will not be re-added. if ($v !== null) { $v->addSystemEventInstanceMessage($this); } return $this; }
/** * @param SystemEventInstance $systemEventInstance The systemEventInstance object to add. */ protected function doAddSystemEventInstance($systemEventInstance) { $this->collSystemEventInstances[] = $systemEventInstance; $systemEventInstance->setSystemEvent($this); }
/** * Filter the query by a related SystemEventInstance object * * @param SystemEventInstance|PropelObjectCollection $systemEventInstance the related object to use as filter * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return SystemEventQuery The current query, for fluid interface * @throws PropelException - if the provided filter is invalid. */ public function filterBySystemEventInstance($systemEventInstance, $comparison = null) { if ($systemEventInstance instanceof SystemEventInstance) { return $this->addUsingAlias(SystemEventPeer::ID, $systemEventInstance->getSystemEventId(), $comparison); } elseif ($systemEventInstance instanceof PropelObjectCollection) { return $this->useSystemEventInstanceQuery()->filterByPrimaryKeys($systemEventInstance->getPrimaryKeys())->endUse(); } else { throw new PropelException('filterBySystemEventInstance() only accepts arguments of type SystemEventInstance or PropelCollection'); } }