public function LTIToolProviderMembershipsEntityController::save in LTI Tool Provider 7
Save a memberships entity.
Parameters
object $entity: The memberships entity to be saved.
Return value
object|boolean The saved memberships entity or FALSE.
Overrides LTIToolProviderMembershipsEntityControllerInterface::save
File
- lti_tool_provider_memberships/
LTIToolProviderMembershipsEntityController.class.php, line 47 - Contains LTIToolProviderMembershipsEntityController.
Class
- LTIToolProviderMembershipsEntityController
- Memberships Entity controller.
Code
public function save($entity) {
$transaction = db_transaction();
try {
$entity->is_new = empty($entity->lti_tool_provider_memberships_id);
if (!isset($entity->date_dropped)) {
$entity->date_updated = REQUEST_TIME;
}
field_attach_presave('lti_tool_provider_memberships', $entity);
$primary_key = $entity->lti_tool_provider_memberships_id ? 'lti_tool_provider_memberships_id' : array();
if (empty($primary_key)) {
drupal_write_record('lti_tool_provider_memberships', $entity);
field_attach_insert('lti_tool_provider_memberships', $entity);
$op = 'insert';
}
else {
drupal_write_record('lti_tool_provider_memberships', $entity, $primary_key);
$op = 'update';
}
$function = 'field_attach_' . $op;
$function('lti_tool_provider_memberships', $entity);
module_invoke_all('entity_' . $op, $entity, 'lti_tool_provider_memberships');
unset($entity->is_new);
db_ignore_slave();
return $entity;
} catch (Exception $e) {
$transaction
->rollback();
drupal_set_message(t('%e', array(
'%e' => $entity->{$e},
)));
watchdog_exception('lti_tool_provider_memberships', $e, NULL, WATCHDOG_ERROR);
return FALSE;
}
}