'aivor_content_job', 'plural' => 'aivor_content_jobs', 'ajax' => false, ) ); } /** * Die Spalten der Liste. * * @return array */ public function get_columns() { return array( 'aivor_job_id' => __( 'Content job', 'aivor-content-import' ), 'target' => __( 'Target', 'aivor-content-import' ), 'author' => __( 'Author', 'aivor-content-import' ), 'mode' => __( 'After import', 'aivor-content-import' ), 'last_import' => __( 'Last import', 'aivor-content-import' ), 'error' => __( 'Status', 'aivor-content-import' ), ); } /** * Laedt die Jobs. * * @return void */ public function prepare_items() { $this->_column_headers = array( $this->get_columns(), array(), array() ); $this->items = ( new JobRepository() )->all(); } /** * Text, wenn noch kein Job angelegt ist. * * @return void */ public function no_items() { esc_html_e( 'No content job yet. Add one with the import job ID from Aivor.', 'aivor-content-import' ); } /** * Die Spalte mit der Aivor-Job-ID samt Aktionen. * * @param Job $item Der Job dieser Zeile. * @return string */ public function column_aivor_job_id( $item ) { $edit_url = add_query_arg( array( 'page' => JobsPage::SLUG, 'action' => 'edit', 'job' => $item->id, ), admin_url( 'admin.php' ) ); $delete_url = wp_nonce_url( add_query_arg( array( 'page' => JobsPage::SLUG, 'action' => 'delete', 'job' => $item->id, ), admin_url( 'admin.php' ) ), 'aivor_content_delete_job_' . $item->id ); $actions = array( 'edit' => sprintf( '%s', esc_url( $edit_url ), esc_html__( 'Edit', 'aivor-content-import' ) ), 'delete' => sprintf( '%s', esc_url( $delete_url ), esc_html__( 'Delete', 'aivor-content-import' ) ), ); $name = '' !== $item->remote_name ? $item->remote_name : __( 'Content job', 'aivor-content-import' ); return sprintf( '%s
%s%s', esc_url( $edit_url ), esc_html( $name ), esc_html( '' !== $item->aivor_job_id ? $item->aivor_job_id : '—' ), $this->row_actions( $actions ) ); } /** * Fehler, Warnung oder Ergebnis der letzten Statusabfrage. * * @param Job $item Der Job dieser Zeile. * @return string */ private function status_cell( Job $item ): string { $warning = ' '; if ( '' !== $item->error ) { return $warning . esc_html( $item->error ); } $remote = array( 'not_found' => __( 'Aivor does not know this import job ID.', 'aivor-content-import' ), 'forbidden' => __( 'The import job belongs to a different Aivor project than the API key.', 'aivor-content-import' ), ); if ( isset( $remote[ $item->remote_status ] ) ) { return $warning . esc_html( $remote[ $item->remote_status ] ); } $mismatch = JobsPage::site_mismatch_warning( $item ); if ( '' !== $mismatch ) { return $warning . esc_html( $mismatch ); } return 'ok' === $item->remote_status ? ' ' . esc_html__( 'Connected', 'aivor-content-import' ) : '—'; } /** * Alle uebrigen Spalten. * * @param Job $item Der Job dieser Zeile. * @param string $column_name Name der Spalte. * @return string */ public function column_default( $item, $column_name ) { switch ( $column_name ) { case 'target': return esc_html( JobsPage::describe_target( $item ) ); case 'author': return esc_html( JobsPage::describe_author( $item ) ); case 'mode': return esc_html( JobsPage::describe_mode( $item ) ); case 'last_import': if ( 0 === $item->last_import ) { return esc_html__( 'never', 'aivor-content-import' ); } return esc_html( wp_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $item->last_import ) ); case 'error': return $this->status_cell( $item ); default: return ''; } } }