.
* ---------------------------------------------------------------------
*/
if (!defined('GLPI_ROOT')) {
die("Sorry. You can't access this file directly");
}
/**
* DocumentType Class
**/
class DocumentType extends CommonDropdown {
static $rightname = 'typedoc';
function getAdditionalFields() {
return [['name' => 'icon',
'label' => __('Icon'),
'type' => 'icon'],
['name' => 'is_uploadable',
'label' => __('Authorized upload'),
'type' => 'bool'],
['name' => 'ext',
'label' => __('Extension'),
'type' => 'text',
'comment' => __('May be a regular expression')],
['name' => 'mime',
'label' => __('MIME type'),
'type' => 'text']];
}
static function getTypeName($nb = 0) {
return _n('Document type', 'Document types', $nb);
}
/**
* Get search function for the class
*
* @return array of search option
**/
function rawSearchOptions() {
$tab = parent::rawSearchOptions();
$tab[] = [
'id' => '3',
'table' => $this->getTable(),
'field' => 'ext',
'name' => __('Extension'),
'datatype' => 'string',
'autocomplete' => true,
];
$tab[] = [
'id' => '6',
'table' => $this->getTable(),
'field' => 'icon',
'name' => __('Icon'),
'massiveaction' => false,
'datatype' => 'specific'
];
$tab[] = [
'id' => '4',
'table' => $this->getTable(),
'field' => 'mime',
'name' => __('MIME type'),
'datatype' => 'string',
'autocomplete' => true,
];
$tab[] = [
'id' => '5',
'table' => $this->getTable(),
'field' => 'is_uploadable',
'name' => __('Authorized upload'),
'datatype' => 'bool'
];
return $tab;
}
static function getSpecificValueToDisplay($field, $values, array $options = []) {
global $CFG_GLPI;
if (!is_array($values)) {
$values = [$field => $values];
}
switch ($field) {
case 'icon' :
if (!empty($values[$field])) {
return "
";
}
}
return parent::getSpecificValueToDisplay($field, $values, $options);
}
/**
* @since 0.84
*
* @param $field
* @param $name (default '')
* @param $values (default '')
* @param $options array
**/
static function getSpecificValueToSelect($field, $name = '', $values = '', array $options = []) {
if (!is_array($values)) {
$values = [$field => $values];
}
$options['display'] = false;
switch ($field) {
case 'icon' :
return Dropdown::dropdownIcons($name, $values[$field],
GLPI_ROOT."/pics/icones", false);
}
return parent::getSpecificValueToSelect($field, $name, $values, $options);
}
/**
* @since 0.85
*
* @param array $options list of options with theses possible keys:
* - bool 'display', echo the generated html or return it
**/
static function showAvailableTypesLink($options = []) {
global $CFG_GLPI;
$p['display'] = true;
//merge default options with options parameter
$p = array_merge($p, $options);
$display = " ";
$display .= "";
$display .= "".__s('Help').">";
$display .= "";
$display .= Ajax::createIframeModalWindow('documenttypelist',
$CFG_GLPI["root_doc"]."/front/documenttype.list.php",
['title' => static::getTypeName(Session::getPluralNumber()),
'display' => false]);
if ($p['display']) {
echo $display;
} else {
return $display;
}
}
}