1: <?php
2:
3: 4: 5:
6: abstract class Quform_Element_Field extends Quform_Element
7: {
8: 9: 10: 11:
12: protected $defaultValue;
13:
14: 15: 16: 17:
18: protected $value;
19:
20: 21: 22: 23:
24: protected $filters = array();
25:
26: 27: 28: 29:
30: protected $validators = array();
31:
32: 33: 34: 35:
36: protected $errors = array();
37:
38: 39: 40: 41:
42: protected $isMultiple = false;
43:
44: 45: 46: 47:
48: protected $belongsTo;
49:
50: 51: 52: 53: 54:
55: public function getUniqueId()
56: {
57: return sprintf('quform_%s_%s', $this->getIdentifier(), $this->form->getUniqueId());
58: }
59:
60: 61: 62: 63: 64:
65: public function getName()
66: {
67: if ($this->getBelongsTo() instanceof Quform_Element) {
68: return $this->getId();
69: }
70:
71: return parent::getName();
72: }
73:
74: 75: 76: 77: 78:
79: public function getIdentifier()
80: {
81: if ($this->getBelongsTo() instanceof Quform_Element) {
82: return sprintf('%d_%d_%d', $this->form->getId(), $this->getBelongsTo()->getId(), $this->getId());
83: }
84:
85: return parent::getIdentifier();
86: }
87:
88: 89: 90: 91: 92:
93: public function getFullyQualifiedName()
94: {
95: $name = $this->getName();
96:
97: if ($this->getBelongsTo() instanceof Quform_Element) {
98: $name = sprintf('%s[%s]', $this->getBelongsTo()->getName(), $name);
99: }
100:
101: if ($this->isMultiple()) {
102: $name .= '[]';
103: }
104:
105: return $name;
106: }
107:
108: 109: 110: 111: 112: 113:
114: public function render(array $context = array())
115: {
116: $context = $this->prepareContext($context);
117: $output = '';
118:
119: if ($this->isVisible()) {
120: $output .= sprintf('<div class="%s">', Quform::escape(Quform::sanitizeClass($this->getElementClasses($context))));
121: $output .= '<div class="quform-spacer">';
122: $output .= $this->getLabelHtml($context);
123: $output .= sprintf('<div class="%s">', Quform::escape(Quform::sanitizeClass($this->getInnerClasses($context))));
124: $output .= $this->getDescriptionHtml('above') . $this->getSubLabelHtml('above');
125: $output .= $this->getInputHtml($context);
126: $output .= $this->getErrorHtml() . $this->getSubLabelHtml() . $this->getDescriptionHtml();
127: $output .= '</div></div></div>';
128: } else if ($this->shouldConvertToHidden()) {
129: $output .= Quform::getHtmlTag('input', array(
130: 'type' => 'hidden',
131: 'name' => $this->getFullyQualifiedName(),
132: 'value' => $this->getValue()
133: ));
134: }
135:
136: return $output;
137: }
138:
139: 140: 141: 142: 143: 144:
145: protected function getElementClasses(array $context = array())
146: {
147: $classes = array(
148: 'quform-element',
149: sprintf('quform-element-%s', $this->config('type')),
150: sprintf('quform-element-%s', $this->getIdentifier()),
151: 'quform-cf'
152: );
153:
154: if (Quform::isNonEmptyString($context['labelPosition'])) {
155: $classes[] = sprintf('quform-labels-%s', $context['labelPosition']);
156: }
157:
158: if ($this->isRequired()) {
159: $classes[] = 'quform-element-required';
160: } else {
161: $classes[] = 'quform-element-optional';
162: }
163:
164: if (Quform::isNonEmptyString($this->config('customElementClass'))) {
165: $classes[] = $this->config('customElementClass');
166: }
167:
168: $classes = apply_filters('quform_element_classes', $classes, $this, $context);
169: $classes = apply_filters('quform_element_classes_' . $this->getIdentifier(), $classes, $this, $context);
170:
171: return $classes;
172: }
173:
174: 175: 176: 177: 178: 179: 180: 181:
182: protected function getLabelHtml(array $context = array(), $forAttribute = true, $id = false)
183: {
184: $label = $this->getLabel($context);
185:
186: if ( ! Quform::isNonEmptyString($label)) {
187: return '';
188: }
189:
190: if ($forAttribute === true) {
191: $forValue = $this->getUniqueId();
192: } elseif (Quform::isNonEmptyString($forAttribute)) {
193: $forValue = $forAttribute;
194: }
195:
196: $output = sprintf('<div class="quform-label quform-label-%s">', $this->getIdentifier());
197:
198: if (Quform::isNonEmptyString($this->config('labelIcon'))) {
199: $output .= sprintf('<span class="quform-label-icon"><i class="%s"></i></span>', $this->config('labelIcon'));
200: }
201:
202: $output .= sprintf(
203: '<label class="quform-label-text"%s%s>%s%s</label>',
204: ($id ? ' id="' . Quform::escape($this->getUniqueId() . '_label') . '"' : ''),
205: (isset($forValue) ? ' for="' . Quform::escape($forValue) . '"' : ''),
206: $label,
207: $this->isRequired() && Quform::isNonEmptyString($requiredText = $this->form->config('requiredText')) ? '<span class="quform-required">' . esc_html($requiredText) . '</span>' : ''
208: );
209:
210: if ($this->form->config('tooltipsEnabled') && Quform::isNonEmptyString($this->form->config('tooltipIcon')) && Quform::isNonEmptyString($tooltip = $this->getTooltip()) && $context['tooltipType'] == 'icon') {
211: $output .= sprintf('<div class="quform-tooltip-icon quform-tooltip-icon-%s">', esc_attr($context['tooltipEvent']));
212: $output .= sprintf('<i class="%s"></i>', $this->form->config('tooltipIcon'));
213: $output .= sprintf('<div class="quform-tooltip-icon-content">%s</div>', $tooltip);
214: $output .= '</div>';
215: }
216:
217: $output .= '</div>';
218:
219: $output = apply_filters('quform_field_label_html_' . $this->getIdentifier(), $output, $this, $this->getForm(), $context);
220:
221: return $output;
222: }
223:
224: 225: 226: 227: 228: 229:
230: public function getLabel(array $context = array())
231: {
232: return apply_filters('quform_field_label_' . $this->getIdentifier(), $this->config('label'), $this, $this->getForm(), $context);
233: }
234:
235: 236: 237: 238: 239: 240:
241: protected function getInnerClasses(array $context = array())
242: {
243: $classes = array(
244: 'quform-inner',
245: sprintf('quform-inner-%s', $this->config('type')),
246: sprintf('quform-inner-%s', $this->getIdentifier())
247: );
248:
249: if (Quform::isNonEmptyString($context['fieldSize'])) {
250: $classes[] = sprintf('quform-field-size-%s', $context['fieldSize']);
251: }
252:
253: if (Quform::isNonEmptyString($context['fieldWidth']) && $context['fieldWidth'] != 'custom') {
254: $classes[] = sprintf('quform-field-width-%s', $context['fieldWidth']);
255: }
256:
257: return $classes;
258: }
259:
260: 261: 262: 263: 264: 265:
266: protected function getDescriptionHtml($which = 'below')
267: {
268: $output = '';
269: $description = $which == 'above' ? $this->config('descriptionAbove') : $this->config('description');
270:
271: if (Quform::isNonEmptyString($description)) {
272: $output = sprintf(
273: '<p class="quform-description quform-description-%s">%s</p>',
274: esc_attr($which),
275: do_shortcode($description)
276: );
277: }
278:
279: return $output;
280: }
281:
282: 283: 284: 285: 286: 287:
288: protected function getInputHtml(array $context = array())
289: {
290: $output = sprintf('<div class="%s">', Quform::escape(Quform::sanitizeClass($this->getInputClasses($context))));
291: $output .= $this->getFieldHtml($context);
292: $output .= $this->getFieldIconsHtml();
293:
294: if ($this->form->config('tooltipsEnabled') && Quform::isNonEmptyString($tooltip = $this->getTooltip()) && Quform::get($context, 'tooltipType') == 'field') {
295: $output .= sprintf('<div class="quform-tooltip-content">%s</div>', $tooltip);
296: }
297:
298: $output .= '</div>';
299:
300: return $output;
301: }
302:
303: 304: 305: 306: 307:
308: protected function getTooltip() {
309: return apply_filters('quform_field_tooltip_' . $this->getIdentifier(), $this->config('tooltip'), $this, $this->getForm());
310: }
311:
312: 313: 314: 315: 316: 317:
318: protected function getInputClasses(array $context = array())
319: {
320: $classes = array(
321: 'quform-input',
322: sprintf('quform-input-%s', $this->config('type')),
323: sprintf('quform-input-%s', $this->getIdentifier()),
324: 'quform-cf'
325: );
326:
327: if (Quform::isNonEmptyString($this->config('fieldIconLeft'))) {
328: $classes[] = 'quform-has-field-icon-left';
329: }
330:
331: if (Quform::isNonEmptyString($this->config('fieldIconRight'))) {
332: $classes[] = 'quform-has-field-icon-right';
333: }
334:
335: return $classes;
336: }
337:
338: 339: 340: 341: 342: 343:
344: abstract protected function getFieldHtml(array $context = array());
345:
346: 347: 348: 349: 350:
351: protected function getFieldIconsHtml()
352: {
353: $output = '';
354:
355: if (Quform::isNonEmptyString($this->config('fieldIconLeft'))) {
356: $output .= '<span class="quform-field-icon quform-field-icon-left">';
357: $output .= sprintf('<i class="%s"></i>', $this->config('fieldIconLeft'));
358: $output .= '</span>';
359: }
360:
361: if (Quform::isNonEmptyString($this->config('fieldIconRight'))) {
362: $output .= '<span class="quform-field-icon quform-field-icon-right">';
363: $output .= sprintf('<i class="%s"></i>', $this->config('fieldIconRight'));
364: $output .= '</span>';
365: }
366:
367: return $output;
368: }
369:
370: 371: 372: 373: 374:
375: public function getAdminLabel()
376: {
377: $adminLabel = apply_filters('quform_field_admin_label_' . $this->getIdentifier(), $this->config('adminLabel'), $this, $this->getForm());
378:
379: if ( ! Quform::isNonEmptyString($adminLabel)) {
380: $adminLabel = $this->getLabel();
381: }
382:
383: return $adminLabel;
384: }
385:
386: 387: 388:
389: public function getEditLabelHtml()
390: {
391: $output = Quform::escape($this->getAdminLabel());
392:
393: if ($this->isRequired()) {
394: $output .= '<span class="qfb-required">*</span>';
395: }
396:
397: return $output;
398: }
399:
400: 401: 402: 403: 404:
405: public function setIsMultiple($flag = true)
406: {
407: $this->isMultiple = (bool) $flag;
408: }
409:
410: 411: 412: 413: 414:
415: public function isMultiple()
416: {
417: return $this->isMultiple;
418: }
419:
420: 421: 422: 423: 424: 425:
426: public function setBelongsTo($belongsTo)
427: {
428: $this->belongsTo = $belongsTo;
429:
430: return $this;
431: }
432:
433: 434: 435: 436: 437:
438: public function getBelongsTo()
439: {
440: return $this->belongsTo;
441: }
442:
443: 444: 445: 446: 447:
448: public function addFilter(Quform_Filter_Interface $filter)
449: {
450: $name = get_class($filter);
451: $this->filters[$name] = $filter;
452: }
453:
454: 455: 456:
457: public function clearFilters()
458: {
459: $this->filters = array();
460: }
461:
462: 463: 464: 465: 466:
467: public function hasFilters()
468: {
469: return count($this->getFilters()) > 0;
470: }
471:
472: 473: 474: 475: 476:
477: public function getFilters()
478: {
479: return $this->filters;
480: }
481:
482: 483: 484: 485: 486: 487:
488: public function hasFilter($filter)
489: {
490: $result = false;
491:
492: if ($filter instanceof Quform_Filter_Interface) {
493: $filter = get_class($filter);
494: }
495:
496: if (is_string($filter)) {
497: if (strpos($filter, 'Quform_Filter_') === false) {
498: $filter = 'Quform_Filter_' . ucfirst($filter);
499: }
500:
501: $result = array_key_exists($filter, $this->getFilters());
502: }
503:
504: return $result;
505: }
506:
507: 508: 509: 510: 511: 512:
513: public function getFilter($filter)
514: {
515: $instance = null;
516:
517: if (strpos($filter, 'Quform_Filter_') === false) {
518: $filter = 'Quform_Filter_' . ucfirst($filter);
519: }
520:
521: $filters = $this->getFilters();
522: if (array_key_exists($filter, $filters)) {
523: $instance = $filters[$filter];
524: }
525:
526: return $instance;
527: }
528:
529: 530: 531: 532: 533:
534: public function removeFilter($filter)
535: {
536: if (strpos($filter, 'Quform_Filter_') === false) {
537: $filter = 'Quform_Filter_' . ucfirst($filter);
538: }
539:
540: if (array_key_exists($filter, $this->filters)) {
541: unset($this->filters[$filter]);
542: }
543: }
544:
545: 546: 547: 548: 549:
550: public function addValidator(Quform_Validator_Interface $validator)
551: {
552: $name = get_class($validator);
553: $this->validators[$name] = $validator;
554: }
555:
556: 557: 558:
559: public function clearValidators()
560: {
561: $this->validators = array();
562: }
563:
564: 565: 566: 567: 568:
569: public function hasValidators()
570: {
571: return count($this->getValidators()) > 0;
572: }
573:
574: 575: 576: 577: 578:
579: public function getValidators()
580: {
581: return $this->validators;
582: }
583:
584: 585: 586: 587: 588: 589:
590: public function hasValidator($validator)
591: {
592: $result = false;
593:
594: if ($validator instanceof Quform_Validator_Interface) {
595: $validator = get_class($validator);
596: }
597:
598: if (is_string($validator)) {
599: if (strpos($validator, 'Quform_Validator_') === false) {
600: $validator = 'Quform_Validator_' . ucfirst($validator);
601: }
602:
603: $result = array_key_exists($validator, $this->getValidators());
604: }
605:
606: return $result;
607: }
608:
609: 610: 611: 612: 613: 614:
615: public function getValidator($validator)
616: {
617: $instance = null;
618:
619: if (strpos($validator, 'Quform_Validator_') === false) {
620: $validator = 'Quform_Validator_' . ucfirst($validator);
621: }
622:
623: $validators = $this->getValidators();
624: if (array_key_exists($validator, $validators)) {
625: $instance = $validators[$validator];
626: }
627:
628: return $instance;
629: }
630:
631: 632: 633: 634: 635:
636: public function removeValidator($validator)
637: {
638: if (strpos($validator, 'Quform_Validator_') === false) {
639: $validator = 'Quform_Validator_' . ucfirst($validator);
640: }
641:
642: if (array_key_exists($validator, $this->validators)) {
643: unset($this->validators[$validator]);
644: }
645: }
646:
647: 648: 649: 650: 651:
652: public function isRequired()
653: {
654: return $this->hasValidator('required');
655: }
656:
657: 658: 659:
660: public function setDefaultValue($value)
661: {
662: $this->defaultValue = $value;
663: }
664:
665: 666: 667:
668: public function getDefaultValue()
669: {
670: return apply_filters('quform_field_default_value_' . $this->getIdentifier(), $this->defaultValue, $this, $this->getForm());
671: }
672:
673: 674: 675:
676: public function hasDefaultValue()
677: {
678: return $this->getDefaultValue() !== $this->getEmptyValue();
679: }
680:
681: 682: 683: 684: 685:
686: public function setValue($value)
687: {
688: $this->value = $this->isValidValue($value) ? $value : $this->getEmptyValue();
689: }
690:
691: 692: 693: 694: 695: 696:
697: public function setValueFromStorage($value)
698: {
699: $value = apply_filters('quform_set_value_from_storage', $value, $this, $this->form);
700: $value = apply_filters('quform_set_value_from_storage_' . $this->form->getId(), $value, $this, $this->form);
701: $value = apply_filters('quform_set_value_from_storage_' . $this->getIdentifier(), $value, $this, $this->form);
702:
703: $value = $this->convertValueFromStorage($value);
704:
705: $this->setValue($value);
706:
707: return $this;
708: }
709:
710: 711: 712: 713: 714: 715:
716: protected function convertValueFromStorage($value)
717: {
718: return $value;
719: }
720:
721: 722: 723: 724: 725: 726:
727: protected function isValidValue($value)
728: {
729: return is_string($value);
730: }
731:
732: 733: 734: 735: 736:
737: public function getValueRaw()
738: {
739: $value = apply_filters('quform_get_value_raw_' . $this->getIdentifier(), $this->value, $this, $this->getForm());
740:
741: return $value;
742: }
743:
744: 745: 746: 747: 748:
749: public function getValue()
750: {
751: $value = (string) $this->value;
752:
753: $this->filterValue($value);
754:
755: $value = apply_filters('quform_get_value_' . $this->getIdentifier(), $value, $this, $this->getForm());
756:
757: return $value;
758: }
759:
760: 761: 762: 763: 764:
765: public function getValueHtml()
766: {
767: $value = Quform::escape($this->getValue());
768:
769: $value = apply_filters('quform_get_value_html_' . $this->getIdentifier(), $value, $this, $this->getForm());
770:
771: return $value;
772: }
773:
774: 775: 776: 777: 778: 779:
780: public function getValueText($separator = ', ')
781: {
782: $value = $this->getValue();
783:
784: $value = apply_filters('quform_get_value_text_' . $this->getIdentifier(), $value, $this, $this->getForm());
785:
786: return $value;
787: }
788:
789: 790: 791: 792: 793:
794: public function getValueForStorage()
795: {
796: $value = $this->getConvertedValueForStorage();
797:
798: $value = apply_filters('quform_get_value_for_storage', $value, $this, $this->form);
799: $value = apply_filters('quform_get_value_for_storage_' . $this->form->getId(), $value, $this, $this->form);
800: $value = apply_filters('quform_get_value_for_storage_' . $this->getIdentifier(), $value, $this, $this->form);
801:
802: return $value;
803: }
804:
805: 806: 807: 808: 809:
810: protected function getConvertedValueForStorage()
811: {
812: return $this->getValue();
813: }
814:
815: 816: 817: 818: 819: 820: 821:
822: protected function shouldConvertToHidden()
823: {
824: return ! $this->isVisible() && $this->config('dynamicDefaultValue') && Quform::isNonEmptyString($this->config('dynamicKey'));
825: }
826:
827: 828: 829: 830: 831:
832: public function isValid()
833: {
834: $this->clearErrors();
835: $skipValidation = false;
836: $valid = true;
837:
838:
839: if ( ! $this->hasValidator('required') && $this->getValueText() === '') {
840: $skipValidation = true;
841: }
842:
843:
844: if ($this->isConditionallyHidden() || ! $this->isVisible()) {
845: $skipValidation = true;
846: }
847:
848: if ( ! $skipValidation) {
849: $value = $this->getValue();
850:
851: foreach ($this->getValidators() as $validator) {
852: if ($validator->isValid($value)) {
853: continue;
854: }
855:
856: $this->addError($validator->getMessage());
857: $valid = false;
858: break;
859: }
860:
861: $valid = apply_filters('quform_element_valid', $valid, $value, $this);
862: $valid = apply_filters('quform_element_valid_' . $this->getIdentifier(), $valid, $value, $this);
863: }
864:
865: return $valid;
866: }
867:
868: 869: 870: 871: 872:
873: public function hasError()
874: {
875: return count($this->errors) > 0;
876: }
877:
878: 879: 880: 881: 882: 883:
884: public function setError($message)
885: {
886: _deprecated_function(__METHOD__, '2.2.0', 'addError');
887:
888: $this->addError($message);
889: }
890:
891: 892: 893: 894: 895:
896: public function addError($message)
897: {
898: $this->errors[] = $message;
899: }
900:
901: 902: 903:
904: public function clearError()
905: {
906: _deprecated_function(__METHOD__, '2.2.0', 'clearErrors');
907:
908: $this->clearErrors();
909: }
910:
911: 912: 913:
914: public function clearErrors()
915: {
916: $this->errors = array();
917: }
918:
919: 920: 921: 922: 923:
924: public function getError()
925: {
926: $errors = $this->getErrors();
927:
928: return count($errors) > 0 ? $errors[0] : '';
929: }
930:
931: 932: 933: 934: 935:
936: public function getErrors()
937: {
938: return $this->errors;
939: }
940:
941: 942: 943:
944: public function getErrorArray()
945: {
946: return array($this->getIdentifier() => $this->getError());
947: }
948:
949: 950: 951:
952: public function reset()
953: {
954: $this->setValue($this->getDefaultValue());
955: }
956:
957: 958: 959: 960: 961:
962: public function setDynamicDefaultValue($key)
963: {
964: $value = '';
965:
966: $dynamicValues = $this->form->getDynamicValues();
967:
968: if (isset($dynamicValues[$key])) {
969: $value = $dynamicValues[$key];
970: }
971:
972: if (isset($_GET[$key])) {
973: $value = $_GET[$key];
974: }
975:
976: $value = $this->prepareDynamicValue($value);
977:
978: $value = apply_filters('quform_element_value', $value, $key);
979: $value = apply_filters('quform_element_value_' . $key, $value, $key);
980:
981: if ($this->isValidValue($value) && $value !== $this->getEmptyValue()) {
982: $this->setDefaultValue($value, false);
983: $this->setValue($this->getDefaultValue());
984: }
985: }
986:
987: 988: 989: 990: 991: 992:
993: public function prepareDynamicValue($value)
994: {
995: return $value;
996: }
997:
998: 999: 1000: 1001: 1002:
1003: protected function filterValue(&$value)
1004: {
1005: foreach ($this->getFilters() as $filter) {
1006: $value = $filter->filter($value);
1007: }
1008: }
1009:
1010: 1011: 1012: 1013: 1014:
1015: protected function filterValueRecursive(&$value)
1016: {
1017: if (is_array($value)) {
1018: array_walk($value, array($this, 'filterValueRecursive'));
1019: } else {
1020: $this->filterValue($value);
1021: }
1022: }
1023:
1024: 1025: 1026: 1027: 1028: 1029:
1030: public function hasValue($value)
1031: {
1032: return $this->getValue() === $value;
1033: }
1034:
1035: 1036: 1037:
1038: public function getEmptyValue()
1039: {
1040: return '';
1041: }
1042:
1043: 1044: 1045: 1046: 1047:
1048: public function isEmpty()
1049: {
1050: return $this->getValue() === $this->getEmptyValue();
1051: }
1052:
1053: 1054: 1055: 1056: 1057: 1058:
1059: protected function getSubLabelHtml($which = 'below')
1060: {
1061: $output = '';
1062: $subLabel = $which == 'above' ? $this->config('subLabelAbove') : $this->config('subLabel');
1063:
1064: if (Quform::isNonEmptyString($subLabel)) {
1065: $output = sprintf(
1066: '<label id="%1$s_sub_label_%2$s" class="quform-sub-label quform-sub-label-%2$s">%3$s</label>',
1067: esc_attr($this->getUniqueId()),
1068: esc_attr($which),
1069: do_shortcode($subLabel)
1070: );
1071: }
1072:
1073: return $output;
1074: }
1075:
1076: 1077: 1078: 1079: 1080:
1081: protected function getErrorHtml()
1082: {
1083: if ( ! $this->hasError()) {
1084: return '';
1085: }
1086:
1087: $output = '<div class="quform-error quform-cf"><div class="quform-error-inner">';
1088:
1089: if (Quform::isNonEmptyString($this->form->config('errorsIcon'))) {
1090: $output .= sprintf('<span class="quform-error-icon"><i class="%s"></i></span>', Quform::escape($this->form->config('errorsIcon')));
1091: }
1092:
1093: $output .= sprintf('<span class="quform-error-text">%s</span>', $this->getError());
1094:
1095: $output .= '</div></div>';
1096:
1097: return $output;
1098: }
1099:
1100: 1101: 1102: 1103: 1104: 1105:
1106: protected function renderCss(array $context = array())
1107: {
1108: $css = '';
1109:
1110: if ($context['labelPosition'] == 'left' && $context['labelWidth'] != '150px') {
1111: $css .= sprintf('.quform-labels-left.quform-element-%1$s > .quform-spacer > .quform-label, .quform-rtl .quform-labels-left.quform-element-%1$s > .quform-spacer > .quform-inner { width: %2$s; }', $this->getIdentifier(), Quform::addCssUnit($context['labelWidth']));
1112: $css .= sprintf('.quform-labels-left.quform-element-%1$s > .quform-spacer > .quform-inner { margin-left: %2$s; }', $this->getIdentifier(), Quform::addCssUnit($context['labelWidth']));
1113: $css .= sprintf('.quform-rtl .quform-labels-left.quform-element-%1$s > .quform-spacer > .quform-inner { margin-right: %2$s; margin-left: 0; }', $this->getIdentifier(), Quform::addCssUnit($context['labelWidth']));
1114: }
1115:
1116: $css .= parent::renderCss($context);
1117:
1118: return $css;
1119: }
1120:
1121: 1122: 1123: 1124: 1125:
1126: protected function getCssSelectors()
1127: {
1128: return array(
1129: 'element' => '%s .quform-element-%s',
1130: 'elementSpacer' => '%s .quform-element-%s > .quform-spacer',
1131: 'elementLabel' => '%s .quform-label-%s',
1132: 'elementLabelText' => '%s .quform-label-%s > label',
1133: 'elementRequiredText' => '%s .quform-label-%s > label > .quform-required',
1134: 'elementInner' => '%s .quform-inner-%s',
1135: 'elementInput' => '%s .quform-input-%s',
1136: 'elementText' => '%s .quform-field-%s',
1137: 'elementTextHover' => '%s .quform-field-%s:hover',
1138: 'elementTextFocus' => '%1$s .quform-field-%2$s:focus, %1$s .quform-field-%2$s:active',
1139: 'elementTextarea' => '%s .quform-field-%s',
1140: 'elementTextareaHover' => '%s .quform-field-%s:hover',
1141: 'elementTextareaFocus' => '%1$s .quform-field-%2$s:focus, %1$s .quform-field-%2$s:active',
1142: 'elementSelect' => '%s .quform-field-%s',
1143: 'elementSelectHover' => '%s .quform-field-%s:hover',
1144: 'elementSelectFocus' => '%1$s .quform-field-%2$s:focus, %1$s .quform-field-%2$s:active',
1145: 'elementIcon' => '%s .quform-field-icon',
1146: 'elementIconHover' => '%s .quform-field-icon:hover',
1147: 'elementSubLabel' => '%s .quform-element-%s .quform-sub-label',
1148: 'elementDescription' => '%s .quform-element-%s .quform-description'
1149: );
1150: }
1151:
1152: 1153: 1154: 1155: 1156: 1157: 1158: 1159:
1160: public function isLogicRuleMatch(array $rule)
1161: {
1162: return $this->isLogicValueMatch($this->getValue(), $rule);
1163: }
1164:
1165: 1166: 1167: 1168: 1169: 1170: 1171:
1172: protected function isLogicValueMatch($value, array $rule)
1173: {
1174: switch ($rule['operator']) {
1175: case 'eq':
1176: return $value === $rule['value'];
1177: case 'neq':
1178: return $value !== $rule['value'];
1179: case 'empty':
1180: return $value === $this->getEmptyValue();
1181: case 'not_empty':
1182: return $value !== $this->getEmptyValue();
1183: case 'gt':
1184: return is_numeric($value) && is_numeric($rule['value']) && (float) $value > (float) $rule['value'];
1185: case 'lt':
1186: return is_numeric($value) && is_numeric($rule['value']) && (float) $value < (float) $rule['value'];
1187: case 'contains':
1188: return preg_match('/' . preg_quote($rule['value'], '/') . '/', $value);
1189: case 'starts_with':
1190: return preg_match('/^' . preg_quote($rule['value'], '/') . '/', $value);
1191: case 'ends_with':
1192: return preg_match('/' . preg_quote($rule['value'], '/') . '$/', $value);
1193: }
1194:
1195: return false;
1196: }
1197: }
1198: