Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit 6ccd95a

Browse files
author
Jamie Snape
committed
Revise landingpage module configuration form and add install script
1 parent 1e7f746 commit 6ccd95a

File tree

12 files changed

+223
-190
lines changed

12 files changed

+223
-190
lines changed
Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1+
; MIDAS Server. Copyright Kitware SAS. Licensed under the Apache License 2.0.
2+
13
[global]
2-
; version of the module
3-
version = 1.0.0
4-
; full name
5-
fullname = Landing Page
6-
; description
7-
description = Module for adding a custom landing page to the Midas instance
8-
; category
9-
category = Core
10-
; dependencies
11-
dependencies =
4+
fullname = "Landing Page"
5+
description = "Display a custom landing page"
6+
category = "Core"
7+
uuid = "00c52901-4892-41a3-9e24-dd9fa56ad1f8"
8+
version = "1.0.0"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
/*=========================================================================
3+
MIDAS Server
4+
Copyright (c) Kitware SAS. 26 rue Louis Guérin. 69100 Villeurbanne, FRANCE
5+
All rights reserved.
6+
More information http://www.kitware.com
7+
8+
Licensed under the Apache License, Version 2.0 (the "License");
9+
you may not use this file except in compliance with the License.
10+
You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0.txt
13+
14+
Unless required by applicable law or agreed to in writing, software
15+
distributed under the License is distributed on an "AS IS" BASIS,
16+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
See the License for the specific language governing permissions and
18+
limitations under the License.
19+
=========================================================================*/
20+
21+
define('LANDINGPAGE_TEXT_KEY', 'text');
22+
define('LANDINGPAGE_TEXT_DEFAULT_VALUE', 'Welcome to __Midas Platform__.');
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?php
2+
/*=========================================================================
3+
MIDAS Server
4+
Copyright (c) Kitware SAS. 26 rue Louis Guérin. 69100 Villeurbanne, FRANCE
5+
All rights reserved.
6+
More information http://www.kitware.com
7+
8+
Licensed under the Apache License, Version 2.0 (the "License");
9+
you may not use this file except in compliance with the License.
10+
You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0.txt
13+
14+
Unless required by applicable law or agreed to in writing, software
15+
distributed under the License is distributed on an "AS IS" BASIS,
16+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
See the License for the specific language governing permissions and
18+
limitations under the License.
19+
=========================================================================*/
20+
21+
/**
22+
* Admin controller for the landingpage module.
23+
*
24+
* @property Landingpage_TextModel $Landingpage_Text
25+
*/
26+
class Landingpage_AdminController extends Landingpage_AppController
27+
{
28+
/** @var array */
29+
public $_models = array('Setting');
30+
31+
/** @var array */
32+
public $_moduleDaos = array('Text');
33+
34+
/** @var array */
35+
public $_moduleModels = array('Text');
36+
37+
/** Index action */
38+
public function indexAction()
39+
{
40+
$this->requireAdminPrivileges();
41+
42+
$this->view->pageTitle = 'Landing Page Module Configuration';
43+
$form = new Landingpage_Form_Admin();
44+
$textDaos = $this->Landingpage_Text->getAll();
45+
46+
if ($this->getRequest()->isPost()) {
47+
$data = $this->getRequest()->getPost();
48+
49+
if ($form->isValid($data)) {
50+
$values = $form->getValues();
51+
52+
if (count($textDaos) > 0) {
53+
$textDao = $textDaos[0];
54+
} else {
55+
/** @var Landingpage_TextDao $textDao */
56+
$textDao = MidasLoader::newDao('Text', $this->moduleName);
57+
}
58+
59+
$textDao->setText($values[LANDINGPAGE_TEXT_KEY]);
60+
$this->Landingpage_Text->save($textDao);
61+
unset($values[LANDINGPAGE_TEXT_KEY]);
62+
63+
foreach ($values as $key => $value) {
64+
$this->Setting->setConfig($key, $value, $this->moduleName);
65+
}
66+
}
67+
68+
$form->populate($data);
69+
} else {
70+
$elements = $form->getElements();
71+
72+
foreach ($elements as $element) {
73+
$name = $element->getName();
74+
75+
if ($name === LANDINGPAGE_TEXT_KEY) {
76+
if (count($textDaos) > 0) {
77+
$value = $textDaos[0]->getText();
78+
$form->setDefault($name, $value);
79+
}
80+
} elseif ($name !== 'csrf' && $name !== 'submit') {
81+
$value = $this->Setting->getValueByName($name, $this->moduleName);
82+
83+
if (!is_null($value)) {
84+
$form->setDefault($name, $value);
85+
}
86+
}
87+
}
88+
}
89+
90+
$this->view->form = $form;
91+
session_start();
92+
}
93+
}

