+ action: add new control methods: comment and editComment.
This commit is contained in:
+76
-40
@@ -229,32 +229,40 @@ class action extends control
|
||||
*/
|
||||
public function comment(string $objectType, int $objectID)
|
||||
{
|
||||
/* 当评论的是任务,需判断当前用户是否拥有任务的权限。 */
|
||||
/* When commenting on a task, you need to determine whether the current user has the permission of the task. */
|
||||
if(strtolower($objectType) == 'task')
|
||||
if(!empty($_POST))
|
||||
{
|
||||
$task = $this->loadModel('task')->getById($objectID);
|
||||
$executions = explode(',', $this->app->user->view->sprints);
|
||||
if(!in_array($task->execution, $executions)) return $this->send(array('result' => 'fail', 'message' => $this->lang->error->accessDenied));
|
||||
}
|
||||
/* 当评论的是用户故事,需判断当前用户是否有此用户故事的权限。 */
|
||||
/* When commenting on a story, you need to determine whether the current user has the permission of the story. */
|
||||
elseif(strtolower($objectType) == 'story')
|
||||
{
|
||||
$story = $this->loadModel('story')->getById($objectID);
|
||||
$executions = explode(',', $this->app->user->view->sprints);
|
||||
$products = explode(',', $this->app->user->view->products);
|
||||
if(!array_intersect(array_keys($story->executions), $executions) && !in_array($story->product, $products) && empty($story->lib)) return $this->send(array('result' => 'fail', 'message' => $this->lang->error->accessDenied));
|
||||
/* 当评论的是任务,需判断当前用户是否拥有任务的权限。 */
|
||||
/* When commenting on a task, you need to determine whether the current user has the permission of the task. */
|
||||
if(strtolower($objectType) == 'task')
|
||||
{
|
||||
$task = $this->loadModel('task')->getById($objectID);
|
||||
$executions = explode(',', $this->app->user->view->sprints);
|
||||
if(!in_array($task->execution, $executions)) return $this->send(array('result' => 'fail', 'message' => $this->lang->error->accessDenied));
|
||||
}
|
||||
/* 当评论的是用户故事,需判断当前用户是否有此用户故事的权限。 */
|
||||
/* When commenting on a story, you need to determine whether the current user has the permission of the story. */
|
||||
elseif(strtolower($objectType) == 'story')
|
||||
{
|
||||
$story = $this->loadModel('story')->getById($objectID);
|
||||
$executions = explode(',', $this->app->user->view->sprints);
|
||||
$products = explode(',', $this->app->user->view->products);
|
||||
if(!array_intersect(array_keys($story->executions), $executions) && !in_array($story->product, $products) && empty($story->lib)) return $this->send(array('result' => 'fail', 'message' => $this->lang->error->accessDenied));
|
||||
}
|
||||
|
||||
/* 获取评论内容并生成一条action数据。 */
|
||||
$commentData = form::data($this->config->action->form->comment)->get();
|
||||
$actionID = $this->action->create($objectType, $objectID, 'Commented', $commentData->comment);
|
||||
if(defined('RUN_MODE') && RUN_MODE == 'api') return $this->send(array('status' => 'success', 'data' => $actionID));
|
||||
|
||||
/* 用于ZIN的新UI。*/
|
||||
/* For new UI with ZIN. */
|
||||
return $this->send(array('status' => 'success', 'closeModal' => true, 'callback' => array('name' => 'zui.HistoryPanel.update', 'params' => array('objectType' => $objectType, 'objectID' => $objectID))));
|
||||
}
|
||||
|
||||
/* 获取评论内容并生成一条action数据。 */
|
||||
$commentData = form::data($this->config->action->form->comment)->get();
|
||||
$actionID = $this->action->create($objectType, $objectID, 'Commented', $commentData->comment);
|
||||
if(defined('RUN_MODE') && RUN_MODE == 'api') return $this->send(array('status' => 'success', 'data' => $actionID));
|
||||
|
||||
/* 用于ZIN的新UI。*/
|
||||
/* For new UI with ZIN. */
|
||||
return $this->send(array('status' => 'success', 'closeModal' => true, 'load' => true));
|
||||
$this->view->title = $this->lang->action->create;
|
||||
$this->view->objectType = $objectType;
|
||||
$this->view->objectID = $objectID;
|
||||
$this->display();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -267,26 +275,54 @@ class action extends control
|
||||
*/
|
||||
public function editComment(int $actionID)
|
||||
{
|
||||
/* 获取表单内的数据。 */
|
||||
/* Get form data. */
|
||||
$commentData = form::data($this->config->action->form->editComment)->get();
|
||||
$action = $this->action->getById($actionID);
|
||||
|
||||
$error = false;
|
||||
|
||||
/* 判断是否符合更新的条件。 */
|
||||
/* Determine whether the update conditions are met. */
|
||||
if(strlen(trim(strip_tags($commentData->lastComment, '<img>'))) != 0)
|
||||
if(!empty($_POST))
|
||||
{
|
||||
$error = $this->action->updateComment($actionID, $commentData->lastComment, $commentData->uid);
|
||||
/* 获取表单内的数据。 */
|
||||
/* Get form data. */
|
||||
$commentData = form::data($this->config->action->form->editComment)->get();
|
||||
|
||||
$error = false;
|
||||
|
||||
/* 判断是否符合更新的条件。 */
|
||||
/* Determine whether the update conditions are met. */
|
||||
if(strlen(trim(strip_tags($commentData->lastComment, '<img>'))) != 0)
|
||||
{
|
||||
$error = $this->action->updateComment($actionID, $commentData->lastComment, $commentData->uid);
|
||||
}
|
||||
|
||||
if(!$error)
|
||||
{
|
||||
/* 不符合更新条件,返回错误。 */
|
||||
/* The update conditions are not met and an error is returned. */
|
||||
dao::$errors['submit'][] = $this->lang->action->historyEdit;
|
||||
return $this->send(array('result' => 'fail', 'message' => dao::getError()));
|
||||
}
|
||||
|
||||
$action = $this->action->getById($actionID);
|
||||
return $this->send(array('status' => 'success', 'closeModal' => true, 'callback' => array('name' => 'zui.HistoryPanel.update', 'params' => array('objectType' => $action->objectType, 'objectID' => $action->objectID))));
|
||||
}
|
||||
|
||||
if(!$error)
|
||||
{
|
||||
/* 不符合更新条件,返回错误。 */
|
||||
/* The update conditions are not met and an error is returned. */
|
||||
dao::$errors['submit'][] = $this->lang->action->historyEdit;
|
||||
return $this->send(array('result' => 'fail', 'message' => dao::getError()));
|
||||
}
|
||||
return $this->send(array('result' => 'success', 'load' => true));
|
||||
$this->view->title = $this->lang->action->editComment;
|
||||
$this->view->actionID = $actionID;
|
||||
$this->view->comment = $this->action->formatActionComment($action->comment);
|
||||
$this->display();
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过 Ajax 获取操作记录列表。
|
||||
* Get action list by ajax.
|
||||
*
|
||||
* @param string $objectType
|
||||
* @param int $objectID
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function ajaxGetList(string $objectType, int $objectID)
|
||||
{
|
||||
$actions = $this->action->getList($objectType, $objectID);
|
||||
$actions = $this->action->buildActionList($actions);
|
||||
return $this->send($actions);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -630,6 +630,67 @@ class actionModel extends model
|
||||
return $actionDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化操作备注。
|
||||
* Format action comment.
|
||||
*
|
||||
* @param string $comment
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function formatActionComment($comment): string
|
||||
{
|
||||
if(str_contains($comment, '<pre class="prettyprint lang-html">'))
|
||||
{
|
||||
$before = explode('<pre class="prettyprint lang-html">', $comment);
|
||||
$after = explode('</pre>', $before[1]);
|
||||
$htmlCode = $after[0];
|
||||
return $before[0] . htmlspecialchars($htmlCode) . $after[1];
|
||||
}
|
||||
|
||||
return strip_tags($comment) === $comment
|
||||
? nl2br($comment)
|
||||
: $comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建操作记录列表,便于前端组件进行渲染。
|
||||
* Build action list for render by frontend component.
|
||||
*
|
||||
* @param array $actions
|
||||
* @param array $users
|
||||
* @param bool $commentEditable
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function buildActionList(array $actions, array $users = null, $commentEditable = true): array
|
||||
{
|
||||
if(empty($users)) $users = $this->loadModel('user')->getPairs('noletter');
|
||||
|
||||
$list = array();
|
||||
foreach($actions as $action)
|
||||
{
|
||||
$item = new stdClass();
|
||||
$item->id = $action->id;
|
||||
if(strlen(trim(($action->comment))) !== 0)
|
||||
{
|
||||
$item->comment = $this->formatActionComment($action->comment);
|
||||
$item->commentEditable = $commentEditable && end($actions) == $action && $action->actor == $this->app->user->account && common::hasPriv('action', 'editComment');
|
||||
}
|
||||
|
||||
if($action->action === 'assigned' || $action->action === 'toaudit') $action->extra = zget($users, $action->extra);
|
||||
$action->actor = zget($users, $action->actor);
|
||||
if(str_contains($action->actor, ':')) $action->actor = substr($action->actor, strpos($action->actor, ':') + 1);
|
||||
|
||||
if(!empty($action->history)) $item->historyChanges = $this->renderChanges($action->objectType, $action->history);
|
||||
|
||||
$item->content = $this->renderAction($action);
|
||||
|
||||
$list[] = $item;
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 打印一个对象的所有操作记录。
|
||||
* Print actions of an object.
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* The comment view file of action module of ZenTaoPMS.
|
||||
* @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
|
||||
* @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
|
||||
* @author Hao Sun <sunhao@easycorp.ltd>
|
||||
* @package action
|
||||
* @link https://www.zentao.net
|
||||
*/
|
||||
namespace zin;
|
||||
|
||||
$actions = array();
|
||||
$actions[] = 'submit';
|
||||
$actions[] = array('data-dismiss' => 'modal', 'text' => $lang->close);
|
||||
|
||||
set::title($title);
|
||||
|
||||
form
|
||||
(
|
||||
set::url('action', 'comment', "objectType=$objectType&objectID=$objectID"),
|
||||
setClass('comment-form'),
|
||||
editor
|
||||
(
|
||||
set::name('comment')
|
||||
),
|
||||
set::actions($actions)
|
||||
);
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* The comment view file of action module of ZenTaoPMS.
|
||||
* @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
|
||||
* @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
|
||||
* @author Hao Sun <sunhao@easycorp.ltd>
|
||||
* @package action
|
||||
* @link https://www.zentao.net
|
||||
*/
|
||||
namespace zin;
|
||||
|
||||
$actions = array();
|
||||
$actions[] = 'submit';
|
||||
$actions[] = isInModal() ? array('data-dismiss' => 'modal', 'text' => $lang->close) : 'cancel';
|
||||
|
||||
set::title($title);
|
||||
|
||||
form
|
||||
(
|
||||
set::url('action', 'editComment', "actionID=$actionID"),
|
||||
setClass('comment-form is-edit'),
|
||||
editor
|
||||
(
|
||||
set::name('lastComment'),
|
||||
html($comment)
|
||||
),
|
||||
set::actions($actions)
|
||||
);
|
||||
Reference in New Issue
Block a user