__( 'Course', 'rooster-lms' ), 'unit_id' => __( 'Lesson', 'rooster-lms' ), 'parent_id' => __( 'Reply to (0 = a question)', 'rooster-lms' ), 'body' => __( 'Text', 'rooster-lms' ), 'state' => __( 'State (1 visible, 2 awaiting approval, 3 hidden, 4 in the trash)', 'rooster-lms' ), 'lang' => __( 'Language', 'rooster-lms' ), 'created_at' => __( 'Written', 'rooster-lms' ), 'updated_at' => __( 'Last changed', 'rooster-lms' ), ), 'id' ), new UserTable( 'course_reviews', 'user_id', 'community', $label, array( 'course_id' => __( 'Course', 'rooster-lms' ), 'rating' => __( 'Rating (1 to 5)', 'rooster-lms' ), 'title' => __( 'Title', 'rooster-lms' ), 'body' => __( 'Text', 'rooster-lms' ), 'state' => __( 'State (1 awaiting approval, 2 approved, 3 rejected, 4 in the trash)', 'rooster-lms' ), 'lang' => __( 'Language', 'rooster-lms' ), 'reply' => __( 'Reply', 'rooster-lms' ), 'created_at' => __( 'Written', 'rooster-lms' ), 'updated_at' => __( 'Last changed', 'rooster-lms' ), ), 'id' ), new UserTable( 'course_waitlist', 'user_id', 'community', $label, array( 'course_id' => __( 'Waiting list of the course', 'rooster-lms' ), 'email' => __( 'E-mail', 'rooster-lms' ), 'confirmed_at' => __( 'Confirmed', 'rooster-lms' ), 'notified_at' => __( 'Told that it opened', 'rooster-lms' ), ), 'id' ), new UserTable( 'wishlists', 'user_id', 'community', $label, array( 'course_id' => __( 'Saved course', 'rooster-lms' ), 'created_at' => __( 'Saved', 'rooster-lms' ), ), 'course_id' ), ); $last = end( $tables ); if ( $last instanceof UserTable && 'people' === $last->table ) { array_splice( $tables, count( $tables ) - 1, 0, $entries ); return $tables; } return array_merge( $tables, $entries ); } public static function purging( $user_id ): void { $user_id = (int) $user_id; if ( $user_id <= 0 ) { return; } Services::discussions()->delete_user( $user_id ); Services::reviews()->delete_user( $user_id ); } public static function exporters( $exporters ) { if ( is_array( $exporters ) ) { $exporters[ self::ID ] = array( 'exporter_friendly_name' => __( 'Rooster LMS: course waiting lists', 'rooster-lms' ), 'callback' => array( self::class, 'export' ), ); } return $exporters; } public static function erasers( $erasers ) { if ( is_array( $erasers ) ) { $erasers[ self::ID ] = array( 'eraser_friendly_name' => __( 'Rooster LMS: course waiting lists', 'rooster-lms' ), 'callback' => array( self::class, 'erase' ), ); } return $erasers; } public static function export( $email, $page = 1 ): array { $items = array(); if ( (int) $page <= 1 ) { foreach ( Services::waitlist()->of_email( (string) $email ) as $row ) { $items[] = array( 'group_id' => self::ID, 'group_label' => __( 'Rooster LMS: course waiting lists', 'rooster-lms' ), 'item_id' => self::ID . '-' . (int) $row['id'], 'data' => array( array( 'name' => __( 'Waiting list of the course', 'rooster-lms' ), 'value' => Waitlist::course_title( (int) $row['course_id'] ) . ' (#' . (int) $row['course_id'] . ')', ), array( 'name' => __( 'E-mail', 'rooster-lms' ), 'value' => (string) $row['email'], ), array( 'name' => __( 'Language', 'rooster-lms' ), 'value' => (string) $row['lang'], ), array( 'name' => __( 'Asked on', 'rooster-lms' ), 'value' => (string) $row['created_at'], ), array( 'name' => __( 'Confirmed', 'rooster-lms' ), 'value' => (string) ( $row['confirmed_at'] ?? '' ), ), array( 'name' => __( 'Told that it opened', 'rooster-lms' ), 'value' => (string) ( $row['notified_at'] ?? '' ), ), ), ); } } return array( 'data' => $items, 'done' => true, ); } public static function erase( $email, $page = 1 ): array { unset( $page ); $n = Services::waitlist()->erase_email( (string) $email ); return array( 'items_removed' => $n > 0, 'items_retained' => false, 'messages' => array(), 'done' => true, ); } public static function before_delete( $post_id ): void { $post_id = (int) $post_id; if ( $post_id <= 0 ) { return; } $row = Db::row( 'SELECT object_type, object_id FROM %i WHERE post_id = %d AND object_type IN (%d, %d)', Db::table( 'object_posts' ), $post_id, ObjectType::COURSE->value, ObjectType::UNIT->value ); if ( null !== $row ) { self::$pending[ $post_id ] = array( (int) $row['object_type'], (int) $row['object_id'] ); } } public static function deleted( $post_id ): void { $post_id = (int) $post_id; if ( ! isset( self::$pending[ $post_id ] ) ) { return; } list( $type, $id ) = self::$pending[ $post_id ]; unset( self::$pending[ $post_id ] ); if ( null !== Db::value( 'SELECT 1 FROM %i WHERE object_type = %d AND object_id = %d LIMIT 1', Db::table( 'object_posts' ), $type, $id ) ) { return; } if ( ObjectType::COURSE->value === $type ) { self::course_gone( $id ); } else { Services::discussions()->delete_unit( $id ); } } public static function course_gone( int $course_id ): array { return array( 'discussions' => Services::discussions()->delete_course( $course_id ), 'course_reviews' => Services::reviews()->delete_course( $course_id ), 'course_waitlist' => Services::waitlist()->delete_course( $course_id ), 'wishlists' => Services::wishlist()->delete_course( $course_id ), ); } }