You are here

function _hosting_get_allowed_platforms in Hostmaster (Aegir) 6

Small helper function to get platforms that haven't been deleted or locked, and are accessible by this user.

We can get called a few times during a page request, so we implement static caching for speed, and because the platforms that are available are unlikely to change during a single page request.

@todo this is not the right way. we need to implement node-level access permissions here, the same way we do for sites. see http://drupal.org/node/725952

Parameters

$uid: The user ID to retrieve the allowed platforms for. If none is specified the currently logged in user will be used.

$reset: Whether to reset the internal static cache or not.

1 call to _hosting_get_allowed_platforms()
hosting_site_available_options in modules/hosting/site/hosting_site.form.inc
Pass in a site node and return an array of valid options for it's fields.

File

modules/hosting/client/hosting_client.module, line 928

Code

function _hosting_get_allowed_platforms($uid = NULL, $reset = FALSE) {
  static $platforms = array();
  if ($reset) {
    $platforms = array();
  }
  if (is_null($uid)) {
    global $user;
    $uid = $user->uid;
  }
  if (!isset($platforms[$uid])) {
    $platforms[$uid] = array();
    $result = db_query("SELECT n.nid, n.title FROM {node} n LEFT JOIN {hosting_platform} h ON n.nid = h.nid\n                      LEFT JOIN {hosting_platform_client_access} p ON n.nid = p.pid\n                      LEFT JOIN {hosting_client_user} c ON c.client = p.cid\n                      WHERE n.type='platform' AND n.status=1 AND h.status > '%d'\n                      AND (c.user= %d OR p.pid IS NULL)", HOSTING_PLATFORM_LOCKED, $uid);
    while ($server = db_fetch_object($result)) {
      $platforms[$uid][$server->nid] = $server->title;
    }
  }
  return $platforms[$uid];
}