123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575 |
- <?php
- function tripal_library_node_info() {
- $nodes = array();
- $nodes['chado_library'] = array(
- 'name' => t('Library'),
- 'base' => 'chado_library',
- 'description' => t('A library from the chado database'),
- 'has_title' => TRUE,
- 'locked' => TRUE,
- 'chado_node_api' => array(
- 'base_table' => 'library',
- 'hook_prefix' => 'chado_library',
- 'record_type_title' => array(
- 'singular' => t('Library'),
- 'plural' => t('Libraries')
- ),
- 'sync_filters' => array(
- 'type_id' => TRUE,
- 'organism_id' => TRUE
- ),
- )
- );
- return $nodes;
- }
- function chado_library_form($node, &$form_state) {
- $form = array();
-
-
-
-
-
-
-
-
-
- $library_id = NULL;
- $libraryname = '';
- $uniquename = '';
- $library_type = '';
- $organism_id = '';
- $description = '';
-
- if (property_exists($node, 'library')) {
- $library = $node->library;
- $library_id = $library->library_id;
- $libraryname = $library->name;
- $uniquename = $library->uniquename;
- $library_type = $library->type_id->cvterm_id;
- $organism_id = $library->organism_id->organism_id;
- $libprop = tripal_library_get_property($library->library_id, 'Library Description');
- $description = $libprop->value;
-
-
- $form['library_id'] = array(
- '#type' => 'value',
- '#value' => $library_id,
- );
- }
-
-
- if (array_key_exists('values', $form_state)) {
- $libraryname = $form_state['values']['libraryname'];
- $uniquename = $form_state['values']['uniquename'];
- $library_type = $form_state['values']['library_type'];
- $organism_id = $form_state['values']['organism_id'];
- $description = $form_state['values']['description'];
- }
-
-
- if (array_key_exists('input', $form_state) and !empty($form_state['input'])) {
- $libraryname = $form_state['input']['libraryname'];
- $uniquename = $form_state['input']['uniquename'];
- $library_type = $form_state['input']['library_type'];
- $organism_id = $form_state['input']['organism_id'];
- $description = $form_state['input']['description'];
- }
- $form['libraryname']= array(
- '#type' => 'textfield',
- '#title' => t('Library Name'),
- '#description' => t('Please enter the name for this library. Library names should be recognizable but do not need to be unique.'),
- '#required' => TRUE,
- '#default_value' => $libraryname,
- );
- $form['uniquename']= array(
- '#type' => 'textfield',
- '#title' => t('Unique Name'),
- '#description' => t('Please enter a unique name for this library. This can be any value used to uniquely identify a library.'),
- '#required' => TRUE,
- '#default_value' => $uniquename,
- );
-
- $types = tripal_get_cvterm_default_select_options('library', 'type_id', 'library types');
- $types[0] = 'Select a Type';
- $form['library_type'] = array(
- '#title' => t('Library Type'),
- '#type' => t('select'),
- '#description' => t("Choose the library type."),
- '#required' => TRUE,
- '#default_value' => $library_type,
- '#options' => $types,
- );
-
- $sql = "SELECT * FROM {organism}";
- $org_rset = chado_query($sql);
- $organisms = array();
- $organisms[''] = '';
- while ($organism = $org_rset->fetchObject()) {
- $organisms[$organism->organism_id] =
- "$organism->genus $organism->species ($organism->common_name)";
- }
- $form['organism_id'] = array(
- '#title' => t('Organism'),
- '#type' => t('select'),
- '#description' => t("Choose the organism with which this library is associated."),
- '#required' => TRUE,
- '#default_value' => $organism_id,
- '#options' => $organisms,
- );
- $form['description']= array(
- '#type' => 'textarea',
- '#title' => t('Library Description'),
- '#description' => t('A brief description of the library'),
- '#required' => TRUE,
- '#default_value' => $description,
- );
-
-
- $select_options = array();
- $prop_cv = tripal_get_default_cv('libraryprop', 'type_id');
- $cv_id = $prop_cv ? $prop_cv->cv_id : NULL;
-
-
- if ($prop_cv->name == 'library_property') {
-
- $cv_result = chado_select_record('cv',array('cv_id'),array('name' => 'library_property'));
- $cv_id = $cv_result[0]->cv_id;
- $select_options = tripal_cv_get_cvterm_options($cv_id);
- $descrip_id = array_search('Library Description', $select_options);
- unset($select_options[$descrip_id]);
- }
- $details = array(
- 'property_table' => 'libraryprop',
- 'chado_id' => $library_id,
- 'cv_id' => $cv_id,
- 'select_options' => $select_options
- );
-
- chado_add_node_form_properties($form, $form_state, $details);
-
-
- $details = array(
- 'linking_table' => 'library_dbxref',
- 'base_foreign_key' => 'library_id',
- 'base_key_value' => $library_id
- );
-
- chado_add_node_form_dbxrefs($form, $form_state, $details);
- return $form;
- }
- function chado_library_validate($node, $form, &$form_state) {
-
- if($node->op == 'Delete') {
- return;
- }
-
-
-
- if (is_null($node->nid) and property_exists($node, 'library_id') and $node->library_id != 0) {
- return;
- }
-
-
- $node->libraryname = trim($node->libraryname);
- $node->uniquename = trim($node->uniquename);
- $node->description = trim($node->description);
- $lib = 0;
-
-
- if (property_exists($node, 'library_id')) {
- $sql = "
- SELECT *
- FROM {library}
- WHERE uniquename = :uname AND NOT library_id = :library_id
- ";
- $lib = chado_query($sql, array(':uname' => $node->uniquename, ':library_id' => $node->library_id))->fetchObject();
- }
- else {
- $sql = "SELECT * FROM {library} WHERE uniquename = :uname";
- $lib = chado_query($sql, array(':uname' => $node->uniquename))->fetchObject();
- }
- if ($lib) {
- form_set_error('uniquename', t('The unique library name already exists. Please choose another'));
- }
- }
- function chado_library_insert($node) {
- $node->libraryname = trim($node->libraryname);
- $node->uniquename = trim($node->uniquename);
- $node->description = trim($node->description);
-
-
-
- if (!property_exists($node, 'library_id')) {
- $values = array(
- 'name' => $node->libraryname,
- 'uniquename' => $node->uniquename,
- 'organism_id' => $node->organism_id,
- 'type_id' => $node->library_type,
- );
- $library = chado_insert_record('library', $values);
- if (!$library) {
- drupal_set_message(t('Unable to add library.', 'warning'));
- watchdog('tripal_library', 'Insert library: Unable to create library where values: %values',
- array('%values' => print_r($values, TRUE)), WATCHDOG_ERROR);
- return;
- }
- $library_id = $library['library_id'];
-
-
- $properties = chado_retrieve_node_form_properties($node);
- $descrip_id = tripal_cv_get_cvterm_by_name('Library Description', NULL, 'library_property');
- $properties[$descrip_id->cvterm_id][0] = $node->description;
- $details = array(
- 'property_table' => 'libraryprop',
- 'base_table' => 'library',
- 'foreignkey_name' => 'library_id',
- 'foreignkey_value' => $library_id
- );
- chado_update_node_form_properties($node, $details, $properties);
-
- $details = array(
- 'linking_table' => 'library_dbxref',
- 'foreignkey_name' => 'library_id',
- 'foreignkey_value' => $library_id
- );
- chado_update_node_form_dbxrefs($node, $details);
- }
- else {
- $library_id = $node->library_id;
- }
-
-
- $check_org_id = chado_get_id_from_nid('library', $node->nid);
- if (!$check_org_id) {
- $record = new stdClass();
- $record->nid = $node->nid;
- $record->vid = $node->vid;
- $record->library_id = $library_id;
- drupal_write_record('chado_library', $record);
- }
- }
- function chado_library_update($node) {
- $node->libraryname = trim($node->libraryname);
- $node->uniquename = trim($node->uniquename);
- $node->description = trim($node->description);
-
- $library_id = chado_get_id_from_nid('library', $node->nid);
- $match = array(
- 'library_id' => $library_id,
- );
- $values = array(
- 'name' => $node->libraryname,
- 'uniquename' => $node->uniquename,
- 'organism_id' => $node->organism_id,
- 'type_id' => $node->library_type,
- );
- $status = chado_update_record('library', $match, $values);
- if (!$status) {
- drupal_set_message(t('Unable to update library.', 'warning'));
- watchdog('tripal_library', 'Update library: Unable to update library where values: %values',
- array('%values' => print_r($values, TRUE)), WATCHDOG_ERROR);
- }
-
-
- $properties = chado_retrieve_node_form_properties($node);
- $descrip_id = tripal_cv_get_cvterm_by_name('Library Description', NULL, 'library_property');
- $properties[$descrip_id->cvterm_id][0] = $node->description;
- $details = array(
- 'property_table' => 'libraryprop',
- 'base_table' => 'library',
- 'foreignkey_name' => 'library_id',
- 'foreignkey_value' => $library_id
- );
- chado_update_node_form_properties($node, $details, $properties);
-
- $details = array(
- 'linking_table' => 'library_dbxref',
- 'foreignkey_name' => 'library_id',
- 'foreignkey_value' => $library_id
- );
- chado_update_node_form_dbxrefs($node, $details);
- }
- function chado_library_load($nodes) {
- foreach ($nodes as $nid => $node) {
-
- $library_id = chado_get_id_from_nid('library', $node->nid);
-
-
- if (!$library_id) {
- continue;
- }
-
- $values = array('library_id' => $library_id);
- $library = chado_generate_var('library', $values);
-
- $library = chado_expand_var($library, 'field', 'library.uniquename');
- $nodes[$nid]->library = $library;
- }
- }
- function chado_library_delete(&$node) {
- $library_id = chado_get_id_from_nid('library', $node->nid);
-
-
- if (!$library_id) {
- return;
- }
-
-
- $sql_del = "DELETE FROM {chado_library} 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 = :vid";
- db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
- $sql_del = "DELETE FROM {node} WHERE nid = :nid AND vid = :vid";
- db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
-
- chado_query("DELETE FROM {libraryprop} WHERE library_id = :library_id", array(':library_id' => $library_id));
- chado_query("DELETE FROM {library} WHERE library_id = :library_id", array(':library_id' => $library_id));
- }
- function chado_library_node_access($node, $op, $account) {
- $node_type = $node;
- if (is_object($node)) {
- $node_type = $node->type;
- }
-
- if($node_type == 'chado_library') {
- if ($op == 'create') {
- if (!user_access('create chado_library', $account)) {
- return NODE_ACCESS_DENY;
- }
- return NODE_ACCESS_ALLOW;
- }
- if ($op == 'update') {
- if (!user_access('edit chado_library', $account)) {
- return NODE_ACCESS_DENY;
- }
- }
- if ($op == 'delete') {
- if (!user_access('delete chado_library', $account)) {
- return NODE_ACCESS_DENY;
- }
- }
- if ($op == 'view') {
- if (!user_access('access chado_library', $account)) {
- return NODE_ACCESS_DENY;
- }
- }
- return NODE_ACCESS_IGNORE;
- }
- }
- function tripal_library_node_view($node, $view_mode, $langcode) {
- switch ($node->type) {
- case 'chado_library':
- if ($view_mode == 'full') {
- $node->content['tripal_library_base'] = array(
- '#markup' => theme('tripal_library_base', array('node' => $node)),
- '#tripal_toc_id' => 'base',
- '#tripal_toc_title' => 'Overview',
- '#weight' => -100,
- );
- $node->content['tripal_library_properties'] = array(
- '#markup' => theme('tripal_library_properties', array('node' => $node)),
- '#tripal_toc_id' => 'properties',
- '#tripal_toc_title' => 'Properties',
- );
- $node->content['tripal_library_publications'] = array(
- '#markup' => theme('tripal_library_publications', array('node' => $node)),
- '#tripal_toc_id' => 'publications',
- '#tripal_toc_title' => 'Publications',
- );
- $node->content['tripal_library_references'] = array(
- '#markup' => theme('tripal_library_references', array('node' => $node)),
- '#tripal_toc_id' => 'references',
- '#tripal_toc_title' => 'Cross References',
- );
- $node->content['tripal_library_synonyms'] = array(
- '#markup' => theme('tripal_library_synonyms', array('node' => $node)),
- '#tripal_toc_id' => 'synonyms',
- '#tripal_toc_title' => 'Synonyms',
- );
- $node->content['tripal_library_terms'] = array(
- '#markup' => theme('tripal_library_terms', array('node' => $node)),
- '#tripal_toc_id' => 'terms',
- '#tripal_toc_title' => 'Annotated Terms',
- );
- }
- if ($view_mode == 'teaser') {
- $node->content['tripal_library_teaser'] = array(
- '#markup' => theme('tripal_library_teaser', array('node' => $node)),
- );
- }
- break;
- case 'chado_organism':
- if ($view_mode == 'full') {
- $node->content['tripal_organism.libraries'] = array(
- '#markup' => theme('tripal_organism.libraries', array('node' => $node)),
- '#tripal_toc_id' => 'libraries',
- '#tripal_toc_title' => 'Libraries',
- );
- }
- break;
- case 'chado_feature':
- if ($view_mode == 'full') {
- $node->content['tripal_feature.libraries'] = array(
- '#markup' => theme('tripal_feature.libraries', array('node' => $node)),
- '#tripal_toc_id' => 'libraries',
- '#tripal_toc_title' => 'Libraries',
- );
- }
- break;
- }
- }
- function tripal_library_node_presave($node) {
- switch ($node->type) {
- case 'chado_library':
-
-
- if (property_exists($node, 'libraryname')) {
-
- $node->title = $node->libraryname;
- }
- else if (property_exists($node, 'library')) {
- $node->title = $node->library->name;
- }
- break;
- }
- }
|