You are here

public function LTIToolProviderOutcomesEntityController::save in LTI Tool Provider 7

Overrides LTIToolProviderOutcomesEntityControllerInterface::save

See also

LTIToolProviderOutcomesEntityControllerInterface::save

File

lti_tool_provider_outcomes/LTIToolProviderOutcomesEntityController.class.php, line 54
Entity controller class for outcomes.

Class

LTIToolProviderOutcomesEntityController

Code

public function save($entity) {
  $transaction = db_transaction();
  try {
    $entity->is_new = empty($enity->lti_tool_provider_outcomes_id);
    if (empty($entity->lti_tool_provider_outcomes_date_joined)) {
      $entity->lti_tool_provider_outcomes_date_joined = REQUEST_TIME;
    }
    field_attach_presave('lti_tool_provider_outcomes', $entity);
    $primary_key = $entity->lti_tool_provider_outcomes_id ? 'lti_tool_provider_outcomes_id' : array();
    if (empty($primary_key)) {
      drupal_write_record('lti_tool_provider_outcomes', $entity);
      field_attach_insert('lti_tool_provider_outcomes', $entity);
      $op = 'insert';
    }
    else {
      drupal_write_record('lti_tool_provider_outcomes', $entity, $primary_key);
      $op = 'update';
    }
    $function = 'field_attach_' . $op;
    $function('lti_tool_provider_outcomes', $entity);
    module_invoke_all('entity_' . $op, $entity, 'lti_tool_provider_outcomes');
    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_outcomes', $e, NULL, WATCHDOG_ERROR);
    return FALSE;
  }
}