SELECT b0_.id AS id_0, b0_.name AS name_1, b0_.type AS type_2, b0_.active AS active_3, b0_.visible AS visible_4, b0_.class_start_date AS class_start_date_5, b0_.class_end_date AS class_end_date_6, b0_.active_until AS active_until_7, b0_.elearn_access_start_date AS elearn_access_start_date_8, b0_.elearn_access_end_date AS elearn_access_end_date_9, b0_.visibile_until AS visibile_until_10, b0_.price AS price_11, b0_.price_for_legal_person AS price_for_legal_person_12, b0_.num_places AS num_places_13, b0_.additional_occupied_places AS additional_occupied_places_14, b0_.location AS location_15, b0_.other_info AS other_info_16, b0_.modified_at AS modified_at_17, b0_.created_at AS created_at_18, b1_.id AS id_19, b1_.promo_title AS promo_title_20, b1_.promo_content AS promo_content_21, b1_.name AS name_22, b1_.alias AS alias_23, b1_.alternative_aliases AS alternative_aliases_24, b1_.active AS active_25, b1_.visible AS visible_26, b1_.category_index AS category_index_27, b1_.short_name AS short_name_28, b1_.description AS description_29, b1_.short_description AS short_description_30, b1_.other_info AS other_info_31, b1_.price AS price_32, b1_.price_for_legal_person AS price_for_legal_person_33, b1_.youtube_url AS youtube_url_34, b1_.num_hours_per_lesson AS num_hours_per_lesson_35, b1_.online_class_price AS online_class_price_36, b1_.meta_description AS meta_description_37, b1_.meta_title AS meta_title_38, b2_.id AS id_39, b2_.filename AS filename_40, b2_.path AS path_41, b2_.mime_type AS mime_type_42, b2_.created_at AS created_at_43, b3_.id AS id_44, b3_.name AS name_45, b3_.alias AS alias_46, b3_.active AS active_47, b3_.position AS position_48, b3_.modified_at AS modified_at_49, b3_.created_at AS created_at_50, b4_.id AS id_51, b4_.name AS name_52, b4_.alias AS alias_53, b4_.active AS active_54, b4_.position AS position_55, b4_.modified_at AS modified_at_56, b4_.created_at AS created_at_57, b5_.id AS id_58, b5_.name AS name_59, b5_.short_description AS short_description_60, b5_.description AS description_61, b5_.curriculum AS curriculum_62, b5_.starts_at AS starts_at_63, b5_.ends_at AS ends_at_64, b5_.active AS active_65, b5_.position AS position_66, b6_.id AS id_67, b7_.id AS id_68, b7_.enabled AS enabled_69, b7_.email AS email_70, b7_.username AS username_71, b7_.netacad_email AS netacad_email_72, b7_.password AS password_73, b7_.phone AS phone_74, b7_.short_description AS short_description_75, b7_.description AS description_76, b7_.position AS position_77, b7_.comments AS comments_78, b7_.visible_in_site AS visible_in_site_79, b7_.key_facts AS key_facts_80, b7_.knowledge AS knowledge_81, b7_.slug AS slug_82, b7_.grants AS grants_83, b7_.lastname AS lastname_84, b7_.firstname AS firstname_85, b7_.modified_at AS modified_at_86, b7_.created_at AS created_at_87, b8_.id AS id_88, b8_.name AS name_89, b8_.description AS description_90, b8_.phone_home AS phone_home_91, b8_.phone_mobile AS phone_mobile_92, b8_.phone_work AS phone_work_93, b8_.email AS email_94, b8_.alt_email AS alt_email_95, b8_.email_opt_in AS email_opt_in_96, b8_.email_opt_changed_at AS email_opt_changed_at_97, b8_.gdpr_accepted_at AS gdpr_accepted_at_98, b8_.ssn AS ssn_99, b8_.company_fiscal_code AS company_fiscal_code_100, b8_.company_name AS company_name_101, b8_.company_registry_number AS company_registry_number_102, b8_.company_bank_account AS company_bank_account_103, b8_.company_bank AS company_bank_104, b8_.id_card_number AS id_card_number_105, b8_.birthdate AS birthdate_106, b8_.contact_first_name AS contact_first_name_107, b8_.contact_last_name AS contact_last_name_108, b8_.contact_picture AS contact_picture_109, b8_.billing_address_state AS billing_address_state_110, b8_.billing_address_city AS billing_address_city_111, b8_.billing_address_street AS billing_address_street_112, b8_.billing_address_street_name AS billing_address_street_name_113, b8_.billing_address_street_no AS billing_address_street_no_114, b8_.billing_address_postal_code AS billing_address_postal_code_115, b8_.billing_address_other AS billing_address_other_116, b8_.billing_address_building AS billing_address_building_117, b8_.billing_address_entrance AS billing_address_entrance_118, b8_.billing_address_floor AS billing_address_floor_119, b8_.billing_address_apt AS billing_address_apt_120, b8_.billing_address_country AS billing_address_country_121, b8_.shipping_address_state AS shipping_address_state_122, b8_.shipping_address_city AS shipping_address_city_123, b8_.shipping_address_street AS shipping_address_street_124, b8_.shipping_address_postal_code AS shipping_address_postal_code_125, b8_.shipping_address_other AS shipping_address_other_126, b8_.shipping_address_country AS shipping_address_country_127, b8_.bad_payer AS bad_payer_128, b8_.refered_by AS refered_by_129, b8_.lead_source_description AS lead_source_description_130, b8_.status_description AS status_description_131, b8_.created_at AS created_at_132, b8_.modified_at AS modified_at_133, b9_.id AS id_134, b9_.filename AS filename_135, b9_.path AS path_136, b9_.mime_type AS mime_type_137, b9_.created_at AS created_at_138, b0_.course_id AS course_id_139, b0_.room_id AS room_id_140, b0_.modified_by_id AS modified_by_id_141, b0_.created_by_id AS created_by_id_142, b1_.company_id AS company_id_143, b1_.category_id AS category_id_144, b1_.picture_id AS picture_id_145, b1_.secondary_picture_id AS secondary_picture_id_146, b1_.promo_picture_id AS promo_picture_id_147, b2_.user_id AS user_id_148, b3_.parent_id AS parent_id_149, b4_.parent_id AS parent_id_150, b5_.course_id AS course_id_151, b5_.class_id AS class_id_152, b6_.class_id AS class_id_153, b6_.user_id AS user_id_154, b7_.user_type_id AS user_type_id_155, b7_.picture_id AS picture_id_156, b7_.profile_picture_id AS profile_picture_id_157, b7_.team_picture_id AS team_picture_id_158, b8_.billing_address_city_id AS billing_address_city_id_159, b8_.billing_address_country_id AS billing_address_country_id_160, b8_.billing_address_region_id AS billing_address_region_id_161, b8_.user_id AS user_id_162, b8_.lead_source_id AS lead_source_id_163, b8_.account_type_id AS account_type_id_164, b8_.created_by_id AS created_by_id_165, b8_.modified_by_id AS modified_by_id_166, b9_.user_id AS user_id_167 FROM ba_class b0_ INNER JOIN ba_course b1_ ON b0_.course_id = b1_.id LEFT JOIN ba_upload b2_ ON b1_.secondary_picture_id = b2_.id INNER JOIN ba_course_category b3_ ON b1_.category_id = b3_.id LEFT JOIN ba_course_category b4_ ON b3_.parent_id = b4_.id LEFT JOIN ba_lesson b5_ ON b0_.id = b5_.class_id LEFT JOIN ba_class_instructor b6_ ON b0_.id = b6_.class_id LEFT JOIN ba_user b7_ ON b6_.user_id = b7_.id LEFT JOIN ba_crm_account b8_ ON b7_.id = b8_.user_id LEFT JOIN ba_upload b9_ ON b7_.picture_id = b9_.id WHERE b0_.active = 1 AND b0_.visible = 1 AND b1_.active = 1 AND b1_.visible = 1 AND b3_.active = 1 AND (b0_.visibile_until >= ? OR b0_.class_start_date >= ? OR b0_.class_start_date IS NULL) ORDER BY b0_.class_start_date ASC