forked from DeuxHuitHuit/datetime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extension.driver.php
executable file
·115 lines (99 loc) · 3.16 KB
/
extension.driver.php
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
<?php
Class extension_datetime extends Extension {
/**
* Extension information
*/
public function about() {
return array(
'name' => 'Date and Time',
'type' => 'Field, Interface',
'repository' => 'http://github.com/nilshoerrmann/datetime/',
'version' => '1.4',
'release-date' => '2010-08-27',
'author' => array(
'name' => 'Nils Hörrmann',
'website' => 'http://nilshoerrmann.de',
'email' => 'post@nilshoerrmann.de'
),
'description' => 'A field for single dates, multiple dates and date ranges',
'compatibility' => array(
'2.0.6' => true,
'2.0.7' => true
)
);
}
/**
* Add callback functions to backend delegates
*/
public function getSubscribedDelegates(){
return array(
array(
'page' => '/backend/',
'delegate' => 'InitaliseAdminPageHead',
'callback' => '__addDateJS'
)
);
}
/**
* Add international dateJS
*/
public function __addDateJS() {
// get current language
$lang = Administration::instance()->Configuration->get('lang', 'symphony');
// check dateJS language
if(file_exists(EXTENSIONS . '/datetime/assets/international/datejs.' . $lang . '.js')) {
Administration::instance()->Page->addScriptToHead(URL . '/extensions/datetime/assets/international/datejs.' . $lang . '.js', 200, false);
}
else {
Administration::instance()->Page->addScriptToHead(URL . '/extensions/datetime/assets/international/datejs.en.js', 200, false);
}
}
/**
* Function to be executed on uninstallation
*/
public function uninstall() {
// drop database table
Administration::instance()->Database->query("DROP TABLE `tbl_fields_datetime`");
}
/**
* Function to be executed if the extension has been updated
*
* @param string $previousVersion - version number of the currently installed extension build
* @return boolean - true on success, false otherwise
*/
public function update($previousVersion) {
/* Go through all the existing datetime tables converting the start/end to datetime */
if(version_compare($previousVersion, '1.3', '<')){
$fields = Administration::instance()->Database->fetchCol("field_id", "SELECT `field_id` from `tbl_fields_datetime`");
foreach($fields as $field) {
Administration::instance()->Database->query(
sprintf("
ALTER TABLE `tbl_entries_data_%d`
MODIFY `end` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
MODIFY `start` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00'
", $field)
);
}
}
return true;
}
/**
* Function to be executed on installation.
*
* @return boolean - true on success, false otherwise
*/
public function install() {
// Create database table and fields.
return Administration::instance()->Database->query(
"CREATE TABLE `tbl_fields_datetime` (
`id` int(11) unsigned NOT NULL auto_increment,
`field_id` int(11) unsigned NOT NULL,
`format` text,
`prepopulate` enum('yes','no') NOT NULL default 'yes',
`allow_multiple_dates` enum('yes','no') NOT NULL default 'yes',
PRIMARY KEY (`id`),
KEY `field_id` (`field_id`)
)"
);
}
}