-
☆ A M B ☆
- 24,524 Posts
How would one go about inserting the current timestamp into a setting (system, context, group, user, etc) so that, for example, [[++created_time]] would produce the timestamp when that setting was created?
Try this:
$setting = $modx->getObject('modSystemSetting', array('key' => 'SettingKey'));
$setting->set('value', time());
If it's a date setting, it will be converted to human-readable form when retrieved, but usually not in the format you want. I would be inclined to make it an integer or text field and use the :strftime output modifier in the setting tag. If it's a date field, you need to do :strtotime:strftime, which is kind of ridiculous.
-
☆ A M B ☆
- 24,524 Posts
I know how to do it in code. I was referring to using the user management GUI. I know for element properties and Media Sources you can use MODX tags, and there are some variables you can use in settings, like {base_url}, I was just wondering if anyone knew of something like that to get a current timestamp, or even the current date.
That's a tough one. Tags in settings are interpreted on the way out, not on the way in (if at all), so even if you could do it, you'd be getting the time the setting was retrieved. There are no events fired when saving a setting.
The only way I can think of would be a plugin attached to OnUserFormSave, using a version of the code above. Something like this:
$settingKey = 'MySetting';
$setting = $modx->getObject('modSystemSetting', array('key' => $settingKey));
if (!$setting) {
$setting = $modx->newObject('modSystemSetting');
$setting->set('key', $settingKey);
$setting->set('value', time());
$setting->save();
} else {
if (empty($setting->get($value)) {
$setting->set('value', time());
setting->save();
}
}
return '';