Yoast\WP\SEO\Dashboard\Infrastructure\Score_Results\Readability_Score_Results

Readability_Score_Results_Collector::build_select()privateYoast 1.0

Builds the select statement for the readability scores query.

Метод класса: Readability_Score_Results_Collector{}

Хуков нет.

Возвращает

Массив<Строку,. string> The select statement for the readability scores query.

Использование

// private - только в коде основоного (родительского) класса
$result = $this->build_select( $readability_score_groups, ?bool $is_troubleshooting ): array;
$readability_score_groups(Readability_Score_Groups_Interface[]) (обязательный)
All readability score groups.
?bool $is_troubleshooting (обязательный)
-

Код Readability_Score_Results_Collector::build_select() Yoast 24.3

private function build_select( array $readability_score_groups, ?bool $is_troubleshooting ): array {
	$select_fields       = [];
	$select_replacements = [];

	// When we don't troubleshoot, we're interested in the amount of posts in a group, when we troubleshoot we want to gather the actual IDs.
	$select_operation = ( $is_troubleshooting === true ) ? 'GROUP_CONCAT' : 'COUNT';
	$selected_info    = ( $is_troubleshooting === true ) ? 'I.object_id' : '1';

	foreach ( $readability_score_groups as $readability_score_group ) {
		$min  = $readability_score_group->get_min_score();
		$max  = $readability_score_group->get_max_score();
		$name = $readability_score_group->get_name();

		if ( $min === null && $max === null ) {
			$select_fields[]       = "{$select_operation}(CASE WHEN I.readability_score = 0 AND I.estimated_reading_time_minutes IS NULL THEN {$selected_info} END) AS %i";
			$select_replacements[] = $name;
		}
		else {
			$needs_ert             = ( $min === 1 ) ? ' OR (I.readability_score = 0 AND I.estimated_reading_time_minutes IS NOT NULL)' : '';
			$select_fields[]       = "{$select_operation}(CASE WHEN ( I.readability_score >= %d AND I.readability_score <= %d ){$needs_ert} THEN {$selected_info} END) AS %i";
			$select_replacements[] = $min;
			$select_replacements[] = $max;
			$select_replacements[] = $name;
		}
	}

	$select_fields = \implode( ', ', $select_fields );

	return [
		'fields'       => $select_fields,
		'replacements' => $select_replacements,
	];
}