A free open source IT asset/license management system
Labels: refactor hydration and properties from Custom Tape to CustomLabelContentProperties
Godfrey M7c4a04d6bdf5
diff --git a/app/Models/Labels/CustomLabels/Concerns/HasCustomLabelContentProperties.php b/app/Models/Labels/CustomLabels/Concerns/HasCustomLabelContentProperties.phpindex 8e6eb1ed66..5520c6871d 100644--- a/app/Models/Labels/CustomLabels/Concerns/HasCustomLabelContentProperties.php+++ b/app/Models/Labels/CustomLabels/Concerns/HasCustomLabelContentProperties.php@@ -33,6 +33,24 @@ trait HasCustomLabelContentPropertiesprotected string $logoHAlign = 'L';protected string $logoVAlign = 'T';+ //Tape only properities+ protected string $barcode1DVAlign = 'M';+ protected string $barcode1DPlacement = 'inline';++ protected float $barcode2DMargin = 0.0;+ protected string $barcode2DPlacement = 'inline';++ protected string $tagPositionMode = 'inline';++ protected string $fieldAlignment = 'L';++ protected float $logoMaxHeight = 12.0;+ protected string $logoPlacement = 'inline';++ protected float $textSizeMod = 1.0;+ protected float $textAreaOffsetY = 0.0;+ protected string $textRenderMode = 'normal';+protected ?float $textAreaWidth = null;protected ?float $textAreaHeight = null;diff --git a/app/Models/Labels/CustomLabels/CustomTapeLabel.php b/app/Models/Labels/CustomLabels/CustomTapeLabel.phpindex adf90f1d55..d295cf0239 100644--- a/app/Models/Labels/CustomLabels/CustomTapeLabel.php+++ b/app/Models/Labels/CustomLabels/CustomTapeLabel.php@@ -30,22 +30,6 @@ abstract class CustomTapeLabel extends Labelprotected float $marginRight = 3.2;protected float $marginBottom = 3.2;protected float $marginLeft = 3.2;- protected string $fieldAlignment = 'R';-- protected float $barcode2DMargin = 0.0;- protected ?string $barcode2DPlacement = null;-- protected ?float $logoMaxHeight = null;- protected ?string $logoPlacement = null;-- protected string $tagPositionMode = 'free';-- protected float $textSizeMod = 1.0;- protected float $textAreaOffsetY = 0.0;- protected string $textRenderMode = 'inline';-- protected string $barcode1DVAlign = 'T';- protected string $barcode1DPlacement = 'full_width';protected int $rotation = 0;protected string $orientation = 'L';@@ -195,177 +179,7 @@ abstract class CustomTapeLabel extends Label: $this->rotation;return $this;-// $sourceUnit = $template->getUnit();-//-// $convert = function ($value) use ($sourceUnit) {-// if ($value === null || $value === '') {-// return $value;-// }-//-// return $sourceUnit === 'in' && is_numeric($value)-// ? (float)$value * 25.4-// : $value;-// };-//-// $this->unit = 'mm';-//-// $map = [-// 'width' => 'getWidth',-// 'height' => 'getHeight',-// 'marginTop' => 'getMarginTop',-// 'marginRight' => 'getMarginRight',-// 'marginBottom' => 'getMarginBottom',-// 'marginLeft' => 'getMarginLeft',-// ];-//-// foreach ($map as $property => $method) {-// if (method_exists($template, $method)) {-// $this->{$property} = (float)$convert($template->{$method}());-// }-// }-//-// $supportMap = [-// 'supportAssetTag' => 'getSupportAssetTag',-// 'support1DBarcode' => 'getSupport1DBarcode',-// 'support2DBarcode' => 'getSupport2DBarcode',-// 'supportFields' => 'getSupportFields',-// 'supportLogo' => 'getSupportLogo',-// 'supportTitle' => 'getSupportTitle',-// ];-//-// foreach ($supportMap as $property => $method) {-// if (method_exists($template, $method)) {-// $this->{$property} = $template->{$method}();-// }-// }-//-// $content = method_exists($template, 'getEditorConfigSections')-// ? ($template->getEditorConfigSections()['content'] ?? [])-// : [];-//-// $contentMap = [-//-// /*-// |---------------------------------------------------------------------------// | Barcode 1D-// |---------------------------------------------------------------------------// */-// 'barcode_size' => 'barcodeSize',-// 'barcode_margin' => 'barcodeMargin',-// 'barcode1D_v_align' => 'barcode1DVAlign',-// 'barcode1D_placement' => 'barcode1DPlacement',-//-// /*-// |---------------------------------------------------------------------------// | Barcode 2D-// |---------------------------------------------------------------------------// */-// 'barcode_2d_size' => 'barcode2DSize',-// 'barcode_2d_margin' => 'barcode2DMargin',-// 'barcode2D_placement' => 'barcode2DPlacement',-//-// /*-// |---------------------------------------------------------------------------// | Tag-// |---------------------------------------------------------------------------// */-// 'tag_position_mode' => 'tagPositionMode',-// 'tag_font_size' => 'tagSize',-// 'tag_offset_x' => 'tagOffsetX',-// 'tag_offset_y' => 'tagOffsetY',-// 'tag_alignment' => 'tagAlignment',-//-// /*-// |---------------------------------------------------------------------------// | Title-// |---------------------------------------------------------------------------// */-// 'title_font_size' => 'titleSize',-// 'title_margin' => 'titleMargin',-//-// /*-// |---------------------------------------------------------------------------// | Fields-// |---------------------------------------------------------------------------// */-// 'field_label_font_size' => 'labelSize',-// 'field_label_margin' => 'labelMargin',-//-// 'field_value_font_size' => 'fieldSize',-// 'field_value_margin' => 'fieldMargin',-//-// 'field_alignment' => 'fieldAlignment',-//-// /*-// |---------------------------------------------------------------------------// | Logo-// |---------------------------------------------------------------------------// */-// 'logo_max_height' => 'logoMaxHeight',-//-// /*-// |---------------------------------------------------------------------------// | Text Area-// |---------------------------------------------------------------------------// */-// 'text_size_mod' => 'textSizeMod',-// 'text_area_offset_y' => 'textAreaOffsetY',-// 'text_render_mode' => 'textRenderMode',-// ];-//-// foreach ($contentMap as $key => $property) {-// if (array_key_exists($key, $content)) {-// $this->{$property} = is_numeric($content[$key])-// ? (float)$convert($content[$key])-// : (string)$content[$key];-// }-// }-//-// $stringContentMap = [-//-// /*-// |---------------------------------------------------------------------------// | Barcode 2D-// |---------------------------------------------------------------------------// */-// 'barcode2D_h_align' => 'barcode2DHAlign',-// 'barcode2D_v_align' => 'barcode2DVAlign',-//-// /*-// |---------------------------------------------------------------------------// | Logo-// |---------------------------------------------------------------------------// */-// 'logo_h_align' => 'logoHAlign',-// 'logo_v_align' => 'logoVAlign',-// 'logo_placement' => 'logoPlacement',-//-// /*-// |---------------------------------------------------------------------------// | Fonts-// |---------------------------------------------------------------------------// */-// 'tag_font' => 'tagFont',-// 'title_font' => 'titleFont',-// 'field_label_font' => 'fieldLabelFont',-// 'field_value_font' => 'fieldValueFont',-// ];-//-// foreach ($stringContentMap as $key => $property) {-// if (array_key_exists($key, $content)) {-// $this->{$property} = (string)$content[$key];-// }-// }-//-// foreach ($stringContentMap as $key => $property) {-// if (array_key_exists($key, $content)) {-// $this->{$property} = (string)$content[$key];-// }-// }-//-// $this->rotation = method_exists($template, 'getRotation') ? (int)$template->getRotation() : $this->rotation;-//-// return $this;+}public function applyEditorConfig(array $config): static@@ -378,107 +192,14 @@ abstract class CustomTapeLabel extends Labelprotected function hydrateFromEditorConfig(array $config): void{- $content = $config['content'] ?? [];- $supports = $config['supports'] ?? [];+ $this->hydrateSupports($config['supports'] ?? []);+ $this->hydrateContent($config['content'] ?? []);- /*- |--------------------------------------------------------------------------- | Supports- |--------------------------------------------------------------------------- */- $this->supportFields = isset($supports['fields']) ? (int)$supports['fields'] : $this->supportFields;- $this->supportAssetTag = (bool)($supports['asset_tag'] ?? $this->supportAssetTag);- $this->support1DBarcode = (bool)($supports['barcode_1d'] ?? $this->support1DBarcode);- $this->support2DBarcode = (bool)($supports['barcode_2d'] ?? $this->support2DBarcode);- $this->supportLogo = (bool)($supports['logo'] ?? $this->supportLogo);- $this->supportTitle = (bool)($supports['title'] ?? $this->supportTitle);-- /*- |--------------------------------------------------------------------------- | 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;- $this->barcode1DVAlign = isset($content['barcode1D_v_align']) ? (string)$content['barcode1D_v_align'] : $this->barcode1DVAlign;- $this->barcode1DPlacement = isset($content['barcode1D_placement']) ? (string)$content['barcode1D_placement'] : $this->barcode1DPlacement;-- /*- |--------------------------------------------------------------------------- | Barcode 2D- |--------------------------------------------------------------------------- */- $this->barcode2DSize = isset($content['barcode_2d_size']) ? (float)$content['barcode_2d_size'] : $this->barcode2DSize;- $this->barcode2DMargin = isset($content['barcode_2d_margin']) ? (float)$content['barcode_2d_margin'] : $this->barcode2DMargin;- $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;- $this->barcode2DPlacement = isset($content['barcode2D_placement']) ? (string)$content['barcode2D_placement'] : $this->barcode2DPlacement;-- /*- |--------------------------------------------------------------------------- | 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->tagPositionMode = isset($content['tag_position_mode']) ? (string)$content['tag_position_mode'] : $this->tagPositionMode;- $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;+ $meta = $config['meta'] ?? [];- /*- |--------------------------------------------------------------------------- | 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;-- $this->fieldAlignment = isset($content['field_alignment']) ? (string)$content['field_alignment'] : $this->fieldAlignment;-- /*- |--------------------------------------------------------------------------- | Logo- |--------------------------------------------------------------------------- */- $this->logoMaxHeight = isset($content['logo_max_height']) ? (float)$content['logo_max_height'] : $this->logoMaxHeight;- $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;- $this->logoPlacement = isset($content['logo_placement']) ? (string)$content['logo_placement'] : $this->logoPlacement;-- /*- |--------------------------------------------------------------------------- | Text Area- |--------------------------------------------------------------------------- */- $this->textSizeMod = isset($content['text_size_mod']) ? (float)$content['text_size_mod'] : $this->textSizeMod;- $this->textAreaOffsetY = isset($content['text_area_offset_y']) ? (float)$content['text_area_offset_y'] : $this->textAreaOffsetY;- $this->textRenderMode = isset($content['text_render_mode']) ? (string)$content['text_render_mode'] : $this->textRenderMode;-- //If the logo and 2D barcode are both present, and one is moved to the other side, they will flip positions.- 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->rotation = isset($meta['rotation']) ? (int)$meta['rotation'] : $this->rotation;+ $this->rotation = isset($meta['rotation'])+ ? (int)$meta['rotation']+ : $this->rotation;}public function write($pdf, $record)