-
-
Save Sentinel-7/ff49da91993d37d99852e31424c765a6 to your computer and use it in GitHub Desktop.
Add groups & fields for MODx ClientConfig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//СОЗДАНИЕ ИЛИ ОБНОВЛЕНИЕ ГРУПП | |
$groups = array( | |
array('id' => 1,'sortorder' => 1,'label' => 'Общие'), | |
array('id' => 2,'sortorder' => 2,'label' => 'Почта'), | |
array('id' => 3,'sortorder' => 3,'label' => 'Политика и куки'), | |
array('id' => 4,'sortorder' => 4,'label' => 'Социальные сети'), | |
); | |
foreach ($groups as $group) | |
{ | |
$check_isset_group = $modx->getObject('cgGroup', array($group['id'])); | |
if (!$check_isset_group) | |
{ | |
$new_group = $modx->newObject('cgGroup'); | |
foreach ($group as $key=>$value) | |
{ | |
$new_group->set($key,$value); | |
} | |
if ($new_group->save()) | |
{ | |
echo "<p>Группа {$group['label']} успешно <strong>создана</strong></p>"; | |
} else { | |
echo "<p>Группу {$group['label']} <strong>создать не удалось</strong></p>"; | |
}; | |
} else { | |
foreach ($group as $key=>$value) | |
{ | |
$check_isset_group->set($key,$value); | |
} | |
if ($check_isset_group->save()) | |
{ | |
echo "<p>Группа {$group['label']} успешно <strong>обновлена</strong></p>"; | |
} else { | |
echo "<p>Группу {$group['label']} <strong>обновить не удалось</strong></p>"; | |
}; | |
} | |
} | |
echo '<hr>'; | |
//СОЗДАНИЕ ИЛИ ОБНОВЛЕНИЕ ПОЛЕЙ | |
/* | |
xtype - textfield / textarea / xcheckbox | |
group - 1- Основные / 2 - Почта / 3 - Политика | |
*/ | |
$client_config_fields = array( | |
array( | |
'key' => 'emailsender', | |
'label' => 'E-mail администратора', | |
'description' => 'Указывать только один адрес! Используется как почта отправителя.', | |
'xtype' => 'textfield', | |
'sortorder' => 10, | |
'value' => 'info@'.$modx->getOption('http_host'), | |
'source' => 0, | |
'group' => 2 | |
), | |
array( | |
'key' => 'main_address', | |
'label' => 'Основной адрес', | |
'description' => 'Используется в шапке', | |
'xtype' => 'textfield', | |
'sortorder' => 10, | |
'value' => '', | |
'source' => 0, | |
'group' => 1 | |
), | |
array( | |
'key' => 'main_phone', | |
'label' => 'Основной телефон', | |
'description' => 'Используется в шапке', | |
'xtype' => 'textfield', | |
'sortorder' => 10, | |
'value' => '8 (8452) 39-84-41', | |
'source' => 0, | |
'group' => 1 | |
), | |
array( | |
'key' => 'insta', | |
'label' => 'Инстаграмм', | |
'description' => '', | |
'xtype' => 'textfield', | |
'sortorder' => 10, | |
'value' => '#1234', | |
'source' => 0, | |
'group' => 4 | |
), | |
); | |
foreach ($client_config_fields as $field) | |
{ | |
$check_isset_field = $modx->getObject('cgSetting', array('key'=>$field['key'])); | |
if (!$check_isset_field) { | |
$new_field = $modx->newObject('cgSetting'); | |
foreach ($field as $key=>$value) | |
{ | |
$new_field->set($key,$value); | |
} | |
if ($new_field->save()) | |
{ | |
echo "<p>Поле {$field['key']} успешно <strong>создано</strong></p>"; | |
} else { | |
echo "<p>Поле {$field['key']} <strong>создать не удалось</strong></p>"; | |
}; | |
} else { | |
foreach ($field as $key=>$value) | |
{ | |
$check_isset_field->set($key,$value); | |
} | |
if ($check_isset_field->save()) | |
{ | |
echo "<p>Поле {$field['key']} успешно <strong>обновлено</strong></p>"; | |
} else { | |
echo "<p>Поле {$field['key']} <strong>обновить не удалось</strong></p>"; | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment