public function CommerceFileLicenseEntity::get_limits in Commerce File 7
Aggregated Limits
Return value
An array of aggregated limits for this license
4 calls to CommerceFileLicenseEntity::get_limits()
- CommerceFileLicenseEntity::get_duration in includes/
commerce_file_license.entity.inc - Duration
- CommerceFileLicenseEntity::get_limit_check_access in includes/
commerce_file_license.entity.inc - Returns check access for a given limit property
- CommerceFileLicenseEntity::get_limit_remaining_value in includes/
commerce_file_license.entity.inc - Returns remaining value for a given limit property
- CommerceFileLicenseEntity::is_unlimited in includes/
commerce_file_license.entity.inc - Returns true if all limits are unlimited
File
- includes/
commerce_file_license.entity.inc, line 616 - Provides a base class for CommerceFileLicenseEntity.
Class
- CommerceFileLicenseEntity
- A Commerce File License entity class.
Code
public function get_limits() {
if (!isset($this->limits)) {
$this->limits = array();
$native = $this
->get_file();
if (empty($native)) {
return $this->limits;
}
// get license wrapper
$wrapper = $this
->get_wrapper();
// initialize items and add native as trunk
$items = array(
$native,
);
$native_fid = $native['fid'];
// line item entity fields
$line_item_file_field_name = _commerce_file_get_field_names('line_item_files');
// license fields
$license_line_items_field_name = _commerce_file_get_field_names('license_line_items');
// process license line items
if (!empty($wrapper->{$license_line_items_field_name})) {
foreach ($wrapper->{$license_line_items_field_name} as $delta => $line_item_wrapper) {
// exit if no file fiel on line item
if (empty($line_item_wrapper->{$line_item_file_field_name})) {
continue;
}
// set qty and exit if there is no qty
$line_qty = $line_item_wrapper->quantity
->value();
if (empty($line_qty)) {
continue;
}
// aggregate files on the line item
$line_aggregated = _commerce_file_field_aggregate_files($line_item_wrapper
->value(), 'commerce_line_item');
// only add files for our license fid
if (isset($line_aggregated[$native_fid])) {
// multiply by quantity if setting is aggregated
foreach ($line_item_wrapper->{$line_item_file_field_name} as $file_field_wrapper) {
foreach ($file_field_wrapper->data as $k => $data) {
if (isset($line_aggregated[$native_fid]['data'][$k]) && !$this
->check_limit_is_unlimited($line_aggregated[$native_fid]['data'][$k])) {
$data_info = $data
->info();
if (!empty($data_info) && !empty($data_info['aggregated'])) {
$line_aggregated[$native_fid]['data'][$k] *= $line_qty;
}
}
}
}
// store in all items
$items[] = $line_aggregated[$native_fid];
}
}
}
// aggregated = native field + sum of all (line item fields X quantity)
$aggregated = call_user_func_array('_commerce_file_field_aggregate_field_items', $items);
// store in license
if (!empty($aggregated['data'])) {
$this->limits = $aggregated['data'];
}
}
return $this->limits;
}