CommonDBTM::getNameID PHP Method

getNameID() public method

Get the name of the object with the ID if the config is set Should Not be overloaded (overload getName() instead)
See also: CommonDBTM::getName
public getNameID ( $options = [] ) : String:
$options array of options - comments : boolean / display comments - complete : boolean / display completename instead of name - additional : boolean / display aditionals information - forceid : boolean override config and display item's ID (false by default)
return String:
    function getNameID($options = array())
    {
        global $CFG_GLPI;
        $p['forceid'] = false;
        $p['comments'] = false;
        if (is_array($options)) {
            foreach ($options as $key => $val) {
                $p[$key] = $val;
            }
        }
        if ($p['forceid'] || $_SESSION['glpiis_ids_visible']) {
            $addcomment = $p['comments'];
            // unset comment
            $p['comments'] = false;
            $name = $this->getName($p);
            //TRANS: %1$s is a name, %2$s is ID
            $name = sprintf(__('%1$s (%2$s)'), $name, $this->getField('id'));
            if ($addcomment) {
                $comment = $this->getComments();
                if (!empty($comment)) {
                    $name = sprintf(__('%1$s - %2$s'), $name, $comment);
                }
            }
            return $name;
        }
        return $this->getName($options);
    }

Usage Example

 /**
  * Get the history name of second item
  *
  * @since version 0.84
  *
  * @param $item the other item (ie. : $item1)
  * @param $case : can be overwrite by object
  *              - 'add' when this CommonDBRelation is added (to and item)
  *              - 'update item previous' transfert : this is removed from the old item
  *              - 'update item next' transfert : this is added to the new item
  *              - 'delete' when this CommonDBRelation is remove (from an item)
  *
  * @return (string) the name of the entry for the database (ie. : correctly slashed)
  **/
 function getHistoryNameForItem2(CommonDBTM $item, $case)
 {
     return $item->getNameID(array('forceid' => true, 'additional' => true));
 }
CommonDBTM