123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720 |
- <?php
- function tripal_library_node_info() {
- $nodes = [];
- $nodes['chado_library'] = [
- 'name' => t('Library (Tripal v2 legacy)'),
- 'base' => 'chado_library',
- 'description' => t('A library from the chado database'),
- 'has_title' => TRUE,
- 'locked' => TRUE,
- 'chado_node_api' => [
- 'base_table' => 'library',
- 'hook_prefix' => 'chado_library',
- 'record_type_title' => [
- 'singular' => t('Library'),
- 'plural' => t('Libraries'),
- ],
- 'sync_filters' => [
- 'type_id' => TRUE,
- 'organism_id' => TRUE,
- ],
- ],
- ];
- return $nodes;
- }
- function chado_library_form($node, &$form_state) {
- $form = [];
-
-
-
-
-
-
-
-
-
- $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 = chado_get_property(
- ['table' => 'library', 'id' => $library->library_id],
- ['type_name' => 'Library Description', 'cv_name' => 'library_property']
- );
- $description = $libprop->value;
-
-
- $form['library_id'] = [
- '#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'] = [
- '#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'] = [
- '#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,
- ];
-
- $lt_cv = tripal_get_default_cv("library", "type_id");
- $types = tripal_get_cvterm_default_select_options('library', 'type_id', 'library types');
- $types[0] = 'Select a Type';
- $lt_message = tripal_set_message("To add additional items to the library type drop down list,
- add a term to the " .
- l($lt_cv->name . " controlled vocabulary",
- "admin/tripal/loaders/chado_vocabs/chado_cv/" . $lt_cv->cv_id . "/cvterm/add",
- ['attributes' => ['target' => '_blank']]
- ),
- TRIPAL_INFO, ['return_html' => TRUE]
- );
- $form['library_type'] = [
- '#title' => t('Library Type'),
- '#type' => t('select'),
- '#description' => t("Choose the library type."),
- '#required' => TRUE,
- '#default_value' => $library_type,
- '#options' => $types,
- '#suffix' => $lt_message,
- ];
-
- $sql = "SELECT * FROM {organism}";
- $org_rset = chado_query($sql);
- $organisms = [];
- $organisms[''] = '';
- while ($organism = $org_rset->fetchObject()) {
- $organisms[$organism->organism_id] =
- "$organism->genus $organism->species ($organism->common_name)";
- }
- $form['organism_id'] = [
- '#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'] = [
- '#type' => 'text_format',
- '#title' => t('Library Description'),
- '#description' => t('A brief description of the library'),
- '#required' => TRUE,
- '#default_value' => $description,
- ];
-
-
- $prop_cv = tripal_get_default_cv('libraryprop', 'type_id');
- $cv_id = $prop_cv ? $prop_cv->cv_id : NULL;
- $details = [
-
- 'property_table' => 'libraryprop',
-
- 'chado_id' => $library_id,
-
- 'cv_id' => $cv_id,
- ];
-
-
-
- if ($prop_cv->name == 'library_property') {
-
- $select_options = [];
- $cv_result = chado_select_record('cv', ['cv_id'], ['name' => 'library_property']);
- $cv_id = $cv_result[0]->cv_id;
- $select_options = tripal_get_cvterm_select_options($cv_id);
- $descrip_id = array_search('Library Description', $select_options);
- unset($select_options[$descrip_id]);
- $details['select_options'] = $select_options;
- }
-
- chado_add_node_form_properties($form, $form_state, $details);
-
-
- $details = [
-
- '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 (property_exists($node, "op") and $node->op != 'Save') {
- return;
- }
-
-
- if (!property_exists($node, 'nid') and property_exists($node, 'library_id') and $node->library_id != 0) {
- return;
- }
-
- $node->libraryname = property_exists($node, 'libraryname') ? trim($node->libraryname) : '';
- $node->uniquename = property_exists($node, 'uniquename') ? trim($node->uniquename) : '';
- $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, [
- ':uname' => $node->uniquename,
- ':library_id' => $node->library_id,
- ])->fetchObject();
- }
- else {
- $sql = "SELECT * FROM {library} WHERE uniquename = :uname";
- $lib = chado_query($sql, [':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) {
- $library_id = '';
-
-
-
- if (!property_exists($node, 'library_id')) {
- $node->libraryname = trim($node->libraryname);
- $node->uniquename = trim($node->uniquename);
- $node->description = trim($node->description['value']);
- $values = [
- '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',
- ['%values' => print_r($values, TRUE)], WATCHDOG_ERROR);
- return;
- }
- $library_id = $library['library_id'];
-
-
- $properties = chado_retrieve_node_form_properties($node);
- $descrip_id = tripal_get_cvterm([
- 'name' => 'Library Description',
- 'cv_id' => ['name' => 'library_property'],
- ]);
- $properties[$descrip_id->cvterm_id][0] = $node->description;
- $details = [
- 'property_table' => 'libraryprop',
-
- 'base_table' => 'library',
-
- 'foreignkey_name' => 'library_id',
-
- 'foreignkey_value' => $library_id
-
- ];
- chado_update_node_form_properties($node, $details, $properties);
-
- $details = [
- '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['value']);
-
- $library_id = chado_get_id_from_nid('library', $node->nid);
- $match = [
- 'library_id' => $library_id,
- ];
- $values = [
- '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',
- ['%values' => print_r($values, TRUE)], WATCHDOG_ERROR);
- }
-
-
- $properties = chado_retrieve_node_form_properties($node);
- $descrip_id = tripal_get_cvterm([
- 'name' => 'Library Description',
- 'cv_id' => ['name' => 'library_property'],
- ]);
- $properties[$descrip_id->cvterm_id][0] = $node->description;
- $details = [
- 'property_table' => 'libraryprop',
-
- 'base_table' => 'library',
-
- 'foreignkey_name' => 'library_id',
-
- 'foreignkey_value' => $library_id
-
- ];
- chado_update_node_form_properties($node, $details, $properties);
-
- $details = [
- '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 = ['library_id' => $library_id];
- $library = chado_generate_var('library', $values);
-
- $library = chado_expand_var($library, 'field', 'library.uniquename');
- $nodes[$nid]->library = $library;
-
- $node->title = chado_get_node_title($node);
- }
- }
- 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, [':nid' => $node->nid, ':vid' => $node->vid]);
- $sql_del = "DELETE FROM {node_revision} WHERE nid = :nid AND vid = :vid";
- db_query($sql_del, [':nid' => $node->nid, ':vid' => $node->vid]);
- $sql_del = "DELETE FROM {node} WHERE nid = :nid AND vid = :vid";
- db_query($sql_del, [':nid' => $node->nid, ':vid' => $node->vid]);
-
- chado_query("DELETE FROM {libraryprop} WHERE library_id = :library_id", [':library_id' => $library_id]);
- chado_query("DELETE FROM {library} WHERE library_id = :library_id", [':library_id' => $library_id]);
- }
- function tripal_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 content', $account)) {
- return NODE_ACCESS_DENY;
- }
- return NODE_ACCESS_ALLOW;
- }
- if ($op == 'update') {
- if (!user_access('edit chado_library content', $account)) {
- return NODE_ACCESS_DENY;
- }
- }
- if ($op == 'delete') {
- if (!user_access('delete chado_library content', $account)) {
- return NODE_ACCESS_DENY;
- }
- }
- if ($op == 'view') {
- if (!user_access('access chado_library content', $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'] = [
- '#theme' => 'tripal_library_base',
- '#node' => $node,
- '#tripal_toc_id' => 'base',
- '#tripal_toc_title' => 'Overview',
- '#weight' => -100,
- ];
- $node->content['tripal_library_features'] = [
- '#theme' => 'tripal_library_features',
- '#node' => $node,
- '#tripal_toc_id' => 'features',
- '#tripal_toc_title' => 'Features',
- ];
- $node->content['tripal_library_properties'] = [
- '#theme' => 'tripal_library_properties',
- '#node' => $node,
- '#tripal_toc_id' => 'properties',
- '#tripal_toc_title' => 'Properties',
- ];
- $node->content['tripal_library_publications'] = [
- '#theme' => 'tripal_library_publications',
- '#node' => $node,
- '#tripal_toc_id' => 'publications',
- '#tripal_toc_title' => 'Publications',
- ];
- $node->content['tripal_library_references'] = [
- '#theme' => 'tripal_library_references',
- '#node' => $node,
- '#tripal_toc_id' => 'references',
- '#tripal_toc_title' => 'Cross References',
- ];
- $node->content['tripal_library_synonyms'] = [
- '#theme' => 'tripal_library_synonyms',
- '#node' => $node,
- '#tripal_toc_id' => 'synonyms',
- '#tripal_toc_title' => 'Synonyms',
- ];
- $node->content['tripal_library_terms'] = [
- '#theme' => 'tripal_library_terms',
- '#node' => $node,
- '#tripal_toc_id' => 'terms',
- '#tripal_toc_title' => 'Annotated Terms',
- ];
- }
- if ($view_mode == 'teaser') {
- $node->content['tripal_library_teaser'] = [
- '#theme' => 'tripal_library_teaser',
- '#node' => $node,
- ];
- }
- break;
- case 'chado_organism':
- if ($view_mode == 'full') {
- $node->content['tripal_organism_libraries'] = [
- '#theme' => 'tripal_organism_libraries',
- '#node' => $node,
- '#tripal_toc_id' => 'libraries',
- '#tripal_toc_title' => 'Libraries',
- ];
- }
- break;
- case 'chado_feature':
- if ($view_mode == 'full') {
- $node->content['tripal_feature_libraries'] = [
- '#theme' => 'tripal_feature_libraries',
- '#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;
- }
- }
- function tripal_library_node_insert($node) {
- switch ($node->type) {
- case 'chado_library':
- $library_id = chado_get_id_from_nid('library', $node->nid);
- $values = ['library_id' => $library_id];
- $library = chado_generate_var('library', $values);
- $library = chado_expand_var($library, 'field', 'library.uniquename');
- $node->library = $library;
-
- $node->title = chado_get_node_title($node);
-
- chado_set_node_url($node);
- break;
- }
- }
- function tripal_library_node_update($node) {
- switch ($node->type) {
- case 'chado_library':
-
- $node->title = chado_get_node_title($node);
-
- chado_set_node_url($node);
- break;
- }
- }
- function chado_library_chado_node_default_title_format() {
- return '[library.name], [library.uniquename] ([library.type_id>cvterm.name])';
- }
- function chado_library_chado_node_default_url_format() {
- return '/library/[library.organism_id>organism.genus]/[library.organism_id>organism.species]/[library.type_id>cvterm.name]/[library.uniquename]';
- }
|