<?php

$user_id = get_current_user_id();
$available_courses = [];


if(!empty($course_query->have_posts())) {
	foreach ($course_query->posts as $course) {
		if ( LD_CMS_HELPER::is_course_admin($course->ID) ) {
			$available_courses[] = $course;
		}
    }
}

if(!empty($available_courses)) {
    ?>
    <div id="ld_cms_course_sub_list">
    <?php
    foreach ($available_courses as $course) {
        
        //Commented lines by W (24/5/2021)
         
	    // if ( !ld_course_check_user_access($course->ID,$user_id) ) {
		   //  continue;
	    // }

	    $available_course_ids[] = $course->ID;
        $data = get_post_meta($course->ID, 'course_schedule', true);

        $lessons = learndash_get_lesson_list($course->ID);
        $quizzes=learndash_get_course_quiz_list($course->ID);

        if (count($lessons) > 0 || count( $quizzes)>0) { ?>
            <div class="independant_node">
                <div class='fc-event fc-h-event fc-daygrid-event fc-daygrid-block-event' data-course-id="<?php echo $course->ID; ?>" data-cid="0" data-lid="0"
                     data-course-type="<?php echo $course->post_type; ?>">
                    <a href="javascript:;" id="csld_tree_node_<?php echo $course->ID; ?>_0_0"
                       class="ld_cms_tree_link"
                       data-type="<?php echo $course->post_type; ?>" data-cid="0" data-lid="0"
                       data-id="<?php echo $course->ID; ?>">+</a>&nbsp;<?php echo $course->post_title; ?>  
              <div class="drag_bars">
                  <span></span>
                <span></span>
              </div>
                </div>
            </div>
        <?php } else { ?>
            <div class="independant_node">
                <div class='fc-event fc-h-event fc-daygrid-event fc-daygrid-block-event' data-course-id="<?php echo $course->ID; ?>" data-cid="0" data-lid="0"
                     data-course-type="<?php echo $course->post_type; ?>">
                    <a href="javascript:;" id="csld_tree_node_<?php echo $course->ID; ?>_0_0"
                         class="ld_cms_tree_link"
                       data-type="<?php echo $course->post_type; ?>" data-cid="0" data-lid="0"
                       data-id="<?php echo $course->ID; ?>"></a>&nbsp;<?php echo $course->post_title; ?> 
              <div  class="drag_bars">
                  <span></span>
                <span></span>
              </div>
                </div>
            </div>
        <?php }
    }
    ?>
    </div>
        <?php
} else {
    ?>
    <p id="ld_cms_sidebar_message"><?php echo sprintf(__('No %s found for your search criteria', "cs_ld_addon"), LearnDash_Custom_Label::label_to_lower('courses')); ?></p>
    <?php
}