base.php
3 weeks ago
exporter.php
3 weeks ago
helpers.php
3 weeks ago
resolver.php
3 weeks ago
updater.php
3 weeks ago
view.php
3 weeks ago
view.php
46 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Wpae\AddonAPI; |
| 4 | |
| 5 | if ( ! defined( 'ABSPATH' ) ) exit; |
| 6 | |
| 7 | class PMXE_Addon_View { |
| 8 | public PMXE_Addon_Base $addon; |
| 9 | |
| 10 | public function __construct( PMXE_Addon_Base $addon ) { |
| 11 | $this->addon = $addon; |
| 12 | } |
| 13 | |
| 14 | private function renderView( $viewName, $extraData = [] ) { |
| 15 | $groups = $this->addon->getGroupsByExportType(); |
| 16 | $groups = array_map( function ( $group ) { |
| 17 | $group['fields'] = $this->addon->getFieldsByGroup( $group['id'] ); |
| 18 | |
| 19 | return $group; |
| 20 | }, $groups ); |
| 21 | |
| 22 | if ( empty( $groups ) ) { |
| 23 | return; |
| 24 | } |
| 25 | |
| 26 | $data = array_merge( [ |
| 27 | 'groups' => $groups, |
| 28 | 'addon' => $this->addon, |
| 29 | ], $extraData ); |
| 30 | |
| 31 | view( $viewName, $data ); |
| 32 | } |
| 33 | |
| 34 | public function render( $i ) { |
| 35 | $this->renderView( 'fields', [ 'i' => $i ] ); |
| 36 | } |
| 37 | |
| 38 | public function filters() { |
| 39 | $this->renderView( 'filters' ); |
| 40 | } |
| 41 | |
| 42 | public function newField() { |
| 43 | $this->renderView( 'new-field' ); |
| 44 | } |
| 45 | } |
| 46 |