You are here

class LTIToolProviderConsumerEntityController in LTI Tool Provider 7

Hierarchy

Expanded class hierarchy of LTIToolProviderConsumerEntityController

1 string reference to 'LTIToolProviderConsumerEntityController'
lti_tool_provider_entity_info in ./lti_tool_provider.module
Implements hook_entity_info().

File

./LTIToolProviderConsumerEntityController.class.php, line 32
Contains LTIToolProviderConsumerEntityController.

View source
class LTIToolProviderConsumerEntityController extends DrupalDefaultEntityController implements LTIToolProviderConsumerEntityControllerInterface {

  /**
   * Create a consumer.
   *
   * @return object
   *   The consumer.
   */
  public function create() {
    $entity = new stdClass();
    $entity->lti_tool_provider_consumer_id = 0;
    $entity->lti_tool_provider_consumer_key = '';
    $entity->lti_tool_provider_consumer_secret = '';
    $entity->lti_tool_provider_consumer_consumer = '';
    $entity->lti_tool_provider_consumer_domain = '';
    $entity->lti_tool_provider_consumer_dummy_pref = FALSE;
    $extra_cols = lti_tool_provider_get_extra_columns();
    foreach ($extra_cols as $col) {
      $entity->{$col} = '';
    }
    return $entity;
  }

  /**
   * Save a consumer.
   *
   * @param object $entity
   *   The consumer.
   *
   * @return object|boolean
   *   The consumer or false if save failed.
   */
  public function save($entity) {
    $transaction = db_transaction();
    try {
      $entity->is_new = empty($enity->lti_tool_provider_consumer_id);
      if (empty($entity->date_joined)) {
        $entity->date_joined = REQUEST_TIME;
      }
      field_attach_presave('lti_tool_provider_consumer', $entity);
      $primary_key = $entity->lti_tool_provider_consumer_id ? 'lti_tool_provider_consumer_id' : array();
      if (empty($primary_key)) {
        drupal_write_record('lti_tool_provider_consumer', $entity);
        field_attach_insert('lti_tool_provider_consumer', $entity);
        $op = 'insert';
      }
      else {
        drupal_write_record('lti_tool_provider_consumer', $entity, $primary_key);
        $op = 'update';
      }
      $function = 'field_attach_' . $op;
      $function('lti_tool_provider_consumer', $entity);
      module_invoke_all('entity_' . $op, $entity, 'lti_tool_provider_consumer');
      unset($entity->is_new);
      db_ignore_slave();
      return $entity;
    } catch (Exception $e) {
      $transaction
        ->rollback();
      drupal_set_message(t('%e', array(
        '%e' => $entity->{$e},
      )));
      watchdog_exception('lti_tool_provider_consumer', $e, NULL, WATCHDOG_ERROR);
      return FALSE;
    }
  }

  /**
   * Delete a consumer.
   *
   * @param object $entity
   *   The consumer.
   */
  public function delete($entity) {
    $this
      ->deleteMultiple(array(
      $entity,
    ));
  }

  /**
   * Delete multiple consumers.
   *
   * @param array $entities
   *   An array of consumers.
   *
   * @throws Exception
   *   From the db api.
   */
  public function deleteMultiple($entities) {
    $ids = array();
    if (!empty($entities)) {
      $transaction = db_transaction();
      try {
        foreach ($entities as $entity) {
          module_invoke_all('lti_tool_provider_consumer_delete', $entity);

          // Invoke hook_entity_delete().
          module_invoke_all('entity_delete', $entity, 'lti_tool_provider_consumer');
          field_attach_delete('lti_tool_provider_consumer', $entity);
          $ids[] = $entity->lti_tool_provider_consumer_id;
        }
        db_delete('lti_tool_provider_consumer')
          ->condition('lti_tool_provider_consumer_id', $ids, 'IN')
          ->execute();
      } catch (Exception $e) {
        $transaction
          ->rollback();
        watchdog_exception('lti_tool_provider_consumer', $e);
        throw $e;
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DrupalDefaultEntityController::$cache protected property Whether this entity type should use the static cache.
DrupalDefaultEntityController::$entityCache protected property Static cache of entities, keyed by entity ID.
DrupalDefaultEntityController::$entityInfo protected property Array of information about the entity.
DrupalDefaultEntityController::$entityType protected property Entity type for this controller instance.
DrupalDefaultEntityController::$hookLoadArguments protected property Additional arguments to pass to hook_TYPE_load().
DrupalDefaultEntityController::$idKey protected property Name of the entity's ID field in the entity database table.
DrupalDefaultEntityController::$revisionKey protected property Name of entity's revision database table field, if it supports revisions.
DrupalDefaultEntityController::$revisionTable protected property The table that stores revisions, if the entity supports revisions.
DrupalDefaultEntityController::attachLoad protected function Attaches data to entities upon loading. 4
DrupalDefaultEntityController::buildQuery protected function Builds the query to load the entity. 4
DrupalDefaultEntityController::cacheGet protected function Gets entities from the static cache. 1
DrupalDefaultEntityController::cacheSet protected function Stores entities in the static entity cache.
DrupalDefaultEntityController::cleanIds protected function Ensures integer entity IDs are valid.
DrupalDefaultEntityController::filterId protected function Callback for array_filter that removes non-integer IDs.
DrupalDefaultEntityController::load public function Implements DrupalEntityControllerInterface::load(). Overrides DrupalEntityControllerInterface::load
DrupalDefaultEntityController::resetCache public function Implements DrupalEntityControllerInterface::resetCache(). Overrides DrupalEntityControllerInterface::resetCache
DrupalDefaultEntityController::__construct public function Constructor: sets basic variables.
LTIToolProviderConsumerEntityController::create public function Create a consumer. Overrides LTIToolProviderConsumerEntityControllerInterface::create
LTIToolProviderConsumerEntityController::delete public function Delete a consumer. Overrides LTIToolProviderConsumerEntityControllerInterface::delete
LTIToolProviderConsumerEntityController::deleteMultiple public function Delete multiple consumers.
LTIToolProviderConsumerEntityController::save public function Save a consumer. Overrides LTIToolProviderConsumerEntityControllerInterface::save