function Course::fix_title

6.x Course.php Course::fix_title($str = "")
7.x Course.php Course::fix_title($str = "")

This function will correct capitalization problems in course titles.

Parameters

string $str:

Return value

string

2 calls to Course::fix_title()
Course::load_descriptive_data in classes/Course.php
This function will load $this will all sorts of descriptive data from the database. For example, hours, title, description, etc.
Course::load_descriptive_transfer_data in classes/Course.php
Similar to load_descriptive_data(), this will load whatever we have for $this transfer course.

File

classes/Course.php, line 1350

Class

Course

Code

function fix_title($str = "") 
 {

  if ($str == "") 
   {
    $str = $this->title;
  }

  // Should we do this at all?  We will look at the "autocapitalize_course_titles" setting.
  $auto = variable_get_for_school("autocapitalize_course_titles", 'yes', $this->school_id);
  if ($auto == "no") {
    // Nope!  Just return.
    $this->title = $str;
    return $str;
  }

  // Otherwise, we may continue with the capitalization scheme:

  $str = str_replace("/", " / ", $str);
  $str = str_replace("/", " / ", $str);
  $str = str_replace("-", " - ", $str);
  $str = str_replace(":", ": ", $str);
  $str = str_replace("(", "( ", $str);

  // Only pad an ampersand if we are not talking about
  // an HTML character.
  if (!strstr($str, "&#")) 
   {
    $str = str_replace("&", " & ", $str);
  }

  // Let's also get rid of extra spaces.
  $str = str_replace("   ", " ", $str);
  $str = str_replace("  ", " ", $str);

  // convert to ucwords and fix some problems introduced by that.
  $str = trim(ucwords(strtolower($str)));

  $str = str_replace("Iii", "III", $str);
  $str = str_replace("Ii", "II", $str);
  $str = str_replace(" Iv", " IV", $str);
  $str = str_replace(" Vi", " VI", $str);
  $str = str_replace(" Of ", " of ", $str);
  $str = str_replace(" The ", " the ", $str);
  $str = str_replace(" In ", " in ", $str);
  $str = str_replace(" And ", " and ", $str);
  $str = str_replace(" An ", " an ", $str);
  $str = str_replace(" A ", " a ", $str);
  $str = str_replace(" To ", " to ", $str);
  $str = str_replace(" For ", " for ", $str);

  // Strange words and abreviations which should be changed.
  $str = str_replace("Afrotc", "AFROTC", $str);
  $str = str_replace("Gis", "GIS", $str);
  $str = str_replace("Dna", "DNA", $str);
  $str = str_replace(" Cpr", "CPR", $str);
  $str = str_replace(" Rn", " RN", $str);
  $str = str_replace(" Micu", " MICU", $str);
  $str = str_replace(" Sicu", " SICU", $str);
  $str = str_replace(" Picu", " PICU", $str);
  $str = str_replace(" Nicu", " NICU", $str);
  $str = str_replace("Uas ", "UAS ", $str);
  $str = str_replace(" Uas", " UAS", $str);


  // Cleanup
  $str = str_replace("( ", "(", $str);
  $str = str_replace(" - ", "-", $str);


  // Is this just a course name by itself?  If so, it should
  // all be capitalized.
  $temp = explode(" ", $str);

  if (count($temp) == 2
   && strlen($temp [0]) <= 4
     && strlen($temp [1]) <= 4) 
   { // We could also test to see if there are numbers starting the
    // second token.
    $str = strtoupper($str);
  }

  // If this contains the word "formerly" then we need to pull out what's
  // there and make it all uppercase, except for the word Formerly.
  if (strstr(strtolower($str), strtolower("formerly "))) 
   {

    $formline = preg_replace("/.*\((formerly .*)\).*/i", "$1", $str);
    $str = str_replace($formline, strtoupper($formline), $str);
    $str = str_replace("FORMERLY ", "Formerly ", $str);
  }


  $this->title = $str;

  return $str;
}