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.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.7.0 3.7.1 3.7.2 3.7.3 3.7.4 3.8.0 3.8.1 3.8.2 3.8.3 3.9.0 3.9.1 3.9.10 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9
tutor / components / CourseFilter.php
tutor / components Last commit date
Constants 1 month ago Accordion.php 3 weeks ago Alert.php 3 weeks ago AttachmentCard.php 3 weeks ago Avatar.php 3 weeks ago Badge.php 3 weeks ago BaseComponent.php 1 month ago Button.php 3 weeks ago ConfirmationModal.php 3 weeks ago CourseFilter.php 3 weeks ago DateFilter.php 3 weeks ago DropdownFilter.php 3 weeks ago EmptyState.php 3 weeks ago FileUploader.php 3 weeks ago InputField.php 3 weeks ago Modal.php 3 weeks ago Nav.php 3 weeks ago Pagination.php 3 weeks ago Popover.php 3 weeks ago PreviewTrigger.php 3 weeks ago Progress.php 3 weeks ago SearchFilter.php 3 weeks ago Sorting.php 3 weeks ago StarRating.php 3 weeks ago StarRatingInput.php 3 weeks ago StatusSelect.php 3 weeks ago SvgIcon.php 3 weeks ago Table.php 3 weeks ago Tabs.php 3 weeks ago Tooltip.php 3 weeks ago WPEditor.php 3 weeks ago
CourseFilter.php
124 lines
1 <?php
2 /**
3 * CourseFilter Component Class.
4 *
5 * Responsible for rendering a course filtering dropdown
6 * with a search box to filter the list.
7 *
8 * @package Tutor\Components
9 * @author Themeum
10 * @link https://themeum.com
11 * @since 4.0.0
12 */
13
14 namespace Tutor\Components;
15
16 use Tutor\Components\Constants\Size;
17 use Tutor\Components\Constants\Variant;
18 use Tutor\Models\CourseModel;
19
20 defined( 'ABSPATH' ) || exit;
21
22 /**
23 * Class CourseFilter
24 *
25 * Example Usage:
26 * ```php
27 * // Minimal — auto-fetches courses for the current user
28 * CourseFilter::make()
29 * ->render();
30 *
31 * // With explicit courses list and total count
32 * CourseFilter::make()
33 * ->courses( $courses )
34 * ->count( $total_announcements )
35 * ->render();
36 *
37 * // Pre-populate options from a custom courses array
38 * CourseFilter::make()
39 * ->courses( CourseModel::get_courses_by_instructor() )
40 * ->render();
41 *
42 * // Retrieve HTML without echoing
43 * $html = CourseFilter::make()->courses( $courses )->get();
44 * ```
45 *
46 * @since 4.0.0
47 */
48 class CourseFilter extends DropdownFilter {
49
50 /**
51 * Constructor.
52 *
53 * Set default values for course filter.
54 */
55 public function __construct() {
56 $this->query_param( 'course-id' );
57 $this->variant( Variant::PRIMARY_SOFT );
58 $this->size( Size::X_SMALL );
59 $this->popover_size( Size::MEDIUM );
60 $this->placeholder( __( 'Search Course', 'tutor' ) );
61 $this->search( true );
62 }
63
64 /**
65 * Set courses list
66 *
67 * @param array|null $courses List of courses.
68 *
69 * @return self
70 */
71 public function courses( $courses = null ): self {
72 $options = self::get_course_filter_options( $courses );
73 $this->options( $options );
74 return $this;
75 }
76
77 /**
78 * Get component content.
79 *
80 * @return string
81 */
82 public function get(): string {
83 if ( empty( $this->options ) ) {
84 $this->courses();
85 }
86
87 return parent::get();
88 }
89
90 /**
91 * Get course filter options for DropdownFilter component.
92 *
93 * @since 4.0.0
94 *
95 * @param array|null $courses Optional. Array of course objects.
96 * If not provided, courses will be fetched based on user permissions.
97 *
98 * @return array
99 */
100 public static function get_course_filter_options( $courses = null ) {
101 $course_options = array(
102 array(
103 'label' => __( 'All Courses', 'tutor' ),
104 'value' => '',
105 ),
106 );
107
108 if ( null === $courses ) {
109 $courses = current_user_can( 'manage_options' ) ? CourseModel::get_courses() : CourseModel::get_courses_by_instructor();
110 }
111
112 if ( ! empty( $courses ) ) {
113 foreach ( $courses as $course ) {
114 $course_options[] = array(
115 'label' => $course->post_title,
116 'value' => $course->ID,
117 );
118 }
119 }
120
121 return $course_options;
122 }
123 }
124