| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Class Qcformbuilder_Forms_API_Privacy |
| 5 |
* |
| 6 |
* Form config abstraction for working with privacy settings of form |
| 7 |
*/ |
| 8 |
class Qcformbuilder_Forms_API_Privacy extends Qcformbuilder_Forms_API_Form |
| 9 |
{ |
| 10 |
/** |
| 11 |
* Report if this form has privacy/GDPR exporter enabled |
| 12 |
* |
| 13 |
* @since 1.7.0 |
| 14 |
* |
| 15 |
* @return true |
| 16 |
*/ |
| 17 |
public function is_privacy_exporter_enabled() |
| 18 |
{ |
| 19 |
return Qcformbuilder_Forms_Forms::is_privacy_export_enabled( $this->form ); |
| 20 |
} |
| 21 |
|
| 22 |
/** |
| 23 |
* Enable privacy export for this form |
| 24 |
* |
| 25 |
* @since 1.7.0 |
| 26 |
* |
| 27 |
* @return Qcformbuilder_Forms_API_Privacy |
| 28 |
*/ |
| 29 |
public function enable_privacy_exporter() |
| 30 |
{ |
| 31 |
$this->form = Qcformbuilder_Forms_Forms::update_privacy_export_enabled($this->form, true ); |
| 32 |
return $this->save_form(); |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Disable privacy export for this form. |
| 37 |
* |
| 38 |
* @return Qcformbuilder_Forms_API_Privacy |
| 39 |
*/ |
| 40 |
public function disable_privacy_exporter() |
| 41 |
{ |
| 42 |
$this->form = Qcformbuilder_Forms_Forms::update_privacy_export_enabled($this->form, false ); |
| 43 |
return $this->save_form(); |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* Get IDs of the fields that can contain personally identifying fields |
| 48 |
* |
| 49 |
* @since 1.7.0 |
| 50 |
* |
| 51 |
* @return array |
| 52 |
*/ |
| 53 |
public function get_pii_fields() |
| 54 |
{ |
| 55 |
return Qcformbuilder_Forms_Forms::personally_identifying_fields($this->form, true ); |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* Get IDs of the fields that can contain email we can use to identify whose personally identifying info a form contains. |
| 60 |
* |
| 61 |
* @since 1.7.0 |
| 62 |
* |
| 63 |
* @return array |
| 64 |
*/ |
| 65 |
public function get_email_identifying_fields() |
| 66 |
{ |
| 67 |
return Qcformbuilder_Forms_Forms::email_identifying_fields($this->form, true ); |
| 68 |
} |
| 69 |
|
| 70 |
/** |
| 71 |
* (re)set PII fields of form |
| 72 |
* |
| 73 |
* @since 1.7.0 |
| 74 |
* |
| 75 |
* @param array $pii_fields New value |
| 76 |
* @return $this |
| 77 |
*/ |
| 78 |
public function set_pii_fields($pii_fields ){ |
| 79 |
foreach( $this->get_fields() as $field ){ |
| 80 |
$this->form[ 'fields' ][ $field[ 'ID' ] ][ 'config' ][ Qcformbuilder_Forms_Field_Util::CONFIG_PERSONAL] = (int) in_array( $field[ 'ID' ], $pii_fields ); |
| 81 |
} |
| 82 |
$this->set_fields(); |
| 83 |
return $this; |
| 84 |
} |
| 85 |
|
| 86 |
/** |
| 87 |
* (re)set email identifying field(s) of form |
| 88 |
* |
| 89 |
* @since 1.7.0 |
| 90 |
* |
| 91 |
* @param array $email_fields New value |
| 92 |
* @return $this |
| 93 |
*/ |
| 94 |
public function set_email_identifying_fields( $email_fields ) |
| 95 |
{ |
| 96 |
foreach( $this->get_fields() as $field ){ |
| 97 |
$this->form[ 'fields' ][ $field[ 'ID' ] ][ 'config' ][ Qcformbuilder_Forms_Field_Util::CONFIG_EMAIL_IDENTIFIER ] = (int) in_array( $field[ 'ID' ], $email_fields ); |
| 98 |
} |
| 99 |
$this->set_fields(); |
| 100 |
return $this; |
| 101 |
} |
| 102 |
|
| 103 |
/** @inheritdoc */ |
| 104 |
public function toArray() |
| 105 |
{ |
| 106 |
return array( |
| 107 |
'ID' => qcformbuilder_forms_very_safe_string($this->form[ 'ID' ]), |
| 108 |
'name' => isset( $this->form[ 'name' ] ) ? qcformbuilder_forms_very_safe_string( $this->form[ 'name' ] ) : '', |
| 109 |
'fields' => $this->get_fields(), |
| 110 |
'emailIdentifyingFields' => $this->get_email_identifying_fields(), |
| 111 |
'piiFields' => $this->get_pii_fields(), |
| 112 |
'privacyExporterEnabled' => $this->is_privacy_exporter_enabled() |
| 113 |
); |
| 114 |
} |
| 115 |
|
| 116 |
/** @inheritdoc */ |
| 117 |
public function set_fields() |
| 118 |
{ |
| 119 |
foreach (Qcformbuilder_Forms_Forms::get_fields($this->form, true) as $field_id => $field) { |
| 120 |
if (Qcformbuilder_Forms_Fields::not_support(Qcformbuilder_Forms_Field_Util::get_type($field, $this->form), 'entry_list')) { |
| 121 |
continue; |
| 122 |
} |
| 123 |
$this->fields[$field_id] = [ |
| 124 |
'ID' => qcformbuilder_forms_very_safe_string($field_id), |
| 125 |
'name' => isset($field['label']) ? qcformbuilder_forms_very_safe_string($field['label']) : '', |
| 126 |
'type' => Qcformbuilder_Forms_Field_Util::get_type($field, $this->form) |
| 127 |
]; |
| 128 |
} |
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
} |