Plugin Directory

Changeset 647401


Ignore:
Timestamp:
01/03/2013 11:28:26 AM (13 years ago)
Author:
raido357
Message:

If only single course, preselect it always

File:
1 edited

Legend:

Unmodified
Added
Removed
  • dippler/trunk/classes/dippler-toolbar.php

    r633434 r647401  
    2222        $course_valid = false;
    2323        //Iterate through course ID's and load data
     24        $total_courses = 0;
     25        $active_course = null;
    2426        foreach ( $this->getList( 'COURSE_ENROLLED', 'id' ) as $course_id ) {
    2527            $course_manager = new DipplerCourseManager ( 'LOAD', $course_id );
     
    3234                }
    3335                $option_list .= '<option value="'.$course->id.'" '.$selected.'>'.$course->title.'</option>';
     36                $total_courses++;
     37                $active_course = $course;
    3438            }
    3539        }
     40       
     41        //If only one course, set it default to be selected all the time
     42        if ( $total_courses == 1 && is_user_logged_in() && !is_null( $active_course ) ) {
     43            $course_valid = true;
     44            $option_list = '<option value="'.$active_course->id.'" selected="selected">'.$active_course->title.'</option>';
     45            global $wp_query;
     46            $wp_query->set( 'dippler-course', $active_course->id ); //Use WP_Query, because main.php getGET method will work then.
     47        }
     48       
    3649        if ( !empty( $option_list ) ) {
    3750            $option_list = '<option value="-1">'.__( 'Select a course', $this->getTextdomain() ).'</option>'.$option_list;
    3851            $html .= $option_list;
    3952        }
     53       
    4054        $html .= '</select>';
    4155        $html .= '</form>';
Note: See TracChangeset for help on using the changeset viewer.