| 1 |
<?php |
| 2 |
|
| 3 |
namespace ConvertPro\Controller; |
| 4 |
if (!defined('ABSPATH')) { |
| 5 |
exit; // Called directly, nothing to do here. |
| 6 |
} |
| 7 |
|
| 8 |
|
| 9 |
use ConvertPro\Classes\Repo; |
| 10 |
|
| 11 |
class Controller |
| 12 |
{ |
| 13 |
public function Run() |
| 14 |
{ |
| 15 |
// write a code here |
| 16 |
// phpcs:ignore |
| 17 |
$action = isset($_GET['action']) ? $_GET['action'] : "index"; |
| 18 |
|
| 19 |
switch ($action) { |
| 20 |
case "index": |
| 21 |
$this->index(); |
| 22 |
break; |
| 23 |
case "create": |
| 24 |
$this->create(); |
| 25 |
break; |
| 26 |
case "edit": |
| 27 |
$this->edit(); |
| 28 |
break; |
| 29 |
case "report": |
| 30 |
$this->report(); |
| 31 |
break; |
| 32 |
default: |
| 33 |
$this->index(); |
| 34 |
break; |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* index view showing |
| 40 |
* |
| 41 |
* @return void |
| 42 |
*/ |
| 43 |
public function index() |
| 44 |
{ |
| 45 |
// write a code here |
| 46 |
$repo = new Repo(); |
| 47 |
$tests = $repo->getAlltests(); |
| 48 |
require_once CONVERTPRO_INCLUDES . '/Template/index-view.php'; |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* create new test |
| 53 |
* |
| 54 |
* @return void |
| 55 |
*/ |
| 56 |
public function create() |
| 57 |
{ |
| 58 |
// write a code here |
| 59 |
$pages = get_pages(); |
| 60 |
require_once CONVERTPRO_INCLUDES . '/Template/create-view.php'; |
| 61 |
} |
| 62 |
|
| 63 |
/** |
| 64 |
* edit function |
| 65 |
* |
| 66 |
* @return void |
| 67 |
*/ |
| 68 |
public function edit() |
| 69 |
{ |
| 70 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- reading which test to show, capability checked by the menu. |
| 71 |
$id = isset($_GET['id']) ? (int) $_GET['id'] : 0; |
| 72 |
$repo = new Repo(); |
| 73 |
$test = $id > 0 ? $repo->gettestvalue($id) : null; |
| 74 |
|
| 75 |
// Rather than an empty screen when the link is wrong or the test has since |
| 76 |
// been deleted, say so and point back at the list. |
| 77 |
if (!$test) { |
| 78 |
printf( |
| 79 |
'<div class="notice notice-error"><p>%s <a href="%s">%s</a></p></div>', |
| 80 |
esc_html__('That test is no longer here.', 'convertpro'), |
| 81 |
esc_url(admin_url('admin.php?page=convertpro-settings')), |
| 82 |
esc_html__('Back to all tests', 'convertpro') |
| 83 |
); |
| 84 |
return; |
| 85 |
} |
| 86 |
|
| 87 |
$pages = get_pages(); |
| 88 |
|
| 89 |
require_once CONVERTPRO_INCLUDES . '/Template/edit-view.php'; |
| 90 |
} |
| 91 |
|
| 92 |
/** |
| 93 |
* report |
| 94 |
*/ |
| 95 |
public function report() |
| 96 |
{ |
| 97 |
// write a code here |
| 98 |
require_once CONVERTPRO_INCLUDES . '/Template/report-view.php'; |
| 99 |
} |
| 100 |
} |
| 101 |
|