function prereqs_content_alter

7.x prereqs.module prereqs_content_alter(&$render, $content_id)
6.x prereqs.module prereqs_content_alter(&$render, $content_id)

Implememnt hook_content_alter

File

modules/prereqs/prereqs.module, line 744
This is the module file for the prereqs module.

Code

function prereqs_content_alter(&$render, $content_id) {




  // TODO: Make this a setting?
  // Do we simply wish to DISPLAY prereq warnings in the popup window at all?      
  if ($content_id == "AdvisingScreen_display_popup_course_description") {

    fp_add_css(fp_get_module_path("prereqs") . "/css/prereqs.css");

    $course = @$render ["#course"]["value"];
    if (!is_object($course)) {
      return; // some kind of problem...
    }

    $student = @$GLOBALS ["screen"]->student;


    $warnings = prereqs_get_prereq_warnings_for_course($course, $student);

    if (count($warnings) > 0) {

      $warning_msg = "";
      foreach ($warnings as $details) {

        $msg = $details ["plain_text"];
        $bool_using_plain_text = TRUE;

        if (isset($details ["full_html"])) {
          $msg = $details ["full_html"];
          $bool_using_plain_text = FALSE;
        }


        $msg = str_replace("\\n", "\n", $msg);
        $msg = str_replace("  ", "  ", $msg);

        if ($bool_using_plain_text) {
          $msg = nl2br($msg);
        }


        $warning_msg .= "<div class='prereq-popup-warning-msg'>" . $msg . "</div>";
      }

      $render ["prereq_warnings"] = array(
        "label" => t("Prerequisites Warning:"),
        "value" => $warning_msg,
        "attributes" => array("class" => "popup-description-section tenpt"),
        "weight" => 500,
      );


      // Do we have permission to override the prereq for this course?
      if (!user_has_permission('override_course_locks')) {
        // Set a temporary variable in our GLOBALS array so we know this course cannot be advised.  Used in the advise.module, to make sure
        // if we get a description from within a group, we do not have this course selected when we change tabs back to the list.
        $GLOBALS ['prereqs_no_advise_course_id'][] = $course->course_id;
        $render ['hidden_vars_and_buttons']['value'] = "<p class='no-override-permission'><label>" . t("Cannot Advise") . "</label>" . t("Sorry, but you do not have permission to override the advising lock on this course.") . "<p>";
      }


    } // count of warnings > 0


  } // simply in the course description popup.




  ///////////////////////////////        
  ///////////////////////////////        
  ///////////////////////////////        
  ///////////////////////////////        
  ///////////////////////////////        







  // We want to place "anticipated availability" for the course in its popup window.
  // Only do this based on our setting.  
  if ($content_id == "AdvisingScreen_display_popup_course_description" && function_exists("course_search_get_course_rotation_schedule")
     && variable_get("prereqs_show_availability_in_popup", "no") == "yes") {
    // This is the popup window we see when we click on a course to get its description.
    //fpm($render);
    $course = @$render ["#course"]["value"];
    if (!is_object($course)) {
      return; // some kind of problem...
    }

    $school_id = $course->school_id;

    // What is the current advising term?
    //fpm($GLOBALS["fp_advising"]);
    $advising_term_id = $GLOBALS ["fp_advising"]["advising_term_id"];

    // Get the advising year from the term.
    $year = substr($advising_term_id, 0, 4);

    $rotation_schedule = course_search_get_course_rotation_schedule($course->course_id, $year, 5);
    $bool_not_anticipated = course_search_get_course_rotation_schedule_not_anticipated($course->course_id);
    //fpm($rotation_schedule);

    $bool_use_term_abbreviation = (variable_get("prereqs_use_term_desc_abbr_in_popup", "yes") == "yes");


    // By default, the scehdule text is saying that nothing is anticipated.
    $schedule_text = "<span class='prereqs-schedule-not-anticipated'>" . variable_get("prereqs_not_anticipated_text", "This course isn't currently anticipated to be offered. Please ask your advisor to learn more.");
    $schedule_text .= "</span>";

    if (!$bool_not_anticipated) {
      $x = "";
      foreach ($rotation_schedule as $term_id) 
       {
        $x .= " <span class='term-rot-avail'>" . htmlentities(get_term_description($term_id, $bool_use_term_abbreviation, $school_id), ENT_QUOTES) . "</span><span class='comma'>,</span>";
      }
      $x = rtrim($x, ',');


      if ($x) {
        $schedule_text = "<span class='term-rotation-schedule-terms'>$x</span>";
      }
    }



    if ($schedule_text) {
      // Add it to our render array.  Weeee.
      $render ["schedule"] = array(
        "label" => t("<b>Anticipated availability:</b>"),
        "value" => " <div class='prereqs-schedule-text'>" . $schedule_text . "</div>",
        "attributes" => array("class" => "popup-description-section tenpt"),
        "weight" => 510,
      );
    }

  } // if content_id == AdvisingScreen_display_popup_course_description and showing availability




  ////////////////////////////////////////////////
  ////////////////////////////////////////////////
  ////////////////////////////////////////////////
  ////////////////////////////////////////////////
  ////////////////////////////////////////////////




  // Show course prereqs in the popup window too.  
  if ($content_id == "AdvisingScreen_display_popup_course_description"
   && variable_get("prereqs_show_courses_in_popup", "no") == "yes") {

    $course = @$render ["#course"]["value"];
    if (!is_object($course)) {
      return; // some kind of problem...
    }

    $prereq_data = prereqs_get_prereq_string_for_course($course->course_id);
    if ($prereq_data != "") {

      fp_add_css(fp_get_module_path("prereqs") . "/css/prereqs.css");

      // Format the string for HTML.
      $prereq_data = "- " . str_replace("\n", "<br>- ", $prereq_data);
      $prereq_data = "<div class='popup-prereq-course-req'>$prereq_data</div>";



      $render ["prereq_courses"] = array(
        "value" => t("<b>Prerequisite courses:</b>") . $prereq_data,
        "attributes" => array("class" => "popup-description-section"),
      );
    }


  } // if in course description popup and showing course prereqs.






  //////////////////////////////////////////////////////
  //////////////////////////////////////////////////////
  //////////////////////////////////////////////////////
  //////////////////////////////////////////////////////




  // This is from the course_search module.  Are we displaying rereq courses in the course description?  
  if ($content_id == "course_search_display_courses" && variable_get("prereqs_show_courses_in_popup", "no") == "yes") {

    // Go through the render array, and find the "blocks" where we have our HTML about the courses.
    foreach ($render as $key => $details) {

      if (strstr($key, "course_search_course_block__")) {
        // Found it!    
        // Get the course_id.
        $course_id = str_replace("course_search_course_block__", "", $key);

        // Okay, let's get our prereq data...
        $prereq_data = prereqs_get_prereq_string_for_course($course_id);
        if ($prereq_data != "") {

          fp_add_css(fp_get_module_path("prereqs") . "/css/prereqs.css");

          // Format the string for HTML.
          $prereq_data = "- " . str_replace("\n", "<br>- ", $prereq_data);
          $prereq_data = "<!-- PREREQ_COURSE--><div class='popup-prereq-course-req'>$prereq_data</div>";

          $html = t("<b>Prerequisite courses:</b>") . $prereq_data;
          //  "attributes" => array("class" => "popup-description-section"),

          // Insert this html just after the description.  (above the <!-- DETAILS --> comment) 
          $render [$key]["value"] = str_replace("<!-- DETAILS -->", "$html<!-- DETAILS -->", $render [$key]["value"]);


        } // prereq_data != ""
      } // in course_search_course_block

    }



  } // course_search display courses
















}