Commit dba52027 authored by m.stenta's avatar m.stenta
Browse files

Issue #2393477: New property: Timestamp

parent 0dc86dd8
......@@ -36,6 +36,7 @@ class LogController extends EntityAPIController {
'name' => '',
'type' => '',
'uid' => $user->uid,
'timestamp' => REQUEST_TIME,
'created' => REQUEST_TIME,
'changed' => REQUEST_TIME,
);
......
......@@ -2,6 +2,7 @@ name = "Log"
description = "A general purpose record keeping system."
core = 7.x
package = "Log"
dependencies[] = date_api
dependencies[] = entity
configure = admin/config/log
files[] = log.class.inc
\ No newline at end of file
......@@ -37,6 +37,10 @@ function log_schema() {
'not null' => TRUE,
'default' => 0,
),
'timestamp' => array(
'description' => 'Timestamp of the event being logged',
'type' => 'int',
),
'created' => array(
'description' => 'Timestamp when the log was created',
'type' => 'int',
......@@ -55,6 +59,7 @@ function log_schema() {
'name' => array('name'),
'type' => array('type'),
'uid' => array('uid'),
'timestamp' => array('timestamp'),
'created' => array('created'),
'modified' => array('changed'),
),
......@@ -141,4 +146,18 @@ function log_update_7000(&$sandbox) {
'default' => 0,
);
db_add_field('log_type', 'name_edit', $spec);
}
/**
* Add 'timestamp' field to Logs.
*/
function log_update_7001(&$sandbox) {
// Add timestamp field to Logs.
$timestamp = array(
'description' => 'Timestamp of the event being logged',
'type' => 'int',
);
db_add_field('log', 'timestamp', $timestamp);
db_add_index('log', 'timestamp', array('timestamp'));
}
\ No newline at end of file
......@@ -268,6 +268,15 @@ function log_entity_property_info_alter(&$info) {
'required' => TRUE,
'schema field' => 'uid',
);
$properties['timestamp'] = array(
'label' => t('Timestamp'),
'type' => 'date',
'description' => t('The timestamp of the event being logged.'),
'setter callback' => 'entity_property_verbatim_set',
'setter permission' => 'administer log module',
'required' => TRUE,
'schema field' => 'timestamp',
);
$properties['created'] = array(
'label' => t('Created'),
'type' => 'date',
......@@ -306,6 +315,13 @@ function log_field_extra_fields() {
'weight' => -10,
);
}
// Display the timestamp field.
$extra_fields['log'][$type->type]['form']['timestamp'] = array(
'label' => t('Timestamp'),
'description' => t('The timestamp of the log entry.'),
'weight' => -5,
);
}
return $extra_fields;
}
......
......@@ -9,8 +9,22 @@
* Log view callback.
*/
function log_view($log) {
// Set the title of the page to the log's label.
drupal_set_title(entity_label('log', $log));
return entity_view('log', array(entity_id('log', $log) => $log), 'full');
// Build the log entity render array.
$output = entity_view('log', array(entity_id('log', $log) => $log), 'full');
// Add the log's timestamp to the render array.
if (!empty($log->timestamp)) {
$date = date('M j Y', $log->timestamp);
$output['log'][$log->id]['timestamp'] = array(
'#markup' => '<strong>Date:</strong> ' . $date,
'#weight' => -100,
);
}
return $output;
}
/**
......@@ -66,10 +80,21 @@ function log_form($form, &$form_state, $log) {
'#title' => t('Name'),
'#description' => t('Leave this blank to automatically generate a name.'),
'#default_value' => $log->name,
'#weight' => -100,
);
}
// Timestamp
$timestamp_default = !empty($log->timestamp) ? date('Y-m-d H:i:s', $log->timestamp) : '';
$form['timestamp'] = array(
'#type' => 'date_select',
'#title' => t('Date'),
'#date_format' => 'M j Y',
'#date_type' => DATE_FORMAT_UNIX,
'#date_year_range' => '-10:+3',
'#default_value' => $timestamp_default,
'#required' => TRUE,
);
$form['uid'] = array(
'#type' => 'value',
'#value' => $log->uid,
......@@ -122,16 +147,24 @@ function log_form_validate($form, &$form_state) {
* Log submit handler.
*/
function log_form_submit($form, &$form_state) {
// Load the log entity from the form values.
$log = $form_state['values']['log'];
// Convert the date to a timestamp.
$form_state['values']['timestamp'] = strtotime($form_state['values']['timestamp']);
// Build the entity from the form values.
entity_form_submit_build_entity('log', $log, $form, $form_state);
// Save the log.
log_save($log);
// Redirect to the log.
$log_uri = entity_uri('log', $log);
$form_state['redirect'] = $log_uri['path'];
// Print a message.
drupal_set_message(t('%title saved.', array('%title' => entity_label('log', $log))));
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment