PluginProbe
Elementor Website Builder – more than just a page builder / 4.3.0-beta3
Elementor Website Builder – more than just a page builder v4.3.0-beta3
4.3.0-beta3 4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 All 452 releases
elementor / modules / mcp / abilities / utils / bulk-operations-result.php

bulk-operations-result.php in Elementor Website Builder – more than just a page builder 4.3.0-beta3, at modules/mcp/abilities/utils/bulk-operations-result.php

66 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Elementor\Modules\Mcp\Abilities\Utils;
4
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 class Bulk_Operations_Result {
10
11 private array $rows = [];
12
13 public function add_success( int $index, string $action, array $extra = [] ): void {
14 $this->rows[ $index ] = array_merge(
15 [
16 'index' => $index,
17 'action' => $action,
18 'status' => 'ok',
19 ],
20 $extra
21 );
22 }
23
24 public function add_error( int $index, string $action, string $code, string $message ): void {
25 $this->rows[ $index ] = [
26 'index' => $index,
27 'action' => $action,
28 'status' => 'error',
29 'code' => $code,
30 'message' => $message,
31 ];
32 }
33
34 public function has( int $index ): bool {
35 return isset( $this->rows[ $index ] );
36 }
37
38 public function to_array(): array {
39 ksort( $this->rows );
40
41 $results = array_values( $this->rows );
42 $ok_count = 0;
43 $error_count = 0;
44
45 foreach ( $results as $result ) {
46 if ( 'ok' === ( $result['status'] ?? '' ) ) {
47 ++$ok_count;
48 } else {
49 ++$error_count;
50 }
51 }
52
53 $status = 'ok';
54 if ( $ok_count > 0 && $error_count > 0 ) {
55 $status = 'partial_error';
56 } elseif ( 0 === $ok_count && $error_count > 0 ) {
57 $status = 'error';
58 }
59
60 return [
61 'status' => $status,
62 'results' => $results,
63 ];
64 }
65 }
66