public function setSubmissionArchiveByRelation(\DataContainer &$dc)
 {
     if ($dc->objModule === null || !$dc->objModule->addSubmissionRelation || $dc->objModule->type != \HeimrichHannot\Submissions\Creator\SubmissionCreator::MODULE_SUBMISSION_READER) {
         return;
     }
     $objSubmission = SubmissionModel::findByPk($dc->id);
     if ($objSubmission === null) {
         return;
     }
     $arrRelation = $GLOBALS['SUBMISSION_RELATIONS'][$dc->objModule->submissionRelation];
     if (!is_array($arrRelation)) {
         return;
     }
     if (!$arrRelation['table'] || !$arrRelation['submissionField']) {
         return;
     }
     if (($objRelatedItem = SubmissionCreator::findRelatedEntity($objSubmission->{$arrRelation['submissionField']}, $arrRelation, $dc->objModule)) === null) {
         return;
     }
     if (!$objRelatedItem->addSubmissionRelation) {
         return;
     }
     if (($objArchive = SubmissionArchiveModel::findByPk($objRelatedItem->submissionRelation)) === null) {
         return;
     }
     // overwrite submission archive by related item submission archive
     $objSubmission->pid = $objArchive->id;
     $objSubmission->save();
 }
 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;
 }
 public static function replaceRelation(array $arrRelation, $strTag)
 {
     $params = preg_split('/::/', $strTag);
     if (!isset($arrRelation['insertTagLink']) || !isset($arrRelation['table'])) {
         return false;
     }
     $relParams = str_replace(array('{', '}'), '', $arrRelation['insertTagLink']);
     $relParams = preg_split('/::/', $relParams);
     // check if given relation inserttag is provided
     if ($relParams[0] != $params[0]) {
         return false;
     }
     $pageId = null;
     $moduleId = null;
     $entityId = null;
     if (($pageIdx = array_search('PAGE_ID', $relParams)) !== false) {
         $pageId = $params[$pageIdx];
     }
     if (($entityIdx = array_search('ENTITY_ID', $relParams)) !== false) {
         $entityId = $params[$entityIdx];
     }
     if (($moduleIdx = array_search('MODULE_ID', $relParams)) !== false) {
         $moduleId = $params[$moduleIdx];
     }
     if ($pageId === null || ($objPage = \PageModel::findPublishedByIdOrAlias($pageId)) === null) {
         return false;
     }
     if ($moduleId === null || ($objModule = \ModuleModel::findByPk($moduleId)) === null) {
         return false;
     }
     if ($entityId === null || ($objEntity = SubmissionCreator::findRelatedEntity($entityId, $arrRelation, $objModule->current())) === null) {
         return false;
     }
     if (StringUtil::endsWith($params[0], '_link')) {
         return SubmissionCreator::getRelationLink($objPage->current(), $objEntity->current(), $arrRelation);
     }
     return false;
 }