Skip to content

Commit 7af89f3

Browse files
committed
Merge branch '4.0.0-dev' into instructor-analytics-free
2 parents 7df5efa + 612584c commit 7af89f3

File tree

20 files changed

+586
-112
lines changed

20 files changed

+586
-112
lines changed

classes/Dashboard.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ public static function get_account_pages() {
8383
'url' => self::get_account_page_url( 'reviews' ),
8484
'template' => tutor_get_template( 'dashboard.account.reviews' ),
8585
),
86+
'billing' => array(
87+
'title' => esc_html__( 'Billing', 'tutor' ),
88+
'icon' => Icon::BILLING,
89+
'icon_active' => Icon::BILLING,
90+
'url' => self::get_account_page_url( 'billing' ),
91+
'template' => tutor_get_template( 'dashboard.account.billing' ),
92+
),
8693
'settings' => array(
8794
'title' => esc_html__( 'Settings', 'tutor' ),
8895
'icon' => Icon::SETTING,

classes/Quiz.php

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Tutor\Models\CourseModel;
2020
use Tutor\Models\QuizModel;
2121
use Tutor\Traits\JsonResponse;
22+
use WP_Post;
2223

2324
/**
2425
* Manage quiz operations.
@@ -28,6 +29,15 @@
2829
class Quiz {
2930
use JsonResponse;
3031

32+
/**
33+
* Quiz post type
34+
*
35+
* @since 4.0.0
36+
*
37+
* @var string
38+
*/
39+
private $post_type;
40+
3141
const META_QUIZ_OPTION = 'tutor_quiz_option';
3242

3343
/**
@@ -65,10 +75,20 @@ class Quiz {
6575
* Register hooks
6676
*
6777
* @since 1.0.0
78+
* @since 4.0.0 $register_hooks param added
79+
*
80+
* @param bool $register_hooks To register hooks.
6881
*
6982
* @return void
7083
*/
71-
public function __construct() {
84+
public function __construct( $register_hooks = true ) {
85+
$this->post_type = tutor()->quiz_post_type;
86+
$this->prepare_allowed_html();
87+
88+
if ( ! $register_hooks ) {
89+
return;
90+
}
91+
7292
add_action( 'wp_ajax_tutor_quiz_timeout', array( $this, 'tutor_quiz_timeout' ) );
7393

7494
// User take the quiz.
@@ -100,8 +120,6 @@ public function __construct() {
100120
*/
101121
add_action( 'wp_ajax_tutor_quiz_abandon', array( $this, 'tutor_quiz_abandon' ) );
102122

103-
$this->prepare_allowed_html();
104-
105123
/**
106124
* Delete quiz attempt
107125
*
@@ -110,6 +128,10 @@ public function __construct() {
110128
add_action( 'wp_ajax_tutor_attempt_delete', array( $this, 'attempt_delete' ) );
111129

112130
add_action( 'tutor_quiz/answer/review/after', array( $this, 'do_auto_course_complete' ), 10, 3 );
131+
132+
// Add quiz title as nav item & render single content on the learning area.
133+
add_action( "tutor_learning_area_nav_item_{$this->post_type}", array( $this, 'render_nav_item' ), 10, 2 );
134+
add_action( "tutor_single_content_{$this->post_type}", array( $this, 'render_single_content' ) );
113135
}
114136

115137
/**
@@ -1260,4 +1282,42 @@ private function get_quiz_attempt_answers_by_attempt_id( int $attempt_id ): arra
12601282

12611283
return $results;
12621284
}
1285+
1286+
/**
1287+
* Render quiz title as nav item to show on the learning area
1288+
*
1289+
* @since 4.0.0
1290+
*
1291+
* @param WP_Post $quiz Quiz post object.
1292+
* @param bool $can_access Can user access this content.
1293+
*
1294+
* @return void
1295+
*/
1296+
public function render_nav_item( WP_Post $quiz, bool $can_access ): void {
1297+
tutor_load_template(
1298+
'learning-area.quiz.nav-item',
1299+
array(
1300+
'quiz' => $quiz,
1301+
'can_access' => $can_access,
1302+
)
1303+
);
1304+
}
1305+
1306+
/**
1307+
* Render content for the a single quiz
1308+
*
1309+
* @since 4.0.0
1310+
*
1311+
* @param WP_Post $quiz Quiz post object.
1312+
*
1313+
* @return void
1314+
*/
1315+
public function render_single_content( WP_Post $quiz ): void {
1316+
tutor_load_template(
1317+
'learning-area.quiz.content',
1318+
array(
1319+
'quiz' => $quiz,
1320+
)
1321+
);
1322+
}
12631323
}

classes/Template.php

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ public function __construct() {
4545
add_filter( 'template_include', array( $this, 'play_private_video' ), 99 );
4646
add_filter( 'tutor_single_content_template', array( $this, 'load_single_lesson_template' ), 99, 2 );
4747
add_filter( 'tutor_single_content_template', array( $this, 'load_quiz_template' ), 99, 2 );
48-
add_filter( 'tutor_single_content_template', array( $this, 'load_assignment_template' ), 99, 2 );
4948

5049
add_filter( 'template_include', array( $this, 'student_public_profile' ), 99 );
5150
add_filter( 'template_include', array( $this, 'tutor_dashboard' ), 99 );
@@ -457,37 +456,6 @@ public function load_quiz_template( $template, $post_type ) {
457456
return $template;
458457
}
459458

460-
/**
461-
* Load assignment template
462-
*
463-
* @since 1.0.0
464-
*
465-
* @since 4.0.0 Post type.
466-
*
467-
* @param string $template template file to load.
468-
* @param string $post_type Post type.
469-
*
470-
* @return string template path
471-
*/
472-
public function load_assignment_template( $template, $post_type ) {
473-
if ( tutor()->lesson_post_type !== $post_type ) {
474-
return $template;
475-
}
476-
477-
if ( is_user_logged_in() ) {
478-
$has_content_access = tutor_utils()->has_enrolled_content_access( 'assignment' );
479-
if ( $has_content_access ) {
480-
$template = tutor_get_template( 'single-assignment' );
481-
} else {
482-
$template = tutor_get_template( 'single.lesson.required-enroll' ); // You need to enroll first.
483-
}
484-
} else {
485-
$template = tutor_get_template( 'login' );
486-
}
487-
488-
return $template;
489-
}
490-
491459
/**
492460
* Student public profile
493461
*

classes/Utils.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6314,21 +6314,24 @@ public function remove_instructor_role( $instructor_id = 0 ) {
63146314
* Get purchase history by customer id
63156315
*
63166316
* @since 1.0.0
6317+
* @since 4.0.0 param $order added.
63176318
*
63186319
* @param integer $user_id user id.
63196320
* @param string $period period.
63206321
* @param string $start_date start date.
63216322
* @param string $end_date end date.
63226323
* @param string $offset offset.
63236324
* @param string $per_page per page.
6325+
* @param string $order order.
63246326
*
63256327
* @return mixed
63266328
*/
6327-
public function get_orders_by_user_id( $user_id = 0, $period = '', $start_date = '', $end_date = '', $offset = '', $per_page = '' ) {
6329+
public function get_orders_by_user_id( $user_id = 0, $period = '', $start_date = '', $end_date = '', $offset = '', $per_page = '', $order = 'DESC' ) {
63286330
global $wpdb;
63296331

63306332
$user_id = $this->get_user_id( $user_id );
63316333
$monetize_by = $this->get_option( 'monetize_by' );
6334+
$order = QueryHelper::get_valid_sort_order( $order );
63326335

63336336
$post_type = '';
63346337
$user_meta = '';
@@ -6377,7 +6380,7 @@ public function get_orders_by_user_id( $user_id = 0, $period = '', $start_date =
63776380
WHERE orders.type = %s
63786381
AND orders.customer_id = %d
63796382
{$period_query}
6380-
ORDER BY orders.id DESC
6383+
ORDER BY orders.id {$order}
63816384
{$offset_limit_query}",
63826385
$post_type,
63836386
$user_id
@@ -6397,7 +6400,7 @@ public function get_orders_by_user_id( $user_id = 0, $period = '', $start_date =
63976400
WHERE post_type = %s
63986401
AND customer.meta_value = %d
63996402
{$period_query}
6400-
ORDER BY {$wpdb->posts}.id DESC
6403+
ORDER BY {$wpdb->posts}.id {$order}
64016404
{$offset_limit_query}
64026405
",
64036406
$post_type,

components/Badge.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -158,21 +158,6 @@ public function circle() {
158158
return $this;
159159
}
160160

161-
/**
162-
* Set custom HTML attribute.
163-
*
164-
* @since 4.0.0
165-
*
166-
* @param string $key Attribute name.
167-
* @param string $value Attribute value.
168-
*
169-
* @return $this
170-
*/
171-
public function attr( $key, $value ) {
172-
$this->attributes[ $key ] = esc_attr( $value );
173-
return $this;
174-
}
175-
176161
/**
177162
* Set the SVG icon for the badge.
178163
*

components/BaseComponent.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,28 @@ public static function make() {
6969
*
7070
* @param array $attrs Key–value pairs of HTML attributes.
7171
*
72-
* @return self
72+
* @return static
7373
*/
74-
public function attrs( array $attrs ): self {
74+
public function attrs( array $attrs ) {
7575
$this->attributes = array_merge( $this->attributes, $attrs );
7676
return $this;
7777
}
7878

79+
/**
80+
* Set a custom HTML attribute.
81+
*
82+
* @since 4.0.0
83+
*
84+
* @param string $key Attribute name.
85+
* @param string $value Attribute value.
86+
*
87+
* @return static
88+
*/
89+
public function attr( $key, $value ) {
90+
$this->attributes[ $key ] = $value;
91+
return $this;
92+
}
93+
7994
/**
8095
* Compile the stored attributes into an HTML string.
8196
*

components/Button.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -181,21 +181,6 @@ public function variant( $variant ) {
181181
return $this;
182182
}
183183

184-
/**
185-
* Set custom HTML attribute.
186-
*
187-
* @since 4.0.0
188-
*
189-
* @param string $key Attribute name.
190-
* @param string $value Attribute value.
191-
*
192-
* @return $this
193-
*/
194-
public function attr( $key, $value ) {
195-
$this->attributes[ $key ] = esc_attr( $value );
196-
return $this;
197-
}
198-
199184
/**
200185
* Set the SVG icon for the button.
201186
*

components/InputField.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -543,21 +543,6 @@ public function required( $required = true ) {
543543
return $this;
544544
}
545545

546-
/**
547-
* Set attributes.
548-
*
549-
* @since 4.0.0
550-
*
551-
* @param string $key Attribute key.
552-
* @param string $value Attribute value.
553-
*
554-
* @return $this
555-
*/
556-
public function attr( $key, $value ) {
557-
$this->attributes[ $key ] = $value;
558-
return $this;
559-
}
560-
561546
/**
562547
* Set disabled state.
563548
*

components/Nav.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -113,22 +113,6 @@ public function variant( $variant = Variant::PRIMARY ): self {
113113
return $this;
114114
}
115115

116-
/**
117-
* Set custom HTML attribute.
118-
*
119-
* @since 4.0.0
120-
*
121-
* @param string $key Attribute name.
122-
* @param string $value Attribute value.
123-
*
124-
* @return $this
125-
*/
126-
public function attr( $key, $value ) {
127-
$this->attributes[ $key ] = esc_attr( $value );
128-
return $this;
129-
}
130-
131-
132116
/**
133117
* Set the nav size.
134118
*

components/Pagination.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,19 @@ protected function get_paginated_links_list() {
240240
* @return string
241241
*/
242242
public function get(): string {
243+
if ( $this->pagination_total <= $this->pagination_limit ) {
244+
return '';
245+
}
246+
243247
$pagination_links = $this->get_paginated_links_list() ?? array();
244248
$pagination_info = $this->render_pagination_info() ?? '';
245249
$links = '';
246250

251+
$classes = array( 'tutor-pagination' );
252+
if ( isset( $this->attributes['class'] ) ) {
253+
$classes[] = $this->attributes['class'];
254+
}
255+
247256
if ( count( $pagination_links ) ) {
248257
foreach ( $pagination_links as $link ) {
249258
$link = str_replace( 'page-numbers dots', 'tutor-pagination-ellipsis', $link );
@@ -258,12 +267,13 @@ public function get(): string {
258267
}
259268

260269
return sprintf(
261-
'<nav class="tutor-pagination" role="navigation" aria-label="Pagination Navigation">
270+
'<nav class="%s" role="navigation" aria-label="Pagination Navigation">
262271
%s
263272
<ul class="tutor-pagination-list">
264273
%s
265274
</ul>
266275
</nav>',
276+
esc_attr( implode( ' ', $classes ) ),
267277
$pagination_info,
268278
$links
269279
);

0 commit comments

Comments
 (0)