/
history.gtw
162 lines (116 loc) · 5.06 KB
/
history.gtw
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
~~LANG:FR@frman:ref-plugins/coordplugins/history~~
History is a coordinator plugin, it brings some features related with user browsing history.
===== Plugin declaration =====
To activate History plugin, set it with its config file in the [coordplugins] section.
<code ini>
[coordplugins]
history = history.coord.ini.php
</code>
If you use several coordinator plugins, the order of the plugins declaration in the config file matters. Hence the first declared plugin has precedence on the others. It means that if this first plugin returns an action, the other ones will not be executed. So you need to choose carefully the order of the plugins declaration according to the priority you wish for every plugin. For example if you consider that the //bar// plugin cannot be executed as long as the //foo// plugin does not return any action, then you should declare them this way:
<code ini>
[coordplugins]
foo = foo.plugin.ini.php
bar = 1
</code>
Keep that in mind when declaring the History plugin.
===== Principle =====
History plugin records couples [actions/parameters]
To have 'myapp~default:index' taken into account and registered by the History plugin, you must ask it specifically with the help of $pluginParams.
By default no record is performed if you don't request it that way.
<code php>
public $pluginParams = array(
'*' => array('history.add'=>false),
'index' => array('history.add'=>true, 'history.label'=>'Home', 'history.title'=>'Go to Homepage')
);
</code>
history.add (:Bool)
If true allows to add a couple to the history
history.label (:String)
A name for this couple
history.title (:String)
A description for this couple
===== Configuration =====
==== Size limit ====
The size of the History is limited to a certain number of couples (default is 10), this limit is customizable in the plugin parameters.
<code ini>
; taille max. de l'historique
maxsize = 20
</code>
==== Avoid duplicates ====
By default, History records couples one after another keeping the duplicates.\\
If you wish the duplicates to be deleted from the History, you must set it in the parameters.
<code ini>
; if single = true then each page will be registered only once in history
; the latter will be retained.
single = true
</code>
==== Keep record of reloads ====
When you execute twice the same couple it is added only once.
If you want the reloads to be visible in the History you must modify the 'double' parameter.
<code ini>
; If double = false pages will not appear twice a follow time in history.
double = false
</code>
===== Change attributes of a couple when executing =====
If you use only $pluginParams to declare the couples, you are soon limited for instance to modify the label according to the parameters.
Example:
We want this couple to have the '**Page Foo**' label
myapp.com/index.php?var=foo&module=myapp&action=default:index
and this couple to have the '**Page Bar**' label
myapp.com/index.php?var=bar&module=myapp&action=default:index
If we use the basic declaration
<code php>
public $pluginParams = array(
'*' => array('history.add'=>false),
'index' => array('history.add'=>true, 'history.label'=>'Page Foo')
);
</code>
the two couples will have the same '**Page Foo**' label.
To get what we want, we must write:
<code php>
public $pluginParams = array(
'*' => array('history.add'=>false),
'index' => array('history.add'=>true)
);
function index() {
$rep = $this->getResponse('html');
if( $this->param('var') !== null ) {
$GLOBALS['gJCoord']->getPlugin('history')->change('label', 'Page '.ucfirst($this->param('var')));
}
$rep->body->assign('MAIN', $rep->body->fetch('myapp~page'));
return $rep;
}
</code>
===== Use History to reload the page =====
One frequent case is: you want to execute an action (after a keystroke for example) and come back to the same page.
To perform this, History plugin provides a simple command.
<code php>
$history = $GLOBALS['gJCoord']->getPlugin('history');
return $history->reload( $this->getResponse('redirect') );
</code>
If you would like to reload the page modifying one or two parameters, you have just to do this:
<code php>
$history = $GLOBALS['gJCoord']->getPlugin('history');
$ret = $history->reload( $this->getResponse('redirect') );
$ret->params['foo'] = 'bar';
return $ret;
</code>
===== Use History to come back to previous page =====
Another frequent case is: get the link to come back to previous page.
<code php>
$history = $GLOBALS['gJCoord']->getPlugin('history');
return $history->back( $this->getResponse('redirect') );
</code>
==== Use History to know how long the internet user has been visiting the site =====
To get this, you must give parameters to the time and session_time_name variables, so that the entrance time on the site is recorded.
<code ini>
; if time = true a variable record time spent on site
time = true
; the name of this variable
session_time_name = "HISTORYTIME"
</code>
Then to catch the time spent on the site, you have just to do
<code php>
$history = $GLOBALS['gJCoord']->getPlugin('history');
$delais = $history->time();
</code>