Tripal Plant PopGen Submit
init_project.inc File Reference

Go to the source code of this file.

Functions

 tpps_init_project (array &$form_state, $accession=NULL)
 

Detailed Description

Defines function to initialize a TPPS Submission in the database.

Definition in file init_project.inc.

Function Documentation

◆ tpps_init_project()

tpps_init_project ( array &  $form_state,
  $accession = NULL 
)

This function initializes the TPPS Submission in the database.

Creates an entry for the submission in the tpps_submission table and also adds it to the chado.dbxref table.

Parameters
array$form_stateThe state of the submission form.
Returns
int The dbxref_id of the submission.

Definition at line 20 of file init_project.inc.

20  {
21 
22  if (empty($accession)) {
23  // This code is deprecated since it doesn't work for TGDR numbers over 999
24  // Code originally written by Peter Richter and kept as a backup
25  // Code deprecated by Rish (12/20/2022) as part of a patch to cater for TGDR
26  // numbers over 999
27 
28  // $values = array(
29  // 'accession' => 'TGDR.*',
30  // );
31 
32  // $options = array(
33  // 'order_by' => array(
34  // 'accession' => 'DESC',
35  // ),
36  // 'limit' => '1',
37  // 'regex_columns' => array('accession'),
38  // );
39 
40  // $result = chado_select_record('dbxref', array('accession'), $values, $options);
41 
42  // Rish: New patch that sorts based on integer instead of string values
43  $result_query = chado_query("SELECT *, substr(accession, 5)::INTEGER as accession_number " .
44  "FROM chado.dbxref WHERE accession LIKE 'TGDR%' " .
45  "ORDER BY accession_number DESC LIMIT 1;", []);
46 
47  if (empty($result_query)) {
48  $accession = 'TGDR001';
49  }
50  else {
51  $result = []; // create an empty array
52  $result[] = $result_query->fetchObject(); // add the first record found into result
53  $accession = substr($result[0]->accession, 4) + 1;
54  while (strlen($accession) < 3) {
55  $accession = "0$accession";
56  }
57  $accession = "TGDR$accession";
58  }
59  }
60 
61  $dbxref_id = chado_insert_record('dbxref', array(
62  'db_id' => variable_get('tpps_local_db')->db_id,
63  'accession' => $accession,
64  ));
65 
66  $form_state['dbxref_id'] = $dbxref_id['dbxref_id'];
67  $form_state['created'] = time();
68  $form_state['accession'] = $accession;
69  $form_state['saved_values']['frontpage']['accession'] = $accession;
70  $form_state['status'] = 'Incomplete';
71 
72  return $dbxref_id;
73 }