Lettersail: online English school for kids on MODX 3 (templates, chunks, snippets, plugins, scripts)
This commit is contained in:
commit
3799cf8de5
96 files changed
+4423
No files matched your search
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
$parent = (int) $modx->getOption('ls_leads');
|
||||
if ($parent <= 0) {
|
||||
$modx->log(MODX\Revolution\modX::LOG_LEVEL_ERROR, 'lsLeadSave: не задана настройка ls_leads');
|
||||
$hook->addError('save', $modx->lexicon('ls_err_save'));
|
||||
return false;
|
||||
}
|
||||
|
||||
$name = (string) $hook->getValue('name');
|
||||
$phone = (string) $hook->getValue('phone');
|
||||
$lines = [
|
||||
'Имя: ' . $name,
|
||||
'Телефон: ' . $phone,
|
||||
'Возраст ребёнка: ' . (string) $hook->getValue('age'),
|
||||
'Согласие на обработку данных: да',
|
||||
'Дата и время: ' . (string) $hook->getValue('sent_at'),
|
||||
'Редакция согласия: ' . (string) $hook->getValue('consent_version'),
|
||||
'Страница отправки: ' . (string) $hook->getValue('page'),
|
||||
];
|
||||
|
||||
$lead = $modx->newObject(MODX\Revolution\modDocument::class);
|
||||
$lead->fromArray([
|
||||
'context_key' => 'data',
|
||||
'parent' => $parent,
|
||||
'pagetitle' => $name . ', ' . $phone,
|
||||
'alias' => 'lead-' . date('YmdHis') . '-' . bin2hex(random_bytes(3)),
|
||||
'introtext' => (string) $hook->getValue('sent_at'),
|
||||
'content' => implode("\n", $lines),
|
||||
'published' => false,
|
||||
'hidemenu' => true,
|
||||
'searchable' => false,
|
||||
'richtext' => false,
|
||||
'template' => 0,
|
||||
]);
|
||||
if (!$lead->save()) {
|
||||
$modx->log(MODX\Revolution\modX::LOG_LEVEL_ERROR, 'lsLeadSave: заявка не сохранена');
|
||||
$hook->addError('save', $modx->lexicon('ls_err_save'));
|
||||
return false;
|
||||
}
|
||||
|
||||
$expired = $modx->getIterator(MODX\Revolution\modResource::class, [
|
||||
'context_key' => 'data',
|
||||
'parent' => $parent,
|
||||
'createdon:<' => strtotime('-12 months'),
|
||||
]);
|
||||
foreach ($expired as $old) {
|
||||
$old->remove();
|
||||
}
|
||||
|
||||
return true;
|
||||
Reference in new issue
Block a user