Block.php
48 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SureCartBlocks\Blocks\Dashboard\OrderDownloads; |
| 4 | |
| 5 | use SureCart\Models\Component; |
| 6 | use SureCart\Models\User; |
| 7 | use SureCartBlocks\Blocks\Dashboard\DashboardPage; |
| 8 | |
| 9 | /** |
| 10 | * Checkout block |
| 11 | */ |
| 12 | class Block extends DashboardPage { |
| 13 | /** |
| 14 | * Render the preview (overview) |
| 15 | * |
| 16 | * @param array $attributes Block attributes. |
| 17 | * @param string $content Post content. |
| 18 | * |
| 19 | * @return function |
| 20 | */ |
| 21 | public function render( $attributes, $content ) { |
| 22 | if ( ! User::current()->isCustomer() ) { |
| 23 | return; |
| 24 | } |
| 25 | return wp_kses_post( |
| 26 | Component::tag( 'sc-downloads-list' ) |
| 27 | ->id( 'customer-downloads-preview' ) |
| 28 | ->with( |
| 29 | [ |
| 30 | 'allLink' => add_query_arg( |
| 31 | [ |
| 32 | 'tab' => $this->getTab(), |
| 33 | 'model' => 'download', |
| 34 | 'action' => 'index', |
| 35 | ], |
| 36 | \SureCart::pages()->url( 'dashboard' ) |
| 37 | ), |
| 38 | 'nonce' => wp_create_nonce( 'customer-download' ), |
| 39 | 'query' => [ |
| 40 | 'order_ids' => array_values( User::current()->customerIds() ), |
| 41 | 'page' => 1, |
| 42 | 'per_page' => 10, |
| 43 | ], |
| 44 | ] |
| 45 | )->render( $attributes['title'] ? "<span slot='heading'>" . $attributes['title'] . '</span>' : '' ) ); |
| 46 | } |
| 47 | } |
| 48 |