PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / trunk
JetFormBuilder — Dynamic Blocks Form Builder vtrunk
3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / modules / form-record / export / single-controller.php
jetformbuilder / modules / form-record / export Last commit date
base-export-controller.php 2 years ago multiple-controller.php 2 months ago single-controller.php 2 years ago
single-controller.php
80 lines
1 <?php
2
3
4 namespace JFB_Modules\Form_Record\Export;
5
6 use JFB_Modules\Form_Record\Query_Views\Record_View;
7 use JFB_Modules\Form_Record\Tools;
8
9 // If this file is called directly, abort.
10 if ( ! defined( 'WPINC' ) ) {
11 die;
12 }
13
14 class Single_Controller extends Base_Export_Controller {
15
16 protected $record_id;
17 protected $record;
18 protected $fields;
19
20 /**
21 * @throws \Exception
22 */
23 public function do_export() {
24 $this->record_id = $this->get_record_id();
25
26 $record_view = Record_View::findOne( array( 'id' => $this->record_id ) );
27 $record_view->set_select( array_keys( $this->extra_columns ) );
28
29 $this->record = $record_view->query()->query_one();
30
31 // set fields & request
32 Tools::apply_context( $this->record );
33
34 $fields_columns = $this->get_field_columns();
35
36 $this->get_exporter()->set_title( $this->get_file_name() );
37 $this->get_exporter()->open();
38
39 // headings
40 $this->get_exporter()->add_row( $this->prepare_row( $fields_columns, $this->extra_columns ) );
41
42 foreach ( jet_fb_context()->iterate_values_table() as $row ) {
43 $this->get_exporter()->add_row(
44 $this->prepare_row( iterator_to_array( $row ), $this->record )
45 );
46 }
47
48 $this->get_exporter()->close();
49 die;
50 }
51
52 /**
53 * @return int
54 * @throws \Exception
55 */
56 protected function get_record_id(): int {
57 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
58 $record_id = absint( $_GET['id'] ?? '' );
59
60 if ( ! $record_id ) {
61 throw new \Exception(
62 esc_html__( 'Record ID is empty', 'jet-form-builder' )
63 );
64 }
65
66 return $record_id;
67 }
68
69 protected function get_file_name(): string {
70 return sprintf(
71 /* translators: %1$s - form title, %2$d - record ID */
72 __( '%1$s record (%2$d)', 'jet-form-builder' ),
73 get_the_title( $this->record['form_id'] ),
74 $this->record_id
75 );
76 }
77
78
79 }
80