Skip to content

Commit ce54c1c

Browse files
committed
Migrate to Namespace
1 parent 67a90f9 commit ce54c1c

26 files changed

Lines changed: 1179 additions & 991 deletions

ajax/satisfaction.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/*
34
* @version $Id: HEADER 15930 2011-10-30 15:47:55Z tsmr $
45
-------------------------------------------------------------------------
@@ -30,6 +31,6 @@
3031

3132
if (isset($_POST['action_default_value'])) {
3233
Dropdown::showNumber('default_value', ['max' => $_POST['default_value'],
33-
'min' => 1,
34-
'value' => $_POST['value']]);
34+
'min' => 1,
35+
'value' => $_POST['value']]);
3536
}

ajax/surveytranslation.form.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
--------------------------------------------------------------------------
2828
*/
2929

30+
use GlpiPlugin\Satisfaction\SurveyTranslation;
31+
3032
Session::checkRight('plugin_satisfaction', UPDATE);
3133

3234
if (!isset($_POST['survey_id']) || !isset($_POST['action'])) {
@@ -36,7 +38,7 @@
3638
global $CFG_GLPI;
3739
$redirection = PLUGINSATISFACTION_WEBDIR."/front/survey.form.php?id=";
3840

39-
$translation = new PluginSatisfactionSurveyTranslation();
41+
$translation = new SurveyTranslation();
4042

4143
switch ($_POST['action']) {
4244
case 'GET':

ajax/viewsubitem_reminder.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,28 @@
2828
*/
2929

3030

31+
use Glpi\Exception\Http\NotFoundHttpException;
32+
use GlpiPlugin\Satisfaction\SurveyReminder;
33+
3134
header("Content-Type: text/html; charset=UTF-8");
3235
Html::header_nocache();
3336

3437
Session::checkLoginUser();
3538
Session::checkRight('plugin_satisfaction', UPDATE);
3639

3740
if (!isset($_POST['type'])) {
38-
throw new \Glpi\Exception\Http\NotFoundHttpException();
41+
throw new NotFoundHttpException();
3942
}
4043
if (!isset($_POST['parenttype'])) {
41-
throw new \Glpi\Exception\Http\NotFoundHttpException();
44+
throw new NotFoundHttpException();
4245
}
4346

4447
if (($item = getItemForItemtype($_POST['type']))
4548
&& ($parent = getItemForItemtype($_POST['parenttype']))) {
4649
if (isset($_POST[$parent->getForeignKeyField()])
4750
&& isset($_POST["id"])
4851
&& $parent->getFromDB($_POST[$parent->getForeignKeyField()])) {
49-
$reminderName = PluginSatisfactionSurveyReminder::PREDEFINED_REMINDER_OPTION_NAME;
52+
$reminderName = SurveyReminder::PREDEFINED_REMINDER_OPTION_NAME;
5053

5154
$options = [
5255
'parent' => $parent

front/survey.form.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,16 @@
2828
*/
2929

3030

31+
use GlpiPlugin\Satisfaction\Menu;
32+
use GlpiPlugin\Satisfaction\Survey;
3133

3234
Session::checkLoginUser();
3335

3436
if (!isset($_GET["id"])) {
3537
$_GET["id"] = "";
3638
}
3739

38-
$survey = new PluginSatisfactionSurvey();
40+
$survey = new Survey();
3941

4042
if (isset($_POST["add"])) {
4143
$survey->check(-1, CREATE, $_POST);
@@ -52,7 +54,7 @@
5254
} else {
5355
$survey->checkGlobal(READ);
5456

55-
Html::header(PluginSatisfactionSurvey::getTypeName(2), '', "admin", "pluginsatisfactionmenu", "survey");
57+
Html::header(Survey::getTypeName(2), '', "admin", Menu::class, "survey");
5658

5759
$survey->display(['id' => $_GET['id']]);
5860

front/survey.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,16 @@
2929

3030

3131
use Glpi\Exception\Http\AccessDeniedHttpException;
32+
use GlpiPlugin\Satisfaction\Menu;
33+
use GlpiPlugin\Satisfaction\Survey;
3234

33-
Html::header(PluginSatisfactionSurvey::getTypeName(2), '', "admin", "pluginsatisfactionmenu");
35+
Html::header(Survey::getTypeName(2), '', "admin", Menu::class);
3436

35-
$satisfaction = new PluginSatisfactionSurvey();
37+
$satisfaction = new Survey();
3638
$satisfaction->checkGlobal(READ);
3739

3840
if ($satisfaction->canView()) {
39-
Search::show('PluginSatisfactionSurvey');
41+
Search::show(Survey::class);
4042
} else {
4143
throw new AccessDeniedHttpException();
4244
}

front/surveyquestion.form.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@
2929

3030

3131
use Glpi\Exception\Http\BadRequestHttpException;
32+
use GlpiPlugin\Satisfaction\SurveyQuestion;
3233

3334
Session::checkLoginUser();
3435

35-
$question = new PluginSatisfactionSurveyQuestion();
36+
$question = new SurveyQuestion();
3637

3738
if (isset($_POST["add"])) {
3839
$question->check(-1, CREATE, $_POST);

front/surveyreminder.form.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@
2929

3030

3131
use Glpi\Exception\Http\BadRequestHttpException;
32+
use GlpiPlugin\Satisfaction\SurveyReminder;
3233

3334
Session::checkLoginUser();
3435

35-
$reminder = new PluginSatisfactionSurveyReminder();
36+
$reminder = new SurveyReminder();
3637

3738
if (isset($_POST["add"])) {
3839
$input = $_POST;

front/surveytranslation.form.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,15 @@
2828
*/
2929

3030

31+
use Glpi\Exception\Http\NotFoundHttpException;
32+
use GlpiPlugin\Satisfaction\SurveyTranslation;
33+
3134
if (!isset($_POST['survey_id']) || !isset($_POST['action'])) {
32-
throw new \Glpi\Exception\Http\NotFoundHttpException();
35+
throw new NotFoundHttpException();
3336
}
3437

3538
$redirection = PLUGINSATISFACTION_WEBDIR."/front/survey.form.php?id=";
36-
$translation = new PluginSatisfactionSurveyTranslation();
39+
$translation = new SurveyTranslation();
3740
switch ($_POST['action']) {
3841
case 'NEW':
3942
$translation->newSurveyTranslation($_POST);

hook.php

Lines changed: 121 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/*
34
* @version $Id: HEADER 15930 2011-10-30 15:47:55Z tsmr $
45
-------------------------------------------------------------------------
@@ -27,47 +28,126 @@
2728
--------------------------------------------------------------------------
2829
*/
2930

31+
use GlpiPlugin\Satisfaction\Menu;
32+
use GlpiPlugin\Satisfaction\NotificationTargetTicket;
33+
use GlpiPlugin\Satisfaction\Profile;
34+
use GlpiPlugin\Satisfaction\Reminder;
35+
use GlpiPlugin\Satisfaction\Survey;
36+
3037
/**
3138
* @return bool
3239
*/
3340
function plugin_satisfaction_install()
3441
{
3542
global $DB;
3643

37-
include_once(Plugin::getPhpDir('satisfaction')."/inc/profile.class.php");
38-
include_once(Plugin::getPhpDir('satisfaction')."/inc/notificationtargetticket.class.php");
39-
4044
if (!$DB->tableExists("glpi_plugin_satisfaction_surveys")) {
41-
$DB->runFile(Plugin::getPhpDir('satisfaction')."/install/sql/empty-1.6.0.sql");
45+
$DB->runFile(Plugin::getPhpDir('satisfaction') . "/install/sql/empty-1.6.0.sql");
4246
} else {
4347
if (!$DB->fieldExists("glpi_plugin_satisfaction_surveyquestions", "type")) {
44-
$DB->runFile(Plugin::getPhpDir('satisfaction')."/install/sql/update-1.1.0.sql");
48+
$DB->runFile(Plugin::getPhpDir('satisfaction') . "/install/sql/update-1.1.0.sql");
4549
}
46-
//version 1.2.1
50+
//version 1.2.1
4751
if (!$DB->fieldExists("glpi_plugin_satisfaction_surveyquestions", "default_value")) {
48-
$DB->runFile(Plugin::getPhpDir('satisfaction')."/install/sql/update-1.2.2.sql");
52+
$DB->runFile(Plugin::getPhpDir('satisfaction') . "/install/sql/update-1.2.2.sql");
4953
}
50-
//version 1.4.1
54+
//version 1.4.1
5155
if (!$DB->tableExists("glpi_plugin_satisfaction_surveytranslations")) {
52-
$DB->runFile(Plugin::getPhpDir('satisfaction')."/install/sql/update-1.4.1.sql");
56+
$DB->runFile(Plugin::getPhpDir('satisfaction') . "/install/sql/update-1.4.1.sql");
5357
}
5458

55-
//version 1.4.3
59+
//version 1.4.3
5660
if (!$DB->tableExists("glpi_plugin_satisfaction_surveyreminders")) {
57-
$DB->runFile(Plugin::getPhpDir('satisfaction')."/install/sql/update-1.4.3.sql");
61+
$DB->runFile(Plugin::getPhpDir('satisfaction') . "/install/sql/update-1.4.3.sql");
5862
}
5963

60-
//version 1.4.5
64+
//version 1.4.5
6165
if (!$DB->fieldExists("glpi_plugin_satisfaction_surveys", "reminders_days")) {
62-
$DB->runFile(Plugin::getPhpDir('satisfaction')."/install/sql/update-1.4.5.sql");
66+
$DB->runFile(Plugin::getPhpDir('satisfaction') . "/install/sql/update-1.4.5.sql");
67+
}
68+
69+
//version 1.7.1
70+
$DB->runFile(Plugin::getPhpDir('satisfaction') . "/install/sql/update-1.7.1.sql");
71+
72+
}
73+
74+
//DisplayPreferences Migration
75+
$classes = ['PluginSatisfactionSurvey' => Survey::class];
76+
77+
foreach ($classes as $old => $new) {
78+
$displayusers = $DB->request([
79+
'SELECT' => [
80+
'users_id'
81+
],
82+
'DISTINCT' => true,
83+
'FROM' => 'glpi_displaypreferences',
84+
'WHERE' => [
85+
'itemtype' => $old,
86+
],
87+
]);
88+
89+
if (count($displayusers) > 0) {
90+
foreach ($displayusers as $displayuser) {
91+
$iterator = $DB->request([
92+
'SELECT' => [
93+
'num',
94+
'id'
95+
],
96+
'FROM' => 'glpi_displaypreferences',
97+
'WHERE' => [
98+
'itemtype' => $old,
99+
'users_id' => $displayuser['users_id'],
100+
'interface' => 'central'
101+
],
102+
]);
103+
104+
if (count($iterator) > 0) {
105+
foreach ($iterator as $data) {
106+
$iterator2 = $DB->request([
107+
'SELECT' => [
108+
'id'
109+
],
110+
'FROM' => 'glpi_displaypreferences',
111+
'WHERE' => [
112+
'itemtype' => $new,
113+
'users_id' => $displayuser['users_id'],
114+
'num' => $data['num'],
115+
'interface' => 'central'
116+
],
117+
]);
118+
if (count($iterator2) > 0) {
119+
foreach ($iterator2 as $dataid) {
120+
$query = $DB->buildDelete(
121+
'glpi_displaypreferences',
122+
[
123+
'id' => $dataid['id'],
124+
]
125+
);
126+
$DB->doQuery($query);
127+
}
128+
} else {
129+
$query = $DB->buildUpdate(
130+
'glpi_displaypreferences',
131+
[
132+
'itemtype' => $new,
133+
],
134+
[
135+
'id' => $data['id'],
136+
]
137+
);
138+
$DB->doQuery($query);
139+
}
140+
}
141+
}
142+
}
63143
}
64144
}
65145

66-
PluginSatisfactionNotificationTargetTicket::install();
67-
PluginSatisfactionProfile::initProfile();
68-
PluginSatisfactionProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']);
146+
NotificationTargetTicket::install();
147+
Profile::initProfile();
148+
Profile::createFirstAccess($_SESSION['glpiactiveprofile']['id']);
69149

70-
CronTask::Register(PluginSatisfactionReminder::class, PluginSatisfactionReminder::CRON_TASK_NAME, DAY_TIMESTAMP);
150+
CronTask::Register(Reminder::class, Reminder::CRON_TASK_NAME, DAY_TIMESTAMP);
71151
return true;
72152
}
73153

@@ -78,42 +158,46 @@ function plugin_satisfaction_uninstall()
78158
{
79159
global $DB;
80160

81-
include_once(Plugin::getPhpDir('satisfaction')."/inc/profile.class.php");
82-
include_once(Plugin::getPhpDir('satisfaction')."/inc/menu.class.php");
83-
include_once(Plugin::getPhpDir('satisfaction')."/inc/notificationtargetticket.class.php");
84-
85161
$tables = [
86-
"glpi_plugin_satisfaction_surveys",
87-
"glpi_plugin_satisfaction_surveyquestions",
88-
"glpi_plugin_satisfaction_surveyanswers",
89-
"glpi_plugin_satisfaction_surveyreminders",
90-
"glpi_plugin_satisfaction_surveytranslations",
91-
"glpi_plugin_satisfaction_reminders"
162+
"glpi_plugin_satisfaction_surveys",
163+
"glpi_plugin_satisfaction_surveyquestions",
164+
"glpi_plugin_satisfaction_surveyanswers",
165+
"glpi_plugin_satisfaction_surveyreminders",
166+
"glpi_plugin_satisfaction_surveytranslations",
167+
"glpi_plugin_satisfaction_reminders",
92168
];
93169

94170
foreach ($tables as $table) {
95171
$DB->dropTable($table, true);
96172
}
97173

98-
$tables_glpi = ["glpi_logs"];
99-
100-
foreach ($tables_glpi as $table_glpi) {
101-
$DB->delete($table_glpi, ['itemtype' => ['LIKE' => 'PluginSatisfaction%']]);
174+
$itemtypes = ['Alert',
175+
'DisplayPreference',
176+
'Document_Item',
177+
'ImpactItem',
178+
'Item_Ticket',
179+
'Link_Itemtype',
180+
'Notepad',
181+
'SavedSearch',
182+
'DropdownTranslation'];
183+
foreach ($itemtypes as $itemtype) {
184+
$item = new $itemtype();
185+
$item->deleteByCriteria(['itemtype' => Survey::class]);
102186
}
103187

104188

105-
//Delete rights associated with the plugin
189+
//Delete rights associated with the plugin
106190
$profileRight = new ProfileRight();
107-
foreach (PluginSatisfactionProfile::getAllRights() as $right) {
191+
foreach (Profile::getAllRights() as $right) {
108192
$profileRight->deleteByCriteria(['name' => $right['field']]);
109193
}
110-
PluginSatisfactionProfile::removeRightsFromSession();
194+
Profile::removeRightsFromSession();
111195

112-
PluginSatisfactionMenu::removeRightsFromSession();
196+
Menu::removeRightsFromSession();
113197

114-
PluginSatisfactionNotificationTargetTicket::uninstall();
198+
NotificationTargetTicket::uninstall();
115199

116-
CronTask::Register(PluginSatisfactionReminder::class, PluginSatisfactionReminder::CRON_TASK_NAME, DAY_TIMESTAMP);
200+
CronTask::Register(Reminder::class, Reminder::CRON_TASK_NAME, DAY_TIMESTAMP);
117201

118202
return true;
119203
}

0 commit comments

Comments
 (0)