-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtripal_cv_xray.module
199 lines (171 loc) · 5.99 KB
/
tripal_cv_xray.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<?php
require_once "includes/api/tripal_cv_xray.api.inc";
require_once "includes/Jobs/tripal_cv_xray.jobs.inc";
require_once "includes/tripal_cv_xray_cvterm_entity_config.form.inc";
require_once "includes/tripal_cv_xray.fields.inc";
require_once "includes/tripal_cv_xray_analysis.form.inc";
/**
* implement hook menu.
*
* @return array
* Menu items.
*/
function tripal_cv_xray_menu() {
$admin_url_base = 'admin/tripal/extension/tripal_cv_xray';
$items[$admin_url_base] = [
'title' => 'Tripal CV X-ray',
'description' => t('The CV-X-ray module allows you to create browsable CV trees with entities mapped onto the terms. For example, you can create a GO tree for organisms that shows features for the organism. These admin settings are for populating the tables necessary for these trees to work.'),
'access arguments' => ['tripal cv xray'],
'page callback' => 'drupal_get_form',
'page arguments' => ['tripal_cv_xray_cvterm_entity_form'],
'file' => 'includes/tripal_cv_xray_cvterm_entity_config.form.inc',
'file_path' => drupal_get_path('module', 'tripal_cv_xray'),
];
$items['tripal_cv_xray/root-tree/%'] = [
'page callback' => 'data__ontology_data_formatter::loadRootTree',
'page arguments' => [2],
'access arguments' => ['access content'],
'file' => 'includes/TripalFields/data__ontology_data/data__ontology_data_formatter.inc',
'file path' => drupal_get_path('module', 'tripal_cv_xray'),
'type' => MENU_CALLBACK,
];
$items['tripal_cv_xray/collections/%/%/%/%'] = [
'title' => t('Create Collection'),
'description' => t('Create a downloadable collection.'),
'access arguments' => ['access content'],
'page callback' => 'drupal_get_form',
'page arguments' => ['tripal_cv_xray_collections_form', 2, 3, 4, 5],
//db shortname, accession, anchor entity ID, mapping bundle ID
'file' => 'includes/tripal_cv_xray_collections.form.inc',
'file path' => drupal_get_path('module', 'tripal_cv_xray'),
];
$items['cv_entities/%/%/%/%'] = [
'type' => MENU_NORMAL_ITEM,
'title' => t('Matching Entities'),
'description' => 'Mapped entities associated with a CVterm',
'page callback' => 'tripal_cv_xray_entity_view',
'page arguments' => [1, 2, 3, 4],
//db shortname, accession, anchor entity ID, mapping bundle ID
'file' => 'includes/tripal_cv_xray_entity_results.inc',
'access arguments' => ['access content'],
'file path' => drupal_get_path('module', 'tripal_cv_xray'),
];
// Same as above but with analysis id
$items['cv_entities/%/%/%/%/%'] = [
'type' => MENU_NORMAL_ITEM,
'title' => t('Matching Entities'),
'description' => 'Mapped entities associated with a CVterm',
'page callback' => 'tripal_cv_xray_entity_view',
'page arguments' => [1, 2, 3, 4, 5],
//db shortname, accession, anchor entity ID, mapping bundle ID
'file' => 'includes/tripal_cv_xray_entity_results.inc',
'access arguments' => ['access content'],
'file path' => drupal_get_path('module', 'tripal_cv_xray'),
];
$items['cv_entities/lookup/%/%/%/%/%/children'] = [
'access arguments' => ['access content'],
'page callback' => 'tripal_cv_xray_entity_child_lookup_ajax',
'page arguments' => [2, 3, 4, 5, 6],
//$vocabulary, $accession, $target_bundle_id, $anchor_entity_id, $analysis_id)
'file' => 'includes/api/tripal_cv_xray.api.inc',
'file path' => drupal_get_path('module', 'tripal_cv_xray'),
'type' => MENU_CALLBACK,
];
return $items;
}
/**
* Implements hook_cron_queue_info().
*
* Defined queues for use by our module.
*
* @return array
*/
function tripal_cv_xray_cron_queue_info() {
$queues = [];
$queues['tripal_cv_xray'] = [
'worker callback' => 'XRayQueue::run',
'time' => 60 * 2,
];
return $queues;
}
/**
* Implements hook_entity_delete().
*
* Deleted entities should be removed from the index.
*/
function tripal_cv_xray_entity_delete($entity, $type) {
tripal_cv_xray_index_remove_single_entity($entity, $type);
}
//TODO: Replace this with an importer hook
//function tripal_cv_xray_entity_insert($entity, $type) {
// tripal_cv_xray_index_single_entity($entity, $type);
//}
/**
* Dispatch a job to index the entity.
*
* @param $entity
* @param $type
*
* @throws \Exception
*/
function tripal_cv_xray_index_single_entity(TripalEntity $entity, string $type) {
if ($type != 'TripalEntity') {
return;
}
$bundle_name = $entity->bundle;
$bundle_id = str_replace('bio_data_', '', $bundle_name);
// Get config for the entity type
$config = db_select('tripal_cv_xray_config', 't')
->fields('t', ['shortname'])
->condition('bundle_id', $bundle_id)
->execute()
->fetchAll();
if (empty($config)) {
return;
}
// Get the bundle object for the indexer
$query = db_select('chado_bundle', 'CB');
$query->fields('CB', ['bundle_id', 'data_table']);
$query->fields('TB', ['label']);
$query->join('tripal_bundle', 'TB', 'TB.id = CB.bundle_id');
$query->condition('bundle_id', $bundle_id);
$bundle = $query->execute()->fetchObject();
// Extract all db names for the indexer
$cvs = [];
foreach ($config as $record) {
$cvs[] = $record->shortname;
}
$job = new XRayIndexerJob([
'entity_id' => $entity->id,
'bundle' => $bundle,
'cv_shortnames' => array_unique($cvs),
]);
// If the entity is in the index, remove it so that it can get re-indexed.
tripal_cv_xray_index_remove_single_entity($entity, $type);
XRayQueue::dispatch($job);
}
/**
* Handle removable of entities from the index.
*
* @param TripalEntity $entity
* @param string $type
*/
function tripal_cv_xray_index_remove_single_entity($entity, string $type) {
if ($type != 'TripalEntity') {
return;
}
// If the entity is in the index, remove it.
db_delete('tripal_cvterm_entity_linker')
->condition('entity_id', $entity->id)
->execute();
}
/**
* Implements hook_permission().
*/
function tripal_cv_xray_permission() {
$items = [];
$items['tripal cv xray'] = [
'title' => t('Access administrative page'),
];
return $items;
}