[BUGFIX] Enable removing all selectable user groups
[TYPO3CMS/Extensions/sr_feuser_register.git] / Classes / View / CreateView.php
1 <?php
2 namespace SJBR\SrFeuserRegister\View;
3
4 /*
5 * Copyright notice
6 *
7 * (c) 2007-2015 Stanislas Rolland <typo3(arobas)sjbr.ca>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * This script is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 */
24
25 use SJBR\SrFeuserRegister\Exception;
26 use SJBR\SrFeuserRegister\Security\SecuredData;
27 use SJBR\SrFeuserRegister\Utility\CssUtility;
28 use SJBR\SrFeuserRegister\Utility\LocalizationUtility;
29 use SJBR\SrFeuserRegister\View\AbstractView;
30 use SJBR\SrFeuserRegister\View\Marker;
31 use TYPO3\CMS\Core\Utility\GeneralUtility;
32
33 /**
34 * Create View
35 */
36 class CreateView extends AbstractView
37 {
38 /**
39 * Generate a record creation form or a first link display to create or edit someone's data
40 *
41 * @return string the template with substituted markers
42 */
43 public function render(array $dataArray, array $origArray, array $securedArray, $cmd, $cmdKey, $mode) {
44 $content = '';
45 $currentArray = $origArray;
46 if (isset($dataArray) && is_array($dataArray)) {
47 foreach ($dataArray as $key => $value) {
48 if (!is_array($value) || $mode === self::MODE_PREVIEW || $this->parameters->getFeUserData('doNotSave')) {
49 $currentArray[$key] = $value;
50 }
51 }
52 }
53
54 if ($this->theTable === 'fe_users') {
55 if ($this->getUsePassword() && !isset($currentArray['password'])) {
56 $currentArray['password'] = '';
57 }
58 if ($this->getUsePasswordAgain()) {
59 $currentArray['password_again'] = $currentArray['password'];
60 }
61 }
62
63 if ($this->conf['create']) {
64 // Call all beforeConfirmCreate hooks before the record has been shown and confirmed
65 if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->extensionKey][$this->prefixId]['registrationProcess'])) {
66 foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->extensionKey][$this->prefixId]['registrationProcess'] as $classRef) {
67 $hookObj= GeneralUtility::makeInstance($classRef);
68 if (method_exists($hookObj,'registrationProcess_beforeConfirmCreate')) {
69 $hookObj->registrationProcess_beforeConfirmCreate($this->theTable, $dataArray, $this->parameters, $cmdKey, $this->conf);
70 }
71 }
72 }
73 $currentArray = array_merge($currentArray, $dataArray);
74 $key = ($cmd === 'invite') ? 'INVITE': 'CREATE';
75 $bNeedUpdateJS = true;
76 if ($cmd === 'create' || $cmd === 'invite') {
77 $subpartMarker = '###TEMPLATE_' . $key . ($mode ? Marker::PREVIEW_SUFFIX : '') . '###';
78 $this->marker->addPasswordTransmissionMarkers($this->getUsePassword(), $this->getUsePasswordAgain());
79 } else {
80 $bNeedUpdateJS = false;
81 if ($GLOBALS['TSFE']->loginUser) {
82 $subpartMarker = '###TEMPLATE_CREATE_LOGIN###';
83 } else {
84 $subpartMarker = '###TEMPLATE_AUTH###';
85 }
86 }
87 $templateCode = $this->marker->getSubpart($this->marker->getTemplateCode(), $subpartMarker);
88 if (empty($templateCode)) {
89 $errorText = LocalizationUtility::translate('internal_no_subtemplate', $this->extensionName);
90 $errorText = sprintf($errorText, $subpartMarker);
91 throw new \Exception($errorText, Exception::MISSING_SUBPART);
92 }
93 $isPreview = ($mode === self::MODE_PREVIEW);
94 $requiredFileds = $this->data->getRequiredFieldsArray($cmdKey);
95 $infoFields = $this->data->getFieldList();
96 $templateCode = $this->marker->removeRequired($templateCode, $this->data->getFailure(), $requiredFileds, $infoFields, $this->data->getSpecialFieldList(), $cmdKey, $isPreview);
97 $this->marker->fillInMarkerArray($currentArray, $securedArray, '', true, 'FIELD_', true, $isPreview);
98 $this->marker->addStaticInfoMarkers($dataArray, $isPreview);
99 $this->marker->addTcaMarkers($dataArray, $origArray, $cmd, $cmdKey, $isPreview, $requiredFileds);
100 $this->marker->addAdditionalMarkers($infoFields, $cmd, $cmdKey, $currentArray, $isPreview);
101 $this->marker->addLabelMarkers($dataArray, $origArray, $securedArray, array(), $requiredFileds, $infoFields, $this->data->getSpecialFieldList());
102 $templateCode = $this->marker->removeStaticInfoSubparts($templateCode, $isPreview);
103 $this->marker->addGeneralHiddenFieldsMarkers($cmd, $this->parameters->getAuthCode(), $this->parameters->getBackURL());
104 $this->marker->addHiddenFieldsMarkers($cmdKey, $mode, $this->conf[$cmdKey . '.']['useEmailAsUsername'], $this->conf[$cmdKey . '.']['fields'], $dataArray);
105 $this->marker->removePasswordMarkers();
106 $deleteUnusedMarkers = true;
107 $content .= $this->marker->substituteMarkerArray($templateCode, $this->marker->getMarkerArray(), '', false, $deleteUnusedMarkers);
108 if (!$isPreview && $bNeedUpdateJS) {
109 $fields = $infoFields . ',' . $this->data->getAdditionalUpdateFields();
110 $fields = implode(',', array_intersect(explode(',', $fields), GeneralUtility::trimExplode(',', $this->conf[$cmdKey . '.']['fields'], 1)));
111 $fields = SecuredData::getOpenFields($fields);
112 $modData = $this->data->modifyDataArrForFormUpdate($dataArray, $cmdKey);
113 $form = $this->conf['formName'] ?: CssUtility::getClassName($this->prefixId, $this->theTable . '_form');
114 $updateJS = $this->getUpdateJS($modData, $form, 'FE[' . $this->theTable . ']', $fields);
115 $content .= $updateJS;
116 }
117 }
118 return $content;
119 }
120 }