-
Notifications
You must be signed in to change notification settings - Fork 0
/
dh_ecology.module
304 lines (269 loc) · 8.99 KB
/
dh_ecology.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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
<?php
//Implement hook_entity_info().
function dh_ecology_entity_info() {
$return = array();
if (db_table_exists('dh_ecology_isolate_type')) {
$return['dh_ecology_isolate_type'] = array(
'label' => t('dH Ecology Isolate Type'),
'entity class' => 'dHEcologyIsolateType',
'controller class' => 'dHEcologyIsolateTypeController',
'base table' => 'dh_ecology_isolate_type',
'fieldable' => TRUE,
'bundle of' => 'dh_ecology_isolate',
'bundles' => array(),
'bundle keys' => array(
),
'exportable' => TRUE,
'entity keys' => array (
'name' => 'bundle',
'id' => 'itid',
'label' => 'name',
),
'access callback' => 'dh_ecology_type_access',
'module' => 'dh_ecology',
// Enable the entity API's admin UI.
'admin ui' => array(
'path' => 'admin/structure/dh_ecology_isolate_type',
'file' => 'dh_ecology.admin.inc',
'controller class' => 'dHEcologyIsolateTypeUIController',
),
);
}
$return['dh_ecology_isolate'] = array(
'label' => t('dH Ecology Isolate'),
// The entity class and controller class extend the classes provided by the
// Entity API
'entity class' => 'dHEcologyIsolate',
'controller class' => 'dHEcologyIsolateController',
'base table' => 'dh_ecology_isolate',
'fieldable' => TRUE,
//'exportable' => TRUE,
'entity keys' => array (
'name' => 'iid',
'id' => 'iid',
'label' => 'isolate',
'bundle' => 'bundle',
),
'bundles' => array(),
'bundle keys' => array(
'bundle' => 'bundle',
),
'property info' => array(),
//'access callback' => 'dh_feature_access',
'access callback' => 'dh_ecology_access',
'module' => 'dh_ecology',
// Enable the entity API's admin UI.
'admin ui' => array(
'path' => 'admin/content/dh_ecology_isolate',
'file' => 'dh_ecology.admin.inc',
'controller class' => 'dHEcologyIsolateUIController',
),
);
return $return;
}
function dh_ecology_entity_info_alter(&$entity_info) {
if (db_table_exists('dh_ecology_isolate_type')) {
foreach (dh_ecology_isolate_get_types() as $type => $info) {
//error_log("Setting type info for $type ");
$entity_info['dh_ecology_isolate']['bundles'][$type] = array(
'label' => $info->name,
'admin' => array(
'path' => 'admin/structure/dh_ecology_isolate_type/manage/%dh_ecology_isolate_type',
'real path' => 'admin/structure/dh_ecology_isolate_type/manage/' . $type,
'bundle argument' => 4,
'access arguments' => array('administer dh_ecology_isolate_type types'),
),
);
}
}
}
function dh_ecology_isolate_get_types($bundle_name = NULL) {
// entity_load will get the Entity controller for our model entity and call the load
// function of that object - we are loading entities by name here.
//error_log("Getting list of dh_ecology_isolate_type");
$bundles = entity_load_multiple_by_name('dh_ecology_isolate_type', isset($bundle_name) ? array($bundle_name) : FALSE);
return isset($bundle_name) ? reset($bundles) : $bundles;
}
function dh_ecology_isolate_type_load($bundle) {
return dh_ecology_isolate_get_types($bundle);
}
function dh_ecology_permission() {
$permissions = array(
'administer dh_ecology types' => array(
'title' => t('Administer dH Ecology types'),
'description' => t('Allows users to configure dH Ecology types and their fields.'),
'restrict access' => FALSE,
),
'create dh_ecology entities' => array(
'title' => t('Create dH Ecology entities'),
'description' => t('Allows users to create dH Ecology entities.'),
'restrict access' => FALSE,
),
'view dh_ecology entities' => array(
'title' => t('View dH Ecology types'),
'description' => t('Allows users to view dH Ecology types.'),
'restrict access' => FALSE,
),
'edit any dh_ecology entities' => array(
'title' => t('Edit any dH Ecology types'),
'description' => t('Allows users to edit any dH Ecology types.'),
'restrict access' => FALSE,
),
'delete any dh_ecology entities' => array(
'title' => t('Delete any dH Ecology Entities'),
'description' => t('Allows users to delete any dH Ecology Entities.'),
'restrict access' => FALSE,
),
);
return $permissions;
}
function dh_ecology_access($op, $entity, $account, $entity_type) {
global $user;
// can we insert request to find ownership eref;s here? This would allow us finegrained control!
//drupal_set_message("Called dh_feature_access $op, " . print_r((array)$entity,1) . ", $account, $entity_type");
//error_log("Called dh_feature_access $op, " . print_r((array)$entity,1) . ", " . print_r((array)$account,1) . ", $entity_type");
if (!isset($account)) {
$account = $user;
}
switch ($op) {
case 'create':
return user_access('administer dh_ecology entities', $account)
|| user_access('create dh_ecology entities', $account);
case 'view':
return user_access('administer dh_ecology entities', $account)
|| user_access('view dh_ecology entities', $account);
case 'delete':
return user_access('administer dh_ecology entities', $account)
|| user_access('delete any dh_ecology entities', $account)
|| user_access('delete own dh_ecology entities', $account);
case 'edit':
case 'update':
return user_access('administer dh_ecology entities')
|| user_access('edit any dh_ecology entities')
|| (user_access('edit own dh_ecology entities') && ($entity->uid == $account->uid));
}
return user_access('administer dh_ecology types');
}
function dh_ecology_type_access($op, $type = NULL, $account = NULL) {
//return TRUE;
return user_access('administer dh_ecology types');
}
function dh_ecology_webform_submission_insert($node, $submission) {
// do handlers that require access to the sid
if (!module_load_include('module', 'dh')) {
drupal_set_message("Cannot load dH");
return;
}
if (!module_load_include('inc', 'dh_ecology', 'dh_ecology.webform')) {
drupal_set_message("Cannot load dh_ecology.webform.inc");
return;
}
$wfmap = dh_ecology_webform_getmap();
dh_webform_handler($node, $submission, $wfmap, 'insert');
return;
}
function dh_ecology_webform_submission_presave($node, &$submission) {
if (!module_load_include('module', 'dh')) {
drupal_set_message("Cannot load dH");
return;
}
if (!module_load_include('inc', 'dh_ecology', 'dh_ecology.webform')) {
drupal_set_message("Cannot load dh_ecology.webform.inc");
return;
}
$wfmap = dh_ecology_webform_getmap();
$submission = dh_webform_handler($node, $submission, $wfmap, 'presave');
return;
}
//****************************
// Contact Type
//****************************
class dHEcologyIsolateType extends Entity {
public $is_new;
public $bundle;
public $name;
public $itid;
public $description;
public function __construct($values = array()) {
parent::__construct($values, 'dh_ecology_isolate_type');
}
protected function defaultLabel() {
return $this->name;
}
}
class dHEcologyIsolateTypeController extends EntityAPIControllerExportable {
public function __construct($entityType) {
parent::__construct($entityType);
}
public function create(array $values = array()) {
// Add values that are specific to our Model
$values += array(
'itid' => '',
'label' => '',
'name' => '',
);
$feature_type = parent::create($values);
return $feature_type;
}
}
class dHEcologyIsolate extends Entity {
public $is_new;
public $iid;
public $isolate;
public $species;
public $bundle;
public $source;
public $acquisition_num;
public $sequence;
public $sequence_location;
public $ecology;
public $genus;
public $host_organism;
public $primer_f;
public $primer_r;
public $type_specimen;
public $uid;
public function __construct($values = array()) {
if (!isset($values['modified'])) {
$values['modified'] = date('U');
}
parent::__construct($values, 'dh_ecology_isolate');
}
protected function defaultLabel() {
return $this->isolate;
}
}
class dHEcologyIsolateController extends EntityAPIControllerExportable {
public function __construct($entityType) {
parent::__construct($entityType);
}
public function create(array $values = array()) {
global $user;
// Add values that are specific to our Model
$values += array(
'isolate' => '',
'bundle' => '',
'species' => '',
'source' => '',
'ecology' => '',
'genus' => '',
'host_organism' => '',
'primer_f' => '',
'primer_r' => '',
'acquisition_num' => '',
'sequence' => null,
'sequence_location' => '',
'type_specimen' => '0'
);
if (!isset($values['uid'])) {
$values['uid'] = $user->uid;
}
$feature_type = parent::create($values);
return $feature_type;
}
public function save($entity, DatabaseTransaction $transaction = NULL) {
$entity->modified = date('U');
return parent::save($entity, $transaction);
}
}
?>