Skip to content

Commit 7f7892a

Browse files
committed
rebase to Skeleton 1.0.8
1 parent 4c7eb2b commit 7f7892a

File tree

11 files changed

+183
-314
lines changed

11 files changed

+183
-314
lines changed

config/module.config.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,48 @@
5252
],
5353
],
5454
],
55+
'project-export' => [
56+
'type' => Segment::class,
57+
'options' => [
58+
'route' => '/project/export[/:action[/:id]]',
59+
'constraints' => [
60+
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
61+
'id' => '[0-9]+',
62+
],
63+
'defaults' => [
64+
'controller' => Controller\ExportController::class,
65+
'action' => 'index',
66+
],
67+
],
68+
],
69+
'project-search' => [
70+
'type' => Segment::class,
71+
'options' => [
72+
'route' => '/project/search[/:action[/:id]]',
73+
'constraints' => [
74+
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
75+
'id' => '[0-9]+',
76+
],
77+
'defaults' => [
78+
'controller' => Controller\SearchController::class,
79+
'action' => 'index',
80+
],
81+
],
82+
],
83+
'project-plugin' => [
84+
'type' => Segment::class,
85+
'options' => [
86+
'route' => '/project/plugin[/:action[/:id]]',
87+
'constraints' => [
88+
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
89+
'id' => '[0-9]+',
90+
],
91+
'defaults' => [
92+
'controller' => Controller\PluginController::class,
93+
'action' => 'index',
94+
],
95+
],
96+
],
5597
],
5698
],
5799

