/**
  * Set the default relation entity within submission entity
  *
  * @param \DataContainer                              $dc
  * @param \HeimrichHannot\Submissions\SubmissionModel $objSubmission
  * @param array                                       $arrRelation
  */
 public static function setDefaultRelation(\DataContainer $dc, \HeimrichHannot\Submissions\SubmissionModel &$objSubmission, array $arrRelation)
 {
     if (($objEntity = static::getRelationFromRequest($dc->objModule, $arrRelation)) === null) {
         return;
     }
     $objSubmission->{$arrRelation['submissionField']} = $objEntity->id;
     $objSubmission->save();
     return;
 }
 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);
                 }
             }
         }
     }
 }
 protected function deleteItem($intId)
 {
     if (($objItem = General::getModelInstance($this->formHybridDataContainer, $intId)) !== null) {
         $objDc = new DC_Hybrid($this->formHybridDataContainer, $objItem, $objItem->id);
         $this->runBeforeDelete($objItem, $objDc);
         // remove previously created locks
         if (in_array('entity_lock', \ModuleLoader::getActive()) && $this->addEntityLock) {
             \HeimrichHannot\EntityLock\EntityLockModel::deleteLocks($this->formHybridDataContainer, $intId);
         }
         // call ondelete callbacks
         if (is_array($GLOBALS['TL_DCA'][$this->formHybridDataContainer]['config']['ondelete_callback'])) {
             foreach ($GLOBALS['TL_DCA'][$this->formHybridDataContainer]['config']['ondelete_callback'] as $callback) {
                 $this->import($callback[0]);
                 $this->{$callback}[0]->{$callback}[1]($objDc);
             }
         }
         $blnDeleted = $objItem->delete() > 0;
         if ($blnDeleted && $this->deleteNotification) {
             if (($objMessage = MessageModel::findPublishedById($this->formHybridSubmissionNotification)) !== null) {
                 $arrSubmissionData = SubmissionModel::prepareData($objItem, $this->formHybridDataContainer, $GLOBALS['TL_DCA'][$this->formHybridDataContainer], $objDc, $this->formHybridEditable);
                 $arrTokens = SubmissionModel::tokenizeData($arrSubmissionData);
                 if ($this->sendDeleteNotification($objMessage, $objItem, $arrSubmissionData, $arrTokens)) {
                     $objMessage->send($arrTokens, $GLOBALS['TL_LANGUAGE']);
                 }
             }
         }
         $this->runAfterDelete($blnDeleted, $objItem, $objDc);
         if ($this->jumpToAfterDelete && ($strUrl = Url::getJumpToPageUrl($this->jumpToAfterDelete))) {
             \Controller::redirect($strUrl);
         }
         return $blnDeleted;
     }
     return false;
 }
 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));
     }
 }
 public static function generateTokens($strTable, \Model $objEntity, \MemberModel $objFormerEditor)
 {
     // entity
     \Controller::loadDataContainer($strTable);
     \System::loadLanguageFile($strTable);
     $arrDca = $GLOBALS['TL_DCA'][$strTable];
     $objDc = new DC_Hybrid($strTable);
     $objDc->activeRecord = $objEntity;
     $arrSubmissionData = SubmissionModel::prepareData($objEntity, $strTable, $arrDca, $objDc);
     $arrTokens = SubmissionModel::tokenizeData($arrSubmissionData, 'entity');
     // former editor
     \Controller::loadDataContainer('tl_member');
     \System::loadLanguageFile('tl_member');
     $arrDca = $GLOBALS['TL_DCA']['tl_member'];
     $objDc = new DC_Hybrid('tl_member');
     $objDc->activeRecord = $objFormerEditor;
     $arrSubmissionData = SubmissionModel::prepareData($objFormerEditor, 'tl_member', $arrDca, $objDc);
     $arrTokens = array_merge(SubmissionModel::tokenizeData($arrSubmissionData, 'former_editor'), $arrTokens);
     $arrTokens['salutation_former_editor'] = NotificationCenterPlus::createSalutation($GLOBALS['TL_LANGUAGE'], $objFormerEditor);
     return $arrTokens;
 }