Przeglądaj źródła

Commit of converted tripal_project module

spficklin 11 lat temu
rodzic
commit
8b988ffc57

+ 10 - 11
tripal_project/includes/tripal_project.admin.inc

@@ -155,8 +155,8 @@ function tripal_project_admin_validate($form, &$form_state) {
       }
       if ($project_id and preg_match("/^\d+$/i" , $project_id)) {
         // get the list of projects
-        $sql = "SELECT * FROM {Project} WHERE project_id = %d";
-        $project = chado_query($sql, $project_id)->fetchObject();
+        $sql = "SELECT * FROM {project} WHERE project_id = :project_id";
+        $project = chado_query($sql, array(':project_id' => $project_id))->fetchObject();
         $to_sync[$project_id] = "$project->genus $project->species";
       }
     }
@@ -182,8 +182,8 @@ function tripal_project_admin_validate($form, &$form_state) {
     foreach ($projects as $project_id) {
       if ($project_id and preg_match("/^\d+$/i" , $project_id)) {
         // get the project info
-        $sql = "SELECT * FROM {project} WHERE project_id = %d";
-        $project = chado_query($sql , $project_id)->fetchObject();
+        $sql = "SELECT * FROM {project} WHERE project_id = :project_id";
+        $project = chado_query($sql , array(':project_id' => $project_id))->fetchObject();
         $job_args[0] = $project_id;
         tripal_add_job("Reindex features for project: $project->genus ".
          "$project->species", 'tripal_project' ,
@@ -199,8 +199,8 @@ function tripal_project_admin_validate($form, &$form_state) {
     foreach ($projects as $project_id) {
       if ($project_id and preg_match("/^\d+$/i", $project_id)) {
         // get the project info
-        $sql = "SELECT * FROM {project} WHERE project_id = %d";
-        $project = chado_query($sql , $project_id)->fetchObject();
+        $sql = "SELECT * FROM {project} WHERE project_id = :project_id";
+        $project = chado_query($sql , array(':project_id' => $project_id))->fetchObject();
         $job_args[0] = $project_id;
         tripal_add_job("Set taxonomy for features in project: ".
           "$project->genus $project->species" , 'tripal_project',
@@ -230,20 +230,19 @@ function tripal_project_sync_projects($project_id = NULL, $job_id = NULL) {
     $results = chado_query($sql);
   }
   else {
-    $sql = "SELECT * FROM {project} P WHERE project_id = %d";
-    $results = chado_query($sql, $project_id);
+    $sql = "SELECT * FROM {project} P WHERE project_id = :project_id";
+    $results = chado_query($sql, array(':project_id' => $project_id));
   }
 
   // We'll use the following SQL statement for checking if the project
   // already exists as a drupal node.
-  $sql = "SELECT * FROM {chado_project} ".
-         "WHERE project_id = %d";
+  $sql = "SELECT * FROM {chado_project} WHERE project_id = :project_id";
 
   while ($project = $results->fetchObject()) {
 
     // check if this project already exists in the drupal database. if it
     // does then skip this project and go to the next one.
-    if (!db_query($sql, $project->project_id)->fetchObject()) {
+    if (!db_query($sql, array(':project_id' => $project->project_id))->fetchObject()) {
 
       $new_node = new stdClass();
       $new_node->type = 'chado_project';

+ 18 - 18
tripal_project/tripal_project.install

@@ -10,6 +10,24 @@
  * multiple project/mysql instances as well as manage and create such project instances
  */
 
+/**
+ * Implementation of hook_requirements().
+ *
+ */
+function tripal_project_requirements($phase) {
+  $requirements = array();
+  if ($phase == 'install') {
+    // make sure chado is installed
+    if (!tripal_core_is_chado_installed()) {
+      $requirements ['tripal_project'] = array(
+        'title' => "tripal_project",
+        'value' => "ERROR: Chado most be installed before this module can be enabled",
+        'severity' => REQUIREMENT_ERROR,
+      );
+    }
+  }
+  return $requirements;
+}
 /**
  * Implementation of hook_install().
  */
@@ -54,24 +72,6 @@ function tripal_project_schema() {
   return $schema;
 }
 
-/**
- * Implementation of hook_requirements(). 
- *
- */
-function tripal_project_requirements($phase) {
-  $requirements = array();
-  if ($phase == 'install') {
-    // make sure chado is installed
-    if (!tripal_core_is_chado_installed()) {
-      $requirements ['tripal_project'] = array(
-            'title' => "tripal_project",
-            'value' => "ERROR: Chado most be installed before this module can be enabled",
-            'severity' => REQUIREMENT_ERROR,
-      );
-    }
-  }
-  return $requirements;
-}
 /*
  * 
  */

+ 35 - 43
tripal_project/tripal_project.module

@@ -15,6 +15,30 @@ require('api/tripal_project.api.inc');
  * @ingroup tripal_modules
  */
 
+/**
+ * Implementation of hook_node_info().
+ *
+ * This node_info, is a simple node that describes the functionallity of the module. It specifies
+ * that the title(Project Name) and body(Description) set to true so that they information can be
+ * entered
+ *
+ *
+ * @ingroup tripal_project
+ */
+function tripal_project_node_info() {
+  return array(
+    'chado_project' => array(
+      'name' => t('Project'),
+      'base' => 'chado_project',
+      'description' => t('A module for interfacing the GMOD chado database with Drupal, providing viewing of projects'),
+      'has_title' => TRUE,
+      'title_label' => t('Project Name'),
+      'had_body' => TRUE,
+      'body_label' => t('Full Description'),
+    )
+  );
+}
+
 /**
  * Implements hook_views_api()
  *
@@ -158,29 +182,6 @@ function chado_project_node_access($node, $op, $account) {
   return NULL;
 }
 
-/**
- * Implementation of hook_node_info().
- *
- * This node_info, is a simple node that describes the functionallity of the module. It specifies
- * that the title(Project Name) and body(Description) set to true so that they information can be
- * entered
- *
- *
- * @ingroup tripal_project
- */
-function tripal_project_node_info() {
-  return array(
-    'chado_project' => array(
-      'name' => t('Project'),
-      'base' => 'chado_project',
-      'description' => t('A module for interfacing the GMOD chado database with Drupal, providing viewing of projects'),
-      'has_title' => TRUE,
-      'title_label' => t('Project Name'),
-      'had_body' => TRUE,
-      'body_label' => t('Full Description'),
-    )
-  );
-}
 /**
  *  We need to let drupal know about our theme functions and their arguments.
  *  We create theme functions to allow users of the module to customize the
@@ -342,8 +343,10 @@ function chado_project_insert($node) {
     $project_id = chado_get_id_for_node('project', $node->nid) ;
     if (!$project_id) {
        // next add the item to the drupal table
-      $sql = "INSERT INTO {chado_project} (nid, vid, project_id) ".
-             "VALUES (:nid, :vid, :project_id)";
+      $sql = "
+        INSERT INTO {chado_project} (nid, vid, project_id) 
+        VALUES (:nid, :vid, :project_id)
+      ";
       db_query($sql, array(':nid' => $node->nid, ':vid' => $node->vid, ':project_id' => $project['project_id']));
     }
   }
@@ -377,20 +380,13 @@ function chado_project_delete($node) {
 
   // Remove data from {chado_project}, {node} and {node_revisions} tables of
   // drupal database
-  $sql_del = "DELETE FROM {chado_project} ".
-             "WHERE nid = :nid ".
-             "AND vid = :vid";
+  $sql_del = "DELETE FROM {chado_project} WHERE nid = :nid AND vid = :vid";
   db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
-  $sql_del = "DELETE FROM {node_revision} ".
-             "WHERE nid = :nid ".
-             "AND vid = :vod";
+  $sql_del = "DELETE FROM {node_revision} WHERE nid = :nid AND vid = :vod";
   db_query($sql_del,  array(':nid' => $node->nid, ':vid' => $node->vid));
-  $sql_del = "DELETE FROM {node} ".
-             "WHERE nid = :nid ".
-             "AND vid = :vid";
+  $sql_del = "DELETE FROM {node} WHERE nid = :nid AND vid = :vid";
   db_query($sql_del,  array(':nid' => $node->nid, ':vid' => $node->vid));
 
-
   // Remove data from project and projectprop tables of chado database as well
   chado_query("DELETE FROM {projectprop} WHERE project_id = :project_id", array(':project_id' => $project_id));
   chado_query("DELETE FROM {project} WHERE project_id = :project_id", array(':project_id' => $project_id));
@@ -409,22 +405,18 @@ function chado_project_delete($node) {
 function chado_project_update($node) {
  if ($node->revision) {
     // there is no way to handle revisions in Chado but leave
-    // this here just to make not we've addressed it.
+    // this here just to make note we've addressed it.
   }
 
   // update the project and the description
   $project_id = chado_get_id_for_node('project', $node->nid) ;
-  $match = array(
-     'project_id' => $project_id,
-  );
+  $match = array('project_id' => $project_id);
   $values = array(
-     'name' => $node->title,
-     'description' => '',
+    'name' => $node->title,
+    'description' => '',
   );
   $status = tripal_core_chado_update('project', $match, $values);
   tripal_project_update_property($project_id, 'project_description', $node->project_description, 1);
-
-
 }
 
 /**