AddonService.php
124 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Wpae\App\Service\Addons; |
| 4 | |
| 5 | |
| 6 | class AddonService |
| 7 | { |
| 8 | public function isUserAddonActive() { |
| 9 | return defined('PMUE_EDITION'); |
| 10 | } |
| 11 | |
| 12 | |
| 13 | public function isWooCommerceAddonActive() { |
| 14 | return defined('PMWE_EDITION'); |
| 15 | } |
| 16 | |
| 17 | public function isAcfAddonActive() { |
| 18 | return defined('PMAE_EDITION'); |
| 19 | } |
| 20 | |
| 21 | public function isWoocommerceAddonActiveAndIsWooCommerceExport() |
| 22 | { |
| 23 | return $this->isWooCommerceAddonActive() && \XmlExportWooCommerce::$is_active; |
| 24 | } |
| 25 | |
| 26 | public function isUserAddonActiveAndIsUserExport() |
| 27 | { |
| 28 | return $this->isUserAddonActive() && \XmlExportUser::$is_active; |
| 29 | } |
| 30 | |
| 31 | public function userExportsExistAndAddonNotInstalled() |
| 32 | { |
| 33 | $exports = new \PMXE_Export_List(); |
| 34 | $exports->getBy('parent_id', 0)->convertRecords(); |
| 35 | |
| 36 | foreach ($exports as $item) { |
| 37 | |
| 38 | if ( |
| 39 | ((in_array('users', $item['options']['cpt']) || in_array('shop_customer', $item['options']['cpt'])) && !$this->isUserAddonActive()) || |
| 40 | ($item['options']['export_type'] == 'advanced' && $item['options']['wp_query_selector'] == 'wp_user_query' && !$this->isUserAddonActive()) |
| 41 | ) { |
| 42 | return true; |
| 43 | } |
| 44 | |
| 45 | } |
| 46 | |
| 47 | return false; |
| 48 | } |
| 49 | |
| 50 | public function hasExportAtOlderVersionThan($version) |
| 51 | { |
| 52 | $exports = new \PMXE_Export_List(); |
| 53 | $exports->getBy('parent_id', 0)->convertRecords(); |
| 54 | |
| 55 | foreach ($exports as $item) { |
| 56 | |
| 57 | if (!isset($item['options']['created_at_version'])) { |
| 58 | continue; |
| 59 | } |
| 60 | |
| 61 | if(version_compare($item['options']['created_at_version'], $version) < 0) { |
| 62 | return true; |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | return false; |
| 67 | } |
| 68 | |
| 69 | public function wooCommerceExportsExistAndAddonNotInstalled() |
| 70 | { |
| 71 | $exports = new \PMXE_Export_List(); |
| 72 | $exports->getBy('parent_id', 0)->convertRecords(); |
| 73 | |
| 74 | foreach ($exports as $item) { |
| 75 | |
| 76 | if(!isset($item['options']['cpt'])) { |
| 77 | continue; |
| 78 | } |
| 79 | |
| 80 | if(!is_array($item['options']['cpt'])) { |
| 81 | $item['options']['cpt'] = array($item['options']['cpt']); |
| 82 | } |
| 83 | |
| 84 | if ( |
| 85 | ( |
| 86 | ( |
| 87 | in_array('product', $item['options']['cpt']) || |
| 88 | in_array('product_variation', $item['options']['cpt']) || |
| 89 | in_array('shop_order', $item['options']['cpt']) || |
| 90 | in_array('shop_review', $item['options']['cpt']) || |
| 91 | in_array('shop_coupon', $item['options']['cpt']) |
| 92 | ) |
| 93 | && !$this->isWooCommerceAddonActive()) |
| 94 | ) { |
| 95 | return true; |
| 96 | } |
| 97 | |
| 98 | } |
| 99 | |
| 100 | return false; |
| 101 | } |
| 102 | |
| 103 | public function acfExportsExistAndNotInstalled() |
| 104 | { |
| 105 | if($this->isAcfAddonActive()) { |
| 106 | return false; |
| 107 | } |
| 108 | |
| 109 | $exports = new \PMXE_Export_List(); |
| 110 | $exports->getBy('parent_id', 0)->convertRecords(); |
| 111 | |
| 112 | foreach ($exports as $item) { |
| 113 | |
| 114 | if(!empty($item['tpl_data']['options']['acf'])) { |
| 115 | return true; |
| 116 | } |
| 117 | |
| 118 | |
| 119 | } |
| 120 | |
| 121 | return false; |
| 122 | } |
| 123 | |
| 124 | } |