name = $name; $this->status = self::STATUS_ENABLED; } /** * @return string */ public function getName() { return $this->name; } /** * @return array|null */ public function getBody() { return $this->body; } /** * @return array|null */ public function getSettings() { return $this->settings; } /** * @return string|null */ public function getStyles() { return $this->styles; } /** * @param string $name */ public function setName($name) { $this->name = $name; } /** * @param array|null $body */ public function setBody($body) { $this->body = $body; } /** * @param array|null $settings */ public function setSettings($settings) { $this->settings = $settings; } /** * @param string|null $styles */ public function setStyles($styles) { $this->styles = $styles; } /** * @param string $status */ public function setStatus(string $status) { $this->status = $status; } /** * @return string */ public function getStatus(): string { return $this->status; } public function toArray(): array { return [ 'id' => $this->getId(), 'name' => $this->getName(), 'body' => $this->getBody(), 'settings' => $this->getSettings(), 'styles' => $this->getStyles(), 'status' => $this->getStatus(), 'created_at' => $this->getCreatedAt(), 'updated_at' => $this->getUpdatedAt(), 'deleted_at' => $this->getDeletedAt(), ]; } public function getBlocksByType(string $type, array $blocks = null): array { $found = []; if ($blocks === null) { $blocks = $this->getBody() ?? []; } foreach ($blocks as $block) { if ($block['type'] === $type) { $found[] = $block; } if (isset($block['body']) && is_array($block['body']) && !empty($block['body'])) { $found = array_merge($found, $this->getBlocksByType($type, $block['body'])); } } return $found; } public function getSegmentBlocksSegmentIds(): array { $listSelectionBlocks = $this->getBlocksByType(FormEntity::SEGMENT_SELECTION_BLOCK_TYPE); $listSelection = []; foreach ($listSelectionBlocks as $listSelectionBlock) { $listSelection = array_unique( array_merge( $listSelection, array_column($listSelectionBlock['params']['values'] ?? [], 'id') ) ); } return $listSelection; } public function getSettingsSegmentIds(): array { return $this->settings['segments'] ?? []; } public function getFields(array $body = null): array { $body = $body ?? $this->getBody(); if (empty($body)) { return []; } $skippedTypes = ['html', 'divider', 'submit']; $nestedTypes = ['column', 'columns']; $fields = []; foreach ($body as $field) { if (!empty($field['type']) && in_array($field['type'], $nestedTypes) && !empty($field['body'])) { $nestedFields = $this->getFields($field['body']); if ($nestedFields) { $fields = array_merge($fields, $nestedFields); } continue; } if (empty($field['id']) || empty($field['type']) || in_array($field['type'], $skippedTypes)) { continue; } if ((int)$field['id'] > 0) { $fields[] = 'cf_' . $field['id']; } else { $fields[] = $field['id']; } } return $fields; } }