modules/landingpage/controllers/ConfigController.php

Lines changed: 0 additions & 61 deletions
This file was deleted.

modules/landingpage/controllers/forms/ConfigForm.php renamed to modules/landingpage/database/InstallScript.php

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,19 @@
1818
limitations under the License.
1919
=========================================================================*/
2020

21-
/** Landingpage module config form */
22-
class Landingpage_ConfigForm extends AppForm
23-
{
24-
/** main config form */
25-
public function createForm()
26-
{
27-
$form = new Zend_Form();
28-
29-
$form->setAction("")->setMethod('post');
30-
31-
$name = new Zend_Form_Element_Textarea('text');
32-
$name->setRequired(true)->setAttrib('cols', '120')->setAttrib('rows', '100')->setValue(
33-
'Add some text or _Markdown_ here'
34-
);
21+
require_once BASE_PATH.'/modules/landingpage/constant/module.php';
3522

36-
$submit = new Zend_Form_Element_Submit('submit');
37-
$submit->setLabel('Edit');
38-
39-
$form->addElements(array($name, $submit));
23+
/** Install the landingpage module. */
24+
class Landingpage_InstallScript extends MIDASModuleInstallScript
25+
{
26+
/** @var string */
27+
public $moduleName = 'landingpage';
4028

41-
return $form;
29+
/** Post database install. */
30+
public function postInstall()
31+
{
32+
/** @var SettingModel $settingModel */
33+
$settingModel = MidasLoader::loadModel('Setting');
34+
$settingModel->setConfig(LANDINGPAGE_TEXT_KEY, LANDINGPAGE_TEXT_DEFAULT_VALUE, $this->moduleName);
4235
}
4336
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
/*=========================================================================
3+
MIDAS Server
4+
Copyright (c) Kitware SAS. 26 rue Louis Guérin. 69100 Villeurbanne, FRANCE
5+
All rights reserved.
6+
More information http://www.kitware.com
7+
8+
Licensed under the Apache License, Version 2.0 (the "License");
9+
you may not use this file except in compliance with the License.
10+
You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0.txt
13+
14+
Unless required by applicable law or agreed to in writing, software
15+
distributed under the License is distributed on an "AS IS" BASIS,
16+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
See the License for the specific language governing permissions and
18+
limitations under the License.
19+
=========================================================================*/
20+
21+
/** Admin form for the landingpage module. */
22+
class Landingpage_Form_Admin extends Zend_Form
23+
{
24+
/** Initialize this form. */
25+
public function init()
26+
{
27+
$this->setName('landingpage_admin');
28+
$this->setMethod('POST');
29+
30+
$csrf = new Midas_Form_Element_Hash('csrf');
31+
$csrf->setSalt('kUjBumZdEykrY8JHB88uzZjv');
32+
$csrf->setDecorators(array('ViewHelper'));
33+
34+
$text = new Zend_Form_Element_Textarea(LANDINGPAGE_TEXT_KEY);
35+
$text->setLabel('Landing Page Text');
36+
$text->setRequired(true);
37+
$text->addValidator('NotEmpty', true);
38+
$text->setAttrib('cols', '120');
39+
$text->setAttrib('rows', '100');
40+
41+
$this->addDisplayGroup(array($text), 'global');
42+
43+
$submit = new Zend_Form_Element_Submit('submit');
44+
$submit->setLabel('Save');
45+
46+
$this->addElements(array($csrf, $text, $submit));
47+
}
48+
}

modules/landingpage/models/dao/TextDao.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,20 @@
1818
limitations under the License.
1919
=========================================================================*/
2020

21-
/** Landingpage text dao */
21+
/**
22+
* Text DAO for the landingpage module.
23+
*
24+
* @method int getLandingpageId()
25+
* @method void setLandingpageId(int $landingpageId)
26+
* @method string getText()
27+
* @method void setText(string $text)
28+
* @package Modules\Landingpage\DAO
29+
*/
2230
class Landingpage_TextDao extends AppDao
2331
{
32+
/** @var string */
2433
public $_model = 'Text';
34+
35+
/** @var string */
2536
public $_module = 'landingpage';
2637
}

modules/landingpage/public/css/config/config.index.css

Lines changed: 0 additions & 1 deletion
This file was deleted.

modules/landingpage/public/js/config/config.index.js

Lines changed: 0 additions & 39 deletions
This file was deleted.

modules/landingpage/public/scss/config/config.index.scss

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)