1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @link http://www.newicon.net/neon |
4
|
|
|
* @copyright Copyright (c) 2020 Newicon Ltd |
5
|
|
|
* @license http://www.newicon.net/neon/license/ |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace neon\daedalus\controllers; |
9
|
|
|
|
10
|
|
|
use neon\daedalus\controllers\common\DaedalusController; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* This controller manages the change log |
14
|
|
|
*/ |
15
|
|
|
class ChangeLogController extends DaedalusController |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* Change log |
19
|
|
|
* @var neon\daedalus\interfaces\IDdsChangeLogManagement |
|
|
|
|
20
|
|
|
*/ |
21
|
|
|
private $cl = null; |
22
|
|
|
public function __construct($id, $module, $config = []) |
23
|
|
|
{ |
24
|
|
|
parent::__construct($id, $module, $config); |
25
|
|
|
$this->cl = neon('dds')->IDdsChangeLogManagement; |
|
|
|
|
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function actionListAll() |
29
|
|
|
{ |
30
|
|
|
$goBackTo = url(['index/index']); |
31
|
|
|
$grid = new \neon\daedalus\grid\ChangeLogGrid(); |
32
|
|
|
$classesWithChangeLog = $this->cl->listClassesWithChangeLog(); |
33
|
|
|
$availableChangeLogs = implode(', ', array_column($classesWithChangeLog, 'label')); |
34
|
|
|
return $this->render('listAll.tpl', [ |
35
|
|
|
'hasChangeLogs' => (count($classesWithChangeLog) > 0), |
36
|
|
|
'availableChangeLogs' => $availableChangeLogs, |
37
|
|
|
'grid' => $grid, |
38
|
|
|
'goBackTo' => $goBackTo |
39
|
|
|
]); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function actionList($type, $uuid=null) |
43
|
|
|
{ |
44
|
|
|
// sort out where we're going back to |
45
|
|
|
$goBackTo = url(['index/list', 'type'=>$type]); |
46
|
|
|
if ($uuid) |
47
|
|
|
$goBackTo = url(['index/list', 'type'=>$type, 'uuid' => $uuid]); |
48
|
|
|
|
49
|
|
|
// check the class has a change log |
50
|
|
|
$class = ['class_type' => $type, 'label'=>ucwords(str_replace('_',' ',$type))]; |
51
|
|
|
$hasChangeLog = $this->cl->hasChangeLog($type); |
52
|
|
|
if (!$hasChangeLog) { |
53
|
|
|
return $this->render('list.tpl', [ |
54
|
|
|
'class'=>$class, |
55
|
|
|
'goBackTo' => $goBackTo, |
56
|
|
|
'hasChangeLog'=>$hasChangeLog, |
57
|
|
|
]); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
$grid = new \neon\daedalus\grid\ChangeLogGrid([ |
61
|
|
|
'classType'=>$type, |
62
|
|
|
'objectUuid'=>$uuid |
63
|
|
|
]); |
64
|
|
|
|
65
|
|
|
return $this->render('list.tpl', [ |
66
|
|
|
'hasChangeLog'=>$hasChangeLog, |
67
|
|
|
'class'=>$class, |
68
|
|
|
'grid' => $grid, |
69
|
|
|
'goBackTo' => $goBackTo |
70
|
|
|
]); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Show a grid of all the content types currently in the system |
75
|
|
|
* @return string |
76
|
|
|
*/ |
77
|
|
|
public function actionViewObject($uuid, $logUuid) |
78
|
|
|
{ |
79
|
|
|
$logEntry = $this->cl->getLogEntry($logUuid); |
80
|
|
|
if (!$logEntry) |
81
|
|
|
return 'Log not found'; |
82
|
|
|
$type = $logEntry['class_type']; |
83
|
|
|
|
84
|
|
|
$class = $this->getClassAsArray($type); |
85
|
|
|
$goBackTo = url(['change-log/list', 'type'=>$type, 'uuid' => $uuid]); |
86
|
|
|
if ($uuid) |
87
|
|
|
$headerTitle = "$class[label] [Object '$uuid'] Change Log"; |
88
|
|
|
else |
89
|
|
|
$headerTitle = "$class[label] Change Log"; |
90
|
|
|
|
91
|
|
|
$title = "Status of $uuid on ".date("d-m-Y \\a\\t H:i:s", strtotime($logEntry['when'])); |
92
|
|
|
$render = [ |
93
|
|
|
'headerTitle'=>$headerTitle, |
94
|
|
|
'title' => $title, |
95
|
|
|
'goBackTo' => $goBackTo, |
96
|
|
|
'history' => [], |
97
|
|
|
'class' => $class, |
98
|
|
|
'object' => null, |
99
|
|
|
'associated_objects' => null |
100
|
|
|
]; |
101
|
|
|
switch ($logEntry['change_key']) { |
102
|
|
|
case 'COMMENT': |
103
|
|
|
if (!$uuid) |
104
|
|
|
$render['title'] = "Comment added on ".date("d-m-Y \\a\\t H:i:s", strtotime($logEntry['when'])); |
105
|
|
|
if (is_array($logEntry['associated_objects']) && count($logEntry['associated_objects'])>0) |
106
|
|
|
$render['associated_objects'] = implode(', ', $logEntry['associated_objects']); |
107
|
|
|
case 'DESTROY': |
108
|
|
|
case 'DELETE': |
109
|
|
|
$renderFile = 'viewLogEntry.tpl'; |
110
|
|
|
$render['logEntry'] = $logEntry; |
111
|
|
|
$render['object'] = ['_uuid'=>$uuid]; |
112
|
|
|
break; |
113
|
|
|
case 'ADD': |
114
|
|
|
case 'EDIT': |
115
|
|
|
case 'UNDELETE': |
116
|
|
|
$renderFile = 'view.tpl'; |
117
|
|
|
$object = $this->cl->getObjectAtLogPoint($uuid, $logUuid); |
118
|
|
|
if ($object) { |
119
|
|
|
$form = neon()->phoebe->getForm('daedalus', $type, []); |
120
|
|
|
$form->label = $title; |
|
|
|
|
121
|
|
|
$form->loadFromDb($object); |
122
|
|
|
$form->printOnly = true; |
123
|
|
|
$render['form'] = $form; |
124
|
|
|
$render['object'] = $object; |
125
|
|
|
} |
126
|
|
|
break; |
127
|
|
|
} |
128
|
|
|
return $this->render($renderFile, $render); |
|
|
|
|
129
|
|
|
|
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Turn on or off the change log |
134
|
|
|
*/ |
135
|
|
|
public function actionSet($type, $to) |
136
|
|
|
{ |
137
|
|
|
$this->cl->setChangeLog($type, $to); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
} |
141
|
|
|
|