course_id ); default: return ''; } } public static function launch_reason( int $course_id ): string { $course = Services::course_repo()->get( $course_id ); $date = null === $course ? '' : Format::date( $course->available_from ); /* translators: %s: the date a lesson opens. */ return '' !== $date ? sprintf( __( 'Opens on %s.', 'rooster-lms' ), $date ) : __( 'Opens when the course starts.', 'rooster-lms' ); } public static function launch_notice( int $user_id, int $course_id, string $css ): string { if ( ! Services::gate()->launch_locked( $user_id, $course_id ) ) { return ''; } $course = Services::course_repo()->get( $course_id ); $date = null === $course ? '' : Format::date( $course->available_from ); $text = '' !== $date /* translators: %s: the date a course starts. */ ? sprintf( __( 'This course opens on %s. Its lessons open then.', 'rooster-lms' ), $date ) : __( 'This course has not started yet. Its lessons open when it starts.', 'rooster-lms' ); return '

' . esc_html( $text ) . '

'; } public static function opens_at( Item $item, int $user_id ): ?string { $enrolment = UnlockRule::DAYS_AFTER_ENROLMENT === $item->rules->unlock ? Learner::enrolment( $user_id, $item->course_id ) : null; return $item->rules->opens_at( null === $enrolment ? null : $enrolment->enrolled_at ); } public static function missing_titles( int $user_id, int $course_id, string $lang ): array { $missing = Services::gate()->missing_prerequisites( $user_id, $course_id ); if ( array() === $missing ) { return array(); } $gate = Services::gate(); $missing = array_values( array_filter( $missing, static fn( int $id ): bool => $gate->can_view_course( $user_id, $id )->allowed ) ); if ( array() === $missing ) { return array(); } $out = array(); foreach ( Services::posts()->titles( ObjectType::COURSE, $missing, $lang ) as $row ) { $out[] = (string) $row['title']; } return $out; } public static function prerequisites_html( int $user_id, int $course_id, string $lang ): string { $titles = self::missing_titles( $user_id, $course_id, $lang ); if ( array() === $titles ) { return array() === Services::gate()->missing_prerequisites( $user_id, $course_id ) ? '' : esc_html__( 'Complete the required courses first.', 'rooster-lms' ); } $list = wp_sprintf( '%l', array_map( static fn( string $title ): string => '' . esc_html( $title ) . '', $titles ) ); /* translators: %s: the titles of one or more courses, as a list ("A, B and C"). */ return sprintf( esc_html__( 'Complete %s first.', 'rooster-lms' ), $list ); } }