function schools_content_alter

7.x schools.module schools_content_alter(&$render, $render_id)
6.x schools.module schools_content_alter(&$render, $render_id)

File

modules/schools/schools.module, line 576
Schools module.

Code

function schools_content_alter(&$render, $render_id) {

  $defs = schools_get_school_definitions(TRUE);


  if ($render_id == 'admin_display_degrees') {

    //fpm($render);
    // Add the school to the table.
    $v = $render ['degrees_table_top']['value'];
    $v = str_replace("</tr>", "<th>School</th></tr>", $v);
    $render ['degrees_table_top']['value'] = $v;

    foreach ($render as $key => $val) {
      if (strstr($key, 'degree_row_')) {
        // Find out the school_id for this degree, if it exists.
        $school_id = intval($val ['data']['db_row']['school_id']);

        $school_code = "-";
        if ($school_id != 0) {
          $school_code = $defs [$school_id]['school_code'];
        }

        // Fill in the school code as the last td in the table row.
        $render [$key]['value'] = str_replace('</tr>', "<td class='degree-school'>$school_code</td></tr>", $render [$key]['value']);


        if ($school_id == 0) {
          continue; // Everyone can edit school_id 0
        }

        // A school id has indeed been set, so we need to see if this user is allowed to edit it or not.          
        if (!user_has_permission('administer_' . $school_id . '_degree_data')) {
          // No, so let's remove it.
          unset($render [$key]);
        }


      }
    } // foreach

  } // admin_display_degrees


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

  if ($render_id == 'admin_display_groups') {

    // Add school to our table top.
    $v = $render ['groups_table_top']['value'];
    $v = str_replace("</tr>", "<th>School</th></tr>", $v);
    $render ['groups_table_top']['value'] = $v;

    foreach ($render as $key => $val) {
      if (strstr($key, 'group_row_')) {
        // Find out the school_id for this group, if it exists.        
        $school_id = intval($val ['data']['db_row']['school_id']);


        $school_code = "-";
        if ($school_id != 0) {
          $school_code = $defs [$school_id]['school_code'];
        }

        // Fill in the school code as the last td in the table row.
        $render [$key]['value'] = str_replace('</tr>', "<td class='group-school'>$school_code</td></tr>", $render [$key]['value']);



        if ($school_id == 0) {
          continue; // everyone can edit school_id 0
        }

        // A school id has indeed been set, so we need to see if this user is allowed to edit it or not.          
        if (!user_has_permission('administer_' . $school_id . '_group_data')) {
          // No, so let's hide it.
          unset($render [$key]);
        }


      }
    } // foreach



  } // admin_display_groups 


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

  if ($render_id == 'admin_display_courses') {

    // Add school to our table top.
    $v = $render ['courses_table_top']['value'];
    $v = str_replace("</tr>", "<th>School</th></tr>", $v);
    $render ['courses_table_top']['value'] = $v;


    foreach ($render as $key => $val) {
      if (strstr($key, 'course_row_')) {
        // Find out the school_id for this degree, if it exists.

        $school_id = intval($val ['data']['db_row']['school_id']);


        $school_code = "-";
        if ($school_id != 0) {
          $school_code = $defs [$school_id]['school_code'];
        }


        // Fill in the school code as the last td in the table row.
        $render [$key]['value'] = str_replace('</tr>', "<td class='course-school'>$school_code</td></tr>", $render [$key]['value']);


        if ($school_id == 0) {
          continue; // everyone can edit school id 0        
        }


        // A school id has indeed been set, so we need to see if this user is allowed to edit it or not.          
        if (!user_has_permission('administer_' . $school_id . '_course_data')) {
          // No, so let's hide it.
          unset($render [$key]);
        }


      }
    } // foreach



  } // admin_display_courses   





  if ($render_id == 'user_display_users') {
    // Add school to our table top.
    $v = $render ['users_table_top']['value'];
    $v = str_replace("</tr>", "<th>School</th></tr>", $v);
    $render ['users_table_top']['value'] = $v;

    foreach ($render as $key => $val) {
      if (strstr($key, 'user_row_')) {
        // Find out the school_id for this degree, if it exists.

        $school_id = intval($val ['data']['db_row']['school_id']);


        $school_code = "-";
        if ($school_id != 0) {
          $school_code = $defs [$school_id]['school_code'];
        }


        // Fill in the school code as the last td in the table row.
        $render [$key]['value'] = str_replace('</tr>', "<td class='course-school'>$school_code</td></tr>", $render [$key]['value']);


        if ($school_id == 0) {
          continue; // everyone can edit school id 0        
        }


        // A school id has indeed been set, so we need to see if this user is allowed to edit it or not.          
        if (!user_has_permission('manage_' . $school_id . '_user_data')) {
          // No, so let's hide it.
          unset($render [$key]);
        }


      }
    } // foreach    


  } // user_display_users




}