28 $result = db_select(
'tpps_submission',
's')
30 ->condition(
'accession', $accession)
32 ->execute()->fetchObject();
36 return unserialize($result->submission_state);
42 $query = db_select(
'tpps_submission',
's');
43 $query->join(
'tpps_submission_dbxref',
's_dbx',
's.tpps_submission_id = s_dbx.tpps_submission_id');
44 $query->join(
'chado.dbxref',
'dbx',
'dbx.dbxref_id = s_dbx.dbxref_id');
46 $query->condition(
'dbx.accession', $accession);
47 $query->condition(
's.status',
'Approved');
49 $query = $query->execute();
50 $result = $query->fetchObject();
54 return unserialize($result->submission_state);
61 $state = variable_get(
'tpps_incomplete_' . $user->mail . $accession, NULL);
66 return variable_get(
'tpps_complete_' . $user->mail . $accession, NULL);
86 $submissions = array();
87 $query = db_select(
'tpps_submission',
's')
90 if (!empty($conditions)) {
91 foreach ($conditions as $key => $cond) {
93 if (!is_array($cond)) {
94 $query->condition($key, $cond);
98 foreach ($cond as $item) {
99 $or->condition($key, $item);
101 $query->condition($or);
107 $results = $query->execute();
108 while (($result = $results->fetchObject())) {
110 $submissions[] = unserialize($result->submission_state);
113 $submissions[] = $result;
129 'status' =>
'Incomplete',
130 'accession' => $state[
'accession'],
131 'dbxref_id' => $state[
'dbxref_id'],
132 'submission_state' => serialize($state),
135 db_insert(
'tpps_submission')
139 if ((!isset($state[
'tpps_type']) or $state[
'tpps_type'] !=
'tppsc')) {
158 $job->logMessage(
'[INFO] Clearing database for study ' . $old_accession);
159 $job->setInterval(1);
163 $job->logMessage(
'[INFO] Alter submission state data from ' . $old_accession .
' to ' . $new_accession);
166 $state = unserialize($submission->submission_state);
168 $job->logMessage(
'Original submission data for ' . $old_accession);
169 $job->logMessage(print_r($state,
true));
173 $state_json = json_encode($state);
176 $state_json = str_replace($old_accession,$new_accession,$state_json);
179 $state = json_decode($state_json,
true);
183 $job->logMessage(
'New submission data for ' . $new_accession);
184 $job->logMessage(print_r($state,
true));
193 $options[
'status'] =
'Approved';
194 $state[
'updated'] = time();
195 $options[
'submission_state'] = serialize($state);
197 db_update(
'tpps_submission')
199 ->condition(
'accession', $old_accession)
203 $job->logMessage(
'[INFO] Update tpps_submission table study ' . $old_accession .
' to ' . $new_accession);
205 $transaction = db_transaction();
207 chado_query(
'UPDATE tpps_submission SET accession = :new_accession WHERE accession = :old_accession', array(
208 ':new_accession' => $new_accession,
209 ':old_accession' => $old_accession
212 catch (\Exception $e) {
213 $transaction->rollback();
217 $job->logMessage(
'Completed! The next job in the queue should reimport the study data for ' . $new_accession);
232 if (empty($options[
'status']) and !empty($state[
'status'])) {
233 $options[
'status'] = $state[
'status'];
235 $state[
'updated'] = time();
236 $options[
'submission_state'] = serialize($state);
243 db_update(
'tpps_submission')
245 ->condition(
'accession', $state[
'accession'])
260 $dbxref_id = $submission->dbxref_id;
261 $state = unserialize($submission->submission_state);
262 db_delete(
'tpps_submission')
263 ->condition(
'accession', $accession)
265 if (empty($state[
'saved_values'][
'frontpage'][
'use_old_tgdr'])) {
266 db_delete(
'chado.dbxref')
267 ->condition(
'dbxref_id', $dbxref_id)
271 drupal_goto(
"user/{$user->uid}/tpps");
284 $tpps_local_db = variable_get(
'tpps_local_db');
285 if (!is_array($alt_accession)) {
286 $alt_accession = array($alt_accession);
292 db_delete(
'tpps_submission_dbxref')
293 ->condition(
'tpps_submission_id', $state_id)
296 foreach ($alt_accession as $acc) {
297 $dbx = chado_select_record(
'dbxref', array(
'*'), array(
298 'db_id' => $tpps_local_db->db_id,
301 $dbxref_id = current($dbx)->dbxref_id ?? NULL;
303 if (empty($dbxref_id)) {
304 $dbx = chado_insert_record(
'dbxref', array(
305 'db_id' => $tpps_local_db->db_id,
308 $dbxref_id = $dbx[
'dbxref_id'];
311 db_insert(
'tpps_submission_dbxref')
313 'tpps_submission_id' => $state_id,
314 'dbxref_id' => $dbxref_id,
328 $query = db_select(
'tpps_tag',
't')
333 while (($result = $query->fetchObject())) {
334 $color = !empty($result->color) ? $result->color :
'white';
335 $edit_link = $result->static ?
"" :
"<a href=\"tpps-tag/edit/{$result->tpps_tag_id}\">edit</a>";
336 $rows[$result->tpps_tag_id] = array(
337 "<span class=\"tag\" style=\"background-color:$color\"><span class=\"tag-text\">{$result->name}</span></span>",
354 'attributes' => array(
355 'class' => array(
'view'),
356 'id' =>
'tpps_table_display',
364 $output = theme(
'table', $vars);
366 drupal_add_js(drupal_get_path(
'module',
'tpps') .
TPPS_JS_PATH);
367 drupal_add_css(drupal_get_path(
'module',
'tpps') .
TPPS_CSS_PATH);
386 drupal_add_js(
'https://cdnjs.cloudflare.com/ajax/libs/tinyColorPicker/1.1.1/jqColorPicker.min.js',
'external');
387 drupal_add_js(drupal_get_path(
'module',
'tpps') .
'/js/tag_colorpicker.js');
389 $form[
'name'] = array(
390 '#type' =>
'textfield',
391 '#title' => t(
'Name'),
392 '#description' => t(
'The name of the new tag'),
394 '#prefix' =>
'<a href="/tpps-tag">Back to TPPS Submission Tags page</a>',
397 $form[
'color'] = array(
398 '#type' =>
'textfield',
399 '#title' => t(
'Color'),
400 '#description' => t(
'The color of the new tag. Can be the name of a color, like "red" or "blue", or can be a hexidecimal color like "#FFFFFF" or "#A2C32F". Hexidecimal colors must start with the "#" character.'),
402 '#suffix' =>
'<div id="color-picker"><a>Toggle Color Picker</a></div>',
405 $form[
'submit'] = array(
407 '#value' => t(
'Submit'),
417 $result = db_select(
'tpps_tag',
't')
419 ->condition(
'name', $form_state[
'values'][
'name'],
'ILIKE')
421 ->execute()->fetchObject();
422 if (!empty($result)) {
423 form_set_error(
'name', t(
"A tag already exists with this name. Please select a different name or use the existing tag."));
431 db_insert(
'tpps_tag')
433 'name' => $form_state[
'values'][
'name'],
434 'color' => $form_state[
'values'][
'color'],
437 drupal_goto(
'tpps-tag');
454 if (empty($tag_id)) {
455 drupal_goto(
'tpps-tag');
458 $tag = db_select(
'tpps_tag',
't')
460 ->condition(
'tpps_tag_id', $tag_id)
462 ->execute()->fetchObject();
464 if (empty($tag) or $tag->static) {
465 drupal_goto(
'tpps-tag');
470 $form[
'name'][
'#default_value'] = $tag->name;
471 $form[
'color'][
'#default_value'] = $tag->color;
485 $result = db_select(
'tpps_tag',
't')
487 ->condition(
'name', $form_state[
'values'][
'name'],
'ILIKE')
488 ->condition(
'tpps_tag_id', $form_state[
'values'][
'id'],
'!=')
490 ->execute()->fetchObject();
491 if (!empty($result)) {
492 form_set_error(
'name', t(
"A tag already exists with this name. Please select a different name or use the existing tag."));
500 db_update(
'tpps_tag')
502 'name' => $form_state[
'values'][
'name'],
503 'color' => $form_state[
'values'][
'color'],
505 ->condition(
'tpps_tag_id', $form_state[
'values'][
'id'])
507 drupal_goto(
'tpps-tag');
520 $query = db_select(
'tpps_submission_tag',
'st');
521 $query->join(
'tpps_submission',
's',
's.tpps_submission_id = st.tpps_submission_id');
522 $query->join(
'tpps_tag',
't',
't.tpps_tag_id = st.tpps_tag_id');
524 $query->condition(
's.accession', $accession);
525 $query = $query->execute();
527 while (($result = $query->fetchObject())) {
528 $results[$result->tpps_tag_id] = array(
529 'id' => $result->tpps_tag_id,
530 'name' => $result->name,
531 'color' => $result->color,
532 'static' => $result->static,
550 foreach ($tags as $tag) {
566 $result = db_select(
'tpps_tag',
't')
568 ->condition(
'tpps_tag_id', $tag)
570 ->execute()->fetchObject();
572 if ($result->static) {
573 drupal_goto(
'tpps-tag');
576 if ($type ==
'add') {
579 if ($type ==
'remove') {
593 if (gettype($tag) ==
'string') {
601 if (!array_key_exists($tag, $tags)) {
602 db_insert(
'tpps_submission_tag')
605 'tpps_tag_id' => $tag,
620 if (gettype($tag) ==
'string') {
626 db_delete(
'tpps_submission_tag')
628 ->condition(
'tpps_tag_id', $tag)
642 $result = db_select(
'tpps_tag',
't')
643 ->fields(
't', array(
'tpps_tag_id'))
644 ->condition(
'name', $name)
646 ->execute()->fetchObject();
649 return $result->tpps_tag_id;
662 if (!empty($state[
'file_info'])) {
663 $state[
'files'] = array();
664 foreach ($state[
'file_info'] as $page_files) {
665 foreach ($page_files as $fid => $name) {
666 $state[
'files'][] = $fid;
667 if ($name ===
'#NO_RENAME') {
670 $old_file = file_load($fid);
671 if ($old_file->uri[0] !=
'/') {
672 $old_path = file_create_url($old_file->uri);
674 $file_load = file_load($fid);
676 if (!preg_match(
'/^(.*\/)(.*)$/', $new_name, $matches)) {
677 preg_match(
'/^(.*\/).*$/', $file->uri, $matches);
678 $new_filename = $matches[1] . $new_filename;
681 if ($new_filename !=
'') {
682 $result = db_query(
'SELECT f.fid 683 FROM {file_managed} f WHERE f.uri = :uri', array(
':uri' => $new_filename));
684 $record = $result->fetchObject();
688 $file = file_load($record->fid);
692 $file->status = FILE_STATUS_PERMANENT;
693 $file = file_save($file);
696 $new_path = file_create_url($file->uri);
697 chado_update_record(
'projectprop', array(
698 'project_id' => $state[
'ids'][
'project_id'],
699 'value' => $old_path,
701 'value' => $new_path,
704 if (!empty($state[
'revised_files'][$fid])) {
705 $rev_fid = $state[
'revised_files'][$fid];
706 $state[
'files'][] = $rev_fid;
708 $file->status = FILE_STATUS_PERMANENT;
732 $state[
'file_rank'] = 0;
733 $project_id = $state[
'ids'][
'project_id'] ?? NULL;
734 if (empty($project_id)) {
737 if (empty($accession)) {
738 throw new Exception(
'Accession cannot be empty');
741 $stocks_sql =
"SELECT stock_id FROM chado.project_stock WHERE project_id = $project_id";
742 chado_query(
"UPDATE chado.project_dbxref SET is_current = FALSE WHERE project_id = $project_id");
743 chado_query(
"DELETE FROM chado.project_organism WHERE project_id = $project_id");
744 chado_query(
"DELETE FROM chado.project_pub WHERE project_id = $project_id");
745 chado_query(
"DELETE FROM chado.projectprop WHERE project_id = $project_id");
746 db_query(
"DELETE FROM public.tpps_project_file_managed WHERE project_id = $project_id");
747 chado_query(
"DELETE FROM chado.phenotype_cvterm WHERE phenotype_id IN (SELECT phenotype_id from chado.stock_phenotype WHERE stock_id in ($stocks_sql))");
748 chado_query(
"DELETE FROM chado.phenotype_to_synonym WHERE phenotype_id IN (SELECT phenotype_id FROM chado.stock_phenotype WHERE stock_id IN ($stocks_sql))");
749 chado_query(
"DELETE FROM chado.phenotype WHERE phenotype_id IN (SELECT phenotype_id FROM chado.stock_phenotype WHERE stock_id IN ($stocks_sql))");
750 chado_query(
"DELETE FROM chado.genotype_call WHERE project_id = $project_id");
751 chado_query(
"DELETE FROM chado.stock_genotype WHERE stock_id IN ($stocks_sql)");
752 chado_query(
"DELETE FROM chado.stock_phenotype WHERE stock_id IN ($stocks_sql)");
753 chado_query(
"DELETE FROM chado.stock WHERE stock_id IN ($stocks_sql)");
754 chado_query(
"DELETE FROM chado.phenotype WHERE uniquename LIKE '" . $accession .
"-%';");
755 echo
"FINISHED DB CLEAR DELETES\n";
759 if(strpos($accession,
'TGDR') !== FALSE && strlen($accession) >= 7) {
760 chado_query(
"DELETE FROM chado.stock WHERE uniquename LIKE :accession", [
761 ':accession' => $accession .
'%' 765 $state[
'ids'] = array(
'project_id' => $project_id);
777 for ($i = 1; $i <= 4; $i++) {
778 $form_state[
'values'] = $form_state[
'saved_values'][$i];
779 $form_state[
'stage'] = $i;
791 switch ($form_state[
'stage']) {
793 $form_state[
'stats'][
'author_count'] = $form_state[
'values'][
'publication'][
'secondaryAuthors'][
'number'] + 1;
794 if (!empty($form_state[
'values'][
'publication'][
'secondaryAuthors'][
'check'])) {
795 $form_state[
'stats'][
'author_count'] =
tpps_file_len($form_state[
'values'][
'publication'][
'secondaryAuthors'][
'file']);
798 $form_state[
'stats'][
'species_count'] = $form_state[
'values'][
'organism'][
'number'];
802 if (empty($form_state[
'tpps_type']) or $form_state[
'tpps_type'] ==
'tpps') {
803 $start =
new DateTime(
"{$form_state['values']['StartingDate']['year']}-{$form_state['values']['StartingDate']['month']}");
804 $end =
new DateTime(
"{$form_state['values']['EndingDate']['year']}-{$form_state['values']['EndingDate']['month']}");
805 $dur = date_diff($start, $end);
806 $form_state[
'stats'][
'duration'] = $dur->format(
'%y years %m months');
811 $form_state[
'stats'][
'tree_count'] = 0;
812 for ($i = 1; $i <= $form_state[
'stats'][
'species_count']; $i++) {
813 $form_state[
'stats'][
'tree_count'] +=
tpps_file_len($form_state[
'values'][
'tree-accession'][
"species-$i"][
'file']);
814 $form_state[
'stats'][
'tree_count'] += $form_state[
'values'][
'tree-accession'][
"species-$i"][
'file-no-header'];
815 if ($form_state[
'stats'][
'species_count'] == 1 or empty($form_state[
'values'][
'tree-accession'][
'check'])) {
822 $form_state[
'stats'][
'phenotype_count'] = 0;
823 $form_state[
'stats'][
'unique_phenotypes'] = 0;
824 for ($i = 1; $i <= $form_state[
'stats'][
'species_count']; $i++) {
825 $phenotype = $form_state[
'values'][
"organism-$i"][
'phenotype'] ?? NULL;
826 $form_state[
'stats'][
'unique_phenotypes'] += $phenotype[
'phenotypes-meta'][
'number'] ?? 0;
827 if (!empty($phenotype[
'file']) and file_load($phenotype[
'file'])) {
828 $rows =
tpps_file_len($phenotype[
'file']) + !empty($phenotype[
'file-no-header']);
829 if ($phenotype[
'format'] == 0) {
830 $phenotype_file_name_cols = $phenotype[
'file-groups'][
'Phenotype Data'][
'0'];
831 $form_state[
'stats'][
'phenotype_count'] += $rows * count($phenotype_file_name_cols);
834 $form_state[
'stats'][
'phenotype_count'] += $rows;
837 if (!empty($phenotype[
'metadata']) and file_load($phenotype[
'metadata'])) {
838 $form_state[
'stats'][
'unique_phenotypes'] +=
tpps_file_len($phenotype[
'metadata']) + !empty($phenotype[
'metadata-no-header']);
843 if (!empty($phenotype[
'iso']) and file_load($phenotype[
'iso'])) {
845 while (($k = array_search(NULL, $headers))) {
848 $num_unique_columns = count(array_unique($headers)) - 1;
850 $form_state[
'stats'][
'phenotype_count'] += $rows * $num_unique_columns;
877 $form[
'accession'] = array(
879 '#value' => $accession,
882 $form[
'status'] = array(
884 '#title' => t(
'Publication Status'),
886 0 => t(
'- Select -'),
887 'In Preparation or Submitted' => t(
'In Preparation or Submitted'),
888 'In Press' => t(
'In Press'),
889 'Published' => t(
'Published'),
891 '#default_value' => $state[
'saved_values'][
TPPS_PAGE_1][
'publication'][
'status'],
893 '#prefix' =>
"<a href=\"$base_url/tpps/details/$accession\">Back to TPPS Details Page</a>",
896 $year_options = array(0 =>
'- Select -');
897 for ($i = 1990; $i <= date(
'Y'); $i++) {
898 $year_options[$i] =
"$i";
901 $form[
'year'] = array(
903 '#title' => t(
'Year of Publication'),
904 '#options' => $year_options,
905 '#description' => t(
'If your publication has not been published yet, please choose the expected year of publication.'),
906 '#default_value' => $state[
'saved_values'][TPPS_PAGE_1][
'publication'][
'year'],
910 $form[
'journal'] = array(
911 '#type' =>
'textfield',
912 '#title' => t(
'Journal'),
913 '#autocomplete_path' =>
'tpps/autocomplete/journal',
914 '#default_value' => $state[
'saved_values'][TPPS_PAGE_1][
'publication'][
'journal'],
918 $form[
'submit'] = array(
920 '#value' => t(
'Submit'),
930 if (empty($form_state[
'values'][
'status'])) {
931 form_set_error(
'status', t(
'Publication Status: field is required.'));
933 if (empty($form_state[
'values'][
'year'])) {
934 form_set_error(
'year', t(
'Publication Year: field is required.'));
942 $accession = $form_state[
'values'][
'accession'];
946 if ($state[
'saved_values'][
TPPS_PAGE_1][
'publication'][
'status'] != $form_state[
'values'][
'status']) {
947 $state[
'saved_values'][
TPPS_PAGE_1][
'publication'][
'status'] = $form_state[
'values'][
'status'];
951 if ($state[
'saved_values'][
TPPS_PAGE_1][
'publication'][
'year'] != $form_state[
'values'][
'year']) {
952 $state[
'saved_values'][
TPPS_PAGE_1][
'publication'][
'year'] = $form_state[
'values'][
'year'];
956 if ($state[
'saved_values'][
TPPS_PAGE_1][
'publication'][
'journal'] != $form_state[
'values'][
'journal']) {
957 $state[
'saved_values'][
TPPS_PAGE_1][
'publication'][
'journal'] = $form_state[
'values'][
'journal'];
962 module_load_include(
'php',
'tpps',
'forms/submit/submit_all');
965 $includes[] = module_load_include(
'php',
'tpps',
'forms/submit/submit_all');
966 $includes[] = module_load_include(
'inc',
'tpps',
'includes/file_parsing');
967 $args = array($accession);
968 $jid = tripal_add_job(
"Update Publication Information - $accession",
'tpps',
'tpps_submit_all', $args, $state[
'submitting_uid'], 10, $includes, TRUE);
969 $state[
'job_id'] = $jid;
tpps_submission_get_tags($accession)
tpps_submission_add_alternative_accession(array $state, $alt_accession)
tpps_submission_clear_db($accession)
tpps_submission_edit_publication_validate(&$form, &$form_state)
tpps_submission_edit_publication(array $form, array &$form_state, $accession=NULL)
tpps_submission_tag_create_validate(&$form, &$form_state)
tpps_update_submission(array $state, array $options=array())
tpps_submission_tag_create_submit($form, &$form_state)
tpps_create_submission(array $state, $uid)
tpps_change_tgdr_number($old_accession, $new_accession, TripalJob $job=NULL)
tpps_submission_edit_publication_submit($form, &$form_state)
tpps_submission_tag_edit_validate(&$form, &$form_state)
tpps_submission_remove_tag($accession, $tag)
tpps_submission_tag_create(array $form, array &$form_state)
tpps_submission_add_tag($accession, $tag)
tpps_get_path_extension($path)
tpps_submission_rename_files($accession)
tpps_file_headers($fid, $no_header=FALSE)
tpps_submission_clear_default_tags($accession)
tpps_delete_submission($accession, $redirect=TRUE)
tpps_load_submission($accession, $state=TRUE)
tpps_submission_tag_manage()
tpps_submission_update_all_stats(array &$form_state)
tpps_submission_update_stats(array &$form_state)
tpps_submission_add_remove_tag($type, $accession, $tag)
tpps_load_submission_multiple(array $conditions=array(), $state=TRUE)
tpps_submission_tag_edit(array $form, array &$form_state, $tag_id=NULL)
tpps_rename_file($fid, $new_name, array $options=array())
tpps_submission_tag_edit_submit($form, &$form_state)