123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- <?php
- function tripal_chado_entity_create(&$entity, $type) {
- if ($type == 'TripalEntity') {
-
- $entity->chado_table = NULL;
- $entity->chado_column = NULL;
- $entity->chado_record = NULL;
- $entity->chado_record_id = NULL;
-
- $bundle = tripal_load_bundle_entity($entity->bundle);
- $chado_table = tripal_get_bundle_variable('chado_table', $bundle->id);
- $chado_column = tripal_get_bundle_variable('chado_column', $bundle->id);
- if ($chado_table) {
- $entity->chado_table = $chado_table;
- $entity->chado_column = $chado_column;
- }
- }
- }
- function tripal_chado_entity_presave($entity, $type) { }
- function tripal_chado_entity_postsave($entity, $type) { }
- function tripal_chado_entity_load($entities, $type) {
- if ($type == 'TripalEntity') {
- foreach ($entities as $entity) {
-
- if (property_exists($entity, 'id')) {
-
- $entity->chado_table = NULL;
- $entity->chado_column = NULL;
- $entity->chado_record = NULL;
- $entity->chado_record_id = NULL;
-
- $bundle = tripal_load_bundle_entity($entity->bundle);
- $chado_table = tripal_get_bundle_variable('chado_table', $bundle->id);
- $chado_column = tripal_get_bundle_variable('chado_column', $bundle->id);
- if ($chado_table) {
- $entity->chado_table = $chado_table;
- $entity->chado_column = $chado_column;
- }
- $chado_entity = db_select('chado_entity' ,'ce')
- ->fields('ce')
- ->condition('ce.entity_id', $entity->id)
- ->execute()
- ->fetchObject();
- $schema = chado_get_schema($chado_table);
- $record = chado_generate_var($chado_table, array($schema['primary key'][0] => $chado_entity->record_id));
- $entity->chado_record = $record;
- $entity->chado_record_id = $chado_entity->record_id;
- }
- }
- }
- }
- function tripal_chado_field_attach_form($entity_type, $entity, &$form, &$form_state, $langcode) { }
- function tripal_chado_entity_insert($entity, $type) { }
- function tripal_chado_entity_update($entity, $type) { }
- function tripal_chaddo_entity_delete($entity, $type) {
- $record = db_select('chado_entity', 'ce')
- ->fields('ce', array('chado_entity_id', 'data_table', 'record_id'))
- ->condition('entity_id', $entity->id)
- ->execute()
- ->fetchObject();
- if ($record && property_exists($record, 'chado_entity_id')) {
-
- $table = $record->data_table;
- $record_id = $record->record_id;
- chado_delete_record($table, array($table . '_id' => $record_id));
-
- $sql = "DELETE FROM {chado_entity} WHERE chado_entity_id = :id";
- db_query($sql, array(':id' => $record->chado_entity_id));
- }
- }
- function tripal_chado_entity_access($op, $entity = NULL, $account = NULL) {
- if (user_access('administer tripal data', $account)) {
- return TRUE;
- }
- if (isset($entity) && $type_name = $entity->type) {
- $op = ($op == 'view') ? 'view' : 'edit';
- if (user_access("$op any $type_name data", $account)) {
- return TRUE;
- }
- }
- return FALSE;
- }
|