settings = $settings ?? new Settings(); $this->gateway = $gateway ?? new Booktics_Public_Gateway(); parent::__construct( $name, $description ); } /** * Status line while the tool runs; each tool names its own. * * @return string */ public function status_label(): string { return ''; } /** * Take the card left by the last run. * * @return array|null */ public function take_card(): ?array { $card = $this->card; $this->card = null; return $card; } /** * Leave a card for the chat screen. * * @param string $card Card name. * @param array $data Card data. * @return void */ protected function set_card( string $card, array $data ): void { $this->card = [ 'card' => $card, 'data' => $data, ]; } /** * Error result when Booktics is not loaded, else null. * * @return array|null */ protected function inactive(): ?array { if ( $this->gateway->is_active() ) { return null; } return [ 'ok' => false, 'error' => 'Booktics is not active on this website.', ]; } /** * "13:30" in the site's time format, e.g. "1:30 PM". * * @param string $hm 24h time. * @return string */ protected function time_label( string $hm ): string { return $this->in_site_time( '2000-01-01 ' . $hm )->format( (string) get_option( 'time_format', 'g:i a' ) ); } /** * "2030-01-15" as weekday plus the site's date format, e.g. "Tue, 15 Jan 2030". * * @param string $ymd Date. * @return string */ protected function date_label( string $ymd ): string { return $this->in_site_time( $ymd )->format( 'D, ' . (string) get_option( 'date_format', 'j M Y' ) ); } /** * Site timezone name, e.g. "Asia/Dhaka". * * @return string */ protected function timezone_label(): string { return Visitor_Timezone::format( wp_timezone_string() ); } /** * A Booktics panel setting (falls back to the panel default). * * @param string $key Field key. * @param mixed $fallback Fallback. * @return mixed */ protected function setting( string $key, $fallback = null ) { return ( new Public_Agent_Settings( $this->settings ) )->integration( 'booktics', $key, $fallback ); } /** * Parse a local date-time string in the site timezone. * * @param string $value Date or date-time. * @return \DateTimeImmutable */ private function in_site_time( string $value ): \DateTimeImmutable { return new \DateTimeImmutable( $value, wp_timezone() ); } }