function tripal_analysis_set_feature_permission

2.x tripal_analysis_privacy.inc tripal_analysis_set_feature_permission($analysis_id, $nid)
3.x tripal_analysis_privacy.inc tripal_analysis_set_feature_permission($analysis_id, $nid)
1.x tripal_analysis_privacy.inc tripal_analysis_set_feature_permission($analysis_id, $nid)

Set permissions for features associated with an analysis @todo Stephen: ensure the $nid param is defined correctly

Parameters

$analysis_id: Features associated with this analysis will have their permissions set

$nid: The node ID of the analysis

File

tripal_analysis/includes/tripal_analysis_privacy.inc, line 49
Perform permission check (required node_privacy_byrole module)

Code

function tripal_analysis_set_feature_permission($analysis_id, $nid) {

  print "Updating feature permissions:\n";

  // Get features associated with the analysis
  $sql = "SELECT feature_id FROM {analysisfeature} WHERE analysis_id = %d";
  $features = chado_query($sql, $analysis_id);

  // Convert feature_id into node_id
  $feature_nids = array();
  $counter = 0;
  $sql = "SELECT nid FROM {chado_feature} WHERE feature_id = %d";
  while ($feature = db_fetch_object($features)) {
    $feature_nids[$counter] = db_result(db_query($sql, $feature->feature_id));
    $counter++;
  }

  //Convert analysis_id into node_id
  $ana_nid = db_result(db_query("SELECT nid FROM {chado_analysis} WHERE analysis_id = %analysis_id", $analysis_id));
  // Get available roles
  $roles = array_keys(user_roles());

  $interval = intval(($counter + 1) * 0.01);
  $idx_iterations = 1;

  // Update permission node by node
  foreach ($feature_nids as $fnid) {
    if ($idx_iterations % $interval == 0) {
      $percentage = (int) ($idx_iterations / ($counter + 1) * 100);
      tripal_job_set_progress($job_id, $percentage);
      print $percentage . "% ";
    }

    db_query("DELETE FROM {node_privacy_byrole} WHERE nid = %d AND realm = 'node_privacy_byrole_role'", $fnid);
    foreach ($roles as $rid) {
      // Get permissions of this analysis for this role
      $rsql = "SELECT * FROM {node_privacy_byrole} WHERE gid = %d AND nid = %d AND realm = 'node_privacy_byrole_role'";
      $ana_perm = db_fetch_object(db_query($rsql, $rid, $ana_nid));
      db_query("INSERT INTO {node_privacy_byrole} (nid, gid, realm, grant_view, grant_update, grant_delete)
                  VALUES (%d, %d, '%s', %d, %d, %d)", $fnid, $rid, 'node_privacy_byrole_role', $ana_perm->grant_view, 
      $ana_perm->grant_update, $ana_perm->grant_delete);
    }
    $node = node_load($fnid);
    node_save($node);
    $idx_iterations++;
  }
}