You are here

class WSEntityAPIController in Web Service Data 7

WSEntityAPIController extends and overrides most EntityAPIController features

Hierarchy

Expanded class hierarchy of WSEntityAPIController

File

modules/wsentities/includes/wsentity.controller.inc, line 18
Provides a controller building upon the core controller but providing more features like full CRUD functionality.

View source
class WSEntityAPIController extends EntityAPIController implements WSEntityAPIControllerInterface {
  protected $cacheComplete = FALSE;
  protected $bundleKey;
  public function __construct($entityType) {

    /**
         TODO: Load entity config object here
         TODO: Find a method of finding out which config object goes with this entity.
      **/
    parent::__construct($entityType);
  }

  /**
   * WS Get's the entity
   */
  public function query($ids, $conditions, $revision_id = FALSE) {

    /*
      TODO: WS RETRIEVE
    */
    return $result;
  }

  /**
   * Implements EntityAPIControllerInterface.
   *
   *  WS Delete's the entity
   *
   * @param $transaction
   *   Optionally a DatabaseTransaction object to use. Allows overrides to pass
   *   in their transaction object.
   */
  public function delete($ids, DatabaseTransaction $transaction = NULL) {
    $entities = $ids ? $this
      ->load($ids) : FALSE;
    if (!$entities) {

      // Do nothing, in case invalid or no ids have been passed.
      return;
    }

    // This transaction causes troubles on MySQL, see
    // http://drupal.org/node/1007830. So we deactivate this by default until
    // is shipped in a point release.
    // $transaction = isset($transaction) ? $transaction : db_transaction();
    try {
      $ids = array_keys($entities);

      /*
        TODO: WS delete
            db_delete($this->entityInfo['base table'])
              ->condition($this->idKey, $ids, 'IN')
              ->execute();
      */

      // Reset the cache as soon as the changes have been applied.
      $this
        ->resetCache($ids);
      foreach ($entities as $id => $entity) {
        $this
          ->invoke('delete', $entity);
      }

      // Ignore slave server temporarily.
      db_ignore_slave();
    } catch (Exception $e) {
      if (isset($transaction)) {
        $transaction
          ->rollback();
      }
      watchdog_exception($this->entityType, $e);
      throw $e;
    }
  }

  /**
   * Implements EntityAPIControllerInterface.
   *
   * @param $transaction
   *   Optionally a DatabaseTransaction object to use. Allows overrides to pass
   *   in their transaction object.
   */
  public function save($entity, DatabaseTransaction $transaction = NULL) {
    $transaction = isset($transaction) ? $transaction : db_transaction();
    try {

      // Load the stored entity, if any.
      if (!empty($entity->{$this->idKey}) && !isset($entity->original)) {

        // In order to properly work in case of name changes, load the original
        // entity using the id key if it is available.
        $entity->original = entity_load_unchanged($this->entityType, $entity->{$this->idKey});
      }
      $this
        ->invoke('presave', $entity);
      if (!empty($entity->{$this->idKey}) && empty($entity->is_new)) {

        /*
          TODO: WS PUT
                $return = drupal_write_record($this->entityInfo['base table'], $entity, $this->idKey);
        */
        $this
          ->resetCache(array(
          $entity->{$this->idKey},
        ));
        $this
          ->invoke('update', $entity);
      }
      else {

        /*
          TODO: WS POST
                $return = drupal_write_record($this->entityInfo['base table'], $entity);
        */
        $this
          ->invoke('insert', $entity);
      }

      // Ignore slave server temporarily.
      db_ignore_slave();
      unset($entity->is_new);
      unset($entity->original);
      return $return;
    } catch (Exception $e) {
      $transaction
        ->rollback();
      watchdog_exception($this->entityType, $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::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.
EntityAPIController::$defaultRevisionKey protected property
EntityAPIController::buildContent public function Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface::buildContent
EntityAPIController::buildQuery protected function Overrides DrupalDefaultEntityController::buildQuery(). Overrides DrupalDefaultEntityController::buildQuery 1
EntityAPIController::create public function Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface::create
EntityAPIController::deleteRevision public function Implements EntityAPIControllerRevisionableInterface::deleteRevision(). Overrides EntityAPIControllerRevisionableInterface::deleteRevision
EntityAPIController::export public function Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface::export 1
EntityAPIController::import public function Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface::import
EntityAPIController::invoke public function Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface::invoke 1
EntityAPIController::load public function Overridden. Overrides DrupalDefaultEntityController::load 1
EntityAPIController::renderEntityProperty protected function Renders a single entity property.
EntityAPIController::resetCache public function Overrides DrupalDefaultEntityController::resetCache(). Overrides DrupalDefaultEntityController::resetCache 1
EntityAPIController::saveRevision protected function Saves an entity revision.
EntityAPIController::view public function Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface::view 1
WSEntityAPIController::$bundleKey protected property Overrides EntityAPIController::$bundleKey
WSEntityAPIController::$cacheComplete protected property Overrides EntityAPIController::$cacheComplete
WSEntityAPIController::delete public function Implements EntityAPIControllerInterface. Overrides EntityAPIController::delete
WSEntityAPIController::query public function WS Get's the entity Overrides EntityAPIController::query
WSEntityAPIController::save public function Implements EntityAPIControllerInterface. Overrides EntityAPIController::save
WSEntityAPIController::__construct public function Overridden. Overrides EntityAPIController::__construct