class CommerceCustomerProfileEntityController in Commerce Core 7
The controller class for customer profiles contains methods for the profile CRUD operations. The load method is inherited from the default controller.
Hierarchy
- class \DrupalDefaultEntityController implements DrupalEntityControllerInterface
Expanded class hierarchy of CommerceCustomerProfileEntityController
1 string reference to 'CommerceCustomerProfileEntityController'
- commerce_customer_entity_info in modules/
customer/ commerce_customer.module - Implements hook_entity_info().
File
- modules/
customer/ includes/ commerce_customer_profile.controller.inc, line 12 - The controller for the customer profile entity containing the CRUD operations.
View source
class CommerceCustomerProfileEntityController extends DrupalCommerceEntityController {
/**
* Create a default customer profile.
*
* @param array $values
* An array of values to set, keyed by property name.
*
* @return
* A customer profile object with all default fields initialized.
*/
public function create(array $values = array()) {
$values += array(
'profile_id' => NULL,
'revision_id' => NULL,
'type' => '',
'uid' => '',
'status' => 1,
'created' => '',
'changed' => '',
);
return parent::create($values);
}
/**
* Saves a customer profile.
*
* When saving a profile without an ID, this function will create a new
* profile at that time. Subsequent profiles that should be saved as new
* revisions should set $profile->revision to TRUE and include a log string in
* $profile->log.
*
* @param $profile
* The full customer profile object to save.
* @param $transaction
* An optional transaction object.
*
* @return
* SAVED_NEW or SAVED_UPDATED depending on the operation performed.
*/
public function save($profile, DatabaseTransaction $transaction = NULL) {
if (!isset($transaction)) {
$transaction = db_transaction();
$started_transaction = TRUE;
}
try {
global $user;
// Determine if we will be inserting a new profile.
$profile->is_new = empty($profile->profile_id);
// Set the timestamp fields.
if ($profile->is_new && empty($profile->created)) {
$profile->created = REQUEST_TIME;
}
else {
// Otherwise if the profile is not new but comes from an entity_create()
// or similar function call that initializes the created timestamp and
// uid value to empty strings, unset them to prevent destroying existing
// data in those properties on update.
if ($profile->created === '') {
unset($profile->created);
}
if ($profile->uid === '') {
unset($profile->uid);
}
}
$profile->changed = REQUEST_TIME;
$profile->revision_uid = $user->uid;
$profile->revision_timestamp = REQUEST_TIME;
if ($profile->is_new || !empty($profile->revision)) {
// When inserting either a new profile or revision, $profile->log must
// be set because {commerce_customer_profile_revision}.log is a text
// column and therefore cannot have a default value. However, it might
// not be set at this point, so we ensure that it is at least an empty
// string in that case.
if (!isset($profile->log)) {
$profile->log = '';
}
}
elseif (empty($profile->log)) {
// If we are updating an existing profile without adding a new revision,
// we need to make sure $profile->log is unset whenever it is empty. As
// long as $profile->log is unset, drupal_write_record() will not attempt
// to update the existing database column when re-saving the revision.
unset($profile->log);
}
return parent::save($profile, $transaction);
} catch (Exception $e) {
if (!empty($started_transaction)) {
$transaction
->rollback();
watchdog_exception($this->entityType, $e);
}
throw $e;
}
}
/**
* Unserializes the data property of loaded customer profiles.
*/
public function attachLoad(&$queried_profiles, $revision_id = FALSE) {
foreach ($queried_profiles as $profile_id => &$profile) {
$profile->data = unserialize($profile->data);
}
// Call the default attachLoad() method. This will add fields and call
// hook_commerce_customer_profile_load().
parent::attachLoad($queried_profiles, $revision_id);
}
/**
* Deletes multiple customer profiles by ID.
*
* @param $profile_ids
* An array of customer profile IDs to delete.
* @param $transaction
* An optional transaction object.
* @param $entity_context
* An optional entity context array that specifies the entity throgh whose
* customer profile reference field the given profiles are being deleted:
* - entity_type: the type of entity
* - entity_id: the unique ID of the entity
*
* @return
* TRUE on success, FALSE otherwise.
*/
public function delete($profile_ids, DatabaseTransaction $transaction = NULL, $entity_context = array()) {
if (!empty($profile_ids)) {
$profiles = $this
->load($profile_ids, array());
$profile_ids_to_remove = array();
// Ensure the customer profiles can actually be deleted.
foreach ((array) $profiles as $profile_id => $profile) {
// If we received an entity context for this profile, add it now.
if (!empty($entity_context)) {
$profile->entity_context = $entity_context;
}
// If the profile cannot be deleted, remove it from the profiles array.
if (!commerce_customer_profile_can_delete($profile)) {
unset($profiles[$profile_id]);
$profile_ids_to_remove[] = $profile_id;
}
}
// If none of the specified profiles can be deleted, return FALSE.
if (empty($profiles)) {
return FALSE;
}
$profile_ids = array_diff($profile_ids, $profile_ids_to_remove);
parent::delete($profile_ids, $transaction);
return TRUE;
}
else {
return FALSE;
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CommerceCustomerProfileEntityController:: |
public | function |
Unserializes the data property of loaded customer profiles. Overrides DrupalDefaultEntityController:: |
|
CommerceCustomerProfileEntityController:: |
public | function |
Create a default customer profile. Overrides DrupalCommerceEntityController:: |
|
CommerceCustomerProfileEntityController:: |
public | function |
Deletes multiple customer profiles by ID. Overrides DrupalCommerceEntityController:: |
|
CommerceCustomerProfileEntityController:: |
public | function |
Saves a customer profile. 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 | 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. |