>|null */ private ?array $maps = null; /** * Instance. */ public static function instance(): Labels { if ( null === self::$instance ) { self::$instance = new self(); } return self::$instance; } /** * Reset (after settings change, and in tests). */ public static function reset(): void { self::$instance = null; } /** * Label for a field value. * * @param string $field Column. * @param mixed $value Stored value. */ public function display( string $field, $value ): string { $value = (string) $value; switch ( $field ) { case 'tear_off': case 'marketing_consent': return '1' === $value ? __( 'Yes', 'thinroof' ) : __( 'No', 'thinroof' ); case 'created_at': case 'updated_at': return '' !== $value ? get_date_from_gmt( $value, 'Y-m-d H:i' ) : ''; } $maps = $this->maps(); if ( isset( $maps[ $field ] ) ) { return $maps[ $field ][ $value ] ?? $value; } return $value; } /** * Build maps lazily. */ private function maps(): array { if ( null !== $this->maps ) { return $this->maps; } $plugin = thinroof(); $pricing = $plugin->settings->get( 'pricing' ); $maps = array( 'status' => Lead_Manager::statuses(), 'budget' => Lead_Validator::budget_options(), 'timeline' => Lead_Validator::timeline_options(), 'material' => array(), ); foreach ( array( 'property_types' => 'property_type', 'project_types' => 'project_type', 'pitches' => 'pitch', 'stories' => 'stories' ) as $group => $field ) { // phpcs:ignore WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound $maps[ $field ] = array(); foreach ( (array) $pricing[ $group ] as $row ) { $maps[ $field ][ (string) $row['key'] ] = (string) $row['label']; } } foreach ( $plugin->pricing->materials() as $key => $row ) { $maps['material'][ $key ] = $row['label']; } $this->maps = $maps; return $maps; } }