| 1 |
<?php |
| 2 |
namespace Elementor\Core\Experiments; |
| 3 |
|
| 4 |
use Elementor\Modules\System_Info\Reporters\Base; |
| 5 |
use Elementor\Plugin; |
| 6 |
|
| 7 |
/** |
| 8 |
* Elementor experiments report. |
| 9 |
* |
| 10 |
* Elementor experiment report handler class responsible for generating a report for |
| 11 |
* the experiments included in Elementor and their status. |
| 12 |
*/ |
| 13 |
class Experiments_Reporter extends Base { |
| 14 |
|
| 15 |
/** |
| 16 |
* Get experiments reporter title. |
| 17 |
* |
| 18 |
* @return string Reporter title. |
| 19 |
*/ |
| 20 |
public function get_title() { |
| 21 |
return esc_html__( 'Elementor Experiments', 'elementor' ); |
| 22 |
} |
| 23 |
|
| 24 |
/** |
| 25 |
* Get experiments report fields. |
| 26 |
* |
| 27 |
* @return array Required report fields with field ID and field label. |
| 28 |
*/ |
| 29 |
public function get_fields() { |
| 30 |
return [ |
| 31 |
'experiments' => '', |
| 32 |
]; |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Get Experiments. |
| 37 |
*/ |
| 38 |
public function get_experiments() { |
| 39 |
$result = []; |
| 40 |
|
| 41 |
$experiments_manager = Plugin::$instance->experiments; |
| 42 |
|
| 43 |
// TODO: Those keys should be at `$experiments_manager`. |
| 44 |
$tracking_keys = [ |
| 45 |
'default', |
| 46 |
'state', |
| 47 |
]; |
| 48 |
|
| 49 |
foreach ( $experiments_manager->get_features() as $feature_name => $feature_data ) { |
| 50 |
$data_to_collect = []; |
| 51 |
|
| 52 |
// Extract only tracking keys. |
| 53 |
foreach ( $tracking_keys as $tracking_key ) { |
| 54 |
$data_to_collect[ $tracking_key ] = $feature_data[ $tracking_key ]; |
| 55 |
} |
| 56 |
|
| 57 |
$result[ $feature_name ] = $data_to_collect; |
| 58 |
} |
| 59 |
|
| 60 |
return [ |
| 61 |
'value' => $result, |
| 62 |
]; |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* Get Raw Experiments. |
| 67 |
* |
| 68 |
* Retrieve a string containing the list of Elementor experiments and each experiment's status (active/inactive). |
| 69 |
* The string is formatted in a non-table structure, and it is meant for export/download of the system info reports. |
| 70 |
* |
| 71 |
* @return array |
| 72 |
*/ |
| 73 |
public function get_raw_experiments() { |
| 74 |
$experiments = Plugin::$instance->experiments->get_features(); |
| 75 |
|
| 76 |
$output = ''; |
| 77 |
|
| 78 |
$is_first_item = true; |
| 79 |
|
| 80 |
foreach ( $experiments as $experiment ) { |
| 81 |
// If the state is default, add the default state to the string. |
| 82 |
$state = Plugin::$instance->experiments->get_feature_state_label( $experiment ); |
| 83 |
|
| 84 |
// The first item automatically has a tab character before it. Add tabs only to the rest of the items. |
| 85 |
if ( ! $is_first_item ) { |
| 86 |
$output .= "\t"; |
| 87 |
} |
| 88 |
|
| 89 |
$output .= $experiment['title'] . ': ' . $state . PHP_EOL; |
| 90 |
|
| 91 |
$is_first_item = false; |
| 92 |
} |
| 93 |
|
| 94 |
return [ |
| 95 |
'value' => $output, |
| 96 |
]; |
| 97 |
} |
| 98 |
|
| 99 |
/** |
| 100 |
* Get HTML Experiments. |
| 101 |
* |
| 102 |
* Retrieve the list of Elementor experiments and each experiment's status (active/inactive), in HTML table format. |
| 103 |
* |
| 104 |
* @return array |
| 105 |
*/ |
| 106 |
public function get_html_experiments() { |
| 107 |
$experiments = Plugin::$instance->experiments->get_features(); |
| 108 |
|
| 109 |
$output = ''; |
| 110 |
|
| 111 |
foreach ( $experiments as $experiment ) { |
| 112 |
// If the state is default, add the default state to the string. |
| 113 |
$state = Plugin::$instance->experiments->get_feature_state_label( $experiment ); |
| 114 |
|
| 115 |
$output .= '<tr><td>' . esc_html( $experiment['title'] ) . ': </td>'; |
| 116 |
$output .= '<td>' . esc_html( $state ) . '</td>'; |
| 117 |
$output .= '</tr>'; |
| 118 |
} |
| 119 |
|
| 120 |
return [ |
| 121 |
'value' => $output, |
| 122 |
]; |
| 123 |
} |
| 124 |
} |
| 125 |
|