You are here

function fckeditor_sorted_roles in FCKeditor - WYSIWYG HTML editor 5.2

Same name and namespace in other branches
  1. 6.2 fckeditor.module \fckeditor_sorted_roles()
  2. 6 fckeditor.module \fckeditor_sorted_roles()

sort roles according to precedence settings. previously sorted roles are followed by latest added roles.

2 calls to fckeditor_sorted_roles()
fckeditor_global_profile_form_build in ./fckeditor.module
fckeditor_user_get_profile in ./fckeditor.module

File

./fckeditor.module, line 1464
FCKeditor - The text editor for Internet - http://www.fckeditor.net Copyright (C) 2003-2007 Frederico Caldeira Knabben

Code

function fckeditor_sorted_roles($clear = FALSE) {
  static $order;
  if (isset($order) && $clear !== TRUE) {
    return $order;
  }
  $order = array();
  $roles = user_roles(0, 'access fckeditor');
  $result = db_query("SELECT settings FROM {fckeditor_settings} WHERE name='FCKeditor Global Profile'");
  $data = db_fetch_object($result);
  if ($data->settings) {
    $settings = unserialize($data->settings);
    if (isset($settings['rank']) && !empty($settings['rank'])) {
      foreach ($settings['rank'] as $rid) {
        if (isset($roles[$rid])) {
          $order[$rid] = $roles[$rid];
          unset($roles[$rid]);
        }
      }
    }
  }
  krsort($roles);

  //sort the remaining unsorted roles by id, descending.
  $order += $roles;
  return $order;
}