diff --git a/module/ai/control.php b/module/ai/control.php
index 6fbf320d4f..34522200dd 100644
--- a/module/ai/control.php
+++ b/module/ai/control.php
@@ -209,6 +209,21 @@ class ai extends control
$this->display();
}
+ /**
+ * Delete a prompt.
+ *
+ * @param int $prompt
+ * @access public
+ * @return void
+ */
+ public function promptDelete($prompt)
+ {
+ $result = $this->ai->deletePrompt($prompt);
+
+ if(dao::isError() || $result === false) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
+ return $this->send(array('result' => 'success'));
+ }
+
/**
* Edit role of prompt, prompt editing step 2.
*
diff --git a/module/ai/model.php b/module/ai/model.php
index 91aa85a7c4..9225205f73 100644
--- a/module/ai/model.php
+++ b/module/ai/model.php
@@ -374,7 +374,7 @@ class aiModel extends model
public function getPrompts($module = '', $status = '', $order = 'id_desc', $pager = null)
{
$prompts = $this->dao->select('*')->from(TABLE_PROMPT)
- ->where('1=1')
+ ->where('deleted')->eq(0)
->beginIF(!empty($module))->andWhere('module')->eq($module)->fi()
->beginIF(!empty($status))->andWhere('status')->eq($status)->fi()
->orderBy($order)
@@ -484,6 +484,29 @@ class aiModel extends model
return true;
}
+ /**
+ * Delete a prompt.
+ *
+ * @param int $id
+ * @access public
+ * @return bool
+ */
+ public function deletePrompt($id)
+ {
+ $prompt = $this->getPromptById($id);
+ if(empty($prompt)) return false;
+
+ $this->dao->update(TABLE_PROMPT)
+ ->set('deleted')->eq(1)
+ ->where('id')->eq($id)
+ ->exec();
+ if(dao::isError()) return false;
+
+ $this->loadModel('action')->create('prompt', $id, 'deleted');
+
+ return true;
+ }
+
/**
* Toggle prompt status.
*
@@ -688,10 +711,8 @@ class aiModel extends model
break;
case 'release':
if(isset($sourceGroups['release'])) $object->release = $this->loadModel('release')->getById($objectId);
- $stories = array_filter(explode(',', $object->release->stories));
- if(isset($sourceGroups['stories'])) $object->stories = $this->loadModel('story')->getByList($stories);
- $bugs = array_filter(explode(',', $object->release->bugs));
- if(isset($sourceGroups['bugs'])) $object->bugs = $this->loadModel('bug')->getByList($bugs);
+ if(isset($sourceGroups['stories'])) $object->stories = $this->loadModel('story')->getByList(array_filter(explode(',', $object->release->stories)));
+ if(isset($sourceGroups['bugs'])) $object->bugs = $this->loadModel('bug')->getByList(array_filter(explode(',', $object->release->bugs)));
break;
case 'productplan':
if(isset($sourceGroups['productplan'])) $object->productplan = $this->loadModel('productplan')->getByID($objectId);
@@ -702,7 +723,7 @@ class aiModel extends model
if(isset($sourceGroups['task'])) $object->task = $this->loadModel('task')->getById($objectId);
break;
case 'case':
- if(isset($sourceGroups['case'])) $object->case = $this->loadModel('testcase')->getById($objectId);
+ if(isset($sourceGroups['case'])) $object->case = $this->loadModel('testcase')->getById($objectId);
if(isset($sourceGroups['steps'])) $object->steps = $object->case->steps;
break;
case 'bug':
@@ -1015,7 +1036,8 @@ class aiModel extends model
public function getPromptsForUser($module)
{
return $this->dao->select('*')->from(TABLE_PROMPT)
- ->where('module')->eq($module)
+ ->where('deleted')->eq(0)
+ ->andWhere('module')->eq($module)
->andWhere('status', true)->eq('active')->orWhere('createdBy')->eq($this->app->user->account)->markRight(1)
->orderBy('id_desc')
->fetchAll();
diff --git a/module/ai/view/promptview.html.php b/module/ai/view/promptview.html.php
index 108dc30c8b..7560913ed8 100644
--- a/module/ai/view/promptview.html.php
+++ b/module/ai/view/promptview.html.php
@@ -64,14 +64,16 @@
' . $lang->goback, '', "class='btn'");?>
-
- status == 'draft') echo html::a(helper::createLink('ai', 'promptassignrole', "prompt=$prompt->id"), '
' . $lang->ai->prompts->action->design, '', "class='btn'");?>
- status == 'draft' && $this->ai->isExecutable($prompt)) echo html::a($this->ai->getTestingLocation($prompt), '
' . $lang->ai->prompts->action->test, '', "class='btn'");?>
- status == 'draft' && $this->ai->isExecutable($prompt)) echo html::a(helper::createLink('ai', 'promptpublish', "id={$prompt->id}"), '
' . $lang->ai->prompts->action->publish, '', "class='btn'");?>
- status == 'active') echo html::a(helper::createLink('ai', 'promptunpublish', "id={$prompt->id}"), '
' . $lang->ai->prompts->action->unpublish, '', "class='btn' id='unpublish-btn'");?>
-
- id"), '
', '', "class='btn' title='{$lang->ai->prompts->action->edit}'");?>
- ', '', "class='btn deleter' title='{$lang->ai->prompts->action->delete}'");?>
+ deleted):?>
+
+ status == 'draft') echo html::a(helper::createLink('ai', 'promptassignrole', "prompt=$prompt->id"), '
' . $lang->ai->prompts->action->design, '', "class='btn'");?>
+ status == 'draft' && $this->ai->isExecutable($prompt)) echo html::a($this->ai->getTestingLocation($prompt), '
' . $lang->ai->prompts->action->test, '', "class='btn'");?>
+ status == 'draft' && $this->ai->isExecutable($prompt)) echo html::a(helper::createLink('ai', 'promptpublish', "id={$prompt->id}"), '
' . $lang->ai->prompts->action->publish, '', "class='btn'");?>
+ status == 'active') echo html::a(helper::createLink('ai', 'promptunpublish', "id={$prompt->id}"), '
' . $lang->ai->prompts->action->unpublish, '', "class='btn' id='unpublish-btn'");?>
+
+ id"), '
', '', "class='btn' title='{$lang->ai->prompts->action->edit}'");?>
+ id"), '
', '', "class='btn deleter' title='{$lang->ai->prompts->action->delete}'");?>
+