function Course::get_bool_assigned_to_group_id

7.x Course.php Course::get_bool_assigned_to_group_id($group_id)
6.x Course.php Course::get_bool_assigned_to_group_id($group_id)

Return TRUE or FALSE if this this course was ever assigned to the supplied group_id. if $group_id == -1, then return TRUE if it was assigned to ANY group.

File

classes/Course.php, line 2051

Class

Course

Code

function get_bool_assigned_to_group_id($group_id) {

  // Trim and force NULL or 0 to be ''.  This is for PHP 8 compatibility.
  $group_id = fp_trim($group_id);
  if (is_numeric($group_id) && intval($group_id) == 0) {
    $group_id = '';
  }

  $bool_yes_specific_group = FALSE;
  $bool_yes_any_group = FALSE;

  foreach ($this->assigned_to_group_ids_array as $k => $v) {
    if (intval($v) > 0 || strlen($v) > 0) {
      $bool_yes_any_group = TRUE;
    }

    // Convert 0 and NULL to '' for PHP 8 compatibility 
    if (is_numeric($v) && intval($v) == 0) {
      $v = '';
    }
    if ($v == NULL) {
      $v = '';
    }

    if ($group_id == $v) {
      $bool_yes_specific_group = TRUE;
    }

  }


  if ($group_id == -1) {
    return $bool_yes_any_group;
  }

  // Else...
  return $bool_yes_specific_group;

}