Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ function plugin_news_install()
`date_end` TIMESTAMP NULL DEFAULT NULL,
`type` INT NOT NULL,
`is_deleted` TINYINT NOT NULL DEFAULT 0,
`is_displayed_onlogin` TINYINT NOT NULL,
`is_displayed_oncentral` TINYINT NOT NULL,
`is_displayed_onlogin` TINYINT NOT NULL,
`is_displayed_oncentral` TINYINT NOT NULL,
`is_displayed_onservicecatalog` TINYINT NOT NULL DEFAULT 0,
`display_dates` TINYINT NOT NULL DEFAULT 1,
`background_color` VARCHAR(255) NOT NULL DEFAULT '$white',
`text_color` VARCHAR(255) NOT NULL DEFAULT '$dark',
Expand Down Expand Up @@ -217,6 +218,11 @@ function plugin_news_install()
('PluginNewsAlert', 6, 4, 0)");
}

// add displayed on service catalog flag
if (!$DB->fieldExists($alert_table, 'is_displayed_onservicecatalog')) {
$migration->addField($alert_table, 'is_displayed_onservicecatalog', 'bool');
}

// add displayed on central flag
if (!$DB->fieldExists($alert_table, 'is_displayed_oncentral')) {
$migration->addField(
Expand Down
66 changes: 45 additions & 21 deletions inc/alert.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,15 @@ public function rawSearchOptions()
'massiveaction' => false,
];

$tab[] = [
'id' => 11,
'table' => $this->getTable(),
'field' => 'is_displayed_onservicecatalog',
'name' => __s('Show on service catalog page', 'news'),
'datatype' => 'bool',
'massiveaction' => false,
];

$tab[] = [
'id' => 10,
'table' => $this->getTable(),
Expand Down Expand Up @@ -248,11 +257,12 @@ public static function findAllToNotify($params = [])
/** @var DBmysql $DB */
global $DB;

$p['show_only_login_alerts'] = false;
$p['show_only_central_alerts'] = false;
$p['show_hidden_alerts'] = false;
$p['show_only_helpdesk_alerts'] = false;
$p['entities_id'] = false;
$p['show_only_login_alerts'] = false;
$p['show_only_central_alerts'] = false;
$p['show_hidden_alerts'] = false;
$p['show_only_helpdesk_alerts'] = false;
$p['show_only_service_catalog_alerts'] = false;
$p['entities_id'] = false;
foreach ($params as $key => $value) {
$p[$key] = $value;
}
Expand All @@ -277,12 +287,13 @@ public static function findAllToNotify($params = [])
}

// filters for query
$targets_sql = [];
$login_sql = [];
$login_show_hidden_sql = ["{$utable}.id" => null];
$entity_sql = [];
$show_helpdesk_sql = [];
$show_central_sql = [];
$targets_sql = [];
$login_sql = [];
$login_show_hidden_sql = ["{$utable}.id" => null];
$entity_sql = [];
$show_helpdesk_sql = [];
$show_central_sql = [];
$show_service_catalog_sql = [];
if (isset($_SESSION['glpiID']) && isset($_SESSION['glpiactiveprofile']['id'])) {
$targets_sql = [
'AND' => [
Expand Down Expand Up @@ -332,6 +343,9 @@ public static function findAllToNotify($params = [])
if ($p['show_only_helpdesk_alerts']) {
$show_helpdesk_sql = ["{$table}.is_displayed_onhelpdesk" => 1];
}
if ($p['show_only_service_catalog_alerts']) {
$show_service_catalog_sql = ["{$table}.is_displayed_onservicecatalog" => 1];
}
if (!$p['show_only_login_alerts']) {
$entity_sql = getEntitiesRestrictCriteria($table, '', $p['entities_id'], true);
}
Expand Down Expand Up @@ -394,6 +408,9 @@ public static function findAllToNotify($params = [])
if ($show_helpdesk_sql !== []) {
$criteria['WHERE'][] = $show_helpdesk_sql;
}
if ($show_service_catalog_sql !== []) {
$criteria['WHERE'][] = $show_service_catalog_sql;
}
$it = $DB->request($criteria);
if (count($it) === 0) {
return false;
Expand Down Expand Up @@ -523,16 +540,22 @@ public static function displayOnTicket()
echo '</th></tr>';
}

public static function displayOnServiceCatalog()
{
self::displayAlerts(['show_only_service_catalog_alerts' => true]);
}

public static function displayAlerts($params = [])
{
/** @var array $CFG_GLPI */
global $CFG_GLPI;

$p['show_only_login_alerts'] = false;
$p['show_only_central_alerts'] = false;
$p['show_hidden_alerts'] = false;
$p['show_only_helpdesk_alerts'] = false;
$p['entities_id'] = false;
$p['show_only_login_alerts'] = false;
$p['show_only_central_alerts'] = false;
$p['show_hidden_alerts'] = false;
$p['show_only_helpdesk_alerts'] = false;
$p['show_only_service_catalog_alerts'] = false;
$p['entities_id'] = false;
foreach ($params as $key => $value) {
$p[$key] = $value;
}
Expand All @@ -545,11 +568,12 @@ public static function displayAlerts($params = [])
}

$hidden_params = [
'show_hidden_alerts' => true,
'show_only_login_alerts' => false,
'show_only_central_alerts' => $p['show_only_central_alerts'],
'show_only_helpdesk_alerts' => $p['show_only_helpdesk_alerts'],
'entities_id' => $p['entities_id'],
'show_hidden_alerts' => true,
'show_only_login_alerts' => false,
'show_only_central_alerts' => $p['show_only_central_alerts'],
'show_only_helpdesk_alerts' => $p['show_only_helpdesk_alerts'],
'show_only_service_catalog_alerts' => $p['show_only_service_catalog_alerts'],
'entities_id' => $p['entities_id'],
];

if (
Expand Down
3 changes: 3 additions & 0 deletions setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ function plugin_init_news()
$PLUGIN_HOOKS['display_central']['news'] = [
'PluginNewsAlert', 'displayOnCentral',
];
$PLUGIN_HOOKS['display_service_catalog']['news'] = [
'PluginNewsAlert', 'displayOnServiceCatalog',
];
$PLUGIN_HOOKS['pre_item_list']['news'] = ['PluginNewsAlert', 'preItemList'];

$PLUGIN_HOOKS['pre_item_form']['news'] = ['PluginNewsAlert', 'preItemForm'];
Expand Down
7 changes: 4 additions & 3 deletions templates/alert_form.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,10 @@
{{ news_fields.checkboxesField(
"show_on_pages",
{
'is_displayed_oncentral' : __('Central page', 'news'),
'is_displayed_onlogin' : __('Login page', 'news'),
'is_displayed_onhelpdesk': __('Helpdesk page', 'news'),
'is_displayed_oncentral' : __('Central page', 'news'),
'is_displayed_onlogin' : __('Login page', 'news'),
'is_displayed_onhelpdesk' : __('Helpdesk page', 'news'),
'is_displayed_onservicecatalog' : __('Service catalog page', 'news'),
},
item.fields,
__('Show on pages', 'news'),
Expand Down