data/install.sql

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ INSERT INTO `permission` (`permission_key`, `module`, `label`, `nav_label`, `nav
2424
('edit', 'OnePlace\\Project\\Controller\\ProjectController', 'Edit', '', '', 0),
2525
('index', 'OnePlace\\Project\\Controller\\ProjectController', 'Index', 'Projects', '/project', 1),
2626
('list', 'OnePlace\\Project\\Controller\\ApiController', 'List', '', '', 1),
27-
('view', 'OnePlace\\Project\\Controller\\ProjectController', 'View', '', '', 0);
27+
('view', 'OnePlace\\Project\\Controller\\ProjectController', 'View', '', '', 0),
28+
('dump', 'OnePlace\\Project\\Controller\\ExportController', 'Excel Dump', '', '', 0),
29+
('index', 'OnePlace\\Project\\Controller\\SearchController', 'Search', '', '', 0);
2830

2931
--
3032
-- Form
@@ -49,12 +51,16 @@ INSERT INTO `core_form_tab` (`Tab_ID`, `form`, `title`, `subtitle`, `icon`, `cou
4951
INSERT INTO `core_form_button` (`Button_ID`, `label`, `icon`, `title`, `href`, `class`, `append`, `form`, `mode`, `filter_check`, `filter_value`) VALUES
5052
(NULL, 'Save Project', 'fas fa-save', 'Save Project', '#', 'primary saveForm', '', 'project-single', 'link', '', ''),
5153
(NULL, 'Edit Project', 'fas fa-edit', 'Edit Project', '/project/edit/##ID##', 'primary', '', 'project-view', 'link', '', ''),
52-
(NULL, 'Add Project', 'fas fa-plus', 'Add Project', '/project/add', 'primary', '', 'project-index', 'link', '', '');
54+
(NULL, 'Add Project', 'fas fa-plus', 'Add Project', '/project/add', 'primary', '', 'project-index', 'link', '', ''),
55+
(NULL, 'Export Projects', 'fas fa-file-excel', 'Export Projects', '/project/export', 'primary', '', 'project-index', 'link', '', ''),
56+
(NULL, 'Find Projects', 'fas fa-searh', 'Find Projects', '/project/search', 'primary', '', 'project-index', 'link', '', ''),
57+
(NULL, 'Export Projects', 'fas fa-file-excel', 'Export Projects', '#', 'primary initExcelDump', '', 'project-search', 'link', '', ''),
58+
(NULL, 'New Search', 'fas fa-searh', 'New Search', '/project/search', 'primary', '', 'project-search', 'link', '', '');
5359

5460
--
5561
-- Fields
5662
--
57-
INSERT INTO `core_form_field` (`Field_ID`, `type`, `label`, `fieldkey`, `tab`, `form`, `class`, `url_view`, `url_ist`, `show_widget_left`, `allow_clear`, `readonly`, `tbl_cached_name`, `tbl_class`, `tbl_permission`) VALUES
63+
INSERT INTO `core_form_field` (`Field_ID`, `type`, `label`, `fieldkey`, `tab`, `form`, `class`, `url_view`, `url_list`, `show_widget_left`, `allow_clear`, `readonly`, `tbl_cached_name`, `tbl_class`, `tbl_permission`) VALUES
5864
(NULL, 'text', 'Name', 'label', 'project-base', 'project-single', 'col-md-3', '/project/view/##ID##', '', 0, 1, 0, '', '', '');
5965

6066
--
@@ -64,4 +70,12 @@ INSERT INTO `core_widget` (`Widget_ID`, `widget_name`, `label`, `permission`) VA
6470
(NULL, 'project_dailystats', 'Project - Daily Stats', 'index-Project\\Controller\\ProjectController'),
6571
(NULL, 'project_taginfo', 'Project - Tag Info', 'index-Project\\Controller\\ProjectController');
6672

73+
--
74+
-- User XP Activity
75+
--
76+
INSERT INTO `user_xp_activity` (`Activity_ID`, `xp_key`, `label`, `xp_base`) VALUES
77+
(NULL, 'project-add', 'Add New Project', '50'),
78+
(NULL, 'project-edit', 'Edit Project', '5'),
79+
(NULL, 'project-export', 'Edit Project', '5');
80+
6781
COMMIT;

src/Controller/ApiController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Main Controller for Project Api
66
*
77
* @category Controller
8-
* @package Application
8+
* @package Project
99
* @author Verein onePlace
1010
* @copyright (C) 2020 Verein onePlace <admin@1plc.ch>
1111
* @license https://opensource.org/licenses/BSD-3-Clause

src/Controller/ProjectController.php

Lines changed: 37 additions & 195 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,20 @@
1717

1818
namespace OnePlace\Project\Controller;
1919

20-
use Application\Controller\CoreController;
20+
use Application\Controller\CoreEntityController;
2121
use Application\Model\CoreEntityModel;
2222
use OnePlace\Project\Model\Project;
2323
use OnePlace\Project\Model\ProjectTable;
2424
use Laminas\View\Model\ViewModel;
2525
use Laminas\Db\Adapter\AdapterInterface;
2626

27-
class ProjectController extends CoreController {
27+
class ProjectController extends CoreEntityController {
2828
/**
2929
* Project Table Object
3030
*
3131
* @since 1.0.0
3232
*/
33-
private $oTableGateway;
33+
protected $oTableGateway;
3434

3535
/**
3636
* ProjectController constructor.
@@ -59,36 +59,10 @@ public function __construct(AdapterInterface $oDbAdapter,ProjectTable $oTableGat
5959
* @return ViewModel - View Object with Data from Controller
6060
*/
6161
public function indexAction() {
62-
# Set Layout based on users theme
63-
$this->setThemeBasedLayout('project');
6462

65-
# Check license
66-
if(!$this->checkLicense('project')) {
67-
$this->flashMessenger()->addErrorMessage('You have no active license for project');
68-
$this->redirect()->toRoute('home');
69-
}
70-
71-
# Add Buttons for breadcrumb
72-
$this->setViewButtons('project-index');
73-
74-
# Set Table Rows for Index
75-
$this->setIndexColumns('project-index');
76-
77-
# Get Paginator
78-
$oPaginator = $this->oTableGateway->fetchAll(true);
79-
$iPage = (int) $this->params()->fromQuery('page', 1);
80-
$iPage = ($iPage < 1) ? 1 : $iPage;
81-
$oPaginator->setCurrentPageNumber($iPage);
82-
$oPaginator->setItemCountPerPage(3);
83-
84-
# Log Performance in DB
85-
$aMeasureEnd = getrusage();
86-
$this->logPerfomance('project-index',$this->rutime($aMeasureEnd,CoreController::$aPerfomanceLogStart,"utime"),$this->rutime($aMeasureEnd,CoreController::$aPerfomanceLogStart,"stime"));
87-
88-
return new ViewModel([
89-
'sTableName'=>'project-index',
90-
'aItems'=>$oPaginator,
91-
]);
63+
# You can just use the default function and customize it via hooks
64+
# or replace the entire function if you need more customization
65+
return $this->generateIndexView('project');
9266
}
9367

9468
/**
@@ -98,57 +72,17 @@ public function indexAction() {
9872
* @return ViewModel - View Object with Data from Controller
9973
*/
10074
public function addAction() {
101-
# Set Layout based on users theme
102-
$this->setThemeBasedLayout('project');
103-
104-
# Check license
105-
if(!$this->checkLicense('project')) {
106-
$this->flashMessenger()->addErrorMessage('You have no active license for project');
107-
$this->redirect()->toRoute('home');
108-
}
109-
110-
# Get Request to decide wether to save or display form
111-
$oRequest = $this->getRequest();
112-
113-
# Display Add Form
114-
if(!$oRequest->isPost()) {
115-
# Add Buttons for breadcrumb
116-
$this->setViewButtons('project-single');
117-
118-
# Load Tabs for View Form
119-
$this->setViewTabs($this->sSingleForm);
120-
121-
# Load Fields for View Form
122-
$this->setFormFields($this->sSingleForm);
123-
124-
# Log Performance in DB
125-
$aMeasureEnd = getrusage();
126-
$this->logPerfomance('project-add',$this->rutime($aMeasureEnd,CoreController::$aPerfomanceLogStart,"utime"),$this->rutime($aMeasureEnd,CoreController::$aPerfomanceLogStart,"stime"));
127-
128-
return new ViewModel([
129-
'sFormName' => $this->sSingleForm,
130-
]);
131-
}
132-
133-
# Get and validate Form Data
134-
$aFormData = $this->parseFormData($_REQUEST);
135-
136-
# Save Add Form
137-
$oProject = new Project($this->oDbAdapter);
138-
$oProject->exchangeArray($aFormData);
139-
$iProjectID = $this->oTableGateway->saveSingle($oProject);
140-
$oProject = $this->oTableGateway->getSingle($iProjectID);
141-
142-
# Save Multiselect
143-
$this->updateMultiSelectFields($_REQUEST,$oProject,'project-single');
144-
145-
# Log Performance in DB
146-
$aMeasureEnd = getrusage();
147-
$this->logPerfomance('project-save',$this->rutime($aMeasureEnd,CoreController::$aPerfomanceLogStart,"utime"),$this->rutime($aMeasureEnd,CoreController::$aPerfomanceLogStart,"stime"));
148-
149-
# Display Success Message and View New Project
150-
$this->flashMessenger()->addSuccessMessage('Project successfully created');
151-
return $this->redirect()->toRoute('project',['action'=>'view','id'=>$iProjectID]);
75+
/**
76+
* You can just use the default function and customize it via hooks
77+
* or replace the entire function if you need more customization
78+
*
79+
* Hooks available:
80+
*
81+
* project-add-before (before show add form)
82+
* project-add-before-save (before save)
83+
* project-add-after-save (after save)
84+
*/
85+
return $this->generateAddView('project');
15286
}
15387

15488
/**
@@ -158,78 +92,17 @@ public function addAction() {
15892
* @return ViewModel - View Object with Data from Controller
15993
*/
16094
public function editAction() {
161-
# Set Layout based on users theme
162-
$this->setThemeBasedLayout('project');
163-
164-
# Check license
165-
if(!$this->checkLicense('project')) {
166-
$this->flashMessenger()->addErrorMessage('You have no active license for project');
167-
$this->redirect()->toRoute('home');
168-
}
169-
170-
# Get Request to decide wether to save or display form
171-
$oRequest = $this->getRequest();
172-
173-
# Display Edit Form
174-
if(!$oRequest->isPost()) {
175-
176-
# Get Project ID from URL
177-
$iProjectID = $this->params()->fromRoute('id', 0);
178-
179-
# Try to get Project
180-
try {
181-
$oProject = $this->oTableGateway->getSingle($iProjectID);
182-
} catch (\RuntimeException $e) {
183-
echo 'Project Not found';
184-
return false;
185-
}
186-
187-
# Attach Project Entity to Layout
188-
$this->setViewEntity($oProject);
189-
190-
# Add Buttons for breadcrumb
191-
$this->setViewButtons('project-single');
192-
193-
# Load Tabs for View Form
194-
$this->setViewTabs($this->sSingleForm);
195-
196-
# Load Fields for View Form
197-
$this->setFormFields($this->sSingleForm);
198-
199-
# Log Performance in DB
200-
$aMeasureEnd = getrusage();
201-
$this->logPerfomance('project-edit',$this->rutime($aMeasureEnd,CoreController::$aPerfomanceLogStart,"utime"),$this->rutime($aMeasureEnd,CoreController::$aPerfomanceLogStart,"stime"));
202-
203-
return new ViewModel([
204-
'sFormName' => $this->sSingleForm,
205-
'oProject' => $oProject,
206-
]);
207-
}
208-
209-
$iProjectID = $oRequest->getPost('Item_ID');
210-
$oProject = $this->oTableGateway->getSingle($iProjectID);
211-
212-
# Update Project with Form Data
213-
$oProject = $this->attachFormData($_REQUEST,$oProject);
214-
215-
# Save Project
216-
$iProjectID = $this->oTableGateway->saveSingle($oProject);
217-
218-
$this->layout('layout/json');
219-
220-
# Parse Form Data
221-
$aFormData = $this->parseFormData($_REQUEST);
222-
223-
# Save Multiselect
224-
$this->updateMultiSelectFields($aFormData,$oProject,'project-single');
225-
226-
# Log Performance in DB
227-
$aMeasureEnd = getrusage();
228-
$this->logPerfomance('project-save',$this->rutime($aMeasureEnd,CoreController::$aPerfomanceLogStart,"utime"),$this->rutime($aMeasureEnd,CoreController::$aPerfomanceLogStart,"stime"));
229-
230-
# Display Success Message and View New User
231-
$this->flashMessenger()->addSuccessMessage('Project successfully saved');
232-
return $this->redirect()->toRoute('project',['action'=>'view','id'=>$iProjectID]);
95+
/**
96+
* You can just use the default function and customize it via hooks
97+
* or replace the entire function if you need more customization
98+
*
99+
* Hooks available:
100+
*
101+
* project-edit-before (before show edit form)
102+
* project-edit-before-save (before save)
103+
* project-edit-after-save (after save)
104+
*/
105+
return $this->generateEditView('project');
233106
}
234107

235108
/**
@@ -239,45 +112,14 @@ public function editAction() {
239112
* @return ViewModel - View Object with Data from Controller
240113
*/
241114
public function viewAction() {
242-
# Set Layout based on users theme
243-
$this->setThemeBasedLayout('project');
244-
245-
# Check license
246-
if(!$this->checkLicense('project')) {
247-
$this->flashMessenger()->addErrorMessage('You have no active license for project');
248-
$this->redirect()->toRoute('home');
249-
}
250-
251-
# Get Project ID from URL
252-
$iProjectID = $this->params()->fromRoute('id', 0);
253-
254-
# Try to get Project
255-
try {
256-
$oProject = $this->oTableGateway->getSingle($iProjectID);
257-
} catch (\RuntimeException $e) {
258-
echo 'Project Not found';
259-
return false;
260-
}
261-
262-
# Attach Project Entity to Layout
263-
$this->setViewEntity($oProject);
264-
265-
# Add Buttons for breadcrumb
266-
$this->setViewButtons('project-view');
267-
268-
# Load Tabs for View Form
269-
$this->setViewTabs($this->sSingleForm);
270-
271-
# Load Fields for View Form
272-
$this->setFormFields($this->sSingleForm);
273-
274-
# Log Performance in DB
275-
$aMeasureEnd = getrusage();
276-
$this->logPerfomance('project-view',$this->rutime($aMeasureEnd,CoreController::$aPerfomanceLogStart,"utime"),$this->rutime($aMeasureEnd,CoreController::$aPerfomanceLogStart,"stime"));
277-
278-
return new ViewModel([
279-
'sFormName'=>$this->sSingleForm,
280-
'oProject'=>$oProject,
281-
]);
115+
/**
116+
* You can just use the default function and customize it via hooks
117+
* or replace the entire function if you need more customization
118+
*
119+
* Hooks available:
120+
*
121+
* project-view-before
122+
*/
123+
return $this->generateViewView('project');
282124
}
283125
}

0 commit comments

Comments
 (0)