← All changes
|
modules/global-classes/global-classes-labels.php
+0
-48
4.1.1
→
4.1.0-beta1
View file →
| @@ -72,56 +72,8 @@ | ||
| 72 | 72 | |
| 73 | 73 | return $result; |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | - public static function generate_unique_label( string $label, array $existing_labels ): string { | |
| 77 | - $prefix = 'DUP_'; | |
| 78 | - $max_length = 50; | |
| 79 | - | |
| 80 | - $has_prefix = str_starts_with( $label, $prefix ); | |
| 81 | - | |
| 82 | - if ( $has_prefix ) { | |
| 83 | - $base = substr( $label, strlen( $prefix ) ); | |
| 84 | - $counter = 1; | |
| 85 | - $candidate = $prefix . $base . $counter; | |
| 86 | - | |
| 87 | - while ( in_array( $candidate, $existing_labels, true ) ) { | |
| 88 | - $candidate = $prefix . $base . ( ++$counter ); | |
| 89 | - } | |
| 90 | - | |
| 91 | - if ( strlen( $candidate ) > $max_length ) { | |
| 92 | - $base = substr( $base, 0, $max_length - strlen( $prefix . $counter ) ); | |
| 93 | - $candidate = $prefix . $base . $counter; | |
| 94 | - } | |
| 95 | - | |
| 96 | - return $candidate; | |
| 97 | - } | |
| 98 | - | |
| 99 | - $available_length = strlen( $label ); | |
| 100 | - $candidate = $prefix . $label; | |
| 101 | - | |
| 102 | - if ( strlen( $candidate ) > $max_length ) { | |
| 103 | - $available_length = $max_length - strlen( $prefix ); | |
| 104 | - $candidate = $prefix . substr( $label, 0, $available_length ); | |
| 105 | - } | |
| 106 | - | |
| 107 | - $base = substr( $label, 0, $available_length ); | |
| 108 | - $counter = 1; | |
| 109 | - | |
| 110 | - while ( in_array( $candidate, $existing_labels, true ) ) { | |
| 111 | - $candidate = $prefix . $base . $counter; | |
| 112 | - | |
| 113 | - if ( strlen( $candidate ) > $max_length ) { | |
| 114 | - $base = substr( $label, 0, $max_length - strlen( $prefix . $counter ) ); | |
| 115 | - $candidate = $prefix . $base . $counter; | |
| 116 | - } | |
| 117 | - | |
| 118 | - ++$counter; | |
| 119 | - } | |
| 120 | - | |
| 121 | - return $candidate; | |
| 122 | - } | |
| 123 | - | |
| 124 | 76 | public function set_labels( array $id_to_label ): bool { |
| 125 | 77 | $kit = $this->get_kit(); |
| 126 | 78 | |
| 127 | 79 | if ( ! $kit ) { |