/**
  * Set different mandatory attributes for checkboxes and radiobuttons
  *
  * @param array &$additionalAttributes
  * @param Field $field
  * @param mixed $iteration
  * @return void
  */
 protected function addMandatoryAttributesForMultipleFields(&$additionalAttributes, $field, $iteration)
 {
     if ($iteration['index'] === 0) {
         if ($field->getMandatory()) {
             if ($this->isNativeValidationEnabled()) {
                 $additionalAttributes['required'] = 'required';
                 // remove required attribute if more checkboxes than 1
                 if ($field->getType() === 'check' && $iteration['total'] > 1) {
                     unset($additionalAttributes['required']);
                 }
             } else {
                 if ($this->isClientValidationEnabled()) {
                     $additionalAttributes['data-parsley-required'] = 'true';
                 }
             }
             if ($this->isClientValidationEnabled()) {
                 $additionalAttributes['data-parsley-required-message'] = LocalizationUtility::translate('validationerror_mandatory_multi');
                 if ($field->getType() === 'check' && $iteration['total'] > 1) {
                     $additionalAttributes['data-parsley-required'] = 'true';
                 }
             }
         }
         if ($this->isClientValidationEnabled()) {
             // define where to show errors
             $additionalAttributes['data-parsley-errors-container'] = '.powermail_field_error_container_' . $field->getMarker();
             // define where to set the error class
             $additionalAttributes['data-parsley-class-handler'] = '.powermail_fieldwrap_' . $field->getUid() . ' div:first';
         }
     }
     // add multiple attribute to bundle checkboxes for parsley
     if ($field->getMandatory() && $this->isClientValidationEnabled() && $field->getType() === 'check' && $iteration['total'] > 1) {
         $additionalAttributes['data-parsley-multiple'] = $field->getMarker();
     }
 }
 /**
  * Get Answer from given field out of Mail object
  *
  * @param \In2code\Powermail\Domain\Model\Field $field
  * @param \In2code\Powermail\Domain\Model\Mail $mail
  * @return \string Answer value
  */
 protected function getAnswerFromField($field, $mail)
 {
     foreach ($mail->getAnswers() as $answer) {
         if ($answer->getField()->getUid() == $field->getUid()) {
             return $answer->getValue();
         }
     }
     return '';
 }
 /**
  * Set different mandatory attributes
  *
  * @param \array $dataArray
  * @param \In2code\Powermail\Domain\Model\Field $field
  * @param \mixed $iteration
  * @return void
  */
 protected function addMandatoryAttributes(&$dataArray, $field, $iteration)
 {
     if ($field->getMandatory() && ($iteration === NULL || $iteration['index'] === 0)) {
         if ($this->isNativeValidationEnabled()) {
             $dataArray['required'] = 'required';
             // don't want the required attribute if more checkboxes
             if ($field->getType() == 'check' && $iteration['total'] > 1) {
                 unset($dataArray['required']);
             }
         } else {
             if ($this->isClientValidationEnabled()) {
                 $dataArray['data-parsley-required'] = 'true';
             }
         }
         if ($this->isClientValidationEnabled()) {
             $dataArray['data-parsley-required-message'] = LocalizationUtility::translate('validationerror_mandatory', $this->extensionName);
             // type radio, checkbox
             if ($field->getType() == 'radio' || $field->getType() == 'check') {
                 // define where to show errors
                 $dataArray['data-parsley-errors-container'] = '.powermail_field_error_container_' . $field->getMarker();
                 // define where to set the error class
                 $dataArray['data-parsley-class-handler'] = '.powermail_fieldwrap_' . $field->getUid() . ' div:first';
                 // overwrite error message
                 $dataArray['data-parsley-required-message'] = LocalizationUtility::translate('validationerror_mandatory_multi', $this->extensionName);
                 if ($field->getType() == 'check' && $iteration['total'] > 1) {
                     $dataArray['data-parsley-required'] = 'true';
                 }
             }
         }
     }
     // add multiple attribute to bundle checkboxes for parsley
     if ($field->getMandatory() && $this->isClientValidationEnabled() && $field->getType() == 'check' && $iteration['total'] > 1) {
         $dataArray['data-parsley-multiple'] = $field->getMarker();
     }
     // Captcha
     if ($field->getType() === 'captcha') {
         if ($this->isNativeValidationEnabled()) {
             $dataArray['required'] = 'required';
         } elseif ($this->isClientValidationEnabled()) {
             $dataArray['data-parsley-required'] = 'true';
         }
         if ($this->isClientValidationEnabled()) {
             $dataArray['data-parsley-errors-container'] = '.powermail_field_error_container_' . $field->getMarker();
             $dataArray['data-parsley-class-handler'] = '.powermail_fieldwrap_' . $field->getUid() . ' > div';
             $dataArray['data-parsley-required-message'] = LocalizationUtility::translate('validationerror_mandatory', $this->extensionName);
         }
     }
 }
 /**
  * Create relative filename for captcha image
  *
  * @param Field $field
  * @return CalculatingCaptchaService
  */
 public function setPathAndFilename(Field $field)
 {
     $this->pathAndFilename = $this->imagePath . sprintf($this->imageFilenamePrefix, $field->getUid());
     return $this;
 }
Example #5
0
 /**
  * Get value for multi fieldtypes (checkbox, radio)
  *
  * @param \In2code\Powermail\Domain\Model\Field $field
  * @param \In2code\Powermail\Domain\Model\Mail $mail To prefill in Edit Action
  * @param \int $cycle Cycle Number (1,2,3...) - if filled checkbox or radiobutton
  * @return string
  */
 protected function getMultiValue(\In2code\Powermail\Domain\Model\Field $field, \In2code\Powermail\Domain\Model\Mail $mail = NULL, $cycle = 0)
 {
     $marker = $field->getMarker();
     $uid = $field->getUid();
     $selected = 0;
     $index = $cycle - 1;
     $options = $field->getModifiedSettings();
     // edit view
     if ($mail !== NULL && $mail->getAnswers()) {
         foreach ($mail->getAnswers() as $answer) {
             if ($answer->getField() === $field) {
                 $values = $answer->getValue();
                 foreach ((array) $values as $value) {
                     if ($value === $options[$index]['value'] || $value === $options[$index]['label']) {
                         $selected = 1;
                     }
                 }
             }
         }
     }
     // if GET/POST with marker (&tx_powermail_pi1[field][marker][index]=value)
     if (isset($this->piVars['field'][$marker]) && is_array($this->piVars['field'][$marker])) {
         foreach (array_keys($this->piVars['field'][$marker]) as $key) {
             if ($this->piVars['field'][$marker][$key] === $options[$index]['value'] || $this->piVars['field'][$marker][$key] === $options[$index]['label']) {
                 $selected = 1;
             }
         }
     } elseif (isset($this->piVars['field'][$marker])) {
         if ($this->piVars['field'][$marker] == $options[$index]['value'] || $this->piVars['field'][$marker] == $options[$index]['label']) {
             $selected = 1;
         }
     } elseif (isset($this->piVars[$marker]) && is_array($this->piVars[$marker])) {
         foreach (array_keys($this->piVars[$marker]) as $key) {
             if ($this->piVars[$marker][$key] === $options[$index]['value'] || $this->piVars[$marker][$key] === $options[$index]['label']) {
                 $selected = 1;
             }
         }
     } elseif (isset($this->piVars[$marker])) {
         if ($this->piVars[$marker] == $options[$index]['value'] || $this->piVars[$marker] == $options[$index]['label']) {
             $selected = 1;
         }
     } elseif (isset($this->piVars['field'][$uid])) {
         if (is_array($this->piVars['field'][$uid])) {
             foreach ($this->piVars['field'][$uid] as $key => $value) {
                 $value = NULL;
                 if ($this->piVars['field'][$uid][$key] == $options[$index]['value'] || $this->piVars['field'][$uid][$key] == $options[$index]['label']) {
                     $selected = 1;
                 }
             }
         } else {
             if ($this->piVars['field'][$uid] == $options[$index]['value'] || $this->piVars['field'][$uid] == $options[$index]['label']) {
                 $selected = 1;
             }
         }
     } elseif (isset($this->piVars['uid' . $uid])) {
         if ($this->piVars['uid' . $uid] == $options[$index]['value'] || $this->piVars['uid' . $uid] == $options[$index]['label']) {
             $selected = 1;
         }
     } elseif ($field->getFeuserValue() && intval($GLOBALS['TSFE']->fe_user->user['uid']) !== 0) {
         // if fe_user is logged in
         if ($GLOBALS['TSFE']->fe_user->user[$field->getFeuserValue()] == $options[$index]['value'] || $GLOBALS['TSFE']->fe_user->user[$field->getFeuserValue()] == $options[$index]['label']) {
             $selected = 1;
         }
     } elseif ($options[$index]['selected']) {
         $selected = 1;
     } elseif (isset($this->settings['prefill.'][$marker]) || isset($this->settings['prefill.'][$marker . '.'])) {
         if (isset($this->settings['prefill.'][$marker . '.']) && is_array($this->settings['prefill.'][$marker . '.'])) {
             $data = \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getGettableProperties($field);
             $this->cObj->start($data);
             if (isset($this->settings['prefill.'][$marker . '.']['0'])) {
                 /**
                  * plugin.tx_powermail.settings.setup.prefill.marker.0 = TEXT
                  * plugin.tx_powermail.settings.setup.prefill.marker.0.value = red
                  */
                 foreach (array_keys($this->settings['prefill.'][$marker . '.']) as $key) {
                     if (stristr($key, '.')) {
                         continue;
                     }
                     $prefill = $this->cObj->cObjGetSingle($this->settings['prefill.'][$marker . '.'][$key], $this->settings['prefill.'][$marker . '.'][$key . '.']);
                     if ($prefill == $options[$index]['value'] || $prefill == $options[$index]['label']) {
                         $selected = 1;
                     }
                 }
             } else {
                 /**
                  * plugin.tx_powermail.settings.setup.prefill.marker = TEXT
                  * plugin.tx_powermail.settings.setup.prefill.marker.value = red
                  */
                 $prefill = $this->cObj->cObjGetSingle($this->settings['prefill.'][$marker], $this->settings['prefill.'][$marker . '.']);
                 if ($prefill == $options[$index]['value'] || $prefill == $options[$index]['label']) {
                     $selected = 1;
                 }
             }
         } else {
             /**
              * plugin.tx_powermail.settings.setup.prefill.marker = red
              */
             if ($this->settings['prefill.'][$marker] == $options[$index]['value'] || $this->settings['prefill.'][$marker] == $options[$index]['label']) {
                 $selected = 1;
             }
         }
     }
     return $selected;
 }