You are here

function _hosting_get_allowed_platforms in Hosting 7.4

Same name and namespace in other branches
  1. 6.2 client/hosting_client.module \_hosting_get_allowed_platforms()
  2. 7.3 client/hosting_client.module \_hosting_get_allowed_platforms()

Get accessible platforms that haven't been deleted or locked.

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

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

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

2 calls to _hosting_get_allowed_platforms()
hosting_migrate_platform in migrate/hosting_migrate.batch.inc
Batch migration of sites between platforms.
hosting_site_available_options in site/hosting_site.form.inc
Pass in a site node and return an array of valid options for it's fields.
1 string reference to '_hosting_get_allowed_platforms'
hosting_migrate_platform in migrate/hosting_migrate.batch.inc
Batch migration of sites between platforms.

File

client/hosting_client.module, line 1131

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\n                        FROM {node} n\n                        LEFT JOIN {hosting_platform} h\n                        ON n.nid = h.nid\n                        LEFT JOIN {hosting_platform_client_access} p\n                        ON n.nid = p.pid\n                        LEFT JOIN {hosting_client_user} c\n                        ON c.client = p.cid\n                        WHERE n.type = :type\n                        AND n.status = :nstatus\n                        AND h.status > :hstatus\n                        AND (c.user = :cuser OR p.pid IS NULL)", array(
      ':type' => 'platform',
      ':nstatus' => 1,
      ':hstatus' => HOSTING_PLATFORM_LOCKED,
      ':cuser' => $uid,
    ));
    foreach ($result as $server) {
      $platforms[$uid][$server->nid] = $server->title;
    }
  }
  return $platforms[$uid];
}