public static function generateTokens($intSubmission, $arrFields = array())
 {
     $arrTokens = array();
     \Controller::loadDataContainer('tl_submission');
     \System::loadLanguageFile('tl_submission');
     $arrDca =& $GLOBALS['TL_DCA']['tl_submission'];
     if (($objSubmission = SubmissionModel::findByPk($intSubmission)) !== null) {
         $objDc = new DC_Hybrid('tl_submission');
         $objDc->activeRecord = $objSubmission;
         // fields
         if (($objSubmissionArchive = $objSubmission->getRelated('pid')) !== null) {
             \Controller::loadDataContainer('tl_submission');
             $arrFields = empty($arrFields) ? deserialize($objSubmissionArchive->submissionFields, true) : $arrFields;
             if (isset($GLOBALS['TL_HOOKS']['preGenerateSubmissionTokens']) && is_array($GLOBALS['TL_HOOKS']['preGenerateSubmissionTokens'])) {
                 foreach ($GLOBALS['TL_HOOKS']['preGenerateSubmissionTokens'] as $arrCallback) {
                     \System::importStatic($arrCallback[0])->{$arrCallback}[1]($objSubmission, $objSubmissionArchive, $arrFields);
                 }
             }
         }
         $arrSubmissionData = static::prepareData($objSubmission, 'tl_submission', $GLOBALS['TL_DCA']['tl_submission'], $objDc, $arrFields, Submissions::getSkipFields());
         $arrTokens = static::tokenizeData($arrSubmissionData);
         // salutation
         $arrTokens['salutation_submission'] = NotificationCenterPlus::createSalutation($GLOBALS['TL_LANGUAGE'], array('gender' => $arrTokens['form_value_gender'], 'title' => $arrTokens['form_value_title'], 'lastname' => $arrTokens['form_value_lastname']));
         $arrTokens['tl_submission'] = $objSubmission->id;
     }
     return $arrTokens;
 }
 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 function modifyPalette(\DataContainer $dc, $blnFrontend = false)
 {
     $arrDca =& $GLOBALS['TL_DCA']['tl_submission'];
     $objSubmission = SubmissionModel::findByPk($dc->id);
     if ($dc->objModule !== null && $dc->objModule->addSubmissionRelation) {
         if ($arrRelation = $GLOBALS['SUBMISSION_RELATIONS'][$dc->objModule->submissionRelation]) {
             if ($arrDca['fields'][$arrRelation['submissionField']]) {
                 // Options callback
                 if (is_array($arrRelation['options_callback'])) {
                     $arrCallback = $arrRelation['options_callback'];
                     unset($arrDca['fields'][$arrRelation['submissionField']]['options_callback']);
                     $arrDca['fields'][$arrRelation['submissionField']]['options'] = static::importStatic($arrCallback[0])->{$arrCallback}[1]($dc, $arrRelation);
                 } elseif (is_callable($arrRelation['options_callback'])) {
                     unset($arrDca['fields'][$arrRelation['submissionField']]['options_callback']);
                     $arrDca['fields'][$arrRelation['submissionField']]['options'] = $arrRelation['options_callback']($dc, $arrRelation);
                 }
                 // set default value from request
                 if ($objSubmission !== null && $arrRelation['setDefaultFromRequest']) {
                     SubmissionCreator::setDefaultRelation($dc, $objSubmission, $arrRelation);
                 }
             }
         }
     }
 }
 public function moveAttachments(\DataContainer $objDc)
 {
     if (($objSubmission = \HeimrichHannot\Submissions\SubmissionModel::findByPk($objDc->id)) === null) {
         return false;
     }
     if (($objSubmissionArchive = $objSubmission->getRelated('pid')) === null) {
         return false;
     }
     if (!$objSubmission->attachments) {
         return false;
     }
     $strSubFolder = Tokens::replace($objSubmissionArchive->attachmentSubFolderPattern, $objSubmission);
     $objFileModels = \FilesModel::findMultipleByUuids(deserialize($objSubmission->attachments, true));
     if ($objFileModels === null || $strSubFolder == '') {
         return false;
     }
     $strFolder = $objSubmissionArchive->attachmentUploadFolder;
     if (\Validator::isUuid($objSubmissionArchive->attachmentUploadFolder)) {
         if (($strFolder = Files::getPathFromUuid($objSubmissionArchive->attachmentUploadFolder)) === null) {
             return false;
         }
     }
     $strTarget = rtrim($strFolder, '/') . '/' . ltrim($strSubFolder, '/');
     while ($objFileModels->next()) {
         if (!file_exists(TL_ROOT . '/' . $objFileModels->path)) {
             continue;
         }
         $objFile = new \File($objFileModels->path, true);
         $objFile->renameTo($strTarget . '/' . basename($objFile->value));
     }
 }