function AdvisingScreen::display_group

7.x AdvisingScreen.php AdvisingScreen::display_group(Group $place_group)
6.x AdvisingScreen.php AdvisingScreen::display_group(Group $place_group)

This function displays a Group object on the degree plan. This is not the selection popup display. It will either show the group as multi rows, filled in with courses, or as a "blank row" for the user to click on.

Parameters

Group $place_group:

Return value

string

1 call to AdvisingScreen::display_group()
AdvisingScreen::display_semester in classes/AdvisingScreen.php
Given a Semester object, this will generate the HTML to draw it out to the screen. We will take advantage of the render engine, so we can utilize hook_content_alter later on.

File

classes/AdvisingScreen.php, line 3542

Class

AdvisingScreen

Code

function display_group(Group $place_group) 
 {
  // Display a group, either filled in with courses,
  // and/or with a "blank row" for the user to
  // click on.
  $rtn = "";

  // Now, if you will recall, all of the groups and their courses, etc,
  // are in the degree_plan's list_groups.  The $place_group object here
  // is just a placeholder.  So, get the real group...

  if (!$group = $this->degree_plan->find_group($place_group->group_id)) 
   {
    fpm("Group not found.");
    return;
  }


  $title = $group->title;

  $display_course_list = new CourseList();

  // Okay, first look for courses in the first level
  // of the group.

  $display_semesterNum = $place_group->assigned_to_semester_num;
  $req_by_degree_id = $group->req_by_degree_id;

  // Make sure all courses and subgroups have the same req_by_degree_id set.
  $group->set_req_by_degree_id($group->req_by_degree_id);

  // What we are trying to do is end up with a list of courses we want to display on the screen (for example,
  // that the student took or were substituted in)
  $group->list_courses->remove_unfulfilled_and_unadvised_courses();
  $group->list_courses->reset_counter();
  while ($group->list_courses->has_more()) 
   {
    $course = $group->list_courses->get_next();

    // Do we have enough hours to keep going?
    $fulfilled_hours = $display_course_list->count_hours("", FALSE, TRUE, FALSE, FALSE, $req_by_degree_id);
    $remaining = $place_group->hours_required - $fulfilled_hours;
    // If the course in question is part of a substitution that is not
    // for this group, then we should skip it.
    if (!($course->course_list_fulfilled_by->is_empty)) 
     {
      $try_c = $course->course_list_fulfilled_by->get_first();
      if ($try_c->get_bool_substitution($req_by_degree_id) == TRUE && $try_c->get_bool_assigned_to_group_id($group->group_id) != TRUE) 
       {
        continue;
      }
    }


    if (!($course->course_list_fulfilled_by->is_empty) && $course->course_list_fulfilled_by->get_first()->get_has_been_displayed($req_by_degree_id) != TRUE && $course->get_has_been_displayed($req_by_degree_id) != TRUE) 
     {
      $c = $course->course_list_fulfilled_by->get_first();
      $ch = $c->get_hours($req_by_degree_id);




      // Because PHP has dumb floating point arithmatic, we are going to round our values to 8 places,
      // otherwise I was getting weird results like 0.34 < 0.34 == true.  I chose 8 places to make sure it wouldn't
      // actually cause the values to round and mess up the math.
      $remaining = round($remaining, 8);
      $ch = round($ch, 8);



      // Is whats remaining actually LESS than the course hours?  If so, we need to skip it.        
      if ($remaining < $ch) 
       {
        continue;
      }


      $c->temp_flag = false;
      $c->icon_filename = $group->icon_filename;
      $c->title_text = "This course is a member of $group->title." . " ($place_group->requirement_type)";
      $c->requirement_type = $place_group->requirement_type;
      $c->req_by_degree_id = $req_by_degree_id;



      $display_course_list->add($c);


    }




    if ($course->bool_advised_to_take && $course->get_has_been_displayed($req_by_degree_id) != true && $course->assigned_to_semester_num == $display_semesterNum) 
     {



      $c = $course;

      if ($remaining < $c->get_hours($req_by_degree_id)) 
       {
        continue;
      }

      $c->temp_flag = true;
      $c->icon_filename = $group->icon_filename;
      $c->req_by_degree_id = $req_by_degree_id;
      $c->title_text = t("The student has been advised to take this course to fulfill a @gt requirement.", array("@gt" => $group->title));



      $display_course_list->add($c);


    }
  }


  $group->list_groups->reset_counter();
  while ($group->list_groups->has_more()) 
   {

    $branch = $group->list_groups->get_next();
    // look for courses at this level...
    if (!$branch->list_courses->is_empty) 
     {

      $branch->list_courses->sort_alphabetical_order();
      $branch->list_courses->reset_counter();
      while ($branch->list_courses->has_more()) 
       {
        $course = $branch->list_courses->get_next();

        // Do we have enough hours to keep going?
        $fulfilled_hours = $display_course_list->count_hours("", FALSE, TRUE, FALSE, FALSE, $req_by_degree_id);
        $remaining = $place_group->hours_required - $fulfilled_hours;


        if (!($course->course_list_fulfilled_by->is_empty) && $course->course_list_fulfilled_by->get_first()->get_has_been_displayed($req_by_degree_id) != true && $course->get_has_been_displayed($req_by_degree_id) != true) 
         {
          $c = $course->course_list_fulfilled_by->get_first();
          if ($remaining < $c->get_hours() || $remaining == 0) 
           {
            continue;
          }

          $c->temp_flag = false;
          $c->icon_filename = $group->icon_filename;
          $c->title_text = "This course is a member of $group->title." . "($place_group->requirement_type)";
          $c->requirement_type = $place_group->requirement_type;
          $c->req_by_degree_id = $req_by_degree_id;


          // TODO:  This right here is how we show specified-repeats in groups with branches.
          // TODO:  Originally we were making sure there wasn't a "match" already in the display_course_list, which was
          //        of course excluding any of our specified repeats.
          //if (!$display_course_list->find_match($c))
          $found_match = $display_course_list->find_match($c);
          if (!$found_match || ($found_match && $c->bool_specified_repeat == TRUE)) {
            $display_course_list->add($c);
          }
          else if (is_object($c->course_transfer)) {
            if (!$display_course_list->find_match($c->course_transfer)) 
             { // Make sure it isn't already in the display list.
              $display_course_list->add($c);
            }
          }


        }

        if ($course->bool_advised_to_take && $course->get_has_been_displayed($req_by_degree_id) != true && $course->assigned_to_semester_num == $display_semesterNum) 
         {

          $c = $course;
          if ($remaining < $c->get_hours($req_by_degree_id) || $remaining == 0) 
           {

            continue;
          }

          $c->temp_flag = true;
          $c->icon_filename = $group->icon_filename;
          $c->req_by_degree_id = $req_by_degree_id;
          $c->title_text = "The student has been advised to take this course to fulfill a $group->title requirement.";
          if (!$display_course_list->find_match($c)) 
           {
            $display_course_list->add($c);
          }

        }


      }

    }
  }




  $display_course_list->sort_advised_last_alphabetical();
  // Make sure we're all on the same page, for what degree_id we're being displayed under.
  $display_course_list->set_req_by_degree_id($req_by_degree_id);


  $rtn .= $this->display_group_course_list($display_course_list, $group, $display_semesterNum);


  // original: $fulfilled_hours = $display_course_list->count_hours("", false, false, TRUE, false, $req_by_degree_id);
  // Changing to new line, to match other argument list for previous occurances of 'fulfilled_hours'. This makes it so that
  // a zero-hour course does not "use up" a 1 hour spot in the course hour counts.
  // TODO:  This might cause a group of *only* zero hour courses to never count as being filled.
  // TODO:  Maybe this difference between the original and this line should be a setting?  Or per-group?    
  $fulfilled_hours = $display_course_list->count_hours("", FALSE, TRUE, FALSE, FALSE, $req_by_degree_id);


  $fulfilled_credit_hours = $display_course_list->count_credit_hours("", false, true);



  $test_hours = $fulfilled_hours;

  // if the fulfilledCreditHours is > than the fulfilledHours,
  // then assign the fulfilledCreditHours to the testHours.
  if ($fulfilled_credit_hours > $fulfilled_hours) 
   { // done to fix a bug involving splitting hours in a substitution.     
    $test_hours = $fulfilled_credit_hours;
  }
  // If there are any remaining hours in this group,
  // draw a "blank" selection row.
  $remaining = $place_group->hours_required - $test_hours;
  $place_group->hours_remaining = $remaining;
  $place_group->hours_fulfilled = $fulfilled_hours;
  $place_group->hours_fulfilled_for_credit = $fulfilled_credit_hours;




  if ($remaining > 0) 
   {
    $rowclass = "";
    // If we have met the min hours (if the group even HAS min hours) then add a class to $rowclass,
    // so we can hide it or whatever with CSS.
    if ($group->has_min_hours_allowed()) {
      if ($test_hours >= $group->min_hours_allowed) {
        $rowclass .= "group-select-min-hours-fulfilled";
      }
    }


    $rtn .= $this->draw_group_select_row($place_group, $remaining, $rowclass);

  }

  return $rtn;
}