class CommerceCouponEntityController in Commerce Coupon 7
Same name and namespace in other branches
- 7.2 includes/commerce_coupon.controller.inc \CommerceCouponEntityController
@file Coupon controller class.
Hierarchy
- class \DrupalDefaultEntityController implements DrupalEntityControllerInterface
- class \DrupalCommerceEntityController implements DrupalCommerceEntityControllerInterface
Expanded class hierarchy of CommerceCouponEntityController
1 string reference to 'CommerceCouponEntityController'
- commerce_coupon_entity_info in ./
commerce_coupon.module - Implements hook_entity_info().
File
- classes/
commerce_coupon.inc, line 8 - Coupon controller class.
View source
class CommerceCouponEntityController extends DrupalCommerceEntityController {
/**
* Create a default coupon.
*
* @param array $values
* An array of values to set, keyed by property name.
* @return
* A product object with all default fields initialized.
*/
public function create(array $values = array()) {
$values += array(
'coupon_id' => '',
'type' => '',
'is_active' => TRUE,
'created' => '',
'changed' => '',
);
return parent::create($values);
}
/**
* Saves a coupon.
*
* @param $commerce_coupon
* The full coupon object to save.
* @param $transaction
* An optional transaction object.
*
* @return
* SAVED_NEW or SAVED_UPDATED depending on the operation performed.
*/
public function save($entity, DatabaseTransaction $transaction = NULL) {
$transaction = isset($transaction) ? $transaction : db_transaction();
// Hardcode the changed time.
$entity->changed = REQUEST_TIME;
if (empty($entity->{$this->idKey}) || !empty($entity->is_new)) {
// Set the creation timestamp if not set, for new entities.
if (empty($entity->created)) {
$entity->created = REQUEST_TIME;
}
}
// Generate a code if no is set:
$code = field_get_items('commerce_coupon', $entity, 'commerce_coupon_code');
if (!isset($code) || empty($code)) {
$entity->commerce_coupon_code[LANGUAGE_NONE][0]['value'] = commerce_coupon_generate_coupon_code();
}
return parent::save($entity);
}
/**
* Deletes multiple coupons by ID.
*
* @param $coupon_ids
* An array of coupon IDs to delete.
* @param $transaction
* An optional transaction object.
*
* @return
* TRUE on success, FALSE otherwise.
*/
public function delete($coupon_ids, DatabaseTransaction $transaction = NULL) {
if (!empty($coupon_ids)) {
$coupons = $this
->load($coupon_ids, array());
// Ensure the coupons can actually be deleted.
foreach ((array) $coupons as $coupon_id => $coupon) {
if (!commerce_coupon_can_delete($coupon)) {
unset($coupons[$coupon_id]);
}
}
// If none of the specified coupons can be deleted, return FALSE.
if (empty($coupons)) {
return FALSE;
}
parent::delete(array_keys($coupons), $transaction);
return TRUE;
}
else {
return FALSE;
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CommerceCouponEntityController:: |
public | function |
Create a default coupon. Overrides DrupalCommerceEntityController:: |
|
CommerceCouponEntityController:: |
public | function |
Deletes multiple coupons by ID. Overrides DrupalCommerceEntityController:: |
|
CommerceCouponEntityController:: |
public | function |
Saves a coupon. Overrides DrupalCommerceEntityController:: |
|
DrupalCommerceEntityController:: |
protected | property | Stores our transaction object, necessary for pessimistic locking to work. | |
DrupalCommerceEntityController:: |
protected | property | Stores the ids of locked entities, necessary for knowing when to release a lock by committing the transaction. | |
DrupalCommerceEntityController:: |
protected | property | Stores the ids of unchanged entities, necessary for knowing if we're dealing with unchanged entities before acting on them. | |
DrupalCommerceEntityController:: |
public | function |
Builds a structured array representing the entity's content. Overrides EntityAPIControllerInterface:: |
2 |
DrupalCommerceEntityController:: |
protected | function |
Override of DrupalDefaultEntityController::buildQuery(). Overrides DrupalDefaultEntityController:: |
|
DrupalCommerceEntityController:: |
public | function |
Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface:: |
|
DrupalCommerceEntityController:: |
public | function |
Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface:: |
|
DrupalCommerceEntityController:: |
public | function |
(Internal use) Invokes a hook on behalf of the entity. Overrides EntityAPIControllerInterface:: |
|
DrupalCommerceEntityController:: |
public | function |
Implements DrupalCommerceEntityControllerInterface::isUnchanged(). Overrides DrupalCommerceEntityControllerInterface:: |
|
DrupalCommerceEntityController:: |
protected | function | Checks the list of tracked locked entities, and if it's empty, commits the transaction in order to remove the acquired locks. | |
DrupalCommerceEntityController:: |
public | function |
Implements DrupalEntityControllerInterface::resetCache(). Overrides DrupalDefaultEntityController:: |
|
DrupalCommerceEntityController:: |
public | function |
Generate an array for rendering the given entities. Overrides EntityAPIControllerInterface:: |
|
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 | Attaches data to entities upon loading. | 4 |
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. |