123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310 |
- <?php
- /**
- * @file
- * This file contains the basic functions needed for this drupal module.
- * The drupal tripal_project module maps directly to the chado general module.
- *
- * For documentation regarding the Chado General module:
- * @see http://gmod.org/wiki/Chado_General_Module
- */
- //-----------------------------------------------------------------------------
- // SECTION: Main Outline for Tripal Project Module
- //-----------------------------------------------------------------------------
- /**
- * Implements hook_views_api()
- *
- * Purpose: Essentially this hook tells drupal that there is views support for
- * for this module which then includes tripal_project.views.inc where all the
- * views integration code is
- *
- */
- function tripal_project_views_api() {
- return array(
- 'api' => 2.0,
- );
- }
- /**
- * 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
- *
- */
- function tripal_project_node_info() {
- return array(
- 'tripal_project' => array(
- 'name' => t('Project'),
- 'module' => 'tripal_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('Description'),
- )
- );
- }
- /**
- * Implementation of hook_form().
- *
- * This form takes the Project Title infromation and the Project description from the user. It
- * then puts the infromation into the Chado_project database table.
- *
- * @parm &$node
- * The node that is created when the database is initialized
- *
- * @parm $form_state
- * The state of the form, that has the user entered information that is neccessary for, setting
- * up the database of the project
- *
- * @return $form
- * The information that was enterd allong with
- *
- */
- function tripal_project_form(&$node, $form_state) {
-
- $type = node_get_types('type', $node);
- //define form elements for the node's title and body.
- $form['title'] = array(
- '#type' => 'textfield',
- '#title' => check_plain($type->title_label),
- '#required' => TRUE,
- '#default_value' => $node->title,
- '#weight' => -5
- );
-
- // Putting body and filter elements to be adjacent them into a sub-array together
- $form['body_filter']['body'] = array(
- '#type' => 'textarea',
- '#title' => check_plain($type->body_label),
- '#default_value' => $node->body,
- '#required' => FALSE
- );
-
- $form['body_filter']['filter'] = filter_form($node->format);
- return $form;
- }
- /**
- * Implements Hook_help()
- *
- * This function simply states, in HTML tags, the creator of the the module and the contact
- * for the programmer
- *
- * @parm $path
- * The absolute path of the module and help information
- *
- * @parm $arg
- * The argument
- */
- function tripal_project_help($path, $arg) {
- switch ($path) {
-
- case 'admin/help#tripal_project':
-
- return '<p>'. t('Module created by:Chad Krilow (e-mail:cnk046@mail.usask.ca)') .'</p>';
-
- break;
- }
- }
- /**
- * Implements hook_perm()
- *
- * This function sets the permission for the user to access the information in the database.
- * This includes creating, inserting, deleting and updating of information in the database
- *
- */
- function tripal_project_perm() {
- return array('create tripal_project', 'edit own tripal_project');
-
- }
- /**
- * Implements hook_access()
- *
- * This function sets the access permission for operations on the database.
- *
- * @parm $op
- * The operation that is to be performed
- *
- * @parm $node
- * The specific node that is to have the operation performed
- *
- * @parm $account
- * The account of the user that is performing the operations
- *
- * @return
- * True if a operation was performed
- *
- */
- function tripal_project_access($op, $node, $account) {
- if ($op == 'create') {
-
- // Only users with permission to do so may create this node type.
- return user_access('create tripal_project', $account);
- }
- // Users who create a node may edit or delete it later, assuming they have the necessary permissions.
- if ($op == 'update' || $op == 'delete') {
-
- if (user_access('edit own tripal_project',$account) && ($account->uid == $node->uid)) {
-
- return TRUE;
- }
- }
- }
- /**
- * Implementation of hook_insert()
- *
- * @parm $node
- * Then node that has the information stored within, accessed given the node-Id
- *
- */
- function tripal_project_insert($node) {
-
- $values = array(
- 'name' => $node->title,
- 'description' => $node->body,
- );
-
- //inserts info into chado table.
- $result = tripal_core_chado_insert('project',$values);
- //inserts the row of vid,nid,project_id into the chado_project table
- db_query("INSERT INTO {chado_project} (vid, nid, project_id) VALUES (%d, %d, %d)", $node->vid, $node->nid, $result['project_id']);
-
- }
- /**
- *
- * Implementation of hook_delete().
- *
- * @param $node
- * The node which is to be deleted, automagically by Drupal Black Box
- *
- */
- function tripal_project_delete($node) {
- // Notice that we're matching all revision, by using the node's nid.
-
- $values = array(
- 'name' => $node->title,
- 'description' => $node->body,
- );
-
- //deleting row in chado table
- tripal_core_chado_delete('project',$values);
-
- //deleteing in drupal chado_project table
- db_query('DELETE FROM {chado_project} WHERE nid = %d', $node->nid);
- }
- /**
- * Implements hook_update()
- *
- * @param $node
- * The node which is to have its containing information updated when the user modifys information
- * pertaining to the specific project
- *
- */
- function tripal_project_update($node){
-
- $result = db_fetch_object(db_query('SELECT * FROM {chado_project} WHERE nid=%d AND vid=%d',$node->nid, $node->vid));
-
- $match= array(
- 'project_id'=>$result->project_id,
- );
-
- $values = array(
- 'name' => $node->title,
- 'description' => $node->body,
- );
-
- //selects:$table, $match, $value when updating
- $result = tripal_core_chado_update('project',$match,$values);
- }
- /**
- * Implementation of tripal_project_load().
- *
- * @param $node
- * The node that is to have its containing infromation loaded
- *
- * @return $node
- * The node, containing the loaded project with the current node-Id
- *
- */
- function tripal_project_load($node) {
- //selecting the coresponding table information
- $result = db_fetch_object(db_query('SELECT * FROM {chado_project} WHERE nid=%d AND vid=%d',$node->nid, $node->vid));
-
- //assigning the project-Id to a variable
- $values = array(
- 'project_id' => $result->project_id,
- );
-
- //the current project set to the 'project' with the $values(project-Id)
- $node->project = tripal_core_generate_chado_var('project',$values);
-
- return $node;
- }
- //-----------------------------------------------------------------------------
- // END OF SOFTWARE
- //-----------------------------------------------------------------------------
|