You are here

function hosting_task_fetch_tasks in Hosting 7.4

Same name and namespace in other branches
  1. 6.2 task/hosting_task.module \hosting_task_fetch_tasks()
  2. 7.3 task/hosting_task.module \hosting_task_fetch_tasks()

@todo Please document this function.

See also

http://drupal.org/node/1354

1 call to hosting_task_fetch_tasks()
hosting_task_table in task/hosting_task.module
A concise table listing of the tasks affecting this node.

File

task/hosting_task.module, line 1820
Web server node type is defined here.

Code

function hosting_task_fetch_tasks($rid) {
  $node = node_load($rid);
  $result = db_query("SELECT n.nid, t.task_type, t.task_status FROM {node} n INNER JOIN {hosting_task} t ON n.vid = t.vid\n    WHERE n.type = :ntype AND t.rid = :trid\n    ORDER BY n.changed ASC", array(
    ':ntype' => 'task',
    ':trid' => $rid,
  ));
  foreach ($result as $obj) {
    $return[$obj->task_type] = array(
      'nid' => $obj->nid,
      'task_status' => $obj->task_status,
      'exists' => TRUE,
    );
  }
  $tasks = hosting_available_tasks($node->type);
  ksort($tasks);
  foreach ($tasks as $type => $hook_task) {
    if (!isset($return[$type])) {
      $return[$type] = array();
    }
    $access_callback = !empty($hook_task['access callback']) ? $hook_task['access callback'] : 'hosting_task_menu_access';
    $task = array();
    $task = array_merge($return[$type], $hook_task);
    $allowed = isset($task['exists']) && !in_array($task['task_status'], array(
      HOSTING_TASK_QUEUED,
      HOSTING_TASK_PROCESSING,
    )) || !isset($task['exists']);
    if ($allowed && empty($task['hidden']) && $access_callback($node, $type)) {
      $task['task_permitted'] = TRUE;
    }
    else {
      $task['task_permitted'] = FALSE;
    }

    // @TODO: Use task defaults array to prevent notices.
    if (!isset($task['dialog'])) {
      $task['dialog'] = FALSE;
    }
    if (!isset($task['task_status'])) {
      $task['task_status'] = NULL;
    }
    $task['class'] = hosting_task_status_class($task['task_status']);
    $return[$type] = $task;
  }
  return $return;
}