5c22deab635ebec8bcbd4bc8a12e87b2068555ab
[TYPO3CMS/Extensions/powermailCond.git] / Classes / Domain / Validator / MandatoryValidator.php
1 <?php
2
3 /**
4 * Class Tx_PowermailCond_Domain_Validator_MandatoryValidator
5 */
6 class Tx_PowermailCond_Domain_Validator_MandatoryValidator extends Tx_Powermail_Domain_Validator_MandatoryValidator {
7
8 /**
9 * Validation of given Params
10 *
11 * @param $params
12 * @return bool
13 */
14 public function isValid($params) {
15 $gp = t3lib_div::_GP('tx_powermail_pi1');
16 $formUid = $gp['form'];
17 $form = $this->formsRepository->findByUid($formUid);
18 if (!method_exists($form, 'getPages')) {
19 return $this->isValid;
20 }
21
22 /* @var $divCond Tx_PowermailCond_Utility_Div */
23 $divCond = t3lib_div::makeInstance('Tx_PowermailCond_Utility_Div');
24 $sessionValues = $divCond->getAllSessionValuesFromForm($formUid, 'deRequiredFields');
25
26 // every page in current form
27 foreach ($form->getPages() as $page) {
28 // every field in current page
29 foreach ($page->getFields() as $field) {
30
31 // if not a mandatory field
32 if (!$field->getMandatory()) {
33 continue;
34 }
35
36 // set error
37 if (is_array($params[$field->getUid()])) {
38 $empty = 1;
39 foreach ($params[$field->getUid()] as $value) {
40 if (strlen($value)) {
41 $empty = 0;
42 break;
43 }
44 }
45 if ($empty) {
46 $this->addError('mandatory', $field->getUid());
47 $this->isValid = FALSE;
48 }
49 } else {
50 // extend this line for powermail_cond
51 if (!strlen($params[$field->getUid()]) && !isset($sessionValues['field_' . $field->getUid()])) {
52 $this->addError('mandatory', $field->getUid());
53 $this->isValid = FALSE;
54 }
55 }
56 }
57 }
58
59 return $this->isValid;
60 }
61 }