Completed
Pull Request — master (#378)
by Darren
19:13
created
core/services/commands/middleware/CapChecker.php 1 patch
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -24,37 +24,37 @@
 block discarded – undo
24 24
 class CapChecker implements CommandBusMiddlewareInterface
25 25
 {
26 26
 
27
-    /**
28
-     * @type CapabilitiesCheckerInterface $capabilities_checker
29
-     */
30
-    private $capabilities_checker;
31
-
32
-
33
-    /**
34
-     * CapChecker constructor
35
-     *
36
-     * @param CapabilitiesCheckerInterface $capabilities_checker
37
-     */
38
-    public function __construct(CapabilitiesCheckerInterface $capabilities_checker)
39
-    {
40
-        $this->capabilities_checker = $capabilities_checker;
41
-    }
42
-
43
-
44
-    /**
45
-     * @param CommandInterface $command
46
-     * @param Closure          $next
47
-     * @return mixed
48
-     * @throws InvalidClassException
49
-     * @throws InsufficientPermissionsException
50
-     */
51
-    public function handle(CommandInterface $command, Closure $next)
52
-    {
53
-        if ($command instanceof CommandRequiresCapCheckInterface) {
54
-            $this->capabilities_checker->processCapCheck(
55
-                $command->getCapCheck()
56
-            );
57
-        }
58
-        return $next($command);
59
-    }
27
+	/**
28
+	 * @type CapabilitiesCheckerInterface $capabilities_checker
29
+	 */
30
+	private $capabilities_checker;
31
+
32
+
33
+	/**
34
+	 * CapChecker constructor
35
+	 *
36
+	 * @param CapabilitiesCheckerInterface $capabilities_checker
37
+	 */
38
+	public function __construct(CapabilitiesCheckerInterface $capabilities_checker)
39
+	{
40
+		$this->capabilities_checker = $capabilities_checker;
41
+	}
42
+
43
+
44
+	/**
45
+	 * @param CommandInterface $command
46
+	 * @param Closure          $next
47
+	 * @return mixed
48
+	 * @throws InvalidClassException
49
+	 * @throws InsufficientPermissionsException
50
+	 */
51
+	public function handle(CommandInterface $command, Closure $next)
52
+	{
53
+		if ($command instanceof CommandRequiresCapCheckInterface) {
54
+			$this->capabilities_checker->processCapCheck(
55
+				$command->getCapCheck()
56
+			);
57
+		}
58
+		return $next($command);
59
+	}
60 60
 }
Please login to merge, or discard this patch.
core/services/commands/CommandHandlerManager.php 2 patches
Indentation   +93 added lines, -93 removed lines patch added patch discarded remove patch
@@ -18,104 +18,104 @@
 block discarded – undo
18 18
 class CommandHandlerManager implements CommandHandlerManagerInterface
19 19
 {
20 20
 
21
-    /**
22
-     * @var CommandHandlerInterface[] $command_handlers
23
-     */
24
-    protected $command_handlers;
21
+	/**
22
+	 * @var CommandHandlerInterface[] $command_handlers
23
+	 */
24
+	protected $command_handlers;
25 25
 
26
-    /**
27
-     * @type LoaderInterface $loader
28
-     */
29
-    private $loader;
26
+	/**
27
+	 * @type LoaderInterface $loader
28
+	 */
29
+	private $loader;
30 30
 
31 31
 
32
-    /**
33
-     * CommandHandlerManager constructor
34
-     *
35
-     * @param LoaderInterface $loader
36
-     */
37
-    public function __construct(LoaderInterface $loader)
38
-    {
39
-        $this->loader = $loader;
40
-    }
32
+	/**
33
+	 * CommandHandlerManager constructor
34
+	 *
35
+	 * @param LoaderInterface $loader
36
+	 */
37
+	public function __construct(LoaderInterface $loader)
38
+	{
39
+		$this->loader = $loader;
40
+	}
41 41
 
42 42
 
43
-    /**
44
-     * By default, Commands and CommandHandlers would normally
45
-     * reside in the same folder under the same namespace,
46
-     * and the names of the two classes would only differ in that
47
-     * one ends in "Command" and the other ends in "CommandHandler".
48
-     * However, if you wanted to utilize a CommandHandler from somewhere else,
49
-     * then this method allows you to add that CommandHandler and specify the FQCN
50
-     * (Fully Qualified ClassName) for the Command class that it should be used for.
51
-     * For example:
52
-     *      by default the "Vendor\some\namespace\DoSomethingCommand"
53
-     *      would resolve to using "Vendor\some\namespace\DoSomethingCommandHandler"
54
-     *      but if you wanted to instead process that commend using:
55
-     *      "Vendor\a\totally\different\namespace\for\DoSomethingCommandHandler"
56
-     *      then the following code:
57
-     *      $CommandHandlerManager = $this->loader->getShared( 'CommandHandlerManagerInterface' );
58
-     *      $CommandHandlerManager->addCommandHandler(
59
-     *          new Vendor\a\totally\different\namespace\for\DoSomethingCommandHandler(),
60
-     *          'Vendor\some\namespace\DoSomethingCommand'
61
-     *      );
62
-     *      would result in the alternate CommandHandler being used to process that Command
63
-     *
64
-     * @param CommandHandlerInterface $command_handler
65
-     * @param string                  $fqcn_for_command Fully Qualified ClassName for Command
66
-     * @return void
67
-     * @throws InvalidCommandHandlerException
68
-     */
69
-    public function addCommandHandler(CommandHandlerInterface $command_handler, $fqcn_for_command = '')
70
-    {
71
-        $command = ! empty($fqcn_for_command)
72
-            ? $fqcn_for_command
73
-            : str_replace('CommandHandler', 'Command', get_class($command_handler));
74
-        if (empty($command)) {
75
-            throw new InvalidCommandHandlerException($command);
76
-        }
77
-        $this->command_handlers[$command] = $command_handler;
78
-    }
43
+	/**
44
+	 * By default, Commands and CommandHandlers would normally
45
+	 * reside in the same folder under the same namespace,
46
+	 * and the names of the two classes would only differ in that
47
+	 * one ends in "Command" and the other ends in "CommandHandler".
48
+	 * However, if you wanted to utilize a CommandHandler from somewhere else,
49
+	 * then this method allows you to add that CommandHandler and specify the FQCN
50
+	 * (Fully Qualified ClassName) for the Command class that it should be used for.
51
+	 * For example:
52
+	 *      by default the "Vendor\some\namespace\DoSomethingCommand"
53
+	 *      would resolve to using "Vendor\some\namespace\DoSomethingCommandHandler"
54
+	 *      but if you wanted to instead process that commend using:
55
+	 *      "Vendor\a\totally\different\namespace\for\DoSomethingCommandHandler"
56
+	 *      then the following code:
57
+	 *      $CommandHandlerManager = $this->loader->getShared( 'CommandHandlerManagerInterface' );
58
+	 *      $CommandHandlerManager->addCommandHandler(
59
+	 *          new Vendor\a\totally\different\namespace\for\DoSomethingCommandHandler(),
60
+	 *          'Vendor\some\namespace\DoSomethingCommand'
61
+	 *      );
62
+	 *      would result in the alternate CommandHandler being used to process that Command
63
+	 *
64
+	 * @param CommandHandlerInterface $command_handler
65
+	 * @param string                  $fqcn_for_command Fully Qualified ClassName for Command
66
+	 * @return void
67
+	 * @throws InvalidCommandHandlerException
68
+	 */
69
+	public function addCommandHandler(CommandHandlerInterface $command_handler, $fqcn_for_command = '')
70
+	{
71
+		$command = ! empty($fqcn_for_command)
72
+			? $fqcn_for_command
73
+			: str_replace('CommandHandler', 'Command', get_class($command_handler));
74
+		if (empty($command)) {
75
+			throw new InvalidCommandHandlerException($command);
76
+		}
77
+		$this->command_handlers[$command] = $command_handler;
78
+	}
79 79
 
80 80
 
81
-    /**
82
-     * @param CommandInterface    $command
83
-     * @param CommandBusInterface $command_bus
84
-     * @return mixed
85
-     * @throws DomainException
86
-     * @throws CommandHandlerNotFoundException
87
-     */
88
-    public function getCommandHandler(CommandInterface $command, CommandBusInterface $command_bus = null)
89
-    {
90
-        $command_name = get_class($command);
91
-        $command_handler = apply_filters(
92
-            'FHEE__EventEspresso_core_services_commands_CommandHandlerManager__getCommandHandler__command_handler',
93
-            str_replace('Command', 'CommandHandler', $command_name),
94
-            $command
95
-        );
96
-        $handler = null;
97
-        // has a command handler already been set for this class ?
98
-        // if not, can we find one via the FQCN ?
99
-        if (isset($this->command_handlers[$command_name])) {
100
-            $handler = $this->command_handlers[$command_name];
101
-        } else if (class_exists($command_handler)) {
102
-            $handler = $this->loader->getShared($command_handler);
103
-        }
104
-        // if Handler requires an instance of the CommandBus, but that has not yet been set
105
-        if ($handler instanceof CompositeCommandHandler && ! $handler->commandBus() instanceof CommandBusInterface) {
106
-            if (! $command_bus instanceof CommandBusInterface) {
107
-                throw new DomainException(
108
-                    esc_html__(
109
-                        'CompositeCommandHandler classes require an instance of the CommandBus.',
110
-                        'event_espresso'
111
-                    )
112
-                );
113
-            }
114
-            $handler->setCommandBus($command_bus);
115
-        }
116
-        if ($handler instanceof CommandHandlerInterface) {
117
-            return $handler;
118
-        }
119
-        throw new CommandHandlerNotFoundException($command_handler);
120
-    }
81
+	/**
82
+	 * @param CommandInterface    $command
83
+	 * @param CommandBusInterface $command_bus
84
+	 * @return mixed
85
+	 * @throws DomainException
86
+	 * @throws CommandHandlerNotFoundException
87
+	 */
88
+	public function getCommandHandler(CommandInterface $command, CommandBusInterface $command_bus = null)
89
+	{
90
+		$command_name = get_class($command);
91
+		$command_handler = apply_filters(
92
+			'FHEE__EventEspresso_core_services_commands_CommandHandlerManager__getCommandHandler__command_handler',
93
+			str_replace('Command', 'CommandHandler', $command_name),
94
+			$command
95
+		);
96
+		$handler = null;
97
+		// has a command handler already been set for this class ?
98
+		// if not, can we find one via the FQCN ?
99
+		if (isset($this->command_handlers[$command_name])) {
100
+			$handler = $this->command_handlers[$command_name];
101
+		} else if (class_exists($command_handler)) {
102
+			$handler = $this->loader->getShared($command_handler);
103
+		}
104
+		// if Handler requires an instance of the CommandBus, but that has not yet been set
105
+		if ($handler instanceof CompositeCommandHandler && ! $handler->commandBus() instanceof CommandBusInterface) {
106
+			if (! $command_bus instanceof CommandBusInterface) {
107
+				throw new DomainException(
108
+					esc_html__(
109
+						'CompositeCommandHandler classes require an instance of the CommandBus.',
110
+						'event_espresso'
111
+					)
112
+				);
113
+			}
114
+			$handler->setCommandBus($command_bus);
115
+		}
116
+		if ($handler instanceof CommandHandlerInterface) {
117
+			return $handler;
118
+		}
119
+		throw new CommandHandlerNotFoundException($command_handler);
120
+	}
121 121
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -103,7 +103,7 @@
 block discarded – undo
103 103
         }
104 104
         // if Handler requires an instance of the CommandBus, but that has not yet been set
105 105
         if ($handler instanceof CompositeCommandHandler && ! $handler->commandBus() instanceof CommandBusInterface) {
106
-            if (! $command_bus instanceof CommandBusInterface) {
106
+            if ( ! $command_bus instanceof CommandBusInterface) {
107 107
                 throw new DomainException(
108 108
                     esc_html__(
109 109
                         'CompositeCommandHandler classes require an instance of the CommandBus.',
Please login to merge, or discard this patch.
core/services/commands/ticket/CreateTicketLineItemCommandHandler.php 2 patches
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -19,41 +19,41 @@
 block discarded – undo
19 19
 {
20 20
 
21 21
 
22
-    /**
23
-     * @var CreateTicketLineItemService $factory
24
-     */
25
-    private $factory;
26
-
27
-
28
-    /**
29
-     * Command constructor
30
-     *
31
-     * @param CreateTicketLineItemService $factory
32
-     */
33
-    public function __construct(CreateTicketLineItemService $factory)
34
-    {
35
-        $this->factory = $factory;
36
-    }
37
-
38
-
39
-    /**
40
-     * @param \EventEspresso\core\services\commands\CommandInterface $command
41
-     * @return \EE_Line_Item
42
-     * @throws \EventEspresso\core\exceptions\InvalidEntityException
43
-     * @throws \EventEspresso\core\exceptions\UnexpectedEntityException
44
-     * @throws \EE_Error
45
-     */
46
-    public function handle(CommandInterface $command)
47
-    {
48
-        /** @var CreateTicketLineItemCommand $command */
49
-        if (! $command instanceof CreateTicketLineItemCommand) {
50
-            throw new InvalidEntityException(get_class($command), 'CreateTicketLineItemCommand');
51
-        }
52
-        // create new line item for ticket
53
-        return $this->factory->create(
54
-            $command->transaction(),
55
-            $command->ticket(),
56
-            $command->quantity()
57
-        );
58
-    }
22
+	/**
23
+	 * @var CreateTicketLineItemService $factory
24
+	 */
25
+	private $factory;
26
+
27
+
28
+	/**
29
+	 * Command constructor
30
+	 *
31
+	 * @param CreateTicketLineItemService $factory
32
+	 */
33
+	public function __construct(CreateTicketLineItemService $factory)
34
+	{
35
+		$this->factory = $factory;
36
+	}
37
+
38
+
39
+	/**
40
+	 * @param \EventEspresso\core\services\commands\CommandInterface $command
41
+	 * @return \EE_Line_Item
42
+	 * @throws \EventEspresso\core\exceptions\InvalidEntityException
43
+	 * @throws \EventEspresso\core\exceptions\UnexpectedEntityException
44
+	 * @throws \EE_Error
45
+	 */
46
+	public function handle(CommandInterface $command)
47
+	{
48
+		/** @var CreateTicketLineItemCommand $command */
49
+		if (! $command instanceof CreateTicketLineItemCommand) {
50
+			throw new InvalidEntityException(get_class($command), 'CreateTicketLineItemCommand');
51
+		}
52
+		// create new line item for ticket
53
+		return $this->factory->create(
54
+			$command->transaction(),
55
+			$command->ticket(),
56
+			$command->quantity()
57
+		);
58
+	}
59 59
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -52,7 +52,7 @@
 block discarded – undo
52 52
     public function handle(CommandInterface $command)
53 53
     {
54 54
         /** @var CreateTicketLineItemCommand $command */
55
-        if (! $command instanceof CreateTicketLineItemCommand) {
55
+        if ( ! $command instanceof CreateTicketLineItemCommand) {
56 56
             throw new InvalidEntityException(get_class($command), 'CreateTicketLineItemCommand');
57 57
         }
58 58
         // create new line item for ticket
Please login to merge, or discard this patch.
core/services/commands/ticket/CancelTicketLineItemCommand.php 1 patch
Indentation   +108 added lines, -108 removed lines patch added patch discarded remove patch
@@ -16,112 +16,112 @@
 block discarded – undo
16 16
 {
17 17
 
18 18
 
19
-    /**
20
-     * @var \EE_Transaction $transaction
21
-     */
22
-    private $transaction;
23
-
24
-    /**
25
-     * @var \EE_Ticket $ticket
26
-     */
27
-    private $ticket;
28
-
29
-    /**
30
-     * @var \EE_Line_Item $ticket_line_item
31
-     */
32
-    protected $ticket_line_item;
33
-
34
-    /**
35
-     * @var int $quantity
36
-     */
37
-    protected $quantity;
38
-
39
-
40
-    /**
41
-     * @param \EE_Registration $registration
42
-     * @param int              $quantity
43
-     */
44
-    public static function fromRegistration(\EE_Registration $registration, $quantity = 1)
45
-    {
46
-        new self(
47
-            $registration->transaction(),
48
-            $registration->ticket(),
49
-            1,
50
-            $registration->ticket_line_item()
51
-        );
52
-    }
53
-
54
-
55
-    /**
56
-     * @param \EE_Line_Item $ticket_line_item
57
-     * @param int           $quantity
58
-     */
59
-    public static function fromTicketLineItem(
60
-        \EE_Line_Item $ticket_line_item,
61
-        $quantity = 1
62
-    ) {
63
-        new self(
64
-            $ticket_line_item->transaction(),
65
-            $ticket_line_item->ticket(),
66
-            $quantity,
67
-            $ticket_line_item
68
-        );
69
-    }
70
-
71
-
72
-    /**
73
-     * CancelTicketLineItemCommand constructor.
74
-     *
75
-     * @param \EE_Transaction $transaction
76
-     * @param \EE_Ticket      $ticket
77
-     * @param int             $quantity
78
-     * @param \EE_Line_Item   $ticket_line_item
79
-     */
80
-    public function __construct(
81
-        \EE_Transaction $transaction,
82
-        \EE_Ticket $ticket,
83
-        $quantity = 1,
84
-        \EE_Line_Item $ticket_line_item = null
85
-    ) {
86
-        $this->transaction = $transaction;
87
-        $this->ticket = $ticket;
88
-        $this->quantity = min(1, absint($quantity));
89
-        $this->ticket_line_item = $ticket_line_item;
90
-    }
91
-
92
-
93
-    /**
94
-     * @return \EE_Transaction
95
-     */
96
-    public function transaction()
97
-    {
98
-        return $this->transaction;
99
-    }
100
-
101
-
102
-    /**
103
-     * @return \EE_Ticket
104
-     */
105
-    public function ticket()
106
-    {
107
-        return $this->ticket;
108
-    }
109
-
110
-
111
-    /**
112
-     * @return \EE_Line_Item
113
-     */
114
-    public function ticketLineItem()
115
-    {
116
-        return $this->ticket_line_item;
117
-    }
118
-
119
-
120
-    /**
121
-     * @return int
122
-     */
123
-    public function quantity()
124
-    {
125
-        return $this->quantity;
126
-    }
19
+	/**
20
+	 * @var \EE_Transaction $transaction
21
+	 */
22
+	private $transaction;
23
+
24
+	/**
25
+	 * @var \EE_Ticket $ticket
26
+	 */
27
+	private $ticket;
28
+
29
+	/**
30
+	 * @var \EE_Line_Item $ticket_line_item
31
+	 */
32
+	protected $ticket_line_item;
33
+
34
+	/**
35
+	 * @var int $quantity
36
+	 */
37
+	protected $quantity;
38
+
39
+
40
+	/**
41
+	 * @param \EE_Registration $registration
42
+	 * @param int              $quantity
43
+	 */
44
+	public static function fromRegistration(\EE_Registration $registration, $quantity = 1)
45
+	{
46
+		new self(
47
+			$registration->transaction(),
48
+			$registration->ticket(),
49
+			1,
50
+			$registration->ticket_line_item()
51
+		);
52
+	}
53
+
54
+
55
+	/**
56
+	 * @param \EE_Line_Item $ticket_line_item
57
+	 * @param int           $quantity
58
+	 */
59
+	public static function fromTicketLineItem(
60
+		\EE_Line_Item $ticket_line_item,
61
+		$quantity = 1
62
+	) {
63
+		new self(
64
+			$ticket_line_item->transaction(),
65
+			$ticket_line_item->ticket(),
66
+			$quantity,
67
+			$ticket_line_item
68
+		);
69
+	}
70
+
71
+
72
+	/**
73
+	 * CancelTicketLineItemCommand constructor.
74
+	 *
75
+	 * @param \EE_Transaction $transaction
76
+	 * @param \EE_Ticket      $ticket
77
+	 * @param int             $quantity
78
+	 * @param \EE_Line_Item   $ticket_line_item
79
+	 */
80
+	public function __construct(
81
+		\EE_Transaction $transaction,
82
+		\EE_Ticket $ticket,
83
+		$quantity = 1,
84
+		\EE_Line_Item $ticket_line_item = null
85
+	) {
86
+		$this->transaction = $transaction;
87
+		$this->ticket = $ticket;
88
+		$this->quantity = min(1, absint($quantity));
89
+		$this->ticket_line_item = $ticket_line_item;
90
+	}
91
+
92
+
93
+	/**
94
+	 * @return \EE_Transaction
95
+	 */
96
+	public function transaction()
97
+	{
98
+		return $this->transaction;
99
+	}
100
+
101
+
102
+	/**
103
+	 * @return \EE_Ticket
104
+	 */
105
+	public function ticket()
106
+	{
107
+		return $this->ticket;
108
+	}
109
+
110
+
111
+	/**
112
+	 * @return \EE_Line_Item
113
+	 */
114
+	public function ticketLineItem()
115
+	{
116
+		return $this->ticket_line_item;
117
+	}
118
+
119
+
120
+	/**
121
+	 * @return int
122
+	 */
123
+	public function quantity()
124
+	{
125
+		return $this->quantity;
126
+	}
127 127
 }
Please login to merge, or discard this patch.
core/services/commands/ticket/CancelTicketLineItemCommandHandler.php 2 patches
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -22,38 +22,38 @@
 block discarded – undo
22 22
 {
23 23
 
24 24
 
25
-    /**
26
-     * @var CancelTicketLineItemService $cancel_ticket_line_item_service
27
-     */
28
-    private $cancel_ticket_line_item_service;
29
-
30
-
31
-    /**
32
-     * Command constructor
33
-     *
34
-     * @param CancelTicketLineItemService $cancel_ticket_line_item_service
35
-     */
36
-    public function __construct(CancelTicketLineItemService $cancel_ticket_line_item_service)
37
-    {
38
-        $this->cancel_ticket_line_item_service = $cancel_ticket_line_item_service;
39
-    }
40
-
41
-
42
-    /**
43
-     * @param \EventEspresso\core\services\commands\CommandInterface $command
44
-     * @return mixed
45
-     */
46
-    public function handle(CommandInterface $command)
47
-    {
48
-        /** @var CancelTicketLineItemCommand $command */
49
-        if (! $command instanceof CancelTicketLineItemCommand) {
50
-            throw new InvalidEntityException(get_class($command), 'CancelTicketLineItemCommand');
51
-        }
52
-        return $this->cancel_ticket_line_item_service->cancel(
53
-            $command->transaction(),
54
-            $command->ticket(),
55
-            $command->quantity(),
56
-            $command->ticketLineItem()
57
-        );
58
-    }
25
+	/**
26
+	 * @var CancelTicketLineItemService $cancel_ticket_line_item_service
27
+	 */
28
+	private $cancel_ticket_line_item_service;
29
+
30
+
31
+	/**
32
+	 * Command constructor
33
+	 *
34
+	 * @param CancelTicketLineItemService $cancel_ticket_line_item_service
35
+	 */
36
+	public function __construct(CancelTicketLineItemService $cancel_ticket_line_item_service)
37
+	{
38
+		$this->cancel_ticket_line_item_service = $cancel_ticket_line_item_service;
39
+	}
40
+
41
+
42
+	/**
43
+	 * @param \EventEspresso\core\services\commands\CommandInterface $command
44
+	 * @return mixed
45
+	 */
46
+	public function handle(CommandInterface $command)
47
+	{
48
+		/** @var CancelTicketLineItemCommand $command */
49
+		if (! $command instanceof CancelTicketLineItemCommand) {
50
+			throw new InvalidEntityException(get_class($command), 'CancelTicketLineItemCommand');
51
+		}
52
+		return $this->cancel_ticket_line_item_service->cancel(
53
+			$command->transaction(),
54
+			$command->ticket(),
55
+			$command->quantity(),
56
+			$command->ticketLineItem()
57
+		);
58
+	}
59 59
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@
 block discarded – undo
51 51
     public function handle(CommandInterface $command)
52 52
     {
53 53
         /** @var CancelTicketLineItemCommand $command */
54
-        if (! $command instanceof CancelTicketLineItemCommand) {
54
+        if ( ! $command instanceof CancelTicketLineItemCommand) {
55 55
             throw new InvalidEntityException(get_class($command), 'CancelTicketLineItemCommand');
56 56
         }
57 57
         return $this->cancel_ticket_line_item_service->cancel(
Please login to merge, or discard this patch.
core/services/commands/ticket/CreateTicketLineItemCommand.php 1 patch
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -16,77 +16,77 @@
 block discarded – undo
16 16
 {
17 17
 
18 18
 
19
-    /**
20
-     * @var \EE_Transaction $transaction
21
-     */
22
-    private $transaction;
23
-
24
-    /**
25
-     * @var \EE_Ticket $ticket
26
-     */
27
-    private $ticket;
28
-
29
-    /**
30
-     * @var int $quantity
31
-     */
32
-    private $quantity = 1;
33
-
34
-    /**
35
-     * @var \EE_Line_Item $ticket_line_item
36
-     */
37
-    protected $ticket_line_item;
38
-
39
-
40
-    /**
41
-     * CreateTicketLineItemCommand constructor.
42
-     *
43
-     * @param \EE_Transaction $transaction
44
-     * @param \EE_Ticket      $ticket
45
-     * @param int             $quantity
46
-     */
47
-    public function __construct(
48
-        \EE_Transaction $transaction,
49
-        \EE_Ticket $ticket,
50
-        $quantity = 1
51
-    ) {
52
-        $this->transaction = $transaction;
53
-        $this->ticket = $ticket;
54
-        $this->quantity = $quantity;
55
-    }
56
-
57
-
58
-    /**
59
-     * @return \EE_Transaction
60
-     */
61
-    public function transaction()
62
-    {
63
-        return $this->transaction;
64
-    }
65
-
66
-
67
-    /**
68
-     * @return \EE_Ticket
69
-     */
70
-    public function ticket()
71
-    {
72
-        return $this->ticket;
73
-    }
74
-
75
-
76
-    /**
77
-     * @return int
78
-     */
79
-    public function quantity()
80
-    {
81
-        return $this->quantity;
82
-    }
83
-
84
-
85
-    /**
86
-     * @return \EE_Line_Item
87
-     */
88
-    public function ticketLineItem()
89
-    {
90
-        return $this->ticket_line_item;
91
-    }
19
+	/**
20
+	 * @var \EE_Transaction $transaction
21
+	 */
22
+	private $transaction;
23
+
24
+	/**
25
+	 * @var \EE_Ticket $ticket
26
+	 */
27
+	private $ticket;
28
+
29
+	/**
30
+	 * @var int $quantity
31
+	 */
32
+	private $quantity = 1;
33
+
34
+	/**
35
+	 * @var \EE_Line_Item $ticket_line_item
36
+	 */
37
+	protected $ticket_line_item;
38
+
39
+
40
+	/**
41
+	 * CreateTicketLineItemCommand constructor.
42
+	 *
43
+	 * @param \EE_Transaction $transaction
44
+	 * @param \EE_Ticket      $ticket
45
+	 * @param int             $quantity
46
+	 */
47
+	public function __construct(
48
+		\EE_Transaction $transaction,
49
+		\EE_Ticket $ticket,
50
+		$quantity = 1
51
+	) {
52
+		$this->transaction = $transaction;
53
+		$this->ticket = $ticket;
54
+		$this->quantity = $quantity;
55
+	}
56
+
57
+
58
+	/**
59
+	 * @return \EE_Transaction
60
+	 */
61
+	public function transaction()
62
+	{
63
+		return $this->transaction;
64
+	}
65
+
66
+
67
+	/**
68
+	 * @return \EE_Ticket
69
+	 */
70
+	public function ticket()
71
+	{
72
+		return $this->ticket;
73
+	}
74
+
75
+
76
+	/**
77
+	 * @return int
78
+	 */
79
+	public function quantity()
80
+	{
81
+		return $this->quantity;
82
+	}
83
+
84
+
85
+	/**
86
+	 * @return \EE_Line_Item
87
+	 */
88
+	public function ticketLineItem()
89
+	{
90
+		return $this->ticket_line_item;
91
+	}
92 92
 }
Please login to merge, or discard this patch.
core/services/commands/attendee/CreateAttendeeCommandHandler.php 2 patches
Indentation   +124 added lines, -124 removed lines patch added patch discarded remove patch
@@ -21,138 +21,138 @@
 block discarded – undo
21 21
 {
22 22
 
23 23
 
24
-    /**
25
-     * @var EEM_Attendee $attendee_model
26
-     */
27
-    protected $attendee_model;
24
+	/**
25
+	 * @var EEM_Attendee $attendee_model
26
+	 */
27
+	protected $attendee_model;
28 28
 
29 29
 
30
-    /**
31
-     * @param EEM_Attendee $attendee_model
32
-     */
33
-    public function __construct(EEM_Attendee $attendee_model)
34
-    {
35
-        $this->attendee_model = $attendee_model;
36
-    }
30
+	/**
31
+	 * @param EEM_Attendee $attendee_model
32
+	 */
33
+	public function __construct(EEM_Attendee $attendee_model)
34
+	{
35
+		$this->attendee_model = $attendee_model;
36
+	}
37 37
 
38 38
 
39
-    /**
40
-     * @param CommandInterface $command
41
-     * @return EE_Attendee
42
-     * @throws EE_Error
43
-     * @throws InvalidEntityException
44
-     */
45
-    public function handle(CommandInterface $command)
46
-    {
47
-        /** @var CreateAttendeeCommand $command */
48
-        if (! $command instanceof CreateAttendeeCommand) {
49
-            throw new InvalidEntityException(get_class($command), 'CreateAttendeeCommand');
50
-        }
51
-        // have we met before?
52
-        $attendee = $this->findExistingAttendee(
53
-            $command->registration(),
54
-            $command->attendeeDetails()
55
-        );
56
-        // did we find an already existing record for this attendee ?
57
-        if ($attendee instanceof EE_Attendee) {
58
-            $attendee = $this->updateExistingAttendeeData(
59
-                $attendee,
60
-                $command->attendeeDetails()
61
-            );
62
-        } else {
63
-            $attendee = $this->createNewAttendee(
64
-                $command->registration(),
65
-                $command->attendeeDetails()
66
-            );
67
-        }
68
-        return $attendee;
69
-    }
39
+	/**
40
+	 * @param CommandInterface $command
41
+	 * @return EE_Attendee
42
+	 * @throws EE_Error
43
+	 * @throws InvalidEntityException
44
+	 */
45
+	public function handle(CommandInterface $command)
46
+	{
47
+		/** @var CreateAttendeeCommand $command */
48
+		if (! $command instanceof CreateAttendeeCommand) {
49
+			throw new InvalidEntityException(get_class($command), 'CreateAttendeeCommand');
50
+		}
51
+		// have we met before?
52
+		$attendee = $this->findExistingAttendee(
53
+			$command->registration(),
54
+			$command->attendeeDetails()
55
+		);
56
+		// did we find an already existing record for this attendee ?
57
+		if ($attendee instanceof EE_Attendee) {
58
+			$attendee = $this->updateExistingAttendeeData(
59
+				$attendee,
60
+				$command->attendeeDetails()
61
+			);
62
+		} else {
63
+			$attendee = $this->createNewAttendee(
64
+				$command->registration(),
65
+				$command->attendeeDetails()
66
+			);
67
+		}
68
+		return $attendee;
69
+	}
70 70
 
71 71
 
72
-    /**
73
-     * find_existing_attendee
74
-     *
75
-     * @param EE_Registration $registration
76
-     * @param  array          $attendee_data
77
-     * @return EE_Attendee
78
-     */
79
-    private function findExistingAttendee(EE_Registration $registration, array $attendee_data)
80
-    {
81
-        $existing_attendee = null;
82
-        // does this attendee already exist in the db ?
83
-        // we're searching using a combination of first name, last name, AND email address
84
-        $ATT_fname = ! empty($attendee_data['ATT_fname'])
85
-            ? $attendee_data['ATT_fname']
86
-            : '';
87
-        $ATT_lname = ! empty($attendee_data['ATT_lname'])
88
-            ? $attendee_data['ATT_lname']
89
-            : '';
90
-        $ATT_email = ! empty($attendee_data['ATT_email'])
91
-            ? $attendee_data['ATT_email']
92
-            : '';
93
-        // but only if those have values
94
-        if ($ATT_fname && $ATT_lname && $ATT_email) {
95
-            $existing_attendee = $this->attendee_model->find_existing_attendee(
96
-                array(
97
-                    'ATT_fname' => $ATT_fname,
98
-                    'ATT_lname' => $ATT_lname,
99
-                    'ATT_email' => $ATT_email,
100
-                )
101
-            );
102
-        }
103
-        return apply_filters(
104
-            'FHEE_EventEspresso_core_services_commands_attendee_CreateAttendeeCommandHandler__findExistingAttendee__existing_attendee',
105
-            $existing_attendee,
106
-            $registration,
107
-            $attendee_data
108
-        );
109
-    }
72
+	/**
73
+	 * find_existing_attendee
74
+	 *
75
+	 * @param EE_Registration $registration
76
+	 * @param  array          $attendee_data
77
+	 * @return EE_Attendee
78
+	 */
79
+	private function findExistingAttendee(EE_Registration $registration, array $attendee_data)
80
+	{
81
+		$existing_attendee = null;
82
+		// does this attendee already exist in the db ?
83
+		// we're searching using a combination of first name, last name, AND email address
84
+		$ATT_fname = ! empty($attendee_data['ATT_fname'])
85
+			? $attendee_data['ATT_fname']
86
+			: '';
87
+		$ATT_lname = ! empty($attendee_data['ATT_lname'])
88
+			? $attendee_data['ATT_lname']
89
+			: '';
90
+		$ATT_email = ! empty($attendee_data['ATT_email'])
91
+			? $attendee_data['ATT_email']
92
+			: '';
93
+		// but only if those have values
94
+		if ($ATT_fname && $ATT_lname && $ATT_email) {
95
+			$existing_attendee = $this->attendee_model->find_existing_attendee(
96
+				array(
97
+					'ATT_fname' => $ATT_fname,
98
+					'ATT_lname' => $ATT_lname,
99
+					'ATT_email' => $ATT_email,
100
+				)
101
+			);
102
+		}
103
+		return apply_filters(
104
+			'FHEE_EventEspresso_core_services_commands_attendee_CreateAttendeeCommandHandler__findExistingAttendee__existing_attendee',
105
+			$existing_attendee,
106
+			$registration,
107
+			$attendee_data
108
+		);
109
+	}
110 110
 
111 111
 
112
-    /**
113
-     * _update_existing_attendee_data
114
-     * in case it has changed since last time they registered for an event
115
-     *
116
-     * @param EE_Attendee $existing_attendee
117
-     * @param  array      $attendee_data
118
-     * @return EE_Attendee
119
-     * @throws EE_Error
120
-     */
121
-    private function updateExistingAttendeeData(EE_Attendee $existing_attendee, array $attendee_data)
122
-    {
123
-        // first remove fname, lname, and email from attendee data
124
-        // because these properties will be exactly the same as the returned attendee object,
125
-        // since they were used in the query to get the attendee object in the first place
126
-        $dont_set = array('ATT_fname', 'ATT_lname', 'ATT_email');
127
-        // now loop thru what's left and add to attendee CPT
128
-        foreach ($attendee_data as $property_name => $property_value) {
129
-            if (! in_array($property_name, $dont_set, true)
130
-                && $this->attendee_model->has_field($property_name)
131
-            ) {
132
-                $existing_attendee->set($property_name, $property_value);
133
-            }
134
-        }
135
-        // better save that now
136
-        $existing_attendee->save();
137
-        return $existing_attendee;
138
-    }
112
+	/**
113
+	 * _update_existing_attendee_data
114
+	 * in case it has changed since last time they registered for an event
115
+	 *
116
+	 * @param EE_Attendee $existing_attendee
117
+	 * @param  array      $attendee_data
118
+	 * @return EE_Attendee
119
+	 * @throws EE_Error
120
+	 */
121
+	private function updateExistingAttendeeData(EE_Attendee $existing_attendee, array $attendee_data)
122
+	{
123
+		// first remove fname, lname, and email from attendee data
124
+		// because these properties will be exactly the same as the returned attendee object,
125
+		// since they were used in the query to get the attendee object in the first place
126
+		$dont_set = array('ATT_fname', 'ATT_lname', 'ATT_email');
127
+		// now loop thru what's left and add to attendee CPT
128
+		foreach ($attendee_data as $property_name => $property_value) {
129
+			if (! in_array($property_name, $dont_set, true)
130
+				&& $this->attendee_model->has_field($property_name)
131
+			) {
132
+				$existing_attendee->set($property_name, $property_value);
133
+			}
134
+		}
135
+		// better save that now
136
+		$existing_attendee->save();
137
+		return $existing_attendee;
138
+	}
139 139
 
140 140
 
141
-    /**
142
-     * create_new_attendee
143
-     *
144
-     * @param EE_Registration $registration
145
-     * @param  array          $attendee_data
146
-     * @return EE_Attendee
147
-     * @throws EE_Error
148
-     */
149
-    private function createNewAttendee(EE_Registration $registration, array $attendee_data)
150
-    {
151
-        // create new attendee object
152
-        $new_attendee = EE_Attendee::new_instance($attendee_data);
153
-        // set author to event creator
154
-        $new_attendee->set('ATT_author', $registration->event()->wp_user());
155
-        $new_attendee->save();
156
-        return $new_attendee;
157
-    }
141
+	/**
142
+	 * create_new_attendee
143
+	 *
144
+	 * @param EE_Registration $registration
145
+	 * @param  array          $attendee_data
146
+	 * @return EE_Attendee
147
+	 * @throws EE_Error
148
+	 */
149
+	private function createNewAttendee(EE_Registration $registration, array $attendee_data)
150
+	{
151
+		// create new attendee object
152
+		$new_attendee = EE_Attendee::new_instance($attendee_data);
153
+		// set author to event creator
154
+		$new_attendee->set('ATT_author', $registration->event()->wp_user());
155
+		$new_attendee->save();
156
+		return $new_attendee;
157
+	}
158 158
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
     public function handle(CommandInterface $command)
46 46
     {
47 47
         /** @var CreateAttendeeCommand $command */
48
-        if (! $command instanceof CreateAttendeeCommand) {
48
+        if ( ! $command instanceof CreateAttendeeCommand) {
49 49
             throw new InvalidEntityException(get_class($command), 'CreateAttendeeCommand');
50 50
         }
51 51
         // have we met before?
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
         $dont_set = array('ATT_fname', 'ATT_lname', 'ATT_email');
127 127
         // now loop thru what's left and add to attendee CPT
128 128
         foreach ($attendee_data as $property_name => $property_value) {
129
-            if (! in_array($property_name, $dont_set, true)
129
+            if ( ! in_array($property_name, $dont_set, true)
130 130
                 && $this->attendee_model->has_field($property_name)
131 131
             ) {
132 132
                 $existing_attendee->set($property_name, $property_value);
Please login to merge, or discard this patch.
core/services/commands/attendee/CreateAttendeeCommand.php 1 patch
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -20,62 +20,62 @@
 block discarded – undo
20 20
 class CreateAttendeeCommand extends Command implements CommandRequiresCapCheckInterface
21 21
 {
22 22
 
23
-    /**
24
-     * array of details where keys are names of EEM_Attendee model fields
25
-     *
26
-     * @var array $attendee_details
27
-     */
28
-    protected $attendee_details;
23
+	/**
24
+	 * array of details where keys are names of EEM_Attendee model fields
25
+	 *
26
+	 * @var array $attendee_details
27
+	 */
28
+	protected $attendee_details;
29 29
 
30
-    /**
31
-     * an existing registration to associate this attendee with
32
-     *
33
-     * @var EE_Registration $registration
34
-     */
35
-    protected $registration;
30
+	/**
31
+	 * an existing registration to associate this attendee with
32
+	 *
33
+	 * @var EE_Registration $registration
34
+	 */
35
+	protected $registration;
36 36
 
37 37
 
38
-    /**
39
-     * CreateAttendeeCommand constructor.
40
-     *
41
-     * @param array           $attendee_details
42
-     * @param EE_Registration $registration
43
-     */
44
-    public function __construct(array $attendee_details, EE_Registration $registration)
45
-    {
46
-        $this->attendee_details = $attendee_details;
47
-        $this->registration = $registration;
48
-    }
38
+	/**
39
+	 * CreateAttendeeCommand constructor.
40
+	 *
41
+	 * @param array           $attendee_details
42
+	 * @param EE_Registration $registration
43
+	 */
44
+	public function __construct(array $attendee_details, EE_Registration $registration)
45
+	{
46
+		$this->attendee_details = $attendee_details;
47
+		$this->registration = $registration;
48
+	}
49 49
 
50 50
 
51
-    /**
52
-     * @return array
53
-     */
54
-    public function attendeeDetails()
55
-    {
56
-        return $this->attendee_details;
57
-    }
51
+	/**
52
+	 * @return array
53
+	 */
54
+	public function attendeeDetails()
55
+	{
56
+		return $this->attendee_details;
57
+	}
58 58
 
59 59
 
60
-    /**
61
-     * @return EE_Registration
62
-     */
63
-    public function registration()
64
-    {
65
-        return $this->registration;
66
-    }
60
+	/**
61
+	 * @return EE_Registration
62
+	 */
63
+	public function registration()
64
+	{
65
+		return $this->registration;
66
+	}
67 67
 
68 68
 
69
-    /**
70
-     * @return CapCheckInterface
71
-     * @throws InvalidDataTypeException
72
-     */
73
-    public function getCapCheck()
74
-    {
75
-        // need cap for non-AJAX admin requests
76
-        if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) {
77
-            return new CapCheck('ee_edit_contacts', 'create_new_contact');
78
-        }
79
-        return new PublicCapabilities('', 'create_new_contact');
80
-    }
69
+	/**
70
+	 * @return CapCheckInterface
71
+	 * @throws InvalidDataTypeException
72
+	 */
73
+	public function getCapCheck()
74
+	{
75
+		// need cap for non-AJAX admin requests
76
+		if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) {
77
+			return new CapCheck('ee_edit_contacts', 'create_new_contact');
78
+		}
79
+		return new PublicCapabilities('', 'create_new_contact');
80
+	}
81 81
 }
Please login to merge, or discard this patch.
core/CPTs/CptQueryModifier.php 2 patches
Indentation   +540 added lines, -540 removed lines patch added patch discarded remove patch
@@ -17,544 +17,544 @@
 block discarded – undo
17 17
 class CptQueryModifier
18 18
 {
19 19
 
20
-    /**
21
-     * @var string $post_type
22
-     */
23
-    protected $post_type = '';
24
-
25
-    /**
26
-     * CPT details from CustomPostTypeDefinitions for specific post type
27
-     *
28
-     * @var array $cpt_details
29
-     */
30
-    protected $cpt_details = array();
31
-
32
-    /**
33
-     * @var \EE_Table_Base[] $model_tables
34
-     */
35
-    protected $model_tables = array();
36
-
37
-    /**
38
-     * @var array $taxonomies
39
-     */
40
-    protected $taxonomies = array();
41
-
42
-    /**
43
-     * meta table for the related CPT
44
-     *
45
-     * @var \EE_Secondary_Table $meta_table
46
-     */
47
-    protected $meta_table;
48
-
49
-    /**
50
-     * EEM_CPT_Base model for the related CPT
51
-     *
52
-     * @var \EEM_CPT_Base $model
53
-     */
54
-    protected $model;
55
-
56
-    /**
57
-     * @var \EE_Request_Handler $request
58
-     */
59
-    protected $request;
60
-
61
-    /**
62
-     * @var \WP_Query $wp_query
63
-     */
64
-    protected $wp_query;
65
-
66
-
67
-    /**
68
-     * CptQueryModifier constructor
69
-     *
70
-     * @param string              $post_type
71
-     * @param array               $cpt_details
72
-     * @param \WP_Query           $WP_Query
73
-     * @param \EE_Request_Handler $request
74
-     */
75
-    public function __construct(
76
-        $post_type,
77
-        array $cpt_details,
78
-        \WP_Query $WP_Query,
79
-        \EE_Request_Handler $request
80
-    ) {
81
-        $this->setRequest($request);
82
-        $this->setWpQuery($WP_Query);
83
-        $this->setPostType($post_type);
84
-        $this->setCptDetails($cpt_details);
85
-        $this->init();
86
-    }
87
-
88
-
89
-    /**
90
-     * @return string
91
-     */
92
-    public function postType()
93
-    {
94
-        return $this->post_type;
95
-    }
96
-
97
-
98
-    /**
99
-     * @param string $post_type
100
-     */
101
-    protected function setPostType($post_type)
102
-    {
103
-        $this->post_type = $post_type;
104
-    }
105
-
106
-
107
-    /**
108
-     * @return array
109
-     */
110
-    public function cptDetails()
111
-    {
112
-        return $this->cpt_details;
113
-    }
114
-
115
-
116
-    /**
117
-     * @param array $cpt_details
118
-     */
119
-    protected function setCptDetails($cpt_details)
120
-    {
121
-        $this->cpt_details = $cpt_details;
122
-    }
123
-
124
-
125
-    /**
126
-     * @return \EE_Table_Base[]
127
-     */
128
-    public function modelTables()
129
-    {
130
-        return $this->model_tables;
131
-    }
132
-
133
-
134
-    /**
135
-     * @param \EE_Table_Base[] $model_tables
136
-     */
137
-    protected function setModelTables($model_tables)
138
-    {
139
-        $this->model_tables = $model_tables;
140
-    }
141
-
142
-
143
-    /**
144
-     * @return array
145
-     */
146
-    public function taxonomies()
147
-    {
148
-        if (empty($this->taxonomies)) {
149
-            $this->initializeTaxonomies();
150
-        }
151
-        return $this->taxonomies;
152
-    }
153
-
154
-
155
-    /**
156
-     * @param array $taxonomies
157
-     */
158
-    protected function setTaxonomies(array $taxonomies)
159
-    {
160
-        $this->taxonomies = $taxonomies;
161
-    }
162
-
163
-
164
-    /**
165
-     * @return \EE_Secondary_Table
166
-     */
167
-    public function metaTable()
168
-    {
169
-        return $this->meta_table;
170
-    }
171
-
172
-
173
-    /**
174
-     * @param \EE_Secondary_Table $meta_table
175
-     */
176
-    public function setMetaTable(\EE_Secondary_Table $meta_table)
177
-    {
178
-        $this->meta_table = $meta_table;
179
-    }
180
-
181
-
182
-    /**
183
-     * @return \EEM_Base
184
-     */
185
-    public function model()
186
-    {
187
-        return $this->model;
188
-    }
189
-
190
-
191
-    /**
192
-     * @param \EEM_Base $CPT_model
193
-     */
194
-    protected function setModel(\EEM_Base $CPT_model)
195
-    {
196
-        $this->model = $CPT_model;
197
-    }
198
-
199
-
200
-    /**
201
-     * @return \EE_Request_Handler
202
-     */
203
-    public function request()
204
-    {
205
-        return $this->request;
206
-    }
207
-
208
-
209
-    /**
210
-     * @param \EE_Request_Handler $request
211
-     */
212
-    protected function setRequest(\EE_Request_Handler $request)
213
-    {
214
-        $this->request = $request;
215
-    }
216
-
217
-    // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
218
-    /**
219
-     * @return \WP_Query
220
-     */
221
-    public function WpQuery()
222
-    {
223
-        return $this->wp_query;
224
-    }
225
-    // phpcs:enable
226
-
227
-    /**
228
-     * @param \WP_Query $wp_query
229
-     */
230
-    public function setWpQuery(\WP_Query $wp_query)
231
-    {
232
-        $this->wp_query = $wp_query;
233
-    }
234
-
235
-
236
-    /**
237
-     * @return void
238
-     * @throws InvalidDataTypeException
239
-     * @throws InvalidInterfaceException
240
-     * @throws InvalidArgumentException
241
-     */
242
-    protected function initializeTaxonomies()
243
-    {
244
-        // check if taxonomies have already been set and that this CPT has taxonomies registered for it
245
-        if (empty($this->taxonomies)
246
-            && isset($this->cpt_details['args']['taxonomies'])
247
-        ) {
248
-            // if so then grab them, but we want the taxonomy name as the key
249
-            $taxonomies = array_flip($this->cpt_details['args']['taxonomies']);
250
-            // then grab the list of ALL taxonomies
251
-            /** @var \EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions
252
-             * $taxonomy_definitions
253
-             */
254
-            $taxonomy_definitions = LoaderFactory::getLoader()->getShared(
255
-                'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions'
256
-            );
257
-            $all_taxonomies = $taxonomy_definitions->getCustomTaxonomyDefinitions();
258
-            foreach ($taxonomies as $taxonomy => &$details) {
259
-                // add details to our taxonomies if they exist
260
-                $details = isset($all_taxonomies[$taxonomy])
261
-                    ? $all_taxonomies[$taxonomy]
262
-                    : array();
263
-            }
264
-            // ALWAYS unset() variables that were passed by reference
265
-            unset($details);
266
-            $this->setTaxonomies($taxonomies);
267
-        }
268
-    }
269
-
270
-
271
-    protected function init()
272
-    {
273
-        $this->setAdditionalCptDetails();
274
-        $this->setRequestVarsIfCpt();
275
-        // convert post_type to model name
276
-        $model_name = str_replace('EE_', '', $this->cpt_details['class_name']);
277
-        // load all tables related to CPT
278
-        $this->setupModelsAndTables($model_name);
279
-        // load and instantiate CPT_*_Strategy
280
-        $CPT_Strategy = $this->cptStrategyClass($model_name);
281
-        // !!!!!!!!!!  IMPORTANT !!!!!!!!!!!!
282
-        // here's the list of available filters in the WP_Query object
283
-        // 'posts_where_paged'
284
-        // 'posts_groupby'
285
-        // 'posts_join_paged'
286
-        // 'posts_orderby'
287
-        // 'posts_distinct'
288
-        // 'post_limits'
289
-        // 'posts_fields'
290
-        // 'posts_join'
291
-        add_filter('posts_fields', array($this, 'postsFields'));
292
-        add_filter('posts_join', array($this, 'postsJoin'));
293
-        add_filter(
294
-            'get_' . $this->post_type . '_metadata',
295
-            array($CPT_Strategy, 'get_EE_post_type_metadata'),
296
-            1,
297
-            4
298
-        );
299
-        add_filter('the_posts', array($this, 'thePosts'), 1, 1);
300
-        if ($this->wp_query->is_main_query()) {
301
-            add_filter('get_edit_post_link', array($this, 'getEditPostLink'), 10, 2);
302
-            $this->addTemplateFilters();
303
-        }
304
-    }
305
-
306
-
307
-    /**
308
-     * sets some basic query vars that pertain to the CPT
309
-     *
310
-     * @access protected
311
-     * @return void
312
-     */
313
-    protected function setAdditionalCptDetails()
314
-    {
315
-        // the post or category or term that is triggering EE
316
-        $this->cpt_details['espresso_page'] = $this->request->is_espresso_page();
317
-        // requested post name
318
-        $this->cpt_details['post_name'] = $this->request->get('post_name');
319
-        // add support for viewing 'private', 'draft', or 'pending' posts
320
-        if (isset($this->wp_query->query_vars['p'])
321
-            && $this->wp_query->query_vars['p'] !== 0
322
-            && is_user_logged_in()
323
-            && current_user_can('edit_post', $this->wp_query->query_vars['p'])
324
-        ) {
325
-            // we can just inject directly into the WP_Query object
326
-            $this->wp_query->query['post_status'] = array('publish', 'private', 'draft', 'pending');
327
-            // now set the main 'ee' request var so that the appropriate module can load the appropriate template(s)
328
-            $this->request->set('ee', $this->cpt_details['singular_slug']);
329
-        }
330
-    }
331
-
332
-
333
-    /**
334
-     * Checks if we're on a EE-CPT archive-or-single page, and if we've never set the EE request var.
335
-     * If so, sets the 'ee' request variable
336
-     * so other parts of EE can know what CPT is getting queried.
337
-     * To Mike's knowledge, this must be called from during or after the pre_get_posts hook
338
-     * in order for is_archive() and is_single() methods to work properly.
339
-     *
340
-     * @return void
341
-     */
342
-    public function setRequestVarsIfCpt()
343
-    {
344
-        // check if ee action var has been set
345
-        if (! $this->request->is_set('ee')) {
346
-            // check that route exists for CPT archive slug
347
-            if (is_archive() && \EE_Config::get_route($this->cpt_details['plural_slug'])) {
348
-                // ie: set "ee" to "events"
349
-                $this->request->set('ee', $this->cpt_details['plural_slug']);
350
-                // or does it match a single page CPT like /event/
351
-            } else if (is_single() && \EE_Config::get_route($this->cpt_details['singular_slug'])) {
352
-                // ie: set "ee" to "event"
353
-                $this->request->set('ee', $this->cpt_details['singular_slug']);
354
-            }
355
-        }
356
-    }
357
-
358
-
359
-    /**
360
-     * setupModelsAndTables
361
-     *
362
-     * @access protected
363
-     * @param string $model_name
364
-     * @throws \EE_Error
365
-     */
366
-    protected function setupModelsAndTables($model_name)
367
-    {
368
-        // get CPT table data via CPT Model
369
-        $model = \EE_Registry::instance()->load_model($model_name);
370
-        if (! $model instanceof \EEM_Base) {
371
-            throw new \EE_Error(
372
-                sprintf(
373
-                    __(
374
-                        'The "%1$s" model could not be loaded.',
375
-                        'event_espresso'
376
-                    ),
377
-                    $model_name
378
-                )
379
-            );
380
-        }
381
-        $this->setModel($model);
382
-        $this->setModelTables($this->model->get_tables());
383
-        // is there a Meta Table for this CPT?
384
-        if (isset($this->cpt_details['tables'][$model_name . '_Meta'])
385
-            && $this->cpt_details['tables'][$model_name . '_Meta'] instanceof \EE_Secondary_Table
386
-        ) {
387
-            $this->setMetaTable($this->cpt_details['tables'][$model_name . '_Meta']);
388
-        }
389
-    }
390
-
391
-
392
-    /**
393
-     * cptStrategyClass
394
-     *
395
-     * @access protected
396
-     * @param  string $model_name
397
-     * @return string
398
-     */
399
-    protected function cptStrategyClass($model_name)
400
-    {
401
-        // creates classname like:  CPT_Event_Strategy
402
-        $CPT_Strategy_class_name = 'CPT_' . $model_name . '_Strategy';
403
-        // load and instantiate
404
-        $CPT_Strategy = \EE_Registry::instance()->load_core(
405
-            $CPT_Strategy_class_name,
406
-            array('WP_Query' => $this->wp_query, 'CPT' => $this->cpt_details)
407
-        );
408
-        if ($CPT_Strategy === null) {
409
-            $CPT_Strategy = \EE_Registry::instance()->load_core(
410
-                'CPT_Default_Strategy',
411
-                array('WP_Query' => $this->wp_query, 'CPT' => $this->cpt_details)
412
-            );
413
-        }
414
-        return $CPT_Strategy;
415
-    }
416
-
417
-
418
-    /**
419
-     * postsFields
420
-     *
421
-     * @access public
422
-     * @param  $SQL
423
-     * @return string
424
-     */
425
-    public function postsFields($SQL)
426
-    {
427
-        // does this CPT have a meta table ?
428
-        if ($this->meta_table instanceof \EE_Secondary_Table) {
429
-            // adds something like ", wp_esp_event_meta.* " to WP Query SELECT statement
430
-            $SQL .= ', ' . $this->meta_table->get_table_name() . '.* ';
431
-        }
432
-        remove_filter('posts_fields', array($this, 'postsFields'));
433
-        return $SQL;
434
-    }
435
-
436
-
437
-    /**
438
-     * postsJoin
439
-     *
440
-     * @access public
441
-     * @param  $SQL
442
-     * @return string
443
-     */
444
-    public function postsJoin($SQL)
445
-    {
446
-        // does this CPT have a meta table ?
447
-        if ($this->meta_table instanceof \EE_Secondary_Table) {
448
-            global $wpdb;
449
-            // adds something like " LEFT JOIN wp_esp_event_meta ON ( wp_esp_event_meta.EVT_ID = wp_posts.ID ) " to WP Query JOIN statement
450
-            $SQL .= ' LEFT JOIN '
451
-                    . $this->meta_table->get_table_name()
452
-                    . ' ON ( '
453
-                    . $this->meta_table->get_table_name()
454
-                    . '.'
455
-                    . $this->meta_table->get_fk_on_table()
456
-                    . ' = '
457
-                    . $wpdb->posts
458
-                    . '.ID ) ';
459
-        }
460
-        remove_filter('posts_join', array($this, 'postsJoin'));
461
-        return $SQL;
462
-    }
463
-
464
-
465
-    /**
466
-     * thePosts
467
-     *
468
-     * @access public
469
-     * @param  \WP_Post[] $posts
470
-     * @return \WP_Post[]
471
-     */
472
-    public function thePosts($posts)
473
-    {
474
-        $CPT_class = $this->cpt_details['class_name'];
475
-        // loop thru posts
476
-        if (is_array($posts) && $this->model instanceof \EEM_CPT_Base) {
477
-            foreach ($posts as $key => $post) {
478
-                if ($post->post_type === $this->post_type) {
479
-                    $post->{$CPT_class} = $this->model->instantiate_class_from_post_object($post);
480
-                }
481
-            }
482
-        }
483
-        remove_filter('the_posts', array($this, 'thePosts'), 1);
484
-        return $posts;
485
-    }
486
-
487
-
488
-    /**
489
-     * @param $url
490
-     * @param $ID
491
-     * @return string
492
-     */
493
-    public function getEditPostLink($url, $ID)
494
-    {
495
-        // need to make sure we only edit links if our cpt
496
-        global $post;
497
-        // notice if the cpt is registered with `show_ee_ui` set to false, we take that to mean that the WordPress core ui
498
-        // for interacting with the CPT is desired and there is no EE UI for interacting with the CPT in the admin.
499
-        if (! $post instanceof \WP_Post
500
-            || $post->post_type !== $this->post_type
501
-            || (
502
-                isset($this->cpt_details['args']['show_ee_ui'])
503
-                && ! $this->cpt_details['args']['show_ee_ui']
504
-            )
505
-        ) {
506
-            return $url;
507
-        }
508
-        // k made it here so all is good.
509
-        return wp_nonce_url(
510
-            add_query_arg(
511
-                array('page' => $this->post_type, 'post' => $ID, 'action' => 'edit'),
512
-                admin_url('admin.php')
513
-            ),
514
-            'edit',
515
-            'edit_nonce'
516
-        );
517
-    }
518
-
519
-
520
-    /**
521
-     * Execute any template filters.
522
-     * This method is only called if in main query.
523
-     *
524
-     * @return void
525
-     */
526
-    public function addTemplateFilters()
527
-    {
528
-        // if requested cpt supports page_templates and it's the main query
529
-        if (! empty($this->cpt_details['args']['page_templates']) && $this->wp_query->is_main_query()) {
530
-            // then let's hook into the appropriate query_template hook
531
-            add_filter('single_template', array($this, 'singleCptTemplate'));
532
-        }
533
-    }
534
-
535
-
536
-    /**
537
-     * Callback for single_template wp filter.
538
-     * This is used to load the set page_template for a single ee cpt if its set.  If "default" then we load the normal
539
-     * hierarchy.
540
-     *
541
-     * @access public
542
-     * @param string $current_template Existing default template path derived for this page call.
543
-     * @return string the path to the full template file.
544
-     */
545
-    public function singleCptTemplate($current_template)
546
-    {
547
-        $object = get_queried_object();
548
-        // does this called object HAVE a page template set that is something other than the default.
549
-        $template = get_post_meta($object->ID, '_wp_page_template', true);
550
-        // exit early if default or not set or invalid path (accounts for theme changes)
551
-        if ($template === 'default'
552
-            || empty($template)
553
-            || ! is_readable(get_stylesheet_directory() . '/' . $template)
554
-        ) {
555
-            return $current_template;
556
-        }
557
-        // made it here so we SHOULD be able to just locate the template and then return it.
558
-        return locate_template(array($template));
559
-    }
20
+	/**
21
+	 * @var string $post_type
22
+	 */
23
+	protected $post_type = '';
24
+
25
+	/**
26
+	 * CPT details from CustomPostTypeDefinitions for specific post type
27
+	 *
28
+	 * @var array $cpt_details
29
+	 */
30
+	protected $cpt_details = array();
31
+
32
+	/**
33
+	 * @var \EE_Table_Base[] $model_tables
34
+	 */
35
+	protected $model_tables = array();
36
+
37
+	/**
38
+	 * @var array $taxonomies
39
+	 */
40
+	protected $taxonomies = array();
41
+
42
+	/**
43
+	 * meta table for the related CPT
44
+	 *
45
+	 * @var \EE_Secondary_Table $meta_table
46
+	 */
47
+	protected $meta_table;
48
+
49
+	/**
50
+	 * EEM_CPT_Base model for the related CPT
51
+	 *
52
+	 * @var \EEM_CPT_Base $model
53
+	 */
54
+	protected $model;
55
+
56
+	/**
57
+	 * @var \EE_Request_Handler $request
58
+	 */
59
+	protected $request;
60
+
61
+	/**
62
+	 * @var \WP_Query $wp_query
63
+	 */
64
+	protected $wp_query;
65
+
66
+
67
+	/**
68
+	 * CptQueryModifier constructor
69
+	 *
70
+	 * @param string              $post_type
71
+	 * @param array               $cpt_details
72
+	 * @param \WP_Query           $WP_Query
73
+	 * @param \EE_Request_Handler $request
74
+	 */
75
+	public function __construct(
76
+		$post_type,
77
+		array $cpt_details,
78
+		\WP_Query $WP_Query,
79
+		\EE_Request_Handler $request
80
+	) {
81
+		$this->setRequest($request);
82
+		$this->setWpQuery($WP_Query);
83
+		$this->setPostType($post_type);
84
+		$this->setCptDetails($cpt_details);
85
+		$this->init();
86
+	}
87
+
88
+
89
+	/**
90
+	 * @return string
91
+	 */
92
+	public function postType()
93
+	{
94
+		return $this->post_type;
95
+	}
96
+
97
+
98
+	/**
99
+	 * @param string $post_type
100
+	 */
101
+	protected function setPostType($post_type)
102
+	{
103
+		$this->post_type = $post_type;
104
+	}
105
+
106
+
107
+	/**
108
+	 * @return array
109
+	 */
110
+	public function cptDetails()
111
+	{
112
+		return $this->cpt_details;
113
+	}
114
+
115
+
116
+	/**
117
+	 * @param array $cpt_details
118
+	 */
119
+	protected function setCptDetails($cpt_details)
120
+	{
121
+		$this->cpt_details = $cpt_details;
122
+	}
123
+
124
+
125
+	/**
126
+	 * @return \EE_Table_Base[]
127
+	 */
128
+	public function modelTables()
129
+	{
130
+		return $this->model_tables;
131
+	}
132
+
133
+
134
+	/**
135
+	 * @param \EE_Table_Base[] $model_tables
136
+	 */
137
+	protected function setModelTables($model_tables)
138
+	{
139
+		$this->model_tables = $model_tables;
140
+	}
141
+
142
+
143
+	/**
144
+	 * @return array
145
+	 */
146
+	public function taxonomies()
147
+	{
148
+		if (empty($this->taxonomies)) {
149
+			$this->initializeTaxonomies();
150
+		}
151
+		return $this->taxonomies;
152
+	}
153
+
154
+
155
+	/**
156
+	 * @param array $taxonomies
157
+	 */
158
+	protected function setTaxonomies(array $taxonomies)
159
+	{
160
+		$this->taxonomies = $taxonomies;
161
+	}
162
+
163
+
164
+	/**
165
+	 * @return \EE_Secondary_Table
166
+	 */
167
+	public function metaTable()
168
+	{
169
+		return $this->meta_table;
170
+	}
171
+
172
+
173
+	/**
174
+	 * @param \EE_Secondary_Table $meta_table
175
+	 */
176
+	public function setMetaTable(\EE_Secondary_Table $meta_table)
177
+	{
178
+		$this->meta_table = $meta_table;
179
+	}
180
+
181
+
182
+	/**
183
+	 * @return \EEM_Base
184
+	 */
185
+	public function model()
186
+	{
187
+		return $this->model;
188
+	}
189
+
190
+
191
+	/**
192
+	 * @param \EEM_Base $CPT_model
193
+	 */
194
+	protected function setModel(\EEM_Base $CPT_model)
195
+	{
196
+		$this->model = $CPT_model;
197
+	}
198
+
199
+
200
+	/**
201
+	 * @return \EE_Request_Handler
202
+	 */
203
+	public function request()
204
+	{
205
+		return $this->request;
206
+	}
207
+
208
+
209
+	/**
210
+	 * @param \EE_Request_Handler $request
211
+	 */
212
+	protected function setRequest(\EE_Request_Handler $request)
213
+	{
214
+		$this->request = $request;
215
+	}
216
+
217
+	// phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
218
+	/**
219
+	 * @return \WP_Query
220
+	 */
221
+	public function WpQuery()
222
+	{
223
+		return $this->wp_query;
224
+	}
225
+	// phpcs:enable
226
+
227
+	/**
228
+	 * @param \WP_Query $wp_query
229
+	 */
230
+	public function setWpQuery(\WP_Query $wp_query)
231
+	{
232
+		$this->wp_query = $wp_query;
233
+	}
234
+
235
+
236
+	/**
237
+	 * @return void
238
+	 * @throws InvalidDataTypeException
239
+	 * @throws InvalidInterfaceException
240
+	 * @throws InvalidArgumentException
241
+	 */
242
+	protected function initializeTaxonomies()
243
+	{
244
+		// check if taxonomies have already been set and that this CPT has taxonomies registered for it
245
+		if (empty($this->taxonomies)
246
+			&& isset($this->cpt_details['args']['taxonomies'])
247
+		) {
248
+			// if so then grab them, but we want the taxonomy name as the key
249
+			$taxonomies = array_flip($this->cpt_details['args']['taxonomies']);
250
+			// then grab the list of ALL taxonomies
251
+			/** @var \EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions
252
+			 * $taxonomy_definitions
253
+			 */
254
+			$taxonomy_definitions = LoaderFactory::getLoader()->getShared(
255
+				'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions'
256
+			);
257
+			$all_taxonomies = $taxonomy_definitions->getCustomTaxonomyDefinitions();
258
+			foreach ($taxonomies as $taxonomy => &$details) {
259
+				// add details to our taxonomies if they exist
260
+				$details = isset($all_taxonomies[$taxonomy])
261
+					? $all_taxonomies[$taxonomy]
262
+					: array();
263
+			}
264
+			// ALWAYS unset() variables that were passed by reference
265
+			unset($details);
266
+			$this->setTaxonomies($taxonomies);
267
+		}
268
+	}
269
+
270
+
271
+	protected function init()
272
+	{
273
+		$this->setAdditionalCptDetails();
274
+		$this->setRequestVarsIfCpt();
275
+		// convert post_type to model name
276
+		$model_name = str_replace('EE_', '', $this->cpt_details['class_name']);
277
+		// load all tables related to CPT
278
+		$this->setupModelsAndTables($model_name);
279
+		// load and instantiate CPT_*_Strategy
280
+		$CPT_Strategy = $this->cptStrategyClass($model_name);
281
+		// !!!!!!!!!!  IMPORTANT !!!!!!!!!!!!
282
+		// here's the list of available filters in the WP_Query object
283
+		// 'posts_where_paged'
284
+		// 'posts_groupby'
285
+		// 'posts_join_paged'
286
+		// 'posts_orderby'
287
+		// 'posts_distinct'
288
+		// 'post_limits'
289
+		// 'posts_fields'
290
+		// 'posts_join'
291
+		add_filter('posts_fields', array($this, 'postsFields'));
292
+		add_filter('posts_join', array($this, 'postsJoin'));
293
+		add_filter(
294
+			'get_' . $this->post_type . '_metadata',
295
+			array($CPT_Strategy, 'get_EE_post_type_metadata'),
296
+			1,
297
+			4
298
+		);
299
+		add_filter('the_posts', array($this, 'thePosts'), 1, 1);
300
+		if ($this->wp_query->is_main_query()) {
301
+			add_filter('get_edit_post_link', array($this, 'getEditPostLink'), 10, 2);
302
+			$this->addTemplateFilters();
303
+		}
304
+	}
305
+
306
+
307
+	/**
308
+	 * sets some basic query vars that pertain to the CPT
309
+	 *
310
+	 * @access protected
311
+	 * @return void
312
+	 */
313
+	protected function setAdditionalCptDetails()
314
+	{
315
+		// the post or category or term that is triggering EE
316
+		$this->cpt_details['espresso_page'] = $this->request->is_espresso_page();
317
+		// requested post name
318
+		$this->cpt_details['post_name'] = $this->request->get('post_name');
319
+		// add support for viewing 'private', 'draft', or 'pending' posts
320
+		if (isset($this->wp_query->query_vars['p'])
321
+			&& $this->wp_query->query_vars['p'] !== 0
322
+			&& is_user_logged_in()
323
+			&& current_user_can('edit_post', $this->wp_query->query_vars['p'])
324
+		) {
325
+			// we can just inject directly into the WP_Query object
326
+			$this->wp_query->query['post_status'] = array('publish', 'private', 'draft', 'pending');
327
+			// now set the main 'ee' request var so that the appropriate module can load the appropriate template(s)
328
+			$this->request->set('ee', $this->cpt_details['singular_slug']);
329
+		}
330
+	}
331
+
332
+
333
+	/**
334
+	 * Checks if we're on a EE-CPT archive-or-single page, and if we've never set the EE request var.
335
+	 * If so, sets the 'ee' request variable
336
+	 * so other parts of EE can know what CPT is getting queried.
337
+	 * To Mike's knowledge, this must be called from during or after the pre_get_posts hook
338
+	 * in order for is_archive() and is_single() methods to work properly.
339
+	 *
340
+	 * @return void
341
+	 */
342
+	public function setRequestVarsIfCpt()
343
+	{
344
+		// check if ee action var has been set
345
+		if (! $this->request->is_set('ee')) {
346
+			// check that route exists for CPT archive slug
347
+			if (is_archive() && \EE_Config::get_route($this->cpt_details['plural_slug'])) {
348
+				// ie: set "ee" to "events"
349
+				$this->request->set('ee', $this->cpt_details['plural_slug']);
350
+				// or does it match a single page CPT like /event/
351
+			} else if (is_single() && \EE_Config::get_route($this->cpt_details['singular_slug'])) {
352
+				// ie: set "ee" to "event"
353
+				$this->request->set('ee', $this->cpt_details['singular_slug']);
354
+			}
355
+		}
356
+	}
357
+
358
+
359
+	/**
360
+	 * setupModelsAndTables
361
+	 *
362
+	 * @access protected
363
+	 * @param string $model_name
364
+	 * @throws \EE_Error
365
+	 */
366
+	protected function setupModelsAndTables($model_name)
367
+	{
368
+		// get CPT table data via CPT Model
369
+		$model = \EE_Registry::instance()->load_model($model_name);
370
+		if (! $model instanceof \EEM_Base) {
371
+			throw new \EE_Error(
372
+				sprintf(
373
+					__(
374
+						'The "%1$s" model could not be loaded.',
375
+						'event_espresso'
376
+					),
377
+					$model_name
378
+				)
379
+			);
380
+		}
381
+		$this->setModel($model);
382
+		$this->setModelTables($this->model->get_tables());
383
+		// is there a Meta Table for this CPT?
384
+		if (isset($this->cpt_details['tables'][$model_name . '_Meta'])
385
+			&& $this->cpt_details['tables'][$model_name . '_Meta'] instanceof \EE_Secondary_Table
386
+		) {
387
+			$this->setMetaTable($this->cpt_details['tables'][$model_name . '_Meta']);
388
+		}
389
+	}
390
+
391
+
392
+	/**
393
+	 * cptStrategyClass
394
+	 *
395
+	 * @access protected
396
+	 * @param  string $model_name
397
+	 * @return string
398
+	 */
399
+	protected function cptStrategyClass($model_name)
400
+	{
401
+		// creates classname like:  CPT_Event_Strategy
402
+		$CPT_Strategy_class_name = 'CPT_' . $model_name . '_Strategy';
403
+		// load and instantiate
404
+		$CPT_Strategy = \EE_Registry::instance()->load_core(
405
+			$CPT_Strategy_class_name,
406
+			array('WP_Query' => $this->wp_query, 'CPT' => $this->cpt_details)
407
+		);
408
+		if ($CPT_Strategy === null) {
409
+			$CPT_Strategy = \EE_Registry::instance()->load_core(
410
+				'CPT_Default_Strategy',
411
+				array('WP_Query' => $this->wp_query, 'CPT' => $this->cpt_details)
412
+			);
413
+		}
414
+		return $CPT_Strategy;
415
+	}
416
+
417
+
418
+	/**
419
+	 * postsFields
420
+	 *
421
+	 * @access public
422
+	 * @param  $SQL
423
+	 * @return string
424
+	 */
425
+	public function postsFields($SQL)
426
+	{
427
+		// does this CPT have a meta table ?
428
+		if ($this->meta_table instanceof \EE_Secondary_Table) {
429
+			// adds something like ", wp_esp_event_meta.* " to WP Query SELECT statement
430
+			$SQL .= ', ' . $this->meta_table->get_table_name() . '.* ';
431
+		}
432
+		remove_filter('posts_fields', array($this, 'postsFields'));
433
+		return $SQL;
434
+	}
435
+
436
+
437
+	/**
438
+	 * postsJoin
439
+	 *
440
+	 * @access public
441
+	 * @param  $SQL
442
+	 * @return string
443
+	 */
444
+	public function postsJoin($SQL)
445
+	{
446
+		// does this CPT have a meta table ?
447
+		if ($this->meta_table instanceof \EE_Secondary_Table) {
448
+			global $wpdb;
449
+			// adds something like " LEFT JOIN wp_esp_event_meta ON ( wp_esp_event_meta.EVT_ID = wp_posts.ID ) " to WP Query JOIN statement
450
+			$SQL .= ' LEFT JOIN '
451
+					. $this->meta_table->get_table_name()
452
+					. ' ON ( '
453
+					. $this->meta_table->get_table_name()
454
+					. '.'
455
+					. $this->meta_table->get_fk_on_table()
456
+					. ' = '
457
+					. $wpdb->posts
458
+					. '.ID ) ';
459
+		}
460
+		remove_filter('posts_join', array($this, 'postsJoin'));
461
+		return $SQL;
462
+	}
463
+
464
+
465
+	/**
466
+	 * thePosts
467
+	 *
468
+	 * @access public
469
+	 * @param  \WP_Post[] $posts
470
+	 * @return \WP_Post[]
471
+	 */
472
+	public function thePosts($posts)
473
+	{
474
+		$CPT_class = $this->cpt_details['class_name'];
475
+		// loop thru posts
476
+		if (is_array($posts) && $this->model instanceof \EEM_CPT_Base) {
477
+			foreach ($posts as $key => $post) {
478
+				if ($post->post_type === $this->post_type) {
479
+					$post->{$CPT_class} = $this->model->instantiate_class_from_post_object($post);
480
+				}
481
+			}
482
+		}
483
+		remove_filter('the_posts', array($this, 'thePosts'), 1);
484
+		return $posts;
485
+	}
486
+
487
+
488
+	/**
489
+	 * @param $url
490
+	 * @param $ID
491
+	 * @return string
492
+	 */
493
+	public function getEditPostLink($url, $ID)
494
+	{
495
+		// need to make sure we only edit links if our cpt
496
+		global $post;
497
+		// notice if the cpt is registered with `show_ee_ui` set to false, we take that to mean that the WordPress core ui
498
+		// for interacting with the CPT is desired and there is no EE UI for interacting with the CPT in the admin.
499
+		if (! $post instanceof \WP_Post
500
+			|| $post->post_type !== $this->post_type
501
+			|| (
502
+				isset($this->cpt_details['args']['show_ee_ui'])
503
+				&& ! $this->cpt_details['args']['show_ee_ui']
504
+			)
505
+		) {
506
+			return $url;
507
+		}
508
+		// k made it here so all is good.
509
+		return wp_nonce_url(
510
+			add_query_arg(
511
+				array('page' => $this->post_type, 'post' => $ID, 'action' => 'edit'),
512
+				admin_url('admin.php')
513
+			),
514
+			'edit',
515
+			'edit_nonce'
516
+		);
517
+	}
518
+
519
+
520
+	/**
521
+	 * Execute any template filters.
522
+	 * This method is only called if in main query.
523
+	 *
524
+	 * @return void
525
+	 */
526
+	public function addTemplateFilters()
527
+	{
528
+		// if requested cpt supports page_templates and it's the main query
529
+		if (! empty($this->cpt_details['args']['page_templates']) && $this->wp_query->is_main_query()) {
530
+			// then let's hook into the appropriate query_template hook
531
+			add_filter('single_template', array($this, 'singleCptTemplate'));
532
+		}
533
+	}
534
+
535
+
536
+	/**
537
+	 * Callback for single_template wp filter.
538
+	 * This is used to load the set page_template for a single ee cpt if its set.  If "default" then we load the normal
539
+	 * hierarchy.
540
+	 *
541
+	 * @access public
542
+	 * @param string $current_template Existing default template path derived for this page call.
543
+	 * @return string the path to the full template file.
544
+	 */
545
+	public function singleCptTemplate($current_template)
546
+	{
547
+		$object = get_queried_object();
548
+		// does this called object HAVE a page template set that is something other than the default.
549
+		$template = get_post_meta($object->ID, '_wp_page_template', true);
550
+		// exit early if default or not set or invalid path (accounts for theme changes)
551
+		if ($template === 'default'
552
+			|| empty($template)
553
+			|| ! is_readable(get_stylesheet_directory() . '/' . $template)
554
+		) {
555
+			return $current_template;
556
+		}
557
+		// made it here so we SHOULD be able to just locate the template and then return it.
558
+		return locate_template(array($template));
559
+	}
560 560
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -291,7 +291,7 @@  discard block
 block discarded – undo
291 291
         add_filter('posts_fields', array($this, 'postsFields'));
292 292
         add_filter('posts_join', array($this, 'postsJoin'));
293 293
         add_filter(
294
-            'get_' . $this->post_type . '_metadata',
294
+            'get_'.$this->post_type.'_metadata',
295 295
             array($CPT_Strategy, 'get_EE_post_type_metadata'),
296 296
             1,
297 297
             4
@@ -342,7 +342,7 @@  discard block
 block discarded – undo
342 342
     public function setRequestVarsIfCpt()
343 343
     {
344 344
         // check if ee action var has been set
345
-        if (! $this->request->is_set('ee')) {
345
+        if ( ! $this->request->is_set('ee')) {
346 346
             // check that route exists for CPT archive slug
347 347
             if (is_archive() && \EE_Config::get_route($this->cpt_details['plural_slug'])) {
348 348
                 // ie: set "ee" to "events"
@@ -367,7 +367,7 @@  discard block
 block discarded – undo
367 367
     {
368 368
         // get CPT table data via CPT Model
369 369
         $model = \EE_Registry::instance()->load_model($model_name);
370
-        if (! $model instanceof \EEM_Base) {
370
+        if ( ! $model instanceof \EEM_Base) {
371 371
             throw new \EE_Error(
372 372
                 sprintf(
373 373
                     __(
@@ -381,10 +381,10 @@  discard block
 block discarded – undo
381 381
         $this->setModel($model);
382 382
         $this->setModelTables($this->model->get_tables());
383 383
         // is there a Meta Table for this CPT?
384
-        if (isset($this->cpt_details['tables'][$model_name . '_Meta'])
385
-            && $this->cpt_details['tables'][$model_name . '_Meta'] instanceof \EE_Secondary_Table
384
+        if (isset($this->cpt_details['tables'][$model_name.'_Meta'])
385
+            && $this->cpt_details['tables'][$model_name.'_Meta'] instanceof \EE_Secondary_Table
386 386
         ) {
387
-            $this->setMetaTable($this->cpt_details['tables'][$model_name . '_Meta']);
387
+            $this->setMetaTable($this->cpt_details['tables'][$model_name.'_Meta']);
388 388
         }
389 389
     }
390 390
 
@@ -399,7 +399,7 @@  discard block
 block discarded – undo
399 399
     protected function cptStrategyClass($model_name)
400 400
     {
401 401
         // creates classname like:  CPT_Event_Strategy
402
-        $CPT_Strategy_class_name = 'CPT_' . $model_name . '_Strategy';
402
+        $CPT_Strategy_class_name = 'CPT_'.$model_name.'_Strategy';
403 403
         // load and instantiate
404 404
         $CPT_Strategy = \EE_Registry::instance()->load_core(
405 405
             $CPT_Strategy_class_name,
@@ -427,7 +427,7 @@  discard block
 block discarded – undo
427 427
         // does this CPT have a meta table ?
428 428
         if ($this->meta_table instanceof \EE_Secondary_Table) {
429 429
             // adds something like ", wp_esp_event_meta.* " to WP Query SELECT statement
430
-            $SQL .= ', ' . $this->meta_table->get_table_name() . '.* ';
430
+            $SQL .= ', '.$this->meta_table->get_table_name().'.* ';
431 431
         }
432 432
         remove_filter('posts_fields', array($this, 'postsFields'));
433 433
         return $SQL;
@@ -496,7 +496,7 @@  discard block
 block discarded – undo
496 496
         global $post;
497 497
         // notice if the cpt is registered with `show_ee_ui` set to false, we take that to mean that the WordPress core ui
498 498
         // for interacting with the CPT is desired and there is no EE UI for interacting with the CPT in the admin.
499
-        if (! $post instanceof \WP_Post
499
+        if ( ! $post instanceof \WP_Post
500 500
             || $post->post_type !== $this->post_type
501 501
             || (
502 502
                 isset($this->cpt_details['args']['show_ee_ui'])
@@ -526,7 +526,7 @@  discard block
 block discarded – undo
526 526
     public function addTemplateFilters()
527 527
     {
528 528
         // if requested cpt supports page_templates and it's the main query
529
-        if (! empty($this->cpt_details['args']['page_templates']) && $this->wp_query->is_main_query()) {
529
+        if ( ! empty($this->cpt_details['args']['page_templates']) && $this->wp_query->is_main_query()) {
530 530
             // then let's hook into the appropriate query_template hook
531 531
             add_filter('single_template', array($this, 'singleCptTemplate'));
532 532
         }
@@ -550,7 +550,7 @@  discard block
 block discarded – undo
550 550
         // exit early if default or not set or invalid path (accounts for theme changes)
551 551
         if ($template === 'default'
552 552
             || empty($template)
553
-            || ! is_readable(get_stylesheet_directory() . '/' . $template)
553
+            || ! is_readable(get_stylesheet_directory().'/'.$template)
554 554
         ) {
555 555
             return $current_template;
556 556
         }
Please login to merge, or discard this patch.