Completed
Branch EDTR/master (83b47e)
by
unknown
25:37 queued 16:41
created

EspressoEventEditor::matchesCurrentRequest()   B

Complexity

Conditions 7
Paths 11

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
nc 11
nop 0
dl 0
loc 13
rs 8.8333
c 0
b 0
f 0
1
<?php
2
3
namespace EventEspresso\core\domain\entities\routing\handlers\admin;
4
5
use EE_Dependency_Map;
6
use EventEspresso\core\domain\entities\routing\data_nodes\domains\EventEditor;
7
use EventEspresso\core\domain\entities\routing\data_nodes\EventEspressoData;
8
use EventEspresso\core\domain\services\assets\EspressoCoreAppAssetManager;
9
use EventEspresso\core\services\graphql\GraphQLManager;
10
11
/**
12
 * Class EspressoEventEditor
13
 * detects and executes logic for the Event Espresso Event Editor
14
 *
15
 * @package EventEspresso\core\domain\entities\routing\admin
16
 * @author  Brent Christensen
17
 * @since   $VID:$
18
 */
19
class EspressoEventEditor extends EspressoEventsAdmin
20
{
21
22
    /**
23
     * returns true if the current request matches this route
24
     *
25
     * @return bool
26
     * @since   $VID:$
27
     */
28
    public function matchesCurrentRequest()
29
    {
30
        global $pagenow;
31
        return parent::matchesCurrentRequest()
32
               && $pagenow
33
               && $pagenow === 'admin.php'
34
               && $this->admin_config->useAdvancedEditor()
35
               && $this->request->getRequestParam('page') === 'espresso_events'
36
               && (
37
                $this->request->getRequestParam('action') === 'create_new'
38
                || $this->request->getRequestParam('action') === 'edit'
39
            );
40
    }
41
42
43
    /**
44
     * @since $VID:$
45
     */
46
    protected function registerDependencies()
47
    {
48
        $this->dependency_map->registerDependencies(
49
            'EventEspresso\core\domain\services\admin\events\editor\EventEditorGraphQLData',
50
            [
51
                'EventEspresso\core\domain\entities\admin\GraphQLData\Datetimes'                 => EE_Dependency_Map::load_from_cache,
52
                'EventEspresso\core\domain\entities\admin\GraphQLData\Prices'                    => EE_Dependency_Map::load_from_cache,
53
                'EventEspresso\core\domain\entities\admin\GraphQLData\PriceTypes'                => EE_Dependency_Map::load_from_cache,
54
                'EventEspresso\core\domain\entities\admin\GraphQLData\Tickets'                   => EE_Dependency_Map::load_from_cache,
55
                'EventEspresso\core\domain\services\admin\events\editor\NewEventDefaultEntities' => EE_Dependency_Map::load_from_cache,
56
                'EventEspresso\core\domain\services\admin\events\editor\EventEntityRelations'    => EE_Dependency_Map::load_from_cache,
57
            ]
58
        );
59
        $this->dependency_map->registerDependencies(
60
            'EventEspresso\core\domain\services\admin\events\editor\EventEntityRelations',
61
            [
62
                'EEM_Datetime'   => EE_Dependency_Map::load_from_cache,
63
                'EEM_Event'      => EE_Dependency_Map::load_from_cache,
64
                'EEM_Price'      => EE_Dependency_Map::load_from_cache,
65
                'EEM_Price_Type' => EE_Dependency_Map::load_from_cache,
66
                'EEM_Ticket'     => EE_Dependency_Map::load_from_cache,
67
            ]
68
        );
69
        $this->dependency_map->registerDependencies(
70
            'EventEspresso\core\domain\services\admin\events\editor\NewEventDefaultEntities',
71
            [
72
                'EEM_Datetime'                                                       => EE_Dependency_Map::load_from_cache,
73
                'EEM_Event'                                                          => EE_Dependency_Map::load_from_cache,
74
                'EEM_Price'                                                          => EE_Dependency_Map::load_from_cache,
75
                'EEM_Price_Type'                                                     => EE_Dependency_Map::load_from_cache,
76
                'EEM_Ticket'                                                         => EE_Dependency_Map::load_from_cache,
77
                'EventEspresso\core\domain\services\admin\entities\DefaultDatetimes' => EE_Dependency_Map::load_from_cache,
78
            ]
79
        );
80
        $this->dependency_map->registerDependencies(
81
            'EventEspresso\core\domain\services\admin\entities\DefaultDatetimes',
82
            [
83
                'EventEspresso\core\domain\services\admin\entities\DefaultTickets' => EE_Dependency_Map::load_from_cache,
84
                'EEM_Datetime'                                                     => EE_Dependency_Map::load_from_cache,
85
            ]
86
        );
87
        $this->dependency_map->registerDependencies(
88
            'EventEspresso\core\domain\services\admin\entities\DefaultTickets',
89
            [
90
                'EventEspresso\core\domain\services\admin\entities\DefaultPrices' => EE_Dependency_Map::load_from_cache,
91
                'EEM_Ticket'                                                      => EE_Dependency_Map::load_from_cache,
92
            ]
93
        );
94
        $this->dependency_map->registerDependencies(
95
            'EventEspresso\core\domain\services\admin\entities\DefaultPrices',
96
            [
97
                'EEM_Price'      => EE_Dependency_Map::load_from_cache,
98
                'EEM_Price_Type' => EE_Dependency_Map::load_from_cache,
99
            ]
100
        );
101
        $this->dependency_map->registerDependencies(
102
            'EventEspresso\core\domain\entities\routing\data_nodes\domains\EventEditor',
103
            [
104
                'EventEspresso\core\domain\services\admin\events\editor\EventEditorGraphQLData' => EE_Dependency_Map::load_from_cache,
105
                'EventEspresso\core\services\json\JsonDataNodeValidator'                        => EE_Dependency_Map::load_from_cache,
106
            ]
107
        );
108
        /** @var EventEspressoData $primary_data_node */
109
        $primary_data_node = $this->loader->getShared(
110
            'EventEspresso\core\domain\entities\routing\data_nodes\EventEspressoData'
111
        );
112
        $primary_data_node->setTargetScript(EspressoCoreAppAssetManager::JS_HANDLE_EDITOR);
113
        /** @var EventEditor $data_node */
114
        $data_node = $this->loader->getShared(
115
            'EventEspresso\core\domain\entities\routing\data_nodes\domains\EventEditor'
116
        );
117
        $this->setDataNode($data_node);
118
    }
119
120
121
    /**
122
     * implements logic required to run during request
123
     *
124
     * @return bool
125
     * @since   $VID:$
126
     */
127
    protected function requestHandler()
128
    {
129
        /** @var GraphQLManager $graphQL_manager */
130
        $graphQL_manager = $this->loader->getShared('EventEspresso\core\services\graphql\GraphQLManager');
131
        $graphQL_manager->init();
132
        $this->asset_manager = $this->loader->getShared(
133
            'EventEspresso\core\domain\services\assets\EspressoCoreAppAssetManager'
134
        );
135
        add_action('admin_enqueue_scripts', [$this->asset_manager, 'enqueueBrowserAssets'], 100);
136
        return true;
137
    }
138
}
139