PluginProbe
Packeta / 1.3.1
Packeta v1.3.1
2.3.2 2.3.1 trunk 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3.0 1.3.1 1.3.2 1.4 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 All 56 releases
packeta / src / Packetery / Module / Log / Page.php

Page.php in Packeta 1.3.1, at src/Packetery/Module/Log/Page.php

107 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Class Page
4 *
5 * @package Packetery\Module\Log
6 */
7
8 declare( strict_types=1 );
9
10
11 namespace Packetery\Module\Log;
12
13 use Packetery\Core\Log\ILogger;
14 use Packetery\Core\Log\Record;
15 use PacketeryLatte\Engine;
16
17 /**
18 * Class Page
19 *
20 * @package Packetery\Module\Log
21 */
22 class Page {
23
24 public const SLUG = 'packeta-logs';
25
26 /**
27 * Engine.
28 *
29 * @var Engine
30 */
31 private $latteEngine;
32
33 /**
34 * Manager.
35 *
36 * @var ILogger
37 */
38 private $logger;
39
40 /**
41 * Page constructor.
42 *
43 * @param Engine $latteEngine Engine.
44 * @param ILogger $manager Manager.
45 */
46 public function __construct( Engine $latteEngine, ILogger $manager ) {
47 $this->latteEngine = $latteEngine;
48 $this->logger = $manager;
49 }
50
51 /**
52 * Registers Page.
53 */
54 public function register(): void {
55 add_submenu_page(
56 \Packetery\Module\Options\Page::SLUG,
57 __( 'Log', 'packeta' ),
58 __( 'Log', 'packeta' ),
59 'manage_options',
60 self::SLUG,
61 [ $this, 'render' ]
62 );
63 }
64
65 /**
66 * Renders Page.
67 */
68 public function render(): void {
69 $translatedActions = [
70 Record::ACTION_PACKET_SENDING => __( 'Packet sending', 'packeta' ),
71 Record::ACTION_CARRIER_LABEL_PRINT => __( 'Carrier label print', 'packeta' ),
72 Record::ACTION_LABEL_PRINT => __( 'Label print', 'packeta' ),
73 Record::ACTION_CARRIER_LIST_UPDATE => __( 'Carrier list update', 'packeta' ),
74 Record::ACTION_CARRIER_NUMBER_RETRIEVING => __( 'Getting external carrier tracking number', 'packeta' ),
75 Record::ACTION_CARRIER_TABLE_NOT_CREATED => __( 'Database carrier table was not created.', 'packeta' ),
76 Record::ACTION_ORDER_TABLE_NOT_CREATED => __( 'Database order table was not created.', 'packeta' ),
77 Record::ACTION_SENDER_VALIDATION => __( 'Sender validation', 'packeta' ),
78 Record::ACTION_PACKET_STATUS_SYNC => __( 'Packet status synchronization', 'packeta' ),
79 ];
80
81 $translatedStatuses = [
82 Record::STATUS_ERROR => __( 'Error', 'packeta' ),
83 Record::STATUS_SUCCESS => __( 'Success', 'packeta' ),
84 ];
85
86 $rows = $this->logger->getRecords( [ 'date' => 'DESC' ] );
87
88 $this->latteEngine->render(
89 PACKETERY_PLUGIN_DIR . '/template/log/page.latte',
90 [
91 'rows' => $rows,
92 'translatedActions' => $translatedActions,
93 'translatedStatuses' => $translatedStatuses,
94 'translations' => [
95 'packeta' => __( 'Packeta', 'packeta' ),
96 'logsPageTitle' => __( 'Log', 'packeta' ),
97 'status' => __( 'Status', 'packeta' ),
98 'dateAndTime' => __( 'Date and time', 'packeta' ),
99 'action' => __( 'Action', 'packeta' ),
100 'note' => __( 'Note', 'packeta' ),
101 'logListIsEmpty' => __( 'API log is empty.', 'packeta' ),
102 ],
103 ]
104 );
105 }
106 }
107