123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- <?php
- class TripalVocabController extends EntityAPIController {
- public function __construct($entity_type) {
- parent::__construct($entity_type);
- }
- public function create(array $values = array()) {
- $this->vocabulary = array_key_exists('vocabulary', $values) ? $values['vocabulary'] : '';
- return parent::create($values);
- }
-
- public function delete($ids, DatabaseTransaction $transaction = NULL) {
- $entities = $ids ? $this->load($ids) : FALSE;
- if (!$entities) {
-
- return;
- }
- $transaction = isset($transaction) ? $transaction : db_transaction();
- try {
- $ids = array_keys($entities);
- foreach ($entities as $id => $entity) {
-
- module_invoke_all('entity_delete', $entity, 'TripalTerm');
- field_attach_delete('TripalVocab', $entity);
- }
- db_delete('tripal_term')
- ->condition('id', $ids)
- ->execute();
- }
- catch (Exception $e) {
- $transaction->rollback();
- watchdog_exception('tripal', $e);
- throw $e;
- return FALSE;
- }
- return TRUE;
- }
-
- public function save($entity, DatabaseTransaction $transaction = NULL) {
- global $user;
- $pkeys = array();
- $transaction = isset($transaction) ? $transaction : db_transaction();
- try {
-
-
- if (empty($entity->id)) {
- $entity->created = time();
- $invocation = 'entity_insert';
- }
- else {
- $invocation = 'entity_update';
- $pkeys = array('id');
- }
-
- module_invoke_all('entity_presave', $entity, 'TripalTerm');
-
- $record = array(
- 'vocabulary' => $entity->vocabulary,
- 'created' => $entity->created,
- 'changed' => time(),
- );
- if ($invocation == 'entity_update') {
- $record['id'] = $entity->id;
- }
- $success = drupal_write_record('tripal_vocab', $record, $pkeys);
- if ($success == SAVED_NEW) {
- $entity->id = $record['id'];
- }
-
-
-
-
- if ($invocation == 'entity_insert') {
- field_attach_insert('TripalVocab', $entity);
- }
- else {
- field_attach_update('TripalVocab', $entity);
- }
-
- module_invoke_all('entity_postsave', $entity, 'TripalTerm');
- module_invoke_all($invocation, $entity, 'TripalTerm');
- return $record;
- }
- catch (Exception $e) {
- $transaction->rollback();
- watchdog_exception('tripal_entity', $e);
- drupal_set_message("Could not save the TripalVocab:" . $e->getMessage(), "error");
- return FALSE;
- }
- }
- }
|