class PaymentMethodEntityController in Payment 7
Entity API controller for payment_method entities.
Hierarchy
- class \DrupalDefaultEntityController implements DrupalEntityControllerInterface- class \EntityAPIController implements EntityAPIControllerRevisionableInterface
 
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;
  }
} 
      