HEX
Server: nginx/1.26.1
System: Linux 850a3e23ecee 5.15.0-122-generic #132-Ubuntu SMP Thu Aug 29 13:45:52 UTC 2024 x86_64
User: (1000)
PHP: 8.2.27
Disabled: NONE
Upload Files
File: /var/www/html/wp-content/plugins/fixed-toc/frontend/data/class-datum-parent-id.php
<?php

/**
 * Generate an parent id datum
 *
 * @since 3.0.0
 *
 * @see Fixedtoc_Datum
 */
class Fixedtoc_Datum_Parent_Id extends Fixedtoc_Datum {

	/**
	 * @since 3.0.0
	 */
	public function set_name() {
		$this->name = 'parent_id';
	}

	/**
	 * @since 3.0.0
	 *
	 * @param Fixedtoc_Data $obj_data
	 */
	public function set_value( Fixedtoc_Data $obj_data ) {
		$data = $obj_data->get_data();
		if ( empty( $data ) ) {
			return;
		}

		$reverse_data    = array_reverse( $data );
		$current_heading = $this->get_heading( $obj_data->get_match() );

		foreach ( $reverse_data as $datum ) {
			if ( $this->get_heading( $datum['element'] ) < $current_heading ) {
				$this->value = $datum['id'];

				return;
			}
		}

		$this->value = false;
	}

	/**
	 * Get heading
	 *
	 * @since 3.0.0
	 * @access private
	 *
	 * @param string $element
	 *
	 * @return int
	 */
	private function get_heading( $element ) {
		return (int) substr( $element, 2, 1 );
	}

}