InvitationService::used(), self::render( ... ), null, 'megaphone' ); return $sections; } public static function render( AccountViewer $viewer ): string { $rows = InvitationRepository::for_user( $viewer->id() ); $interest = self::interest( $viewer->id() ); if ( array() === $rows ) { return Markup::notice( __( 'You have no invitations.', 'rooster-lms' ) ) . $interest; } $lang = Switcher::current(); $units = array_values( array_unique( array_filter( array_map( static fn( array $r ): int => (int) $r['unit_id'], $rows ) ) ) ); $courses = array_values( array_unique( array_map( static fn( array $r ): int => (int) $r['course_id'], $rows ) ) ); $utitles = array() === $units ? array() : Services::posts()->titles( ObjectType::UNIT, $units, $lang ); $ctitles = Services::posts()->titles( ObjectType::COURSE, $courses, $lang ); $now = Clock::now(); $html = '
'; foreach ( $rows as $row ) { $unit = (int) $row['unit_id']; $course = (int) $row['course_id']; $title = $unit > 0 ? (string) ( $utitles[ $unit ]['title'] ?? '' ) : (string) ( $ctitles[ $course ]['title'] ?? '' ); $title = '' === $title && $course <= 0 ? (string) ( $row['cohort_name'] ?? '' ) : $title; $join = YesAction::JOIN_COHORT->value === (int) ( $row['yes_action'] ?? 0 ); $answer = RsvpAnswer::tryFrom( (int) $row['answer'] ) ?? RsvpAnswer::NONE; $offered = RsvpAnswer::offered( (int) $row['rsvp'] ); $inv = InvitationRepository::get( (int) $row['invitation_id'] ); $closes = null === $inv ? '' : RsvpService::closes_at( $inv ); $open = array() !== $offered && ( '' === $closes || $closes >= $now ); $url = $unit > 0 ? Links::unit( $unit, $course ) : ''; $body = ''; if ( null !== $row['starts_at'] ) { $body .= '

' . esc_html( Format::date( (string) $row['starts_at'], (string) get_option( 'date_format', 'j F Y' ) . ' ' . (string) get_option( 'time_format', 'H:i' ) ) ) . '

'; } /* translators: %s: the answer (Yes, No, Maybe, No answer). */ $body .= '

' . esc_html( sprintf( __( 'Your answer: %s', 'rooster-lms' ), $answer->label() ) ) . '

'; if ( $open ) { $options = ''; foreach ( $offered as $choice ) { $options .= ''; } $body .= '
' . '' . '

' . '' . '

' . Ui::button( __( 'Save my answer', 'rooster-lms' ), 'primary', array( 'type' => 'submit' ) ) . '

'; } $head = '' !== $url ? '' . esc_html( $title ) . '' : esc_html( $title ); $html .= '

' . $head . '

' . $body . '
'; } return $html . '
' . $interest; } private static function interest( int $user_id ): string { $courses = Interest::courses_of( $user_id ); if ( array() === $courses ) { return ''; } $titles = Services::posts()->titles( ObjectType::COURSE, $courses, Switcher::current() ); $items = ''; foreach ( $courses as $course ) { $title = (string) ( $titles[ $course ]['title'] ?? '' ); $items .= '
  • ' . esc_html( '' !== $title ? $title : __( 'A course', 'rooster-lms' ) ) . ' ' . esc_html__( 'Stop these notices', 'rooster-lms' ) . '
  • '; } return '

    ' . esc_html__( 'Courses you asked to hear about', 'rooster-lms' ) . '

    ' . esc_html__( 'We e-mail you when these courses send their next invitation.', 'rooster-lms' ) . '

    '; } }