/**
  * Adds a message to the queue.
  *
  * @param Message   $message
  * @param           $tokens
  * @param           $language
  *
  * @return $this
  */
 public function addMessage(Message $message, $tokens, $language)
 {
     $gateway = $message->getRelated('gateway');
     if ($gateway === null || $gateway->type !== 'queue') {
         throw new \InvalidArgumentException('You cannot add a message to the queue that does not belong to any queue gateway.');
     }
     $objQueuedMessage = new QueuedMessage();
     $objQueuedMessage->message = $message->id;
     $objQueuedMessage->sourceQueue = $gateway->id;
     $objQueuedMessage->targetGateway = $gateway->queue_targetGateway;
     $objQueuedMessage->dateAdded = time();
     $objQueuedMessage->setTokens($tokens);
     $objQueuedMessage->language = $language;
     $objQueuedMessage->save();
     return $this;
 }
 public function addTokens(Message $objMessage, &$arrTokens, $strLanguage, $objGatewayModel)
 {
     if (($objNotification = $objMessage->getRelated('pid')) === null || !$objNotification->type) {
         return true;
     }
     // check for submission id
     if (!is_numeric($arrTokens['tl_submission'])) {
         return true;
     }
     if (($objSubmission = SubmissionModel::findByPk($arrTokens['tl_submission'])) === null) {
         return true;
     }
     if (!is_array($GLOBALS['SUBMISSION_RELATIONS'])) {
         return true;
     }
     foreach ($GLOBALS['SUBMISSION_RELATIONS'] as $strKey => $arrRelation) {
         if (!$arrRelation['table'] || !$arrRelation['submissionField']) {
             continue;
         }
         if ($objSubmission->{$arrRelation['submissionField']} < 1) {
             continue;
         }
         if (($objItem = SubmissionCreator::findRelatedEntity($objSubmission->{$arrRelation['submissionField']}, $arrRelation)) === null) {
             continue;
         }
         \Controller::loadDataContainer($arrRelation['table']);
         $objDc = new DC_Hybrid($arrRelation['table']);
         $objDc->activeRecord = $objItem;
         $arrData = SubmissionModel::prepareData($objItem, $arrRelation['table'], $GLOBALS['TL_DCA'][$arrRelation['table']], $objDc);
         $arrTokens = array_merge($arrTokens, SubmissionModel::tokenizeData($arrData, 'event'));
         // Options callback
         if (is_array($arrRelation['addTokens_callback']) && isset($arrCallback[0]) && class_exists($arrCallback[0])) {
             $arrCallback = $arrRelation['addTokens_callback'];
             $arrTokens = \Controller::importStatic($arrCallback[0])->{$arrCallback}[1]($objItem, $arrTokens, $arrRelation, $objNotification, $strLanguage, $objGatewayModel);
         } elseif (is_callable($arrRelation['addTokens_callback'])) {
             $arrTokens = $arrRelation['addTokens_callback']($objItem, $arrTokens, $arrRelation, $objNotification, $strLanguage, $objGatewayModel);
         }
     }
     return true;
 }