.
* ---------------------------------------------------------------------
*/
if (!defined('GLPI_ROOT')) {
die("Sorry. You can't access this file directly");
}
class SavedSearch_User extends CommonDBRelation {
public $auto_message_on_action = false;
static public $itemtype_1 = 'SavedSearch';
static public $items_id_1 = 'savedsearches_id';
static public $itemtype_2 = 'User';
static public $items_id_2 = 'users_id';
static function getSpecificValueToDisplay($field, $values, array $options = []) {
if (!is_array($values)) {
$values = [$field => $values];
}
switch ($field) {
case 'users_id':
if (!empty($values[$field])) {
return "" . __('Yes') . "";
} else {
return "" . __('No') . "";
}
break;
}
return parent::getSpecificValueToDisplay($field, $values, $options);
}
static function getSpecificValueToSelect($field, $name = '', $values = '', array $options = []) {
if (!is_array($values)) {
$values = [$field => $values];
}
$options['display'] = false;
switch ($field) {
case 'users_id':
$options['name'] = $name;
$options['value'] = $values[$field];
return Dropdown::showFromArray(
$options['name'],
[
'1' => __('Yes'),
'0' => __('No')
],
$options
);
}
return parent::getSpecificValueToSelect($field, $name, $values, $options);
}
function prepareInputForUpdate($input) {
return $this->can($input['id'], READ) ? $input : false;
}
/**
* Summary of getDefault
* @param mixed $users_id id of the user
* @param mixed $itemtype type of item
* @return array|boolean same output than SavedSearch::getParameters()
* @since 9.2
*/
static function getDefault($users_id, $itemtype) {
global $DB;
$iter = $DB->request(['SELECT' => 'savedsearches_id',
'FROM' => 'glpi_savedsearches_users',
'WHERE' => ['users_id' => $users_id,
'itemtype' => $itemtype]]);
if (count($iter)) {
$row = $iter->next();
// Load default bookmark for this $itemtype
$bookmark = new SavedSearch();
// Only get data for bookmarks
return $bookmark->getParameters($row['savedsearches_id']);
}
return false;
}
}