Skip to content

Commit 62ec571

Browse files
author
Walid
committed
Add creation date to items
1 parent 41cadee commit 62ec571

File tree

7 files changed

+94
-73
lines changed

7 files changed

+94
-73
lines changed

fields/field.constant.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
@link http://www.glpi-project.org/
2525
@since 2009
2626
---------------------------------------------------------------------- */
27-
27+
2828
global $GO_FIELDS;
2929

3030
$GO_FIELDS['id']['name'] = __("ID");
@@ -61,6 +61,9 @@
6161
$GO_FIELDS['date_mod']['name'] = __("Last update");
6262
$GO_FIELDS['date_mod']['input_type'] = 'datetime';
6363

64+
$GO_FIELDS['date_creation']['name'] = __('Creation date');
65+
$GO_FIELDS['date_creation']['input_type'] = 'datetime';
66+
6467
$GO_FIELDS['url']['name'] = __("URL");
6568
$GO_FIELDS['url']['field'] = 'url';
6669
$GO_FIELDS['url']['input_type'] = 'text';

hook.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ function plugin_genericobject_install() {
9595
include_once(GLPI_ROOT."/plugins/genericobject/inc/object.class.php");
9696
include_once(GLPI_ROOT."/plugins/genericobject/inc/type.class.php");
9797

98-
$migration = new Migration('2.4.0');
99-
98+
$migration = new Migration('0.85+1.1');
99+
100100
foreach (
101101
array(
102102
'PluginGenericobjectField',
@@ -119,7 +119,7 @@ function plugin_genericobject_install() {
119119
}
120120
}
121121
}
122-
122+
123123
if (!is_dir(GENERICOBJECT_CLASS_PATH)) {
124124
@ mkdir(GENERICOBJECT_CLASS_PATH, 0777, true)
125125
or die("Can't create folder " . GENERICOBJECT_CLASS_PATH);
@@ -149,9 +149,9 @@ function plugin_genericobject_uninstall() {
149149

150150
foreach (
151151
array(
152-
'PluginGenericobjectType',
152+
'PluginGenericobjectType',
153153
'PluginGenericobjectProfile',
154-
'PluginGenericobjectField',
154+
'PluginGenericobjectField',
155155
'PluginGenericobjectTypeFamily'
156156
) as $itemtype
157157
) {
@@ -198,4 +198,4 @@ function plugin_genericobject_MassiveActions($type) {
198198
} else {
199199
return array();
200200
}
201-
}
201+
}

inc/autoload.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,3 @@ public function register()
7272
spl_autoload_register(array($this, 'autoload'));
7373
}
7474
}
75-

inc/object.class.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,6 @@ function showForm($id, $options=array(), $previsualisation = false) {
464464
}
465465

466466
$this->fields['id'] = $id;
467-
$options['colspan'] = 4;
468467
$this->initForm($id,$options);
469468
$this->showFormHeader($options);
470469

@@ -512,7 +511,7 @@ function showForm($id, $options=array(), $previsualisation = false) {
512511

513512
static function getFieldsToHide() {
514513
return array('id', 'is_recursive', 'is_template', 'template_name', 'is_deleted',
515-
'entities_id', 'notepad', 'date_mod');
514+
'entities_id', 'notepad', 'date_mod', 'date_creation');
516515
}
517516

518517

@@ -746,9 +745,10 @@ function getSearchOptions() {
746745
function getObjectSearchOptions($with_linkfield = false) {
747746
global $DB, $GO_FIELDS, $GO_BLACKLIST_FIELDS;
748747

749-
$datainjection_blacklisted = array('id', 'date_mod', 'entities_id');
748+
$datainjection_blacklisted = array('id', 'date_mod', 'entities_id', 'date_creation');
750749
$index_exceptions = array('name' => 1, 'id' => 2, 'comment' => 16, 'date_mod' => 19,
751-
'entities_id' => 80, 'is_recursive' => 86, 'notepad' => 90);
750+
'entities_id' => 80, 'is_recursive' => 86, 'notepad' => 90,
751+
'date_creation' => 121);
752752
$index = 3;
753753
$options = array();
754754
$options['common'] = __('Characteristics');

inc/type.class.php

Lines changed: 58 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -212,15 +212,6 @@ function prepareInputForUpdate($input) {
212212
if (isset ($input["is_active"]) && $input["is_active"]) {
213213
self::registerOneType($this->fields['itemtype']);
214214
}
215-
216-
if (isset($input['use_plugin_geninventorynumber'])) {
217-
switch ($input['use_plugin_geninventorynumber']) {
218-
case 0:
219-
220-
break;
221-
case 1:
222-
}
223-
}
224215
return $input;
225216
}
226217

@@ -245,7 +236,7 @@ function pre_deleteItem() {
245236

246237
//Delete loans associated with this type
247238
self::deleteUnicity($itemtype);
248-
239+
249240
//Delete reservations with this tyoe
250241
self::deleteReservations($itemtype);
251242
self::deleteReservationItems($itemtype);
@@ -257,7 +248,7 @@ function pre_deleteItem() {
257248
PluginGenericobjectProfile::deleteTypeFromProfile($itemtype);
258249

259250
self::deleteTicketAssignation($itemtype);
260-
251+
261252
//Remove associations to simcards with this type
262253
self::deleteSimcardAssignation($itemtype);
263254

@@ -270,8 +261,8 @@ function pre_deleteItem() {
270261
self::deleteItemtypeReferencesInGLPI($itemtype);
271262

272263
self::deleteItemTypeFilesAndClasses($name, $this->getTable(), $itemtype);
273-
274-
self::deleteNotepad($itemtype);
264+
265+
//self::deleteNotepad($itemtype);
275266

276267
if (preg_match("/PluginGenericobject(.*)/", $itemtype, $results)) {
277268
$newrightname = 'plugin_genericobject_'.strtolower($results[1]).'s';
@@ -363,6 +354,18 @@ function getSearchOptions() {
363354
$sopt[20]['name'] = _n('Project', 'Projects', 2);
364355
$sopt[20]['datatype'] = 'bool';
365356

357+
$sopt[21]['table'] = $this->getTable();
358+
$sopt[21]['field'] = 'date_mod';
359+
$sopt[21]['name'] = __('Last update');
360+
$sopt[21]['datatype'] = 'datetime';
361+
$sopt[21]['massiveaction'] = false;
362+
363+
$sopt[121]['table'] = $this->getTable();
364+
$sopt[121]['field'] = 'date_creation';
365+
$sopt[121]['name'] = __('Creation date');
366+
$sopt[121]['datatype'] = 'datetime';
367+
$sopt[121]['massiveaction'] = false;
368+
366369
return $sopt;
367370
}
368371

@@ -490,8 +493,8 @@ function showBehaviorForm($ID, $options=array()) {
490493
"use_contracts" => _n("Contract", "Contracts", 2),
491494
"use_documents" => _n("Document", "Documents", 2),
492495
"use_loans" => _n("Reservation", "Reservations", 2),
493-
// Disable unicity feature; see #16
494-
// Related code : search for #16
496+
// Disable unicity feature; see #16
497+
// Related code : search for #16
495498
// "use_unicity" => __("Fields unicity"),
496499
"use_global_search" => __("Global search"),
497500
"use_projects" => _n("Project", "Projects", 2),
@@ -516,27 +519,27 @@ function showBehaviorForm($ID, $options=array()) {
516519

517520
switch ($right) {
518521
case 'use_deleted':
519-
Html::showCheckbox(array('name' => $right,
522+
Html::showCheckbox(array('name' => $right,
520523
'checked' => $this->canBeDeleted()));
521524
break;
522525

523526
case 'use_recursivity':
524-
Html::showCheckbox(array('name' => $right, 'value' => $this->canBeRecursive(),
527+
Html::showCheckbox(array('name' => $right, 'value' => $this->canBeRecursive(),
525528
'checked' => $this->canBeRecursive()));
526529
break;
527530

528531
case 'use_notes':
529-
Html::showCheckbox(array('name' => $right,
532+
Html::showCheckbox(array('name' => $right,
530533
'checked' => $this->canUseNotepad()));
531534
break;
532535

533536
case 'use_template':
534-
Html::showCheckbox(array('name' => $right,
537+
Html::showCheckbox(array('name' => $right,
535538
'checked' => $this->canUseTemplate()));
536539
break;
537540

538541
default :
539-
Html::showCheckbox(array('name' => $right,
542+
Html::showCheckbox(array('name' => $right,
540543
'checked' => $this->fields[$right]));
541544
break;
542545
}
@@ -565,7 +568,7 @@ function showBehaviorForm($ID, $options=array()) {
565568
switch ($right) {
566569
case 'use_plugin_datainjection' :
567570
if ($plugin->isActivated('datainjection')) {
568-
Html::showCheckbox(array('name' => $right,
571+
Html::showCheckbox(array('name' => $right,
569572
'checked' => $this->fields[$right]));
570573
} else {
571574
echo Dropdown::EMPTY_VALUE;
@@ -575,7 +578,7 @@ function showBehaviorForm($ID, $options=array()) {
575578

576579
case 'use_plugin_pdf' :
577580
if ($plugin->isActivated('pdf')) {
578-
Html::showCheckbox(array('name' => $right,
581+
Html::showCheckbox(array('name' => $right,
579582
'checked' => $this->fields[$right]));
580583
} else {
581584
echo Dropdown::EMPTY_VALUE;
@@ -585,7 +588,7 @@ function showBehaviorForm($ID, $options=array()) {
585588

586589
case 'use_plugin_order' :
587590
if ($plugin->isActivated('order')) {
588-
Html::showCheckbox(array('name' => $right,
591+
Html::showCheckbox(array('name' => $right,
589592
'checked' => $this->fields[$right]));
590593
} else {
591594
echo Dropdown::EMPTY_VALUE;
@@ -595,7 +598,7 @@ function showBehaviorForm($ID, $options=array()) {
595598

596599
case 'use_plugin_uninstall' :
597600
if ($plugin->isActivated('uninstall')) {
598-
Html::showCheckbox(array('name' => $right,
601+
Html::showCheckbox(array('name' => $right,
599602
'checked' => $this->fields[$right]));
600603
} else {
601604
echo Dropdown::EMPTY_VALUE;
@@ -605,7 +608,7 @@ function showBehaviorForm($ID, $options=array()) {
605608

606609
case 'use_plugin_simcard' :
607610
if ($plugin->isActivated('simcard')) {
608-
Html::showCheckbox(array('name' => $right,
611+
Html::showCheckbox(array('name' => $right,
609612
'checked' => $this->fields[$right]));
610613
} else {
611614
echo Dropdown::EMPTY_VALUE;
@@ -732,7 +735,7 @@ static function addNewObject($name, $itemtype, $options = array()) {
732735

733736
if ($params['overwrite_locales']) {
734737
//Add language file
735-
self::addLocales($name, $itemtype);
738+
self::addLocales($name, $itemtype);
736739
}
737740

738741
//Add file needed by datainjectin plugin
@@ -890,8 +893,11 @@ public static function addTable($itemtype) {
890893
`name` VARCHAR( 255 ) collate utf8_unicode_ci NOT NULL DEFAULT '',
891894
`comment` text COLLATE utf8_unicode_ci,
892895
`notepad` text COLLATE utf8_unicode_ci,
893-
`date_mod` DATETIME NULL ,
894-
PRIMARY KEY ( `id` )
896+
`date_mod` DATETIME DEFAULT NULL,
897+
`date_creation` DATETIME DEFAULT NULL,
898+
PRIMARY KEY ( `id` ),
899+
KEY `date_mod` (`date_mod`),
900+
KEY `date_creation` (`date_creation`)
895901
) ENGINE = MYISAM COMMENT = '$itemtype' DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
896902
$DB->query($query);
897903

@@ -913,10 +919,14 @@ public static function addItemsTable($itemtype) {
913919
$query = "CREATE TABLE IF NOT EXISTS `".getTableForItemType($itemtype)."_items` (
914920
`id` int(11) NOT NULL AUTO_INCREMENT,
915921
`items_id` int(11) NOT NULL DEFAULT '0' COMMENT 'RELATION to various table, according to itemtype (ID)',
922+
`date_mod` DATETIME DEFAULT NULL,
923+
`date_creation` DATETIME DEFAULT NULL,
916924
`$fk` int(11) NOT NULL DEFAULT '0',
917925
`itemtype` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
918926
PRIMARY KEY (`id`),
919927
KEY `$fk` (`$fk`),
928+
KEY `date_mod` (`date_mod`),
929+
KEY `date_creation` (`date_creation`),
920930
KEY `item` (`itemtype`,`items_id`)
921931
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
922932
$DB->query($query);
@@ -1291,7 +1301,11 @@ public static function addDropdownTable($table, $options = array()) {
12911301
`id` int(11) NOT NULL auto_increment,
12921302
`name` varchar(255) collate utf8_unicode_ci default NULL,
12931303
`comment` text collate utf8_unicode_ci,
1304+
`date_mod` DATETIME DEFAULT NULL,
1305+
`date_creation` DATETIME NOT NULL,
12941306
PRIMARY KEY (`id`),
1307+
KEY `date_mod` (`date_mod`),
1308+
KEY `date_creation` (`date_creation`),
12951309
KEY `name` (`name`)
12961310
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
12971311
$DB->query($query);
@@ -1381,7 +1395,7 @@ public static function deleteTicketAssignation($itemtype) {
13811395
*/
13821396
public static function deleteSimcardAssignation($itemtype) {
13831397
global $DB;
1384-
1398+
13851399
$plugin = new Plugin();
13861400
if ($plugin->isActivated('simcard') && $plugin->isActivated('simcard')) {
13871401
$types = array('PluginSimcardSimcard_Item');
@@ -1457,25 +1471,25 @@ static function deleteNetworking($itemtype) {
14571471
$networkport->delete($port);
14581472
}
14591473
}
1460-
1474+
14611475
/**
14621476
* Delete reservations for an itemtype
14631477
* @param $itemtype
14641478
* @return nothing
14651479
*/
14661480
static function deleteReservations($itemtype) {
14671481
global $DB;
1468-
1482+
14691483
$reservation = new Reservation();
1470-
$query = "DELETE FROM
1471-
`glpi_reservations`
1484+
$query = "DELETE FROM
1485+
`glpi_reservations`
14721486
WHERE `reservationitems_id` in (
14731487
SELECT `id` from `glpi_reservationitems` WHERE `itemtype`='$itemtype'
14741488
)";
14751489
$DB->query($query);
14761490
}
1477-
1478-
/**
1491+
1492+
/**
14791493
* Delete reservations for an itemtype
14801494
* @param $itemtype
14811495
* @return nothing
@@ -1788,7 +1802,7 @@ function canUsePluginSimcard() {
17881802
}
17891803
return $this->fields['use_plugin_simcard'];
17901804
}
1791-
1805+
17921806
function canUsePluginGeninventoryNumber() {
17931807
$plugin = new Plugin();
17941808
if (!$plugin->isInstalled("geninventorynumber")
@@ -1846,7 +1860,8 @@ static function install(Migration $migration) {
18461860
`is_active` tinyint(1) NOT NULL default '0',
18471861
`name` varchar(255) collate utf8_unicode_ci default NULL,
18481862
`comment` text NULL,
1849-
`date_mod` datetime NOT NULL default '0000-00-00 00:00:00',
1863+
`date_mod` datetime DEFAULT NULL,
1864+
`date_creation` datetime DEFAULT NULL,
18501865
`use_global_search` tinyint(1) NOT NULL default '0',
18511866
`use_unicity` tinyint(1) NOT NULL default '0',
18521867
`use_history` tinyint(1) NOT NULL default '0',
@@ -1881,15 +1896,18 @@ static function install(Migration $migration) {
18811896
$migration->addField($table, "use_projects", "bool");
18821897
$migration->addField($table, "use_notepad", "bool");
18831898
$migration->addField($table, "comment", "text");
1884-
$migration->addField($table, "date_mod", "datetime");
1899+
if (!$migration->addField($table, "date_mod", "datetime")) {
1900+
$migration->changeField($table, "date_mod", "date_mod", "datetime");
1901+
}
1902+
$migration->addField($table, "date_creation", "datetime");
18851903
$migration->addField($table, "linked_itemtypes", "text");
18861904
$migration->addField($table, "plugin_genericobject_typefamilies_id", "integer");
18871905
$migration->addField($table, "use_plugin_simcard", "bool");
18881906
$migration->migrationOneTable($table);
18891907

18901908
// Migrate notepad data
18911909
$allGenericObjectTypes = PluginGenericobjectType::getTypes(true);
1892-
1910+
18931911
$notepad = new Notepad();
18941912
foreach ($allGenericObjectTypes as $genericObjectType => $genericObjectData) {
18951913
$genericObjectTypeInstance = new $genericObjectType();
@@ -1916,7 +1934,7 @@ static function install(Migration $migration) {
19161934
$migration->dropField($genericObjectTypeInstance->getTable(), "notepad");
19171935
$migration->migrationOneTable($genericObjectTypeInstance->getTable());
19181936
}
1919-
1937+
19201938
//Displayprefs
19211939
$prefs = array(10 => 6, 9 => 5, 8 => 4, 7 => 3, 6 => 2, 2 => 1, 4 => 1, 11 => 7, 12 => 8,
19221940
14 => 10, 15 => 11);

0 commit comments

Comments
 (0)