PluginProbe
Timetics – Appointment Booking Calendar & Scheduling / 1.0.49
Timetics – Appointment Booking Calendar & Scheduling v1.0.49
1.0.61 1.0.60 1.0.59 1.0.58 1.0.57 1.0.56 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.20 1.0.21 1.0.22 1.0.23 1.0.24 All 62 releases
timetics / base / importer.php

importer.php in Timetics – Appointment Booking Calendar & Scheduling 1.0.49, at base/importer.php

110 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Data Importer Class
4 *
5 * @package Timetics
6 */
7 namespace Timetics\Base;
8
9 use Exception;
10 use Timetics\Utils\Validator;
11
12 /**
13 * Class Importer
14 */
15 abstract class Importer {
16 use Validator;
17
18 /**
19 * Store file
20 *
21 * @var array
22 */
23 protected $file;
24
25 /**
26 * Store data that will be imported
27 *
28 * @var array
29 */
30 protected $data;
31
32 /**
33 * Store number of rows
34 *
35 * @var integer
36 */
37 protected $total_row = 0;
38
39 /**
40 * Store total imported rows
41 *
42 * @var integer
43 */
44 protected $total_imported_row;
45
46 /**
47 * Import data
48 *
49 * @return mixed
50 */
51 abstract function import();
52
53 /**
54 * Read file that will be imported
55 *
56 * @param array $file
57 *
58 * @return void
59 */
60 public function read_file() {
61 $file = $this->file;
62 $file_type = ! empty( $file['type'] ) ? $file['type'] : '';
63 $file_name = ! empty( $file['tmp_name'] ) ? $file['tmp_name'] : '';
64
65 switch ( $file_type ) {
66 case 'application/json':
67 $this->data = JsonReader::get_data( $file_name );
68 break;
69 case 'text/csv':
70 $this->data = CsvReader::get_data( $file_name );
71 break;
72 default:
73 throw new Exception( esc_html__( 'You must provide a valid file type', 'timetics' ) );
74 }
75
76 $this->set_total_row();
77 }
78
79 /**
80 * Get total number of rows
81 *
82 * @return integer
83 */
84 public function get_total_rows() {
85 return $this->total_row;
86 }
87
88 /**
89 * Set total row
90 *
91 * @return void
92 */
93 protected function set_total_row() {
94 if ( ! $this->data ) {
95 return;
96 }
97
98 $this->total_row = count( $this->data );
99 }
100
101 /**
102 * Get total imported rows
103 *
104 * @return integer
105 */
106 public function get_total_imported_rows() {
107 return $this->total_imported_row;
108 }
109 }
110