setId( $pixel['id'] ) ->setType( $pixel['type'] ) ->setEvents( $pixel['events'] ); } $settingsDTO->setPixels( $pixels ); if ( ! empty( $settings['token'] ) ) { $settingsDTO->setToken( $settings['token'] ); } if ( ! empty( $settings['disabled_events'] ) ) { $settingsDTO->setDisabledEvents( $settings['disabled_events'] ); } if ( ! empty( $settings['gdprCookie'] ) ) { $settingsDTO->setGdprCookie( $settings['gdprCookie'] ); } if ( ! empty( $settings['forms'] ) ) { $forms = array(); foreach ( $settings['forms'] as $form ) { $matches = array(); foreach ( $form['matches'] as $match ) { $matches[] = ( new FormFieldMatchDTO() ) ->setOtField( empty( $match['otField'] ) ? null : $match['otField'] ) ->setFormField( $match['formField'] ); } $forms[] = ( new FormSettingsDTO() ) ->setFormId( $form['formId'] ) ->setPlugin( $form['plugin'] ) ->setMatches( $matches ); } $settingsDTO->setForms( $forms ); } return $settingsDTO; } /** * @return PixelSettingsDTO[] */ public function getPixels() { return $this->pixels; } /** * @param array $pixels */ public function setPixels( $pixels ) { $this->pixels = $pixels; return $this; } /** * @return FormSettingsDTO[] */ public function getForms() { return $this->forms; } /** * @return FormSettingsDTO */ public function getForm( $formId, $plugin ) { foreach ( $this->forms as $form ) { if ( $form->getFormId() == $formId && $form->getPlugin() == $plugin ) { return $form; } } return null; } /** * @param array $forms */ public function setForms( $forms ) { $this->forms = $forms; return $this; } /** * @return mixed */ public function getToken() { return $this->token; } /** * @param mixed $token */ public function setToken( $token ) { $this->token = $token; return $this; } /** * @return mixed */ public function getDisabledEvents() { return $this->disabledEvents; } /** * @param mixed $disabledEvents */ public function setDisabledEvents( $disabledEvents ) { $this->disabledEvents = $disabledEvents; return $this; } /** * @return string */ public function getGdprCookie() { return $this->gdprCookie; } /** * @param string $gdprCookie */ public function setGdprCookie( $gdprCookie ) { $this->gdprCookie = $gdprCookie; return $this; } public function __toArray() { return array( 'token' => $this->getToken(), 'pixels' => $this->getPixels(), 'disabled_events' => $this->getDisabledEvents(), ); } } }