Skip to content

Commit

Permalink
Add creation date to items
Browse files Browse the repository at this point in the history
  • Loading branch information
Walid committed Aug 20, 2016
1 parent 41cadee commit 62ec571
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 73 deletions.
5 changes: 4 additions & 1 deletion fields/field.constant.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
@link http://www.glpi-project.org/
@since 2009
---------------------------------------------------------------------- */

global $GO_FIELDS;

$GO_FIELDS['id']['name'] = __("ID");
Expand Down Expand Up @@ -61,6 +61,9 @@
$GO_FIELDS['date_mod']['name'] = __("Last update");
$GO_FIELDS['date_mod']['input_type'] = 'datetime';

$GO_FIELDS['date_creation']['name'] = __('Creation date');
$GO_FIELDS['date_creation']['input_type'] = 'datetime';

$GO_FIELDS['url']['name'] = __("URL");
$GO_FIELDS['url']['field'] = 'url';
$GO_FIELDS['url']['input_type'] = 'text';
Expand Down
12 changes: 6 additions & 6 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ function plugin_genericobject_install() {
include_once(GLPI_ROOT."/plugins/genericobject/inc/object.class.php");
include_once(GLPI_ROOT."/plugins/genericobject/inc/type.class.php");

$migration = new Migration('2.4.0');
$migration = new Migration('0.85+1.1');

foreach (
array(
'PluginGenericobjectField',
Expand All @@ -119,7 +119,7 @@ function plugin_genericobject_install() {
}
}
}

if (!is_dir(GENERICOBJECT_CLASS_PATH)) {
@ mkdir(GENERICOBJECT_CLASS_PATH, 0777, true)
or die("Can't create folder " . GENERICOBJECT_CLASS_PATH);
Expand Down Expand Up @@ -149,9 +149,9 @@ function plugin_genericobject_uninstall() {

foreach (
array(
'PluginGenericobjectType',
'PluginGenericobjectType',
'PluginGenericobjectProfile',
'PluginGenericobjectField',
'PluginGenericobjectField',
'PluginGenericobjectTypeFamily'
) as $itemtype
) {
Expand Down Expand Up @@ -198,4 +198,4 @@ function plugin_genericobject_MassiveActions($type) {
} else {
return array();
}
}
}
1 change: 0 additions & 1 deletion inc/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,3 @@ public function register()
spl_autoload_register(array($this, 'autoload'));
}
}

8 changes: 4 additions & 4 deletions inc/object.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,6 @@ function showForm($id, $options=array(), $previsualisation = false) {
}

$this->fields['id'] = $id;
$options['colspan'] = 4;
$this->initForm($id,$options);
$this->showFormHeader($options);

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

static function getFieldsToHide() {
return array('id', 'is_recursive', 'is_template', 'template_name', 'is_deleted',
'entities_id', 'notepad', 'date_mod');
'entities_id', 'notepad', 'date_mod', 'date_creation');
}


Expand Down Expand Up @@ -746,9 +745,10 @@ function getSearchOptions() {
function getObjectSearchOptions($with_linkfield = false) {
global $DB, $GO_FIELDS, $GO_BLACKLIST_FIELDS;

$datainjection_blacklisted = array('id', 'date_mod', 'entities_id');
$datainjection_blacklisted = array('id', 'date_mod', 'entities_id', 'date_creation');
$index_exceptions = array('name' => 1, 'id' => 2, 'comment' => 16, 'date_mod' => 19,
'entities_id' => 80, 'is_recursive' => 86, 'notepad' => 90);
'entities_id' => 80, 'is_recursive' => 86, 'notepad' => 90,
'date_creation' => 121);
$index = 3;
$options = array();
$options['common'] = __('Characteristics');
Expand Down
98 changes: 58 additions & 40 deletions inc/type.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,15 +212,6 @@ function prepareInputForUpdate($input) {
if (isset ($input["is_active"]) && $input["is_active"]) {
self::registerOneType($this->fields['itemtype']);
}

if (isset($input['use_plugin_geninventorynumber'])) {
switch ($input['use_plugin_geninventorynumber']) {
case 0:

break;
case 1:
}
}
return $input;
}

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

//Delete loans associated with this type
self::deleteUnicity($itemtype);

//Delete reservations with this tyoe
self::deleteReservations($itemtype);
self::deleteReservationItems($itemtype);
Expand All @@ -257,7 +248,7 @@ function pre_deleteItem() {
PluginGenericobjectProfile::deleteTypeFromProfile($itemtype);

self::deleteTicketAssignation($itemtype);

//Remove associations to simcards with this type
self::deleteSimcardAssignation($itemtype);

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

self::deleteItemTypeFilesAndClasses($name, $this->getTable(), $itemtype);
self::deleteNotepad($itemtype);

//self::deleteNotepad($itemtype);

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

$sopt[21]['table'] = $this->getTable();
$sopt[21]['field'] = 'date_mod';
$sopt[21]['name'] = __('Last update');
$sopt[21]['datatype'] = 'datetime';
$sopt[21]['massiveaction'] = false;

$sopt[121]['table'] = $this->getTable();
$sopt[121]['field'] = 'date_creation';
$sopt[121]['name'] = __('Creation date');
$sopt[121]['datatype'] = 'datetime';
$sopt[121]['massiveaction'] = false;

return $sopt;
}

Expand Down Expand Up @@ -490,8 +493,8 @@ function showBehaviorForm($ID, $options=array()) {
"use_contracts" => _n("Contract", "Contracts", 2),
"use_documents" => _n("Document", "Documents", 2),
"use_loans" => _n("Reservation", "Reservations", 2),
// Disable unicity feature; see #16
// Related code : search for #16
// Disable unicity feature; see #16
// Related code : search for #16
// "use_unicity" => __("Fields unicity"),
"use_global_search" => __("Global search"),
"use_projects" => _n("Project", "Projects", 2),
Expand All @@ -516,27 +519,27 @@ function showBehaviorForm($ID, $options=array()) {

switch ($right) {
case 'use_deleted':
Html::showCheckbox(array('name' => $right,
Html::showCheckbox(array('name' => $right,
'checked' => $this->canBeDeleted()));
break;

case 'use_recursivity':
Html::showCheckbox(array('name' => $right, 'value' => $this->canBeRecursive(),
Html::showCheckbox(array('name' => $right, 'value' => $this->canBeRecursive(),
'checked' => $this->canBeRecursive()));
break;

case 'use_notes':
Html::showCheckbox(array('name' => $right,
Html::showCheckbox(array('name' => $right,
'checked' => $this->canUseNotepad()));
break;

case 'use_template':
Html::showCheckbox(array('name' => $right,
Html::showCheckbox(array('name' => $right,
'checked' => $this->canUseTemplate()));
break;

default :
Html::showCheckbox(array('name' => $right,
Html::showCheckbox(array('name' => $right,
'checked' => $this->fields[$right]));
break;
}
Expand Down Expand Up @@ -565,7 +568,7 @@ function showBehaviorForm($ID, $options=array()) {
switch ($right) {
case 'use_plugin_datainjection' :
if ($plugin->isActivated('datainjection')) {
Html::showCheckbox(array('name' => $right,
Html::showCheckbox(array('name' => $right,
'checked' => $this->fields[$right]));
} else {
echo Dropdown::EMPTY_VALUE;
Expand All @@ -575,7 +578,7 @@ function showBehaviorForm($ID, $options=array()) {

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

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

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

case 'use_plugin_simcard' :
if ($plugin->isActivated('simcard')) {
Html::showCheckbox(array('name' => $right,
Html::showCheckbox(array('name' => $right,
'checked' => $this->fields[$right]));
} else {
echo Dropdown::EMPTY_VALUE;
Expand Down Expand Up @@ -732,7 +735,7 @@ static function addNewObject($name, $itemtype, $options = array()) {

if ($params['overwrite_locales']) {
//Add language file
self::addLocales($name, $itemtype);
self::addLocales($name, $itemtype);
}

//Add file needed by datainjectin plugin
Expand Down Expand Up @@ -890,8 +893,11 @@ public static function addTable($itemtype) {
`name` VARCHAR( 255 ) collate utf8_unicode_ci NOT NULL DEFAULT '',
`comment` text COLLATE utf8_unicode_ci,
`notepad` text COLLATE utf8_unicode_ci,
`date_mod` DATETIME NULL ,
PRIMARY KEY ( `id` )
`date_mod` DATETIME DEFAULT NULL,
`date_creation` DATETIME DEFAULT NULL,
PRIMARY KEY ( `id` ),
KEY `date_mod` (`date_mod`),
KEY `date_creation` (`date_creation`)
) ENGINE = MYISAM COMMENT = '$itemtype' DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
$DB->query($query);

Expand All @@ -913,10 +919,14 @@ public static function addItemsTable($itemtype) {
$query = "CREATE TABLE IF NOT EXISTS `".getTableForItemType($itemtype)."_items` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`items_id` int(11) NOT NULL DEFAULT '0' COMMENT 'RELATION to various table, according to itemtype (ID)',
`date_mod` DATETIME DEFAULT NULL,
`date_creation` DATETIME DEFAULT NULL,
`$fk` int(11) NOT NULL DEFAULT '0',
`itemtype` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`),
KEY `$fk` (`$fk`),
KEY `date_mod` (`date_mod`),
KEY `date_creation` (`date_creation`),
KEY `item` (`itemtype`,`items_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
$DB->query($query);
Expand Down Expand Up @@ -1291,7 +1301,11 @@ public static function addDropdownTable($table, $options = array()) {
`id` int(11) NOT NULL auto_increment,
`name` varchar(255) collate utf8_unicode_ci default NULL,
`comment` text collate utf8_unicode_ci,
`date_mod` DATETIME DEFAULT NULL,
`date_creation` DATETIME NOT NULL,
PRIMARY KEY (`id`),
KEY `date_mod` (`date_mod`),
KEY `date_creation` (`date_creation`),
KEY `name` (`name`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
$DB->query($query);
Expand Down Expand Up @@ -1381,7 +1395,7 @@ public static function deleteTicketAssignation($itemtype) {
*/
public static function deleteSimcardAssignation($itemtype) {
global $DB;

$plugin = new Plugin();
if ($plugin->isActivated('simcard') && $plugin->isActivated('simcard')) {
$types = array('PluginSimcardSimcard_Item');
Expand Down Expand Up @@ -1457,25 +1471,25 @@ static function deleteNetworking($itemtype) {
$networkport->delete($port);
}
}

/**
* Delete reservations for an itemtype
* @param $itemtype
* @return nothing
*/
static function deleteReservations($itemtype) {
global $DB;

$reservation = new Reservation();
$query = "DELETE FROM
`glpi_reservations`
$query = "DELETE FROM
`glpi_reservations`
WHERE `reservationitems_id` in (
SELECT `id` from `glpi_reservationitems` WHERE `itemtype`='$itemtype'
)";
$DB->query($query);
}
/**

/**
* Delete reservations for an itemtype
* @param $itemtype
* @return nothing
Expand Down Expand Up @@ -1788,7 +1802,7 @@ function canUsePluginSimcard() {
}
return $this->fields['use_plugin_simcard'];
}

function canUsePluginGeninventoryNumber() {
$plugin = new Plugin();
if (!$plugin->isInstalled("geninventorynumber")
Expand Down Expand Up @@ -1846,7 +1860,8 @@ static function install(Migration $migration) {
`is_active` tinyint(1) NOT NULL default '0',
`name` varchar(255) collate utf8_unicode_ci default NULL,
`comment` text NULL,
`date_mod` datetime NOT NULL default '0000-00-00 00:00:00',
`date_mod` datetime DEFAULT NULL,
`date_creation` datetime DEFAULT NULL,
`use_global_search` tinyint(1) NOT NULL default '0',
`use_unicity` tinyint(1) NOT NULL default '0',
`use_history` tinyint(1) NOT NULL default '0',
Expand Down Expand Up @@ -1881,15 +1896,18 @@ static function install(Migration $migration) {
$migration->addField($table, "use_projects", "bool");
$migration->addField($table, "use_notepad", "bool");
$migration->addField($table, "comment", "text");
$migration->addField($table, "date_mod", "datetime");
if (!$migration->addField($table, "date_mod", "datetime")) {
$migration->changeField($table, "date_mod", "date_mod", "datetime");
}
$migration->addField($table, "date_creation", "datetime");
$migration->addField($table, "linked_itemtypes", "text");
$migration->addField($table, "plugin_genericobject_typefamilies_id", "integer");
$migration->addField($table, "use_plugin_simcard", "bool");
$migration->migrationOneTable($table);

// Migrate notepad data
$allGenericObjectTypes = PluginGenericobjectType::getTypes(true);

$notepad = new Notepad();
foreach ($allGenericObjectTypes as $genericObjectType => $genericObjectData) {
$genericObjectTypeInstance = new $genericObjectType();
Expand All @@ -1916,7 +1934,7 @@ static function install(Migration $migration) {
$migration->dropField($genericObjectTypeInstance->getTable(), "notepad");
$migration->migrationOneTable($genericObjectTypeInstance->getTable());
}

//Displayprefs
$prefs = array(10 => 6, 9 => 5, 8 => 4, 7 => 3, 6 => 2, 2 => 1, 4 => 1, 11 => 7, 12 => 8,
14 => 10, 15 => 11);
Expand Down
Loading

0 comments on commit 62ec571

Please sign in to comment.