function _CourseList::remove_duplicates

4.x _CourseList.php _CourseList::remove_duplicates()
5.x _CourseList.php _CourseList::remove_duplicates()

Removes null's and duplicate courses from the list.

File

classes/_CourseList.php, line 2656

Class

_CourseList

Code

function remove_duplicates() 
 {
  // Go through and remove duplicates from the list.
  // Also remove null's

  $tarray = array();
  $new_list = new CourseList();
  // Do this by adding elements to an array.
  // course_id => index in list.
  for ($t = 0; $t < $this->count; $t++) 
   {
    $course = $this->array_list [$t];
    if ($course == null) 
     {
      continue;
    }

    $tarray [$course->course_id] = -1;
  }

  for ($t = 0; $t < $this->count; $t++) 
   {
    $course = $this->array_list [$t];
    if ($course == null) 
     {
      continue;
    }

    //if (is_object($course->courseFulfilledBy))
    if (!($course->course_list_fulfilled_by->is_empty)) 
     {
      $tarray [$course->course_id] = $t;
      continue;
    }

    if ($tarray [$course->course_id] * 1 < 0) 
     {
      $tarray [$course->course_id] = $t;
    }

  }

  // Now, go through tarray and rebuild the newList.
  foreach ($tarray as $course_id => $i) 
   {
    $new_list->add($this->array_list [$i]);
  }

  // Switch over the reference.
  $this->array_list = $new_list->array_list;
  $this->reset_counter();

}