BaseController.php
3 years ago
ChargeController.php
3 years ago
CustomerController.php
3 years ago
DownloadController.php
3 years ago
InvoiceController.php
3 years ago
OrderController.php
3 years ago
PaymentMethodController.php
2 years ago
SubscriptionController.php
3 years ago
UserController.php
3 years ago
BaseController.php
82 lines
| 1 | <?php |
| 2 | namespace SureCartBlocks\Controllers; |
| 3 | |
| 4 | use SureCart\Models\User; |
| 5 | |
| 6 | /** |
| 7 | * Base controller for dashboard pages. |
| 8 | */ |
| 9 | abstract class BaseController { |
| 10 | /** |
| 11 | * Get a query param. |
| 12 | * |
| 13 | * @param string $name The query param name. |
| 14 | * @param mixed $fallback The fallback value. |
| 15 | * |
| 16 | * @return string|false |
| 17 | */ |
| 18 | protected function getParam( $name, $fallback = false ) { |
| 19 | return isset( $_GET[ $name ] ) ? sanitize_text_field( wp_unslash( $_GET[ $name ] ) ) : $fallback; |
| 20 | } |
| 21 | /** |
| 22 | * Get the current tab. |
| 23 | * |
| 24 | * @return string|false |
| 25 | */ |
| 26 | protected function getTab() { |
| 27 | return $this->getParam( 'tab' ); |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * Get the current page. |
| 32 | * |
| 33 | * @return integer |
| 34 | */ |
| 35 | protected function getPage() { |
| 36 | return $this->getParam( 'page', 1 ); |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Get the current id. |
| 41 | * |
| 42 | * @return integer|false |
| 43 | */ |
| 44 | protected function getId() { |
| 45 | return $this->getParam( 'id' ); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Get the users customer ids. |
| 50 | * |
| 51 | * @return array |
| 52 | */ |
| 53 | protected function customerIds() { |
| 54 | return array_values( (array) User::current()->customerIds() ); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Render not found view. |
| 59 | * |
| 60 | * @return string |
| 61 | */ |
| 62 | protected function notFound() { |
| 63 | return '<sc-alert type="danger" open>' . esc_html__( 'Not found.', 'surecart' ) . '</sc-alert>'; |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Render not found view. |
| 68 | * |
| 69 | * @return string |
| 70 | */ |
| 71 | protected function noAccess() { |
| 72 | return '<sc-alert type="danger" open>' . esc_html__( 'You do not have permission to do this.', 'surecart' ) . '</sc-alert>'; |
| 73 | } |
| 74 | |
| 75 | protected function isLiveMode() { |
| 76 | if ( 'false' === sanitize_text_field( wp_unslash( $_GET['live_mode'] ?? '' ) ) ) { |
| 77 | return false; |
| 78 | } |
| 79 | return true; |
| 80 | } |
| 81 | } |
| 82 |