class MerciLineItemEntityControllerDeprecated in MERCI (Manage Equipment Reservations, Checkout and Inventory) 7.3
The controller class for line items contains methods for the line item CRUD operations. The load method is inherited from the default controller.
Hierarchy
- class \DrupalDefaultEntityController implements DrupalEntityControllerInterface
- class \MerciDefaultEntityController implements EntityAPIControllerInterface
Expanded class hierarchy of MerciLineItemEntityControllerDeprecated
File
- merci_line_item/
includes/ merci_line_item.controller.inc, line 438 - Provides a central controller for Drupal Commerce.
View source
class MerciLineItemEntityControllerDeprecated extends MerciDefaultEntityController {
/**
* Create a new entity.
*
* @param array $values
* An array of values to set, keyed by property name.
* @return
* A new instance of the entity type.
*/
public function create(array $values = array()) {
$values += array(
'line_item_id' => NULL,
'entity_id' => 0,
'type' => MERCI_LINE_ITEM,
'line_item_label' => '',
'quantity' => 1,
'created' => '',
'changed' => '',
'data' => array(),
);
return parent::create($values);
}
/**
* Saves a line item.
*
* @param $line_item
* The full line item object to save.
* @param $transaction
* An optional transaction object.
*
* @return
* SAVED_NEW or SAVED_UPDATED depending on the operation performed.
*/
public function save($line_item, DatabaseTransaction $transaction = NULL) {
if (!isset($transaction)) {
$transaction = db_transaction();
$started_transaction = TRUE;
}
$wrapper = entity_metadata_wrapper('merci_line_item', $line_item);
try {
// Set the timestamp fields.
if (empty($line_item->line_item_id) && empty($line_item->created)) {
$line_item->created = REQUEST_TIME;
}
else {
// Otherwise if the line item is not new but comes from an entity_create()
// or similar function call that initializes the created timestamp to an
// empty string, unset it to prevent destroying existing data in that
// property on update.
if ($line_item->created === '') {
unset($line_item->created);
}
}
// return parent::save($line_item, $transaction);
} catch (Exception $e) {
if (!empty($started_transaction)) {
$transaction
->rollback();
watchdog_exception($this->entityType, $e);
}
throw $e;
}
return parent::save($line_item, $transaction);
}
/**
* Unserializes the data property of loaded line items.
*/
public function attachLoad(&$queried_line_items, $revision_id = FALSE) {
foreach ($queried_line_items as $line_item_id => &$line_item) {
$line_item->data = unserialize($line_item->data);
}
// Call the default attachLoad() method. This will add fields and call
// hook_merci_line_item_load().
parent::attachLoad($queried_line_items, $revision_id);
}
/**
* Delete permanently saved line items.
*
* In case of failures, an exception is thrown.
*
* @param $line_item_ids
* An array of line item IDs to delete.
* @param $transaction
* An optional transaction object to pass thru. If passed the caller is
* responsible for rolling back the transaction if something goes wrong.
*/
public function delete($line_item_ids, DatabaseTransaction $transaction = NULL) {
$line_items = $line_item_ids ? $this
->load($line_item_ids) : FALSE;
if (!$line_items) {
// Do nothing, in case invalid or no ids have been passed.
return;
}
if (!isset($transaction)) {
$transaction = db_transaction();
$started_transaction = TRUE;
}
try {
// First attempt to delete references for the given line items.
foreach ($line_items as $line_item_id => $line_item) {
//merci_line_item_delete_references($line_item);
}
return parent::delete($line_item_ids, $transaction);
} catch (Exception $e) {
if (!empty($started_transaction)) {
$transaction
->rollback();
watchdog_exception($this->entityType, $e);
}
throw $e;
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DrupalDefaultEntityController:: |
protected | property | Whether this entity type should use the static cache. | |
DrupalDefaultEntityController:: |
protected | property | Static cache of entities, keyed by entity ID. | |
DrupalDefaultEntityController:: |
protected | property | Array of information about the entity. | |
DrupalDefaultEntityController:: |
protected | property | Entity type for this controller instance. | |
DrupalDefaultEntityController:: |
protected | property | Additional arguments to pass to hook_TYPE_load(). | |
DrupalDefaultEntityController:: |
protected | property | Name of the entity's ID field in the entity database table. | |
DrupalDefaultEntityController:: |
protected | property | Name of entity's revision database table field, if it supports revisions. | |
DrupalDefaultEntityController:: |
protected | property | The table that stores revisions, if the entity supports revisions. | |
DrupalDefaultEntityController:: |
protected | function | Gets entities from the static cache. | 1 |
DrupalDefaultEntityController:: |
protected | function | Stores entities in the static entity cache. | |
DrupalDefaultEntityController:: |
protected | function | Ensures integer entity IDs are valid. | |
DrupalDefaultEntityController:: |
protected | function | Callback for array_filter that removes non-integer IDs. | |
DrupalDefaultEntityController:: |
public | function |
Implements DrupalEntityControllerInterface::load(). Overrides DrupalEntityControllerInterface:: |
|
DrupalDefaultEntityController:: |
public | function | Constructor: sets basic variables. | |
MerciDefaultEntityController:: |
protected | property | Stores our transaction object, necessary for pessimistic locking to work. | |
MerciDefaultEntityController:: |
protected | property | Stores the ids of locked entities, necessary for knowing when to release a lock by committing the transaction. | |
MerciDefaultEntityController:: |
public | function |
Builds a structured array representing the entity's content. Overrides EntityAPIControllerInterface:: |
|
MerciDefaultEntityController:: |
protected | function |
Override of DrupalDefaultEntityController::buildQuery(). Overrides DrupalDefaultEntityController:: |
|
MerciDefaultEntityController:: |
public | function |
Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface:: |
|
MerciDefaultEntityController:: |
public | function |
Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface:: |
|
MerciDefaultEntityController:: |
public | function |
(Internal use) Invokes a hook on behalf of the entity. Overrides EntityAPIControllerInterface:: |
|
MerciDefaultEntityController:: |
protected | function | Checks the list of tracked locked entities, and if it's empty, commits the transaction in order to remove the acquired locks. | |
MerciDefaultEntityController:: |
public | function |
Implements DrupalEntityControllerInterface::resetCache(). Overrides DrupalDefaultEntityController:: |
|
MerciDefaultEntityController:: |
public | function |
Generate an array for rendering the given entities. Overrides EntityAPIControllerInterface:: |
|
MerciLineItemEntityControllerDeprecated:: |
public | function |
Unserializes the data property of loaded line items. Overrides DrupalDefaultEntityController:: |
|
MerciLineItemEntityControllerDeprecated:: |
public | function |
Create a new entity. Overrides MerciDefaultEntityController:: |
|
MerciLineItemEntityControllerDeprecated:: |
public | function |
Delete permanently saved line items. Overrides MerciDefaultEntityController:: |
|
MerciLineItemEntityControllerDeprecated:: |
public | function |
Saves a line item. Overrides MerciDefaultEntityController:: |