A free open source IT asset/license management system
move hydration method to trait for Sheets
Godfrey M1d0e49c62d48
diff --git a/app/Models/Labels/CustomLabels/Concerns/HasCustomLabelContentProperties.php b/app/Models/Labels/CustomLabels/Concerns/HasCustomLabelContentProperties.phpindex 94d99ca7cd..8e6eb1ed66 100644--- a/app/Models/Labels/CustomLabels/Concerns/HasCustomLabelContentProperties.php+++ b/app/Models/Labels/CustomLabels/Concerns/HasCustomLabelContentProperties.php@@ -165,4 +165,70 @@ trait HasCustomLabelContentProperties{return $this->textAreaHeight;}++ protected function hydrateSheetPage(array $page): void+ {+ $this->pageWidth = isset($page['width']) ? (float)$page['width'] : $this->pageWidth;+ $this->pageHeight = isset($page['height']) ? (float)$page['height'] : $this->pageHeight;+ $this->pageMarginTop = isset($page['margin_top']) ? (float)$page['margin_top'] : $this->pageMarginTop;+ $this->pageMarginRight = isset($page['margin_right']) ? (float)$page['margin_right'] : $this->pageMarginRight;+ $this->pageMarginBottom = isset($page['margin_bottom']) ? (float)$page['margin_bottom'] : $this->pageMarginBottom;+ $this->pageMarginLeft = isset($page['margin_left']) ? (float)$page['margin_left'] : $this->pageMarginLeft;+ }++ protected function hydrateSheetGrid(array $grid): void+ {+ $this->rows = isset($grid['rows']) ? (int)$grid['rows'] : $this->rows;+ $this->columns = isset($grid['columns']) ? (int)$grid['columns'] : $this->columns;+ $this->labelRowSpacing = isset($grid['row_spacing']) ? (float)$grid['row_spacing'] : $this->labelRowSpacing;+ $this->labelColumnSpacing = isset($grid['column_spacing']) ? (float)$grid['column_spacing'] : $this->labelColumnSpacing;+ }++ protected function hydrateSheetLabel(array $label): void+ {+ $this->labelWidth = isset($label['width']) ? (float)$label['width'] : $this->labelWidth;+ $this->labelHeight = isset($label['height']) ? (float)$label['height'] : $this->labelHeight;+ $this->labelMarginTop = isset($label['padding_top']) ? (float)$label['padding_top'] : $this->labelMarginTop;+ $this->labelMarginRight = isset($label['padding_right']) ? (float)$label['padding_right'] : $this->labelMarginRight;+ $this->labelMarginBottom = isset($label['padding_bottom']) ? (float)$label['padding_bottom'] : $this->labelMarginBottom;+ $this->labelMarginLeft = isset($label['padding_left']) ? (float)$label['padding_left'] : $this->labelMarginLeft;+ }++ protected function hydrateContent(array $content): void+ {+ $this->hydrateNumericContent($content);+ $this->hydrateStringContent($content);++ if (array_key_exists('barcode2D_h_align', $content)) {+ $this->syncLogoAnd2DBarcodeHAlign('barcode2D_h_align');+ } elseif (array_key_exists('logo_h_align', $content)) {+ $this->syncLogoAnd2DBarcodeHAlign('logo_h_align');+ }+ }++ protected function hydrateNumericContent(array $content): void+ {+ foreach ($this->editorNumericContentMap() as $key => $property) {+ if (+ array_key_exists($key, $content)+ && $content[$key] !== ''+ && $content[$key] !== null+ ) {+ $this->{$property} = (float)$content[$key];+ }+ }+ }++ protected function hydrateStringContent(array $content): void+ {+ foreach ($this->editorStringContentMap() as $key => $property) {+ if (+ array_key_exists($key, $content)+ && $content[$key] !== ''+ && $content[$key] !== null+ ) {+ $this->{$property} = (string)$content[$key];+ }+ }+ }}\ No newline at end of filediff --git a/app/Models/Labels/CustomLabels/CustomSheetLabel.php b/app/Models/Labels/CustomLabels/CustomSheetLabel.phpindex 737e753f12..3b15464292 100644--- a/app/Models/Labels/CustomLabels/CustomSheetLabel.php+++ b/app/Models/Labels/CustomLabels/CustomSheetLabel.php@@ -208,131 +208,11 @@ abstract class CustomSheetLabel extends RectangleSheet$supports = $config['supports'] ?? [];$content = $config['content'] ?? [];- /*- |--------------------------------------------------------------------------- | Page- |--------------------------------------------------------------------------- */- $this->pageWidth = isset($page['width']) ? (float) $page['width'] : $this->pageWidth;- $this->pageHeight = isset($page['height']) ? (float) $page['height'] : $this->pageHeight;- $this->pageMarginTop = isset($page['margin_top']) ? (float) $page['margin_top'] : $this->pageMarginTop;- $this->pageMarginRight = isset($page['margin_right']) ? (float) $page['margin_right'] : $this->pageMarginRight;- $this->pageMarginBottom = isset($page['margin_bottom']) ? (float) $page['margin_bottom'] : $this->pageMarginBottom;- $this->pageMarginLeft = isset($page['margin_left']) ? (float) $page['margin_left'] : $this->pageMarginLeft;-- /*- |--------------------------------------------------------------------------- | Grid- |--------------------------------------------------------------------------- */- $this->rows = isset($grid['rows']) ? (int) $grid['rows'] : $this->rows;- $this->columns = isset($grid['columns']) ? (int) $grid['columns'] : $this->columns;- $this->labelRowSpacing = isset($grid['row_spacing']) ? (float) $grid['row_spacing'] : $this->labelRowSpacing;- $this->labelColumnSpacing = isset($grid['column_spacing']) ? (float) $grid['column_spacing'] : $this->labelColumnSpacing;-- /*- |--------------------------------------------------------------------------- | Label- |--------------------------------------------------------------------------- */- $this->labelWidth = isset($label['width']) ? (float) $label['width'] : $this->labelWidth;- $this->labelHeight = isset($label['height']) ? (float) $label['height'] : $this->labelHeight;- $this->labelMarginTop = isset($label['padding_top']) ? (float) $label['padding_top'] : $this->labelMarginTop;- $this->labelMarginRight = isset($label['padding_right']) ? (float) $label['padding_right'] : $this->labelMarginRight;- $this->labelMarginBottom = isset($label['padding_bottom']) ? (float) $label['padding_bottom'] : $this->labelMarginBottom;- $this->labelMarginLeft = isset($label['padding_left']) ? (float) $label['padding_left'] : $this->labelMarginLeft;-- /*- |--------------------------------------------------------------------------- | Supports- |--------------------------------------------------------------------------- */- $this->supportFields = isset($supports['fields']) ? (int) $supports['fields'] : $this->supportFields;- $this->supportTitle = (bool)($supports['title'] ?? $this->supportTitle);- $this->support1DBarcode = (bool)($supports['barcode_1d'] ?? $this->support1DBarcode);- $this->support2DBarcode = (bool)($supports['barcode_2d'] ?? $this->support2DBarcode);- $this->supportLogo = (bool)($supports['logo'] ?? $this->supportLogo);- $this->supportAssetTag = (bool)($supports['asset_tag'] ?? $this->supportAssetTag);-- /*- |--------------------------------------------------------------------------- | Barcode 1D- |--------------------------------------------------------------------------- */- $this->barcodeSize = isset($content['barcode_size']) ? (float) $content['barcode_size'] : $this->barcodeSize;- $this->barcodeMargin = isset($content['barcode_margin']) ? (float) $content['barcode_margin'] : $this->barcodeMargin;-- /*- |--------------------------------------------------------------------------- | Barcode 2D- |--------------------------------------------------------------------------- */- $this->barcode2DSize = isset($content['barcode_2d_size']) ? (float) $content['barcode_2d_size'] : $this->barcode2DSize;- $this->barcode2DHAlign = isset($content['barcode2D_h_align']) ? (string)$content['barcode2D_h_align'] : $this->barcode2DHAlign;- $this->barcode2DVAlign = isset($content['barcode2D_v_align']) ? (string)$content['barcode2D_v_align'] : $this->barcode2DVAlign;-- /*- |--------------------------------------------------------------------------- | Tag- |--------------------------------------------------------------------------- */- $this->tagFont = isset($content['tag_font']) ? (string)$content['tag_font'] : $this->tagFont;- $this->tagSize = isset($content['tag_font_size']) ? (float) $content['tag_font_size'] : $this->tagSize;- $this->tagAlignment = isset($content['tag_alignment']) ? (string)$content['tag_alignment'] : $this->tagAlignment;- $this->tagOffsetX = isset($content['tag_offset_x']) ? (float) $content['tag_offset_x'] : $this->tagOffsetX;- $this->tagOffsetY = isset($content['tag_offset_y']) ? (float) $content['tag_offset_y'] : $this->tagOffsetY;-- /*- |--------------------------------------------------------------------------- | Title- |--------------------------------------------------------------------------- */- $this->titleFont = isset($content['title_font']) ? (string)$content['title_font'] : $this->titleFont;- $this->titleSize = isset($content['title_font_size']) ? (float) $content['title_font_size'] : $this->titleSize;- $this->titleMargin = isset($content['title_margin']) ? (float) $content['title_margin'] : $this->titleMargin;- $this->titleOffsetX = isset($content['title_offset_x']) ? (float) $content['title_offset_x'] : $this->titleOffsetX;-- /*- |--------------------------------------------------------------------------- | Fields- |--------------------------------------------------------------------------- */- $this->fieldLabelFont = isset($content['field_label_font']) ? (string)$content['field_label_font'] : $this->fieldLabelFont;- $this->labelSize = isset($content['field_label_font_size']) ? (float)$content['field_label_font_size'] : $this->labelSize;- $this->labelMargin = isset($content['field_label_margin']) ? (float) $content['field_label_margin'] : $this->labelMargin;-- $this->fieldValueFont = isset($content['field_value_font']) ? (string)$content['field_value_font'] : $this->fieldValueFont;- $this->fieldSize = isset($content['field_value_font_size']) ? (float)$content['field_value_font_size'] : $this->fieldSize;- $this->fieldMargin = isset($content['field_value_margin']) ? (float) $content['field_value_margin'] : $this->fieldMargin;-- /*- |--------------------------------------------------------------------------- | Logo- |--------------------------------------------------------------------------- */- $this->logoMaxWidth = isset($content['logo_max_width']) ? (float)$content['logo_max_width'] : $this->logoMaxWidth;- $this->logoMargin = isset($content['logo_margin']) ? (float)$content['logo_margin'] : $this->logoMargin;- $this->logoHAlign = isset($content['logo_h_align']) ? (string)$content['logo_h_align'] : $this->logoHAlign;- $this->logoVAlign = isset($content['logo_v_align']) ? (string)$content['logo_v_align'] : $this->logoVAlign;-- /*- |--------------------------------------------------------------------------- | Text Area- |--------------------------------------------------------------------------- */- $this->textAreaWidth = isset($content['text_area_width']) && $content['text_area_width'] !== ''- ? (float)$content['text_area_width']- : $this->textAreaWidth;-- $this->textAreaHeight = isset($content['text_area_height']) && $content['text_area_height'] !== ''- ? (float)$content['text_area_height']- : $this->textAreaHeight;- //If the logo and 2D barcode are both present, and one is moved to the other side, they will flip positions in the gui input.- if (array_key_exists('barcode2D_h_align', $content)) {- $this->syncLogoAnd2DBarcodeHAlign('barcode2D_h_align');- } elseif (array_key_exists('logo_h_align', $content)) {- $this->syncLogoAnd2DBarcodeHAlign('logo_h_align');- }+ $this->hydrateSheetPage($page);+ $this->hydrateSheetGrid($grid);+ $this->hydrateSheetLabel($label);+ $this->hydrateSupports($supports);+ $this->hydrateContent($content);}public function write($pdf, $record)