Skip to content

Commit f84b353

Browse files
committed
fix(form): forbid purge of a form when there are answers
Signed-off-by: btry <tbugier@teclib.com>
1 parent 576c891 commit f84b353

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

inc/form.class.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public static function canCreate() {
6060
* @return boolean True if he can read requests
6161
*/
6262
public static function canView() {
63-
return Session::haveRight("entity", UPDATE);
63+
return Session::haveRight('entity', UPDATE);
6464
}
6565

6666
/**
@@ -69,7 +69,19 @@ public static function canView() {
6969
* @return boolean True if he can read requests
7070
*/
7171
public static function canDelete() {
72-
return Session::haveRight("entity", UPDATE);
72+
return Session::haveRight('entity', UPDATE);
73+
}
74+
75+
public function canPurgeItem() {
76+
$DbUtil = new DbUtils();
77+
78+
$criteria = [
79+
PluginFormcreatorForm::getForeignKeyField() => $this->getID(),
80+
];
81+
if ($DbUtil->countElementsInTable(PluginFormcreatorForm_Answer::getTable(), $criteria) > 0) {
82+
return false;
83+
}
84+
return Session::haveRight('entity', UPDATE);
7385
}
7486

7587
/**

0 commit comments

Comments
 (0)