You are here

class PaymentMethodEntityController in Payment 7

Entity API controller for payment_method entities.

Hierarchy

Expanded class hierarchy of PaymentMethodEntityController

1 string reference to 'PaymentMethodEntityController'
payment_entity_info in ./payment.module
Implements hook_entity_info().

File

./payment.classes.inc, line 630
The API and related functions for executing and managing payments.

View source
class PaymentMethodEntityController extends EntityAPIControllerExportable {

  /**
   * {@inheritdoc}
   */
  function load($ids = array(), $conditions = array()) {
    static $unavailable = NULL;
    $entities = parent::load($ids, $conditions);
    foreach ($entities as $payment_method) {

      // Cast non-string scalars to their original types, because some backends
      // store/return all variables as strings.
      $payment_method->enabled = (bool) $payment_method->enabled;
      $payment_method->pmid = (int) $payment_method->pmid;
      $payment_method->status = (int) $payment_method->status;
      $payment_method->uid = (int) $payment_method->uid;
    }

    // Load PaymentMethodUnavailable for all requested IDs that did not match
    // any existing payment methods.
    if (is_array($ids)) {

      // If the entities were loaded by PID.
      if (is_numeric(reset($ids))) {
        $diff = array_diff($ids, array_keys($entities));
      }
      else {
        $names = array();
        foreach ($entities as $entity) {
          $names[] = $entity->name;
        }
        $diff = array_diff($ids, $names);
      }
      if ($diff && is_null($unavailable)) {
        $unavailable = new PaymentMethodUnavailable();
      }
      foreach ($diff as $pmid) {
        $entities[$pmid] = $unavailable;
      }
      ksort($entities);
    }
    return $entities;
  }

  /**
   * {@inheritdoc}
   */
  function attachLoad(&$queries_entities, $revision_id = FALSE) {
    foreach ($queries_entities as $entity) {
      $entity->controller = payment_method_controller_load($entity->controller_class_name);
      if (!$entity->controller) {
        $entity->controller = payment_method_controller_load('PaymentMethodControllerUnavailable');
      }
      unset($entity->controller_class_name);
    }
    parent::attachLoad($queries_entities, $revision_id);
  }

  /**
   * {@inheritdoc}
   */
  function save($entity, DatabaseTransaction $transaction = NULL) {
    $entity->controller_class_name = $entity->controller->name;
    $return = parent::save($entity, $transaction);

    // Cast non-string scalars to their original types, because some backends
    // store/return all variables as strings.
    $entity->pmid = (int) $entity->pmid;
    unset($entity->controller_class_name);
    return $return;
  }

  /**
   * {@inheritdoc}
   */
  function export($entity, $prefix = '') {

    // The payment method controller should not be exported. Instead, we
    // temporarily replace it with a property that only stores its class name.
    $controller = $entity->controller;
    $entity->controller_class_name = $controller->name;
    unset($entity->controller);
    $export = parent::export($entity, $prefix);
    $entity->controller = $controller;
    unset($entity->controller_class_name);
    return $export;
  }

  /**
   * {@inheritdoc}
   */
  function import($export) {
    if ($payment = parent::import($export)) {
      $payment->controller = payment_method_controller_load($payment->controller_class_name);
      unset($payment->controller_class_name);
      return $payment;
    }
    return FALSE;
  }

}

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::cleanIds protected function Ensures integer entity IDs are valid.
DrupalDefaultEntityController::filterId protected function Callback for array_filter that removes non-integer IDs.
EntityAPIController::$bundleKey protected property
EntityAPIController::$cacheComplete protected property
EntityAPIController::$defaultRevisionKey protected property
EntityAPIController::buildContent public function Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface::buildContent
EntityAPIController::create public function Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface::create
EntityAPIController::deleteRevision public function Implements EntityAPIControllerRevisionableInterface::deleteRevision(). Overrides EntityAPIControllerRevisionableInterface::deleteRevision
EntityAPIController::query public function Builds and executes the query for loading.
EntityAPIController::renderEntityProperty protected function Renders a single entity property.
EntityAPIController::saveRevision protected function Saves an entity revision.
EntityAPIControllerExportable::$entityCacheByName protected property
EntityAPIControllerExportable::$nameKey protected property
EntityAPIControllerExportable::applyConditions protected function
EntityAPIControllerExportable::buildQuery protected function Support loading by name key. Overrides EntityAPIController::buildQuery
EntityAPIControllerExportable::cacheGet protected function Overridden. Overrides DrupalDefaultEntityController::cacheGet
EntityAPIControllerExportable::cacheGetByName protected function Like cacheGet() but keyed by name.
EntityAPIControllerExportable::cacheSet protected function Overridden. Overrides DrupalDefaultEntityController::cacheSet
EntityAPIControllerExportable::delete public function Overridden to care about reverted entities. Overrides EntityAPIController::delete
EntityAPIControllerExportable::invoke public function Overridden to care about reverted bundle entities and to skip Rules. Overrides EntityAPIController::invoke
EntityAPIControllerExportable::resetCache public function Overrides DrupalDefaultEntityController::resetCache(). Overrides EntityAPIController::resetCache
EntityAPIControllerExportable::view public function Implements EntityAPIControllerInterface. Overrides EntityAPIController::view
EntityAPIControllerExportable::__construct public function Overridden. Overrides EntityAPIController::__construct
PaymentMethodEntityController::attachLoad function Overridden. Overrides EntityAPIControllerExportable::attachLoad
PaymentMethodEntityController::export function Overridden. Overrides EntityAPIControllerExportable::export
PaymentMethodEntityController::import function Implements EntityAPIControllerInterface. Overrides EntityAPIController::import
PaymentMethodEntityController::load function Overridden to support passing numeric ids as well as names as $ids. Overrides EntityAPIControllerExportable::load
PaymentMethodEntityController::save function Overridden to care exportables that are overridden. Overrides EntityAPIControllerExportable::save