1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
<?php
namespace hji\construction\admin\controllers;
use hji\common\utils\GFHelper;
use hji\construction\App;
use hji\construction\core\Controller;
use hji\construction\models\Settings;
class GeneralPageController extends Controller
{
protected $settings;
public function __construct(Settings $settings)
{
$this->settings = $settings;
}
public function setActionHooks()
{
}
public function renderPage()
{
$request = $this->services()->getRequest();
$importNonce = $request->get('import_nonce');
if ($importNonce && wp_verify_nonce($importNonce, 'nc_import_forms'))
{
if ($request->get('delete_existing_forms') == 1)
{
$this->settings->deleteDefaultForms();
add_settings_error($this->settings->getSettingsKey(), 'general', 'Existing New Construction forms have been deleted.', 'updated');
}
$result = $this->settings->installDefaultForms();
if (is_wp_error($result))
{
add_settings_error($this->settings->getSettingsKey(), 'general', $result->get_error_message());
}
else
{
add_settings_error($this->settings->getSettingsKey(), 'general', 'New Construction Gravity Forms successfully installed.', 'updated');
}
}
$view = $this->services()->getView();
$pageModel = new \stdClass();
$pageModel->class = 'hji-nc-admin';
$pageModel->title = __('New Construction Settings', App::$textdomain);
$data['page'] = $pageModel;
$data['settings'] = $this->settings;
$data['gravityFormsPluginExists'] = GFHelper::gravityFormsExists();
$forms = ($data['gravityFormsPluginExists']) ? GFHelper::getFormsListByKey('new_construction') : null;
$data['existingForms'] = $forms;
$data['existingFormIDs'] = (!empty($forms)) ? implode(',', $forms) : null;
$forms = ($data['gravityFormsPluginExists']) ? GFHelper::getFormsByKey('new_construction:community_inquiry') : null;
$data['communityFormId'] = (isset($forms[0])) ? $forms[0] : null;
$forms = ($data['gravityFormsPluginExists']) ? GFHelper::getFormsByKey('new_construction:property_inquiry') : null;
$data['propertyFormId'] = (isset($forms[0])) ? $forms[0] : null;
echo $view->render('admin-general-page.twig', $data);
}
}