/** * Construct history for an item * * @param $item CommonDBTM object * @param $oldvalues array of old values updated * @param $values array of all values of the item * * @return boolean for success (at least 1 log entry added) **/ static function constructHistory(CommonDBTM $item, &$oldvalues, &$values) { if (!count($oldvalues)) { return false; } // needed to have $SEARCHOPTION list($real_type, $real_id) = $item->getLogTypeID(); $searchopt = Search::getOptions($real_type); if (!is_array($searchopt)) { return false; } $result = 0; // type for which getValueToDisplay() could be used (fully tested) $oktype = array('Entity'); foreach ($oldvalues as $key => $oldval) { $changes = array(); // Parsing $SEARCHOPTION to find changed field foreach ($searchopt as $key2 => $val2) { if (!is_array($val2)) { // skip sub-title continue; } // Linkfield or standard field not massive action enable if ($val2['linkfield'] == $key || $key == $val2['field'] && $val2['table'] == $item->getTable()) { $id_search_option = $key2; // Give ID of the $SEARCHOPTION if ($val2['table'] == $item->getTable()) { $changes = array($id_search_option, addslashes($oldval), $values[$key]); } else { // other cases ; link field -> get data from dropdown if ($val2["table"] != 'glpi_auth_tables') { $changes = array($id_search_option, addslashes(sprintf(__('%1$s (%2$s)'), Dropdown::getDropdownName($val2["table"], $oldval), $oldval)), addslashes(sprintf(__('%1$s (%2$s)'), Dropdown::getDropdownName($val2["table"], $values[$key]), $values[$key]))); } } break; } } if (count($changes)) { $result = self::history($real_id, $real_type, $changes); } } return $result; }