CustomerFieldsFactory.php
11 months ago
CustomerOrderFieldsFactory.php
1 year ago
CustomerReviewFieldsFactory.php
1 year ago
CustomerSubscriptionFieldsFactory.php
11 months ago
OrderFieldsFactory.php
2 months ago
TermOptionsBuilder.php
2 years ago
TermParentsLoader.php
1 year ago
index.php
3 years ago
TermParentsLoader.php
41 lines
| 1 | <?php declare(strict_types = 1); |
| 2 | |
| 3 | namespace MailPoet\Automation\Integrations\WooCommerce\Fields; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | class TermParentsLoader { |
| 9 | /** |
| 10 | * @param int[] $termIds |
| 11 | * @return int[] |
| 12 | */ |
| 13 | public function getParentIds(array $termIds): array { |
| 14 | global $wpdb; |
| 15 | if (count($termIds) === 0) { |
| 16 | return []; |
| 17 | } |
| 18 | |
| 19 | $result = $wpdb->get_col( |
| 20 | $wpdb->prepare( |
| 21 | " |
| 22 | SELECT DISTINCT tt.parent |
| 23 | FROM {$wpdb->term_taxonomy} AS tt |
| 24 | WHERE tt.parent != 0 |
| 25 | AND tt.term_id IN (" . implode(',', array_fill(0, count($termIds), '%s')) . ") |
| 26 | ", |
| 27 | $termIds |
| 28 | ) |
| 29 | ); |
| 30 | $parentIds = array_map('intval', $result); |
| 31 | if (count($parentIds) === 0) { |
| 32 | return []; |
| 33 | } |
| 34 | return array_values( |
| 35 | array_unique( |
| 36 | array_merge($parentIds, $this->getParentIds($parentIds)) |
| 37 | ) |
| 38 | ); |
| 39 | } |
| 40 | } |
| 41 |