You are here

function _hosting_package_instances_load in Hosting 5

Same name and namespace in other branches
  1. 6.2 package/hosting_package.instance.inc \_hosting_package_instances_load()
  2. 7.4 package/hosting_package.instance.inc \_hosting_package_instances_load()
  3. 7.3 package/hosting_package.instance.inc \_hosting_package_instances_load()
2 calls to _hosting_package_instances_load()
hosting_package_instances_load in package/hosting_package.instance.inc
hosting_package_instance_load in package/hosting_package.instance.inc

File

package/hosting_package.instance.inc, line 98
API for mapping packages to various Hosting node types

Code

function _hosting_package_instances_load($param, $multiple = FALSE) {
  $arguments = array();
  if (is_numeric($param)) {
    $cond = 'iid = %d';
    $arguments[] = $param;
  }
  elseif (is_array($param)) {

    // Turn the conditions into a query.
    foreach ($param as $key => $value) {
      $cond[] = $key . " = '%s'";
      $arguments[] = $value;
    }
    $cond = implode(' AND ', $cond);
  }
  else {
    return FALSE;
  }
  $instances = array();
  $result = db_query("SELECT \n      n.title, r.type, p.package_type, p.nid,\n      i.iid, i.version, i.schema_version,\n      i.status, p.description, p.short_name, i.rid,\n      i.package_id\n      FROM {hosting_package_instance} i \n        LEFT JOIN {hosting_package} p ON p.nid=i.package_id \n        LEFT JOIN {node} n ON p.nid=n.nid\n        LEFT JOIN {node} r ON r.nid=i.rid\n      WHERE " . $cond, $arguments);
  while ($instance = db_fetch_object($result)) {
    $languages = array(
      'en' => 'en',
    );

    // load language options: if argument is null, load all language options
    $lang_result = db_query("SELECT DISTINCT(language) FROM {hosting_package_languages} WHERE iid = %d", $instance->iid);
    while ($language = db_fetch_object($lang_result)) {
      $languages[$language->language] = _hosting_language_name($language->language);
    }
    $instance->languages = $languages;
    if (!$multiple) {
      return $instance;
    }
    $instances[$instance->iid] = $instance;
  }
  return $instances;
}