| 1 |
<?php |
| 2 |
/** |
| 3 |
* Troubleshoot Clues. |
| 4 |
* |
| 5 |
* @since 0.0.0 |
| 6 |
* @package Troubleshoot |
| 7 |
*/ |
| 8 |
|
| 9 |
/** |
| 10 |
* Troubleshoot Clues. |
| 11 |
* |
| 12 |
* @since 0.0.0 |
| 13 |
*/ |
| 14 |
class PDT_Clues { |
| 15 |
/** |
| 16 |
* Parent plugin class. |
| 17 |
* |
| 18 |
* @since 0.0.0 |
| 19 |
* |
| 20 |
* @var Troubleshoot |
| 21 |
*/ |
| 22 |
protected $plugin = null; |
| 23 |
|
| 24 |
/** |
| 25 |
* Constructor. |
| 26 |
* |
| 27 |
* @since 0.0.0 |
| 28 |
* |
| 29 |
* @param Troubleshoot $plugin Main plugin object. |
| 30 |
*/ |
| 31 |
public function __construct( $plugin ) { |
| 32 |
$this->plugin = $plugin; |
| 33 |
$this->hooks(); |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* Initiate our hooks. |
| 38 |
* |
| 39 |
* @since 0.0.0 |
| 40 |
*/ |
| 41 |
public function hooks() { |
| 42 |
|
| 43 |
} |
| 44 |
|
| 45 |
public function get( $args ) { |
| 46 |
|
| 47 |
} |
| 48 |
|
| 49 |
public function get_id_from_args( $args ) { |
| 50 |
$case = $this->plugin->cases->get_active(); |
| 51 |
if ( empty( $case['clues']['0'] ) ) { |
| 52 |
return null; |
| 53 |
} |
| 54 |
|
| 55 |
// If specified, make sure that data is there |
| 56 |
if ( !empty( $args['id'] ) && $case['clues'][(int)$args['id']] ) { |
| 57 |
return (int)$args['id']; |
| 58 |
} |
| 59 |
|
| 60 |
// Use latest clue by default |
| 61 |
return count( $case['clues'] ) - 1; |
| 62 |
} |
| 63 |
|
| 64 |
public function create( $args ) { |
| 65 |
if ( !isset( $args['outcome'] ) ) { |
| 66 |
return new WP_Error( 'outcome', __( 'outcome field required' , 'plugin-detective' ) ); |
| 67 |
} |
| 68 |
|
| 69 |
$case = $this->plugin->cases->get_active(); |
| 70 |
if ( is_a( $case, 'WP_Error' ) ) { |
| 71 |
return $case; |
| 72 |
} |
| 73 |
|
| 74 |
$active_plugins = array(); |
| 75 |
$plugins = $this->plugin->installed->get_plugins(); |
| 76 |
foreach ($plugins as $key => $plugin) { |
| 77 |
if ( empty( $plugin['Active'] ) ) { |
| 78 |
continue; |
| 79 |
} |
| 80 |
|
| 81 |
$active_plugins[] = $plugin['plugin_file']; |
| 82 |
} |
| 83 |
|
| 84 |
$case['clues'][] = array( |
| 85 |
'outcome' => $args['outcome'], |
| 86 |
'active_plugins' => $active_plugins, |
| 87 |
'cleared_suspects' => $case['cleared_suspects'], |
| 88 |
'prime_suspects' => $case['prime_suspects'], |
| 89 |
'culprits' => $case['culprits'], |
| 90 |
'date_created' => gmdate( 'Y-m-d H:i:s' ), |
| 91 |
); |
| 92 |
|
| 93 |
$case = $this->plugin->cases->update( array( |
| 94 |
'clues' => $case['clues'], |
| 95 |
) ); |
| 96 |
|
| 97 |
return $this->plugin->cases->review( $case ); |
| 98 |
} |
| 99 |
|
| 100 |
public function update( $args ) { |
| 101 |
|
| 102 |
} |
| 103 |
|
| 104 |
public function delete( $args ) { |
| 105 |
$case = $this->plugin->cases->get_active(); |
| 106 |
if ( is_a( $case, 'WP_Error' ) ) { |
| 107 |
return $case; |
| 108 |
} |
| 109 |
|
| 110 |
$clue_id = $this->get_id_from_args( $args ); |
| 111 |
unset( $case['clues'][$clue_id] ); |
| 112 |
|
| 113 |
return $this->plugin->cases->update( array( |
| 114 |
'clues' => $case['clues'], |
| 115 |
) ); |
| 116 |
} |
| 117 |
} |
| 118 |
|