function PaymentEntityController::attachLoad in Payment 7
Attaches data to entities upon loading.
This will attach fields, if the entity is fieldable. It calls hook_entity_load() for modules which need to add data to all entities. It also calls hook_TYPE_load() on the loaded entities. For example hook_node_load() or hook_user_load(). If your hook_TYPE_load() expects special parameters apart from the queried entities, you can set $this->hookLoadArguments prior to calling the method. See NodeController::attachLoad() for an example.
Parameters
$queried_entities: Associative array of query results, keyed on the entity ID.
$revision_id: ID of the revision that was loaded, or FALSE if the most current revision was loaded.
Overrides DrupalDefaultEntityController::attachLoad
File
- ./
payment.classes.inc, line 337 - The API and related functions for executing and managing payments.
Class
- PaymentEntityController
- Entity API controller for payment entities.
Code
function attachLoad(&$queried_entities, $revision_id = FALSE) {
$pids = array_keys($queried_entities);
// Load the payments's payment methods.
$pmids = array();
foreach ($queried_entities as $payment) {
$pmids[] = $payment->pmid;
}
$methods = entity_load('payment_method', $pmids);
// Load line items.
$result = db_select('payment_line_item')
->fields('payment_line_item')
->condition('pid', $pids)
->execute();
$line_items = array();
while ($line_item_data = $result
->fetchAssoc('name', PDO::FETCH_ASSOC)) {
$line_item_data['description_arguments'] = unserialize($line_item_data['description_arguments']);
$line_item_data['amount'] = (double) $line_item_data['amount'];
$line_item_data['tax_rate'] = (double) $line_item_data['tax_rate'];
$line_item_data['quantity'] = (double) $line_item_data['quantity'];
$line_items[$line_item_data['pid']][$line_item_data['name']] = new PaymentLineItem($line_item_data);
}
// Load the payments's status items.
$result = db_select('payment_status_item')
->fields('payment_status_item')
->condition('pid', $pids)
->orderBy('psiid')
->execute();
$status_items = array();
while ($data = $result
->fetchObject()) {
$status_item = new PaymentStatusItem($data->status, $data->created, $data->pid, $data->psiid);
$status_items[$status_item->pid][] = $status_item;
}
// Add all data to the payments.
foreach ($queried_entities as $payment) {
$payment->statuses = $status_items[$payment->pid];
$payment->line_items = isset($line_items[$payment->pid]) ? $line_items[$payment->pid] : array();
$payment->method = $methods[$payment->pmid];
unset($payment->pmid);
}
parent::attachLoad($queried_entities, $revision_id);
}