class EntityLegalDocumentVersionController in Entity Legal 7
Same name and namespace in other branches
- 7.2 entity_legal.entity_controller.inc \EntityLegalDocumentVersionController
Legal document version exportable controller.
Hierarchy
- class \DrupalDefaultEntityController implements DrupalEntityControllerInterface
- class \EntityAPIController implements EntityAPIControllerRevisionableInterface
Expanded class hierarchy of EntityLegalDocumentVersionController
1 string reference to 'EntityLegalDocumentVersionController'
- entity_legal_entity_info in ./
entity_legal.module - Implements hook_entity_info().
File
- ./
entity_legal.entity_controller.inc, line 129 - Entity API controller classes for entity_legal module.
View source
class EntityLegalDocumentVersionController extends EntityAPIControllerExportable {
/**
* {@inheritdoc}
*/
public function create(array $values = array()) {
global $user;
if (empty($values['uid'])) {
$values['uid'] = $user->uid;
}
if (empty($values['created'])) {
$values['created'] = time();
}
return parent::create($values);
}
/**
* {@inheritdoc}
*/
public function save($entity, DatabaseTransaction $transaction = NULL) {
if (!empty($entity->is_new)) {
$entity->created = time();
$entity->updated = time();
}
return parent::save($entity, $transaction);
}
/**
* Get acceptances for the given version of this document.
*
* @param EntityLegalDocumentVersion $legal_document_entity_version
* The legal document entity to get the acceptances of.
* @param bool|object $account
* The account the acceptance belongs to, or all accounts if not set.
*
* @return array
* The acceptances associated with this legal document entity and account.
*/
public function getAcceptances(EntityLegalDocumentVersion $legal_document_entity_version, $account = FALSE) {
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', ENTITY_LEGAL_DOCUMENT_ACCEPTANCE_ENTITY_NAME)
->propertyCondition('document_version_name', $legal_document_entity_version->name);
if ($account) {
$query
->propertyCondition('uid', $account->uid);
}
$results = $query
->execute();
if (!empty($results)) {
$results = entity_load(ENTITY_LEGAL_DOCUMENT_ACCEPTANCE_ENTITY_NAME, array_keys($results[ENTITY_LEGAL_DOCUMENT_ACCEPTANCE_ENTITY_NAME]));
}
return $results;
}
}