PluginProbe
Import WP – CSV & XML Import Export for WordPress / 2.7.9
Import WP – CSV & XML Import Export for WordPress v2.7.9
2.15.1 2.15.0 2.14.24 2.14.23 2.7.0 2.7.1 2.7.10 2.7.11 2.7.12 2.7.13 2.7.14 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 2.8.0 2.8.1 2.8.2 2.8.3 2.9.0 2.9.1 All 144 releases
jc-importer / class / Common / Exporter / Mapper / AbstractMapper.php

AbstractMapper.php in Import WP – CSV & XML Import Export for WordPress 2.7.9, at class/Common/Exporter/Mapper/AbstractMapper.php

122 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ImportWP\Common\Exporter\Mapper;
4
5 abstract class AbstractMapper
6 {
7 protected $filters;
8 protected $record = [];
9 public $records = [];
10
11 public function get_value($column, $template_data = null)
12 {
13 if (is_null($template_data)) {
14 $template_data = $this->record();
15 }
16
17 $parts = explode('.', $column);
18 if (count($parts) == 2) {
19
20 // handle looped data
21 if (isset($template_data[$parts[0]], $template_data[$parts[0]][0], $template_data[$parts[0]][0][$parts[1]])) {
22 return array_reduce($template_data[$parts[0]], function ($carry, $item) use ($parts) {
23 if (isset($item[$parts[1]])) {
24 $carry[] = $item[$parts[1]];
25 }
26 return $carry;
27 }, []);
28 }
29
30 // handled grouped data or single
31 return isset($template_data[$parts[0]], $template_data[$parts[0]][$parts[1]]) ? $template_data[$parts[0]][$parts[1]] : '';
32 }
33
34 return isset($template_data[$column]) ? $template_data[$column] : '';
35 }
36
37 public function set_filters($filters = [])
38 {
39 $this->filters = $filters;
40 }
41
42 /**
43 * Filter record
44 *
45 * @param array $post
46 * @return boolean
47 */
48 public function filter()
49 {
50 $result = false;
51
52 if (empty($this->filters)) {
53 return $result;
54 }
55
56 foreach ($this->filters as $group) {
57
58 $result = true;
59
60 if (empty($group)) {
61 continue;
62 }
63
64 foreach ($group as $row) {
65
66 $left = $this->get_value($row['left']);
67 $right = $row['right'];
68 $right_parts = array_map('trim', explode(',', $right));
69
70 switch ($row['condition']) {
71 case 'equal':
72 if ($left != $right) {
73 $result = false;
74 }
75 break;
76 case 'contains':
77 if (stripos($left, $right) === false) {
78 $result = false;
79 }
80 break;
81 case 'in':
82 if (!in_array($left, $right_parts)) {
83 $result = false;
84 }
85 break;
86 case 'not-equal':
87 if ($left == $right) {
88 $result = false;
89 }
90 break;
91 case 'not-contains':
92 if (stripos($left, $right) !== false) {
93 $result = false;
94 }
95 break;
96 case 'not-in':
97 if (in_array($left, $right_parts)) {
98 $result = false;
99 }
100 break;
101 }
102 }
103
104 if ($result) {
105 return true;
106 }
107 }
108
109
110 return $result;
111 }
112
113 public function record($index = 0)
114 {
115 if (isset($this->records[$index])) {
116 return $this->records[$index];
117 }
118
119 return $this->record;
120 }
121 }
122