From d42cf9b277729feac0ad6e83d8d503c8f7c10f61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BB=94=E5=93=A5?= Date: Tue, 31 Oct 2017 07:31:28 +0800 Subject: [PATCH 1/6] * add score init --- db/update9.5.1.sql | 1 + module/custom/lang/zh-cn.php | 1 + module/custom/view/score.html.php | 42 +++++------ module/score/config.php | 74 +++++++++--------- module/score/control.php | 23 ++++++ module/score/lang/zh-cn.php | 19 ++++- module/score/model.php | 121 +++++++++++++++++++++++------- module/score/view/init.html.php | 64 ++++++++++++++++ www/js/my.full.js | 6 +- 9 files changed, 259 insertions(+), 92 deletions(-) create mode 100644 module/score/view/init.html.php diff --git a/db/update9.5.1.sql b/db/update9.5.1.sql index 7223eb3bf6..1fbe58313e 100644 --- a/db/update9.5.1.sql +++ b/db/update9.5.1.sql @@ -88,6 +88,7 @@ CREATE TABLE `zt_score` ( `score` decimal(12,1) NOT NULL DEFAULT '0.0', `after` decimal(12,1) NOT NULL DEFAULT '0.0', `time` datetime NOT NULL, + `objectID` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), KEY `account` (`account`), KEY `model` (`model`), diff --git a/module/custom/lang/zh-cn.php b/module/custom/lang/zh-cn.php index 4c9205a2c6..e7470b42cf 100644 --- a/module/custom/lang/zh-cn.php +++ b/module/custom/lang/zh-cn.php @@ -17,6 +17,7 @@ $lang->custom->setPublic = '设为公共'; $lang->custom->required = '必填项'; $lang->custom->score = '积分'; $lang->custom->scoreReset = '重置积分'; +$lang->custom->scoreInit = '初始化积分'; $lang->custom->object['story'] = '需求'; $lang->custom->object['task'] = '任务'; diff --git a/module/custom/view/score.html.php b/module/custom/view/score.html.php index 9b3127bd93..1cb97f36e6 100644 --- a/module/custom/view/score.html.php +++ b/module/custom/view/score.html.php @@ -10,25 +10,25 @@ */ ?> -
-
- - - - - - - - - -
custom->score; ?>custom->scoreList, isset($config->global->score) ? $config->global->score : 0, '', 'block'); ?>
" . $lang->custom->scoreReset, '', "class='btn'");?>
-
-
- +
+
+ + + + + + + + + +
custom->score; ?>custom->scoreList, isset($config->global->score) ? $config->global->score : 0, '', 'block'); ?>
global->scoreInit) ? common::printLink('score', 'refresh', '', " " . $lang->custom->scoreReset, '', ' id="scoreRefresh" class="btn iframe" data-width="480"', true, true) : common::printLink('score', 'init', '', " " . $lang->custom->scoreInit, '', ' id="scoreInit" class="btn iframe" data-width="480"', true, true); ?>
+
+
+ \ No newline at end of file diff --git a/module/score/config.php b/module/score/config.php index c83cf8a182..692a3e6697 100644 --- a/module/score/config.php +++ b/module/score/config.php @@ -1,55 +1,55 @@ score = new stdClass(); -$config->score->model['user']['login'] = array('num' => 3, 'time' => 24, 'score' => 1, 'other' => ''); -$config->score->model['user']['changePassword'] = array('num' => 1, 'time' => 0, 'score' => 10, 'other' => array(1 => 2, 2 => 5)); -$config->score->model['user']['editProfile'] = array('num' => 1, 'time' => 0, 'score' => 10, 'other' => ''); +$config->score->model['user']['login'] = array('num' => 3, 'time' => 24, 'score' => 1, 'ext' => ''); +$config->score->model['user']['changePassword'] = array('num' => 1, 'time' => 0, 'score' => 10, 'ext' => array(1 => 2, 2 => 5)); +$config->score->model['user']['editProfile'] = array('num' => 1, 'time' => 0, 'score' => 10, 'ext' => ''); -$config->score->model['tutorial']['keepAll'] = array('num' => 1, 'time' => 0, 'score' => 100, 'other' => ''); +$config->score->model['tutorial']['keepAll'] = array('num' => 1, 'time' => 0, 'score' => 100, 'ext' => ''); -$config->score->model['ajax']['selectTheme'] = array('num' => 1, 'time' => 0, 'score' => 10, 'other' => ''); -$config->score->model['ajax']['selectLang'] = array('num' => 1, 'time' => 0, 'score' => 10, 'other' => ''); -$config->score->model['ajax']['showSearchMenu'] = array('num' => 1, 'time' => 0, 'score' => 10, 'other' => ''); -$config->score->model['ajax']['dragSelected'] = array('num' => 1, 'time' => 0, 'score' => 20, 'other' => ''); -$config->score->model['ajax']['lastNext'] = array('num' => 1, 'time' => 0, 'score' => 20, 'other' => ''); -$config->score->model['ajax']['switchToDataTable'] = array('num' => 1, 'time' => 0, 'score' => 1, 'other' => ''); -$config->score->model['ajax']['submitPage'] = array('num' => 1, 'time' => 0, 'score' => 1, 'other' => ''); -$config->score->model['ajax']['customMenu'] = array('num' => 1, 'time' => 0, 'score' => 1, 'other' => ''); -$config->score->model['ajax']['quickDump'] = array('num' => 1, 'time' => 0, 'score' => 10, 'other' => ''); -$config->score->model['ajax']['batchCreate'] = array('num' => 1, 'time' => 0, 'score' => 20, 'other' => ''); -$config->score->model['ajax']['batchEdit'] = array('num' => 1, 'time' => 0, 'score' => 20, 'other' => ''); +$config->score->model['ajax']['selectTheme'] = array('num' => 1, 'time' => 0, 'score' => 10, 'ext' => ''); +$config->score->model['ajax']['selectLang'] = array('num' => 1, 'time' => 0, 'score' => 10, 'ext' => ''); +$config->score->model['ajax']['showSearchMenu'] = array('num' => 1, 'time' => 0, 'score' => 10, 'ext' => ''); +$config->score->model['ajax']['dragSelected'] = array('num' => 1, 'time' => 0, 'score' => 20, 'ext' => ''); +$config->score->model['ajax']['lastNext'] = array('num' => 1, 'time' => 0, 'score' => 20, 'ext' => ''); +$config->score->model['ajax']['switchToDataTable'] = array('num' => 1, 'time' => 0, 'score' => 1, 'ext' => ''); +$config->score->model['ajax']['submitPage'] = array('num' => 1, 'time' => 0, 'score' => 1, 'ext' => ''); +$config->score->model['ajax']['customMenu'] = array('num' => 1, 'time' => 0, 'score' => 1, 'ext' => ''); +$config->score->model['ajax']['quickDump'] = array('num' => 1, 'time' => 0, 'score' => 10, 'ext' => ''); +$config->score->model['ajax']['batchCreate'] = array('num' => 1, 'time' => 0, 'score' => 20, 'ext' => ''); +$config->score->model['ajax']['batchEdit'] = array('num' => 1, 'time' => 0, 'score' => 20, 'ext' => ''); -$config->score->model['doc']['create'] = array('num' => 0, 'time' => 0, 'score' => 1, 'other' => ''); +$config->score->model['doc']['create'] = array('num' => 0, 'time' => 0, 'score' => 1, 'ext' => ''); -$config->score->model['todo']['create'] = array('num' => 5, 'time' => 24, 'score' => 1, 'other' => ''); +$config->score->model['todo']['create'] = array('num' => 5, 'time' => 24, 'score' => 1, 'ext' => ''); -$config->score->model['story']['create'] = array('num' => 0, 'time' => 0, 'score' => 1, 'other' => ''); -$config->score->model['story']['close'] = array('num' => 0, 'time' => 0, 'score' => 1, 'other' => array('createID' => 2));//每个需求被完成关闭,需求的创建者额外增加2分,关闭者增加1分 +$config->score->model['story']['create'] = array('num' => 0, 'time' => 0, 'score' => 1, 'ext' => ''); +$config->score->model['story']['close'] = array('num' => 0, 'time' => 0, 'score' => 1, 'ext' => array('createID' => 2));//每个需求被完成关闭,需求的创建者额外增加2分,关闭者增加1分 -$config->score->model['task']['create'] = array('num' => 0, 'time' => 0, 'score' => 1, 'other' => ''); -$config->score->model['task']['close'] = array('num' => 0, 'time' => 0, 'score' => 1, 'other' => ''); -$config->score->model['task']['finish'] = array('num' => 0, 'time' => 0, 'score' => 1, 'other' => array(1 => 2, 2 => 1, 3 => 0)); +$config->score->model['task']['create'] = array('num' => 0, 'time' => 0, 'score' => 1, 'ext' => ''); +$config->score->model['task']['close'] = array('num' => 0, 'time' => 0, 'score' => 1, 'ext' => ''); +$config->score->model['task']['finish'] = array('num' => 0, 'time' => 0, 'score' => 1, 'ext' => array(1 => 2, 2 => 1, 3 => 0)); -$config->score->model['bug']['create'] = array('num' => 0, 'time' => 0, 'score' => 1, 'other' => ''); -$config->score->model['bug']['confirmBug'] = array('num' => 0, 'time' => 0, 'score' => 1, 'other' => array(1 => 3, 2 => 2, 3 => 1)); -$config->score->model['bug']['createFormCase'] = array('num' => 0, 'time' => 0, 'score' => 1, 'other' => ''); -$config->score->model['bug']['resolve'] = array('num' => 0, 'time' => 0, 'score' => 1, 'other' => array(1 => 3, 2 => 2, 3 => 1)); -$config->score->model['bug']['saveTplModal'] = array('num' => 0, 'time' => 0, 'score' => 20, 'other' => ''); +$config->score->model['bug']['create'] = array('num' => 0, 'time' => 0, 'score' => 1, 'ext' => ''); +$config->score->model['bug']['confirmBug'] = array('num' => 0, 'time' => 0, 'score' => 1, 'ext' => array(1 => 3, 2 => 2, 3 => 1)); +$config->score->model['bug']['createFormCase'] = array('num' => 0, 'time' => 0, 'score' => 1, 'ext' => ''); +$config->score->model['bug']['resolve'] = array('num' => 0, 'time' => 0, 'score' => 1, 'ext' => array(1 => 3, 2 => 2, 3 => 1)); +$config->score->model['bug']['saveTplModal'] = array('num' => 0, 'time' => 0, 'score' => 20, 'ext' => ''); -$config->score->model['testTask']['runCase'] = array('num' => 0, 'time' => 0, 'score' => 1, 'other' => ''); +$config->score->model['testTask']['runCase'] = array('num' => 0, 'time' => 0, 'score' => 1, 'ext' => ''); -$config->score->model['testcase']['create'] = array('num' => 0, 'time' => 0, 'score' => 1, 'other' => ''); +$config->score->model['testcase']['create'] = array('num' => 0, 'time' => 0, 'score' => 1, 'ext' => ''); -$config->score->model['build']['create'] = array('num' => 0, 'time' => 0, 'score' => 10, 'other' => ''); +$config->score->model['build']['create'] = array('num' => 0, 'time' => 0, 'score' => 10, 'ext' => ''); -$config->score->model['project']['create'] = array('num' => 0, 'time' => 0, 'score' => 10, 'other' => ''); -$config->score->model['project']['close'] = array('num' => 0, 'time' => 0, 'score' => 0, 'other' => array('manager' => array(20, 10), 'member' => array(5, 5))); +$config->score->model['project']['create'] = array('num' => 0, 'time' => 0, 'score' => 10, 'ext' => ''); +$config->score->model['project']['close'] = array('num' => 0, 'time' => 0, 'score' => 0, 'ext' => array('manager' => array(20, 10), 'member' => array(5, 5))); -$config->score->model['productplan']['create'] = array('num' => 0, 'time' => 0, 'score' => 10, 'other' => ''); +$config->score->model['productplan']['create'] = array('num' => 0, 'time' => 0, 'score' => 10, 'ext' => ''); -$config->score->model['release']['create'] = array('num' => 0, 'time' => 0, 'score' => 10, 'other' => ''); +$config->score->model['release']['create'] = array('num' => 0, 'time' => 0, 'score' => 10, 'ext' => ''); -$config->score->model['block']['set'] = array('num' => 1, 'time' => 0, 'score' => 20, 'other' => ''); +$config->score->model['block']['set'] = array('num' => 1, 'time' => 0, 'score' => 20, 'ext' => ''); -$config->score->model['search']['saveQuery'] = array('num' => 1, 'time' => 0, 'score' => 1, 'other' => ''); -$config->score->model['search']['saveQueryAdvanced'] = array('num' => 1, 'time' => 0, 'score' => 1, 'other' => ''); +$config->score->model['search']['saveQuery'] = array('num' => 1, 'time' => 0, 'score' => 1, 'ext' => ''); +$config->score->model['search']['saveQueryAdvanced'] = array('num' => 1, 'time' => 0, 'score' => 1, 'ext' => ''); diff --git a/module/score/control.php b/module/score/control.php index 797f197249..f271b7c464 100644 --- a/module/score/control.php +++ b/module/score/control.php @@ -59,4 +59,27 @@ class score extends control { $this->loadModel('score')->score('ajax', $method); } + + public function init($lastID = 0) + { + if(helper::isAjaxRequest()) + { + $result = $this->score->init($lastID); + if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError())); + if($result['status'] == 'finish') + { + $this->send(array('result' => 'finished', 'message' => $this->lang->score->initFinish)); + } + else + { + $this->send(array('result' => 'unfinished', 'message' => $this->lang->score->processed, 'lastID' => $result['lastID'])); + } + } + $this->display(); + } + + public function refresh() + { + $this->display(); + } } \ No newline at end of file diff --git a/module/score/lang/zh-cn.php b/module/score/lang/zh-cn.php index c2a0efbbcd..76dbc60e99 100644 --- a/module/score/lang/zh-cn.php +++ b/module/score/lang/zh-cn.php @@ -1,8 +1,19 @@ score->common = '积分'; -$lang->score->record = '积分记录'; -$lang->score->current = '当前积分'; -$lang->score->level = '等级积分'; +$lang->score->common = '积分'; +$lang->score->record = '积分记录'; +$lang->score->current = '当前积分'; +$lang->score->level = '等级积分'; +$lang->score->init = '初始化'; +$lang->score->initTips = '初始化将根据历史记录计算,执行时间可能会比较长.
请勿在未完成前关闭窗口'; +$lang->score->initStart = '开始初始化'; +$lang->score->initLoading = '正在初始化...'; +$lang->score->initFinish = '初始化完成'; +$lang->score->refresh = '重置积分'; +$lang->score->refreshTips = '重置积分将对所有用户积分清零,执行时间可能会比较长.
请勿在未完成前关闭窗口'; +$lang->score->refreshStart = '开始重置所有积分'; +$lang->score->refreshLoading = '积分重置中...'; +$lang->score->refreshFinish = '重置完成'; +$lang->score->processed = '正在处理中...'; $lang->score->id = '编号'; $lang->score->userID = '用户ID'; diff --git a/module/score/model.php b/module/score/model.php index def18a562c..2b9b4561c1 100644 --- a/module/score/model.php +++ b/module/score/model.php @@ -9,6 +9,8 @@ */ class scoreModel extends model { + public static $num = 0; + /** * get user score logs * @@ -29,23 +31,27 @@ class scoreModel extends model * @param string $model * @param string $method * @param string $param + * @param string $account + * @param string $time * * @access public * @return bool */ - public function score($model = '', $method = '', $param = '') + public function score($model = '', $method = '', $param = '', $account = '', $time = '') { - if(empty($this->config->score->model[$model][$method])) return true; - $rule = $this->config->score->model[$model][$method]; - $desc = $this->lang->score->models[$model]; - $user = $this->app->user->account; + if(!isset($this->config->score->model[$model][$method]) || empty($this->config->score->model[$model][$method])) return true; + $rule = $this->config->score->model[$model][$method]; + $desc = $this->lang->score->models[$model]; + $user = empty($account) ? $this->app->user->account : $account; + $time = empty($time) ? helper::now() : $time; + $objectID = is_numeric($param) ? $param : 0; switch($model) { case 'user': if($method == 'login') $desc = $this->lang->score->methods[$model][$method] . 'IP:' . helper::getRemoteIp(); if($method == 'changePassword') { - if(!empty($rule['other'][$param])) $rule['score'] = $rule['score'] + $rule['other'][$param]; + if(!empty($rule['ext'][$param])) $rule['score'] = $rule['score'] + $rule['ext'][$param]; $desc = $this->lang->score->methods[$model][$method]; } break; @@ -63,8 +69,8 @@ class scoreModel extends model if(!empty($createUser)) { $newRule = $rule; - $newRule['score'] = $rule['other']['createID']; - $this->saveScore($createUser->openedBy, $newRule, $model, $method, $desc); + $newRule['score'] = $rule['ext']['createID']; + $this->saveScore($createUser->openedBy, $newRule, $model, $method, $desc, $objectID, $time); unset($newRule); } } @@ -76,7 +82,7 @@ class scoreModel extends model $desc = $this->lang->score->methods[$model][$method] . 'ID:' . $param; //每完成一个任务,增加初始积分1 + 工时积分round(工时 /10 * 预计 / 消耗) + 优先级积分(p1 2, p2, 1) 如果任务取消了,没有积分。 $task = $this->loadModel('task')->getById($param); - if(!empty($rule['other'][$task->pri])) $rule['score'] = $rule['score'] + $rule['other'][$task->pri]; + if(!empty($rule['ext'][$task->pri])) $rule['score'] = $rule['score'] + $rule['ext'][$task->pri]; if(!empty($task->estimate)) $rule['score'] = $rule['score'] + round(($task->consumed / 10 * $task->estimate / $task->consumed), 1); } break; @@ -94,10 +100,16 @@ class scoreModel extends model if($method == 'saveTplModal') $desc = $this->lang->score->methods[$model][$method] . 'ID:' . $param; if($method == 'confirmBug') { - $user = $param->openedBy; - if(!empty($rule['other'][$param->severity])) $rule['score'] = $rule['score'] + $rule['other'][$param->severity]; + $objectID = $param->id; + $user = $param->openedBy; + $desc .= 'ID:' . $param->id; + if(!empty($rule['ext'][$param->severity])) $rule['score'] = $rule['score'] + $rule['ext'][$param->severity]; + } + if($method == 'resolve' && !empty($rule['ext'][$param->severity])) + { + $objectID = $param->id; + $rule['score'] = $rule['score'] + $rule['ext'][$param->severity]; } - if($method == 'resolve' && !empty($rule['other'][$param->severity])) $rule['score'] = $rule['score'] + $rule['other'][$param->severity]; break; case 'testTask': if($method == 'runCase') $desc = $this->lang->score->methods[$model][$method] . 'ID:' . $param; @@ -109,20 +121,21 @@ class scoreModel extends model if($method == 'create') $desc .= 'ID:' . $param; if($method == 'close') { - $desc = $this->lang->score->methods[$model][$method] . ',' . $desc . 'ID:' . $param->id; + $desc = $this->lang->score->methods[$model][$method] . ',' . $desc . 'ID:' . $param->id; + $objectID = $param->id; if(!empty($param->PM)) { - $rule['score'] = $param->end > date('Y-m-d') ? $rule['other']['manager'][0] + $rule['other']['manager'][1] : $rule['other']['manager'][0]; - $this->saveScore($param->PM, $rule, $model, $method, $desc); + $rule['score'] = $param->end > date('Y-m-d') ? $rule['ext']['manager'][0] + $rule['ext']['manager'][1] : $rule['ext']['manager'][0]; + $this->saveScore($param->PM, $rule, $model, $method, $desc, $objectID, $time); } $teams = $this->dao->select('account')->from(TABLE_TEAM)->where('project')->eq($param->id)->fetchGroup('account'); if(!empty($teams)) { $users = array_keys($teams); - $rule['score'] = $param->end > date('Y-m-d') ? $rule['other']['member'][0] + $rule['other']['member'][1] : $rule['other']['member'][0]; + $rule['score'] = $param->end > date('Y-m-d') ? $rule['ext']['member'][0] + $rule['ext']['member'][1] : $rule['ext']['member'][0]; foreach($users as $user) { - if($user != $param->PM) $this->saveScore($user, $rule, $model, $method, $desc); + if($user != $param->PM) $this->saveScore($user, $rule, $model, $method, $desc, $objectID, $time); } } } @@ -145,7 +158,7 @@ class scoreModel extends model $desc = $this->lang->score->methods[$model][$method]; break; } - $this->saveScore($user, $rule, $model, $method, $desc); + $this->saveScore($user, $rule, $model, $method, $desc, $objectID, $time); } /** @@ -156,11 +169,13 @@ class scoreModel extends model * @param string $model * @param string $method * @param string $desc + * @param int $objectID + * @param string $time * * @access private * @return bool */ - private function saveScore($account = '', $rule = array(), $model = '', $method = '', $desc = '') + private function saveScore($account = '', $rule = array(), $model = '', $method = '', $desc = '', $objectID = 0, $time = '') { if(!empty($rule['num']) || !empty($rule['time'])) { @@ -171,7 +186,8 @@ class scoreModel extends model } else { - $count = $this->dao->select('id')->from(TABLE_SCORE)->where('account')->eq($account)->andWhere('time')->between(date('Y-m-d 0:0:0'), date('Y-m-d 23:59:59'))->andWhere('model')->eq($model)->andWhere('method')->eq($method)->count(); + $timestamp = empty($time) ? time() : strtotime($time); + $count = $this->dao->select('id')->from(TABLE_SCORE)->where('account')->eq($account)->andWhere('time')->between(date('Y-m-d 0:0:0', $timestamp), date('Y-m-d 23:59:59', $timestamp))->andWhere('model')->eq($model)->andWhere('method')->eq($method)->count(); if($count >= $rule['num']) return true; } } @@ -181,15 +197,16 @@ class scoreModel extends model { $user = $this->loadModel('user')->getById($account); - $data = new stdClass(); - $data->account = $account; - $data->model = $model; - $data->method = $method; - $data->desc = $desc; - $data->before = $user->score; - $data->score = $rule['score']; - $data->after = $user->score + $rule['score']; - $data->time = helper::now(); + $data = new stdClass(); + $data->account = $account; + $data->model = $model; + $data->method = $method; + $data->desc = $desc; + $data->objectID = $objectID; + $data->before = $user->score; + $data->score = $rule['score']; + $data->after = $user->score + $rule['score']; + $data->time = empty($time) ? helper::now() : $time; $this->dao->insert(TABLE_SCORE)->data($data)->exec(); $this->dao->query("UPDATE " . TABLE_USER . " SET `score`=`score` + " . $rule['score'] . ",`score_level`=`score_level` + " . $rule['score'] . " WHERE `account`='" . $account . "'"); $this->dao->commit(); @@ -202,6 +219,7 @@ class scoreModel extends model /** * reset all user score and level score + * * @access public * @return void */ @@ -209,4 +227,49 @@ class scoreModel extends model { } + + /** + * Score init from action + * + * @param int $lastID + * + * @access public + * @return array + */ + public function init($lastID = 0) + { + if($lastID == 0) + { + $this->dao->query("UPDATE " . TABLE_USER . " SET `score`=0,`score_level`=0"); + $this->dao->query("TRUNCATE TABLE " . TABLE_SCORE); + } + $actions = $this->dao->select('*')->from(TABLE_ACTION)->where('id')->gt($lastID)->orderBy('id_asc')->limit(100)->fetchAll('id'); + if(empty($actions)) + { + $this->loadModel('setting')->setItem('system.common.global.scoreInit', 1); + return array('num' => 0, 'status' => 'finish'); + } + foreach($actions as $action) + { + $param = $action->objectID; + if($action->objectType == 'project' && $action->action == 'closed') $param = $this->dao->findById($action->objectID)->from(TABLE_PROJECT)->fetch(); + if($action->objectType == 'bug' && ($action->action == 'bugconfirmed' || $action->action == 'resolved')) $param = $this->dao->findById($action->objectID)->from(TABLE_BUG)->fetch(); + $this->score($action->objectType, $this->fix_key($action->action), $param, $action->actor, $action->date); + } + return array('status' => 'more', 'lastID' => max(array_keys($actions))); + } + + /** + * fix action type for score + * + * @param $string + * + * @access private + * @return mixed + */ + private function fix_key($string) + { + $strings = array('created' => 'create', 'closed' => 'close', 'finished' => 'finish', 'bugconfirmed' => 'confirmBug', 'resolved' => 'resolve'); + return isset($strings[$string]) ? $strings[$string] : $string; + } } \ No newline at end of file diff --git a/module/score/view/init.html.php b/module/score/view/init.html.php new file mode 100644 index 0000000000..f79f8e0e51 --- /dev/null +++ b/module/score/view/init.html.php @@ -0,0 +1,64 @@ + + * @package score + * @version $Id$ + * @link http://www.zentao.net + */ +?> + +
+ +
+

score->init; ?>

+
+

score->initTips; ?>

+

+ +

+
+
+ + + + \ No newline at end of file diff --git a/www/js/my.full.js b/www/js/my.full.js index a37638381c..3712882c44 100644 --- a/www/js/my.full.js +++ b/www/js/my.full.js @@ -705,6 +705,11 @@ function checkTable($table) var isChecked = $checkbox.prop('checked'); if(!$this.is(':checkbox')) { + if(!$.cookie('ajax_dragSelected') && $checkbox.size() > 2) + { + $.cookie('ajax_dragSelected', 'on', {expires: config.cookieLife, path: config.webRoot}); + $.get(createLink('score', 'ajax', "method=dragSelected")); + } isChecked = checked === true || checked === false ? checked : !isChecked; $checkbox.prop('checked', isChecked); } @@ -714,7 +719,6 @@ function checkTable($table) $tr.closest('.table').find('.rows-selector').prop('checked', false); } }; - var isSelectableTable = $table.hasClass('table-selectable'); $table.selectable( From 3d0dff1420ba66a141f3569f586c7f9d2a2383cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BB=94=E5=93=A5?= Date: Tue, 31 Oct 2017 10:03:54 +0800 Subject: [PATCH 2/6] * add score auth --- db/update9.5.1.sql | 2 +- module/common/lang/en.php | 2 +- module/common/lang/zh-cn.php | 2 +- module/common/lang/zh-tw.php | 2 +- module/common/model.php | 4 +- module/group/lang/resource.php | 4 +- module/my/control.php | 24 +++++++++++ module/my/lang/en.php | 1 + module/my/lang/zh-cn.php | 1 + module/my/lang/zh-tw.php | 1 + module/score/control.php | 53 +++++++------------------ module/score/model.php | 38 +++++++++++++----- module/score/view/browse.html.php | 53 ------------------------- module/score/view/init.html.php | 2 +- module/score/view/refresh.html.php | 64 ++++++++++++++++++++++++++++++ 15 files changed, 143 insertions(+), 110 deletions(-) delete mode 100644 module/score/view/browse.html.php create mode 100644 module/score/view/refresh.html.php diff --git a/db/update9.5.1.sql b/db/update9.5.1.sql index 8dbe395d1d..17036e2ff9 100644 --- a/db/update9.5.1.sql +++ b/db/update9.5.1.sql @@ -78,7 +78,7 @@ ALTER TABLE `zt_team` DROP PRIMARY KEY; ALTER TABLE `zt_team` ADD PRIMARY KEY (`project`, `task`, `account`); ALTER TABLE `zt_user` ADD `score` DECIMAL(12,1) NOT NULL DEFAULT '0' AFTER `deleted`; -ALTER TABLE `zt_user` ADD `score_level` DECIMAL(12,1) NOT NULL DEFAULT '0' AFTER `score`; +ALTER TABLE `zt_user` ADD `scoreLevel` DECIMAL(12,1) NOT NULL DEFAULT '0' AFTER `score`; CREATE TABLE `zt_score` ( `id` bigint(12) unsigned NOT NULL AUTO_INCREMENT, diff --git a/module/common/lang/en.php b/module/common/lang/en.php index 3de4a704e0..8c0f61f444 100644 --- a/module/common/lang/en.php +++ b/module/common/lang/en.php @@ -175,7 +175,7 @@ $lang->my->menu->dynamic = 'Dynamic|my|dynamic|'; $lang->my->menu->profile = array('link' => 'Profile|my|profile', 'alias' => 'editprofile'); $lang->my->menu->changePassword = 'Password|my|changepassword'; $lang->my->menu->manageContacts = 'Contact|my|managecontacts'; -$lang->my->menu->score = array('link' => 'Score|score|browse', 'subModule' => 'score'); +$lang->my->menu->score = 'Score|score|browse'; $lang->todo = new stdclass(); $lang->todo->menu = $lang->my->menu; diff --git a/module/common/lang/zh-cn.php b/module/common/lang/zh-cn.php index 81c8b2c620..48271a6558 100644 --- a/module/common/lang/zh-cn.php +++ b/module/common/lang/zh-cn.php @@ -175,7 +175,7 @@ $lang->my->menu->dynamic = '动态|my|dynamic|'; $lang->my->menu->profile = array('link' => '档案|my|profile', 'alias' => 'editprofile'); $lang->my->menu->changePassword = '密码|my|changepassword'; $lang->my->menu->manageContacts = '联系人|my|managecontacts'; -$lang->my->menu->score = array('link' => '积分|score|browse', 'subModule' => 'score'); +$lang->my->menu->score = '积分|my|score'; $lang->todo = new stdclass(); $lang->todo->menu = $lang->my->menu; diff --git a/module/common/lang/zh-tw.php b/module/common/lang/zh-tw.php index 4a68c6a53b..612d7e10c5 100644 --- a/module/common/lang/zh-tw.php +++ b/module/common/lang/zh-tw.php @@ -175,7 +175,7 @@ $lang->my->menu->dynamic = '動態|my|dynamic|'; $lang->my->menu->profile = array('link' => '檔案|my|profile', 'alias' => 'editprofile'); $lang->my->menu->changePassword = '密碼|my|changepassword'; $lang->my->menu->manageContacts = '聯繫人|my|managecontacts'; -$lang->my->menu->score = array('link' => '積分|score|browse', 'subModule' => 'score'); +$lang->my->menu->score = '積分|my|score'; $lang->todo = new stdclass(); $lang->todo->menu = $lang->my->menu; diff --git a/module/common/model.php b/module/common/model.php index 0fb9910539..d4637cf1bf 100644 --- a/module/common/model.php +++ b/module/common/model.php @@ -1162,8 +1162,8 @@ class commonModel extends model global $app; if(!empty($app->user->admin)) return true; - if($module = 'todo' and ($method == 'create' or $method == 'batchcreate')) return true; - if($module = 'effort' and ($method == 'createforobject' or $method == 'batchcreate')) return true; + if($module == 'todo' and ($method == 'create' or $method == 'batchcreate')) return true; + if($module == 'effort' and ($method == 'createforobject' or $method == 'batchcreate')) return true; // limited project $limitedProject = false; diff --git a/module/group/lang/resource.php b/module/group/lang/resource.php index 23ef7835c1..b8cdc4885e 100644 --- a/module/group/lang/resource.php +++ b/module/group/lang/resource.php @@ -85,6 +85,7 @@ $lang->resource->my->unbind = 'unbind'; $lang->resource->my->manageContacts = 'manageContacts'; $lang->resource->my->deleteContacts = 'deleteContacts'; $lang->resource->my->limited = 'limited'; +$lang->resource->my->score = 'score'; $lang->my->methodOrder[0] = 'index'; $lang->my->methodOrder[5] = 'todo'; @@ -101,7 +102,8 @@ $lang->my->methodOrder[55] = 'changePassword'; $lang->my->methodOrder[60] = 'unbind'; $lang->my->methodOrder[65] = 'manageContacts'; $lang->my->methodOrder[75] = 'deleteContacts'; -$lang->my->methodOrder[80] = 'limited'; +$lang->my->methodOrder[80] = 'score'; +$lang->my->methodOrder[85] = 'limited'; /* Todo. */ $lang->resource->todo = new stdclass(); diff --git a/module/my/control.php b/module/my/control.php index 1e44bd4f92..b851d2dc49 100644 --- a/module/my/control.php +++ b/module/my/control.php @@ -37,6 +37,30 @@ class my extends control $this->display(); } + /** + * Get score list + * + * @param int $recTotal + * @param int $recPerPage + * @param int $pageID + * + * @access public + * @return mixed + */ + public function score($recTotal = 0, $recPerPage = 20, $pageID = 1) + { + $this->app->loadClass('pager', $static = true); + $pager = new pager($recTotal, $recPerPage, $pageID); + $scores = $this->loadModel('score')->getScores($pager); + + $this->view->title = $this->lang->score->common; + $this->view->user = $this->loadModel('user')->getById($this->app->user->account); + $this->view->pager = $pager; + $this->view->scores = $scores; + $this->display(); + } + + /** * My todos. * diff --git a/module/my/lang/en.php b/module/my/lang/en.php index eea0299035..a7a97bf96e 100644 --- a/module/my/lang/en.php +++ b/module/my/lang/en.php @@ -18,6 +18,7 @@ $lang->my->unbind = 'Unbind Ranger'; $lang->my->manageContacts = 'Maintain Contact'; $lang->my->deleteContacts = 'Delete Contact'; $lang->my->limited = 'Restricted operation (editing only content related to itself)'; +$lang->my->score = 'Score'; $lang->my->taskMenu = new stdclass(); $lang->my->taskMenu->assignedToMe = 'Assigned to Me'; diff --git a/module/my/lang/zh-cn.php b/module/my/lang/zh-cn.php index 5cc94ef9e7..5730690d15 100644 --- a/module/my/lang/zh-cn.php +++ b/module/my/lang/zh-cn.php @@ -18,6 +18,7 @@ $lang->my->unbind = '解除然之绑定'; $lang->my->manageContacts = '维护联系人'; $lang->my->deleteContacts = '删除联系人'; $lang->my->limited = '受限操作(只能编辑与自己相关的内容)'; +$lang->my->score = '积分'; $lang->my->taskMenu = new stdclass(); $lang->my->taskMenu->assignedToMe = '指派给我'; diff --git a/module/my/lang/zh-tw.php b/module/my/lang/zh-tw.php index 6ee5ca897a..bedb913c94 100644 --- a/module/my/lang/zh-tw.php +++ b/module/my/lang/zh-tw.php @@ -18,6 +18,7 @@ $lang->my->unbind = '解除然之綁定'; $lang->my->manageContacts = '維護聯繫人'; $lang->my->deleteContacts = '刪除聯繫人'; $lang->my->limited = '受限操作(只能編輯與自己相關的內容)'; +$lang->my->score = '積分'; $lang->my->taskMenu = new stdclass(); $lang->my->taskMenu->assignedToMe = '指派給我'; diff --git a/module/score/control.php b/module/score/control.php index f271b7c464..cec152cb98 100644 --- a/module/score/control.php +++ b/module/score/control.php @@ -9,44 +9,6 @@ */ class score extends control { - /** - * score constructor. - * - * @param string $module - * @param string $method - * - * @access public - * @return mixed - */ - public function __construct($module = '', $method = '') - { - parent::__construct($module, $method); - $this->loadModel('my')->setMenu(); - } - - /** - * Get score list - * - * @param int $recTotal - * @param int $recPerPage - * @param int $pageID - * - * @access public - * @return mixed - */ - public function browse($recTotal = 0, $recPerPage = 20, $pageID = 1) - { - $this->app->loadClass('pager', $static = true); - $pager = new pager($recTotal, $recPerPage, $pageID); - $scores = $this->score->getScores($pager); - - $this->view->title = $this->lang->score->common; - $this->view->user = $this->loadModel('user')->getById($this->app->user->account); - $this->view->pager = $pager; - $this->view->scores = $scores; - $this->display(); - } - /** * Ajax action score * @@ -78,8 +40,21 @@ class score extends control $this->display(); } - public function refresh() + public function refresh($lastID = 0) { + if(helper::isAjaxRequest()) + { + $result = $this->score->refresh($lastID); + if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError())); + if($result['status'] == 'finish') + { + $this->send(array('result' => 'finished', 'message' => $this->lang->score->refreshFinish)); + } + else + { + $this->send(array('result' => 'unfinished', 'message' => $this->lang->score->refreshLoading, 'lastID' => $result['lastID'])); + } + } $this->display(); } } \ No newline at end of file diff --git a/module/score/model.php b/module/score/model.php index 2b9b4561c1..b558d4dfdb 100644 --- a/module/score/model.php +++ b/module/score/model.php @@ -48,7 +48,7 @@ class scoreModel extends model switch($model) { case 'user': - if($method == 'login') $desc = $this->lang->score->methods[$model][$method] . 'IP:' . helper::getRemoteIp(); + if($method == 'login') $desc = $this->lang->score->methods[$model][$method]; if($method == 'changePassword') { if(!empty($rule['ext'][$param])) $rule['score'] = $rule['score'] + $rule['ext'][$param]; @@ -87,7 +87,7 @@ class scoreModel extends model } break; case 'bug': - $desc .= 'ID:' . $param; + if(is_numeric($param)) $desc .= 'ID:' . $param; if($method == 'createFormCase') { $desc = $this->lang->score->models['testcase'] . 'ID:' . $param; @@ -125,14 +125,14 @@ class scoreModel extends model $objectID = $param->id; if(!empty($param->PM)) { - $rule['score'] = $param->end > date('Y-m-d') ? $rule['ext']['manager'][0] + $rule['ext']['manager'][1] : $rule['ext']['manager'][0]; + $rule['score'] = $param->end > date('Y-m-d', $time) ? $rule['ext']['manager'][0] + $rule['ext']['manager'][1] : $rule['ext']['manager'][0]; $this->saveScore($param->PM, $rule, $model, $method, $desc, $objectID, $time); } $teams = $this->dao->select('account')->from(TABLE_TEAM)->where('project')->eq($param->id)->fetchGroup('account'); if(!empty($teams)) { $users = array_keys($teams); - $rule['score'] = $param->end > date('Y-m-d') ? $rule['ext']['member'][0] + $rule['ext']['member'][1] : $rule['ext']['member'][0]; + $rule['score'] = $param->end > date('Y-m-d', $time) ? $rule['ext']['member'][0] + $rule['ext']['member'][1] : $rule['ext']['member'][0]; foreach($users as $user) { if($user != $param->PM) $this->saveScore($user, $rule, $model, $method, $desc, $objectID, $time); @@ -208,7 +208,7 @@ class scoreModel extends model $data->after = $user->score + $rule['score']; $data->time = empty($time) ? helper::now() : $time; $this->dao->insert(TABLE_SCORE)->data($data)->exec(); - $this->dao->query("UPDATE " . TABLE_USER . " SET `score`=`score` + " . $rule['score'] . ",`score_level`=`score_level` + " . $rule['score'] . " WHERE `account`='" . $account . "'"); + $this->dao->query("UPDATE " . TABLE_USER . " SET `score`=`score` + " . $rule['score'] . ",`scoreLevel`=`scoreLevel` + " . $rule['score'] . " WHERE `account`='" . $account . "'"); $this->dao->commit(); } catch(ErrorException $e) @@ -218,14 +218,32 @@ class scoreModel extends model } /** - * reset all user score and level score - * + * refresh all user score and level score + * + * @param int $lastID + * * @access public * @return void */ - public function resetScore() + public function refresh($lastID = 0) { - + if($lastID == 0) + { + $this->dao->query("DROP TABLE IF EXISTS `score_bak`"); + $this->dao->query("RENAME TABLE " . TABLE_SCORE . ' TO score_bak'); + $this->dao->query("CREATE TABLE " . TABLE_SCORE . ' LIKE score_bak'); + $this->dao->query("UPDATE " . TABLE_USER . " SET `score`=0,`scoreLevel`=0"); + } + $actions = $this->dao->select('*')->from('score_bak')->where('id')->gt($lastID)->orderBy('id_asc')->limit(100)->fetchAll('id'); + if(empty($actions)) return array('num' => 0, 'status' => 'finish'); + foreach($actions as $action) + { + $param = $action->objectID; + if($action->model == 'project' && $action->method == 'close') $param = $this->dao->findById($action->objectID)->from(TABLE_PROJECT)->fetch(); + if($action->model == 'bug' && ($action->method == 'confirmBug' || $action->method == 'resolve')) $param = $this->dao->findById($action->objectID)->from(TABLE_BUG)->fetch(); + $this->score($action->model, $action->method, $param, $action->account, $action->time); + } + return array('status' => 'more', 'lastID' => max(array_keys($actions))); } /** @@ -240,7 +258,7 @@ class scoreModel extends model { if($lastID == 0) { - $this->dao->query("UPDATE " . TABLE_USER . " SET `score`=0,`score_level`=0"); + $this->dao->query("UPDATE " . TABLE_USER . " SET `score`=0,`scoreLevel`=0"); $this->dao->query("TRUNCATE TABLE " . TABLE_SCORE); } $actions = $this->dao->select('*')->from(TABLE_ACTION)->where('id')->gt($lastID)->orderBy('id_asc')->limit(100)->fetchAll('id'); diff --git a/module/score/view/browse.html.php b/module/score/view/browse.html.php deleted file mode 100644 index 6843840b89..0000000000 --- a/module/score/view/browse.html.php +++ /dev/null @@ -1,53 +0,0 @@ - - * @package score - * @version $Id$ - * @link http://www.zentao.net - */ -?> - -
-
icons['score']); ?>score->record; ?>
-
- score; ?> - -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
score->time; ?>score->model; ?>score->method; ?>score->before; ?>score->score; ?>score->after; ?>score->desc; ?>
time; ?>score->models[$score->model]; ?>score->methods[$score->model][$score->method]; ?>before; ?>score; ?>after; ?>desc; ?>
- show(); ?> -
- \ No newline at end of file diff --git a/module/score/view/init.html.php b/module/score/view/init.html.php index f79f8e0e51..c40c52c3ea 100644 --- a/module/score/view/init.html.php +++ b/module/score/view/init.html.php @@ -55,7 +55,7 @@ } else { - $('#loading_content').html("
  • " + response.message + "
  • "); + $('#loading_content').html("
  • " + response.message + "
  • "); setTimeout(function(){score_init(response.lastID);}, 2000); } }); diff --git a/module/score/view/refresh.html.php b/module/score/view/refresh.html.php new file mode 100644 index 0000000000..b986358fa9 --- /dev/null +++ b/module/score/view/refresh.html.php @@ -0,0 +1,64 @@ + + * @package score + * @version $Id$ + * @link http://www.zentao.net + */ +?> + +
    + +
    +

    score->refresh; ?>

    +
    +

    score->refreshTips; ?>

    +

    + +

    +
    +
    + + + + \ No newline at end of file From 09395f45e8ddac81364ad34a851e1e5431533c60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BB=94=E5=93=A5?= Date: Tue, 31 Oct 2017 10:14:12 +0800 Subject: [PATCH 3/6] * add score for my model --- module/my/view/score.html.php | 53 +++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 module/my/view/score.html.php diff --git a/module/my/view/score.html.php b/module/my/view/score.html.php new file mode 100644 index 0000000000..df9b8f02ee --- /dev/null +++ b/module/my/view/score.html.php @@ -0,0 +1,53 @@ + + * @package score + * @version $Id$ + * @link http://www.zentao.net + */ +?> + +
    +
    icons['score']); ?>score->record; ?>
    +
    + score; ?> + +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    score->time; ?>score->model; ?>score->method; ?>score->before; ?>score->score; ?>score->after; ?>score->desc; ?>
    time; ?>score->models[$score->model]; ?>score->methods[$score->model][$score->method]; ?>before; ?>score; ?>after; ?>desc; ?>
    + show(); ?> +
    + \ No newline at end of file From e3ea70b43ac85436bf35f1a4b2965447ae7c7e06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BB=94=E5=93=A5?= Date: Tue, 31 Oct 2017 11:13:09 +0800 Subject: [PATCH 4/6] * change score module --- db/update9.5.1.sql | 2 +- module/block/control.php | 4 +- module/block/model.php | 2 +- module/bug/model.php | 14 ++-- module/build/model.php | 2 +- module/custom/model.php | 2 +- module/doc/model.php | 2 +- module/my/control.php | 4 +- module/my/view/score.html.php | 10 +-- module/productplan/model.php | 2 +- module/project/model.php | 4 +- module/release/model.php | 2 +- module/score/config.php | 106 ++++++++++++++--------------- module/score/control.php | 29 ++++++-- module/score/lang/zh-cn.php | 12 ++-- module/score/model.php | 84 ++++++++++++++--------- module/score/view/refresh.html.php | 36 +++++----- module/search/model.php | 4 +- module/story/model.php | 12 ++-- module/task/model.php | 12 ++-- module/testcase/model.php | 4 +- module/testtask/model.php | 2 +- module/todo/model.php | 4 +- module/tutorial/control.php | 2 +- module/user/control.php | 2 +- module/user/model.php | 4 +- 26 files changed, 200 insertions(+), 163 deletions(-) diff --git a/db/update9.5.1.sql b/db/update9.5.1.sql index 3f5b805613..2e51b8c49d 100644 --- a/db/update9.5.1.sql +++ b/db/update9.5.1.sql @@ -83,7 +83,7 @@ ALTER TABLE `zt_user` ADD `scoreLevel` DECIMAL(12,1) NOT NULL DEFAULT '0' AFT CREATE TABLE `zt_score` ( `id` bigint(12) unsigned NOT NULL AUTO_INCREMENT, `account` varchar(30) NOT NULL, - `model` varchar(30) NOT NULL, + `module` varchar(30) NOT NULL, `method` varchar(30) NOT NULL, `desc` varchar(250) NOT NULL DEFAULT '', `before` decimal(12,1) NOT NULL DEFAULT '0.0', diff --git a/module/block/control.php b/module/block/control.php index dbddafe7cb..f41958fba4 100644 --- a/module/block/control.php +++ b/module/block/control.php @@ -131,7 +131,7 @@ class block extends control $this->dao->delete()->from(TABLE_BLOCK)->where('`id`')->eq($id)->andWhere('account')->eq($this->app->user->account)->andWhere('module')->eq($module)->exec(); } if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError())); - $this->loadModel('score')->score('block', 'set'); + $this->loadModel('score')->create('block', 'set'); $this->send(array('result' => 'success')); } @@ -158,7 +158,7 @@ class block extends control } if(dao::isError()) $this->send(array('result' => 'fail')); - $this->loadModel('score')->score('block', 'set'); + $this->loadModel('score')->create('block', 'set'); $this->send(array('result' => 'success')); } diff --git a/module/block/model.php b/module/block/model.php index 4105500cfb..de9c3f02fc 100644 --- a/module/block/model.php +++ b/module/block/model.php @@ -50,7 +50,7 @@ class blockModel extends model $data->params = helper::jsonEncode($data->params); $this->dao->replace(TABLE_BLOCK)->data($data)->exec(); - $this->loadModel('score')->score('block', 'set'); + $this->loadModel('score')->create('block', 'set'); } /** diff --git a/module/bug/model.php b/module/bug/model.php index 8c47787223..22c1d22fc7 100644 --- a/module/bug/model.php +++ b/module/bug/model.php @@ -85,7 +85,7 @@ class bugModel extends model $bugID = $this->dao->lastInsertID(); $this->file->updateObjectID($this->post->uid, $bugID, 'bug'); $this->file->saveUpload('bug', $bugID); - empty($bug->case) ? $this->loadModel('score')->score('bug', 'create', $bugID) : $this->loadModel('score')->score('bug', 'createFormCase', $bug->case); + empty($bug->case) ? $this->loadModel('score')->create('bug', 'create', $bugID) : $this->loadModel('score')->create('bug', 'createFormCase', $bug->case); return array('status' => 'created', 'id' => $bugID); } return false; @@ -200,7 +200,7 @@ class bugModel extends model $this->dao->insert(TABLE_BUG)->data($bug)->autoCheck()->batchCheck($this->config->bug->create->requiredFields, 'notempty')->exec(); $bugID = $this->dao->lastInsertID(); - $this->loadModel('score')->score('bug', 'create', $bugID); + $this->loadModel('score')->create('bug', 'create', $bugID); if(!empty($data->uploadImage[$i]) and !empty($file)) { $file['objectType'] = 'bug'; @@ -224,7 +224,7 @@ class bugModel extends model if(is_dir($realPath)) $classFile->removeDir($realPath); unset($_SESSION['bugImagesFile']); } - $this->loadModel('score')->score('ajax', 'batchCreate'); + $this->loadModel('score')->create('ajax', 'batchCreate'); return $actions; } @@ -655,7 +655,7 @@ class bugModel extends model } } } - $this->loadModel('score')->score('ajax', 'batchEdit'); + $this->loadModel('score')->create('ajax', 'batchEdit'); return $allChanges; } @@ -759,7 +759,7 @@ class bugModel extends model ->get(); $this->dao->update(TABLE_BUG)->data($bug)->where('id')->eq($bugID)->exec(); - $this->loadModel('score')->score('bug', 'confirmBug', $oldBug); + $this->loadModel('score')->create('bug', 'confirmBug', $oldBug); if(!dao::isError()) return common::createChanges($oldBug, $bug); } @@ -848,7 +848,7 @@ class bugModel extends model ->checkIF($bug->resolution == 'fixed', 'resolvedBuild','notempty') ->where('id')->eq((int)$bugID) ->exec(); - $this->loadModel('score')->score('bug', 'resolve', $oldBug); + $this->loadModel('score')->create('bug', 'resolve', $oldBug); /* Link bug to build and release. */ $this->linkBugToBuild($bugID, $bug->resolvedBuild); } @@ -1855,7 +1855,7 @@ class bugModel extends model $condition = "`type`='bug' and account='{$this->app->user->account}'"; $this->dao->insert(TABLE_USERTPL)->data($template)->batchCheck('title, content', 'notempty')->check('title', 'unique', $condition)->exec(); - $this->loadModel('score')->score('bug', 'saveTplModal', $this->dao->lastInsertID()); + $this->loadModel('score')->create('bug', 'saveTplModal', $this->dao->lastInsertID()); } /** diff --git a/module/build/model.php b/module/build/model.php index b120518b44..a48985152d 100644 --- a/module/build/model.php +++ b/module/build/model.php @@ -213,7 +213,7 @@ class buildModel extends model $buildID = $this->dao->lastInsertID(); $this->file->updateObjectID($this->post->uid, $buildID, 'build'); $this->file->saveUpload('build', $buildID); - $this->loadModel('score')->score('build', 'create', $buildID); + $this->loadModel('score')->create('build', 'create', $buildID); return $buildID; } } diff --git a/module/custom/model.php b/module/custom/model.php index 978859cc16..97bbf22598 100644 --- a/module/custom/model.php +++ b/module/custom/model.php @@ -372,7 +372,7 @@ class customModel extends model } $this->loadModel('setting')->setItem($settingKey, $menu); - $this->loadModel('score')->score('ajax', 'customMenu'); + $this->loadModel('score')->create('ajax', 'customMenu'); } /** diff --git a/module/doc/model.php b/module/doc/model.php index b453f3976b..d1bb2b5820 100644 --- a/module/doc/model.php +++ b/module/doc/model.php @@ -431,7 +431,7 @@ class docModel extends model $docContent->doc = $docID; $docContent->files = join(',', array_keys($files)); $this->dao->insert(TABLE_DOCCONTENT)->data($docContent)->exec(); - $this->loadModel('score')->score('doc', 'create', $docID); + $this->loadModel('score')->create('doc', 'create', $docID); return array('status' => 'new', 'id' => $docID); } return false; diff --git a/module/my/control.php b/module/my/control.php index b851d2dc49..c7710775ca 100644 --- a/module/my/control.php +++ b/module/my/control.php @@ -51,16 +51,16 @@ class my extends control { $this->app->loadClass('pager', $static = true); $pager = new pager($recTotal, $recPerPage, $pageID); - $scores = $this->loadModel('score')->getScores($pager); + $scores = $this->loadModel('score')->getListByAccount($this->app->user->account, $pager); $this->view->title = $this->lang->score->common; $this->view->user = $this->loadModel('user')->getById($this->app->user->account); $this->view->pager = $pager; $this->view->scores = $scores; + $this->display(); } - /** * My todos. * diff --git a/module/my/view/score.html.php b/module/my/view/score.html.php index df9b8f02ee..9e3a979015 100644 --- a/module/my/view/score.html.php +++ b/module/my/view/score.html.php @@ -1,10 +1,10 @@ - * @package score + * @package my * @version $Id$ * @link http://www.zentao.net */ @@ -21,7 +21,7 @@ score->time; ?> - score->model; ?> + score->module; ?> score->method; ?> score->before; ?> score->score; ?> @@ -33,8 +33,8 @@ time; ?> - score->models[$score->model]; ?> - score->methods[$score->model][$score->method]; ?> + score->models[$score->module]; ?> + score->methods[$score->module][$score->method]; ?> before; ?> score; ?> after; ?> diff --git a/module/productplan/model.php b/module/productplan/model.php index 5923f7bcb6..22f6b0604b 100644 --- a/module/productplan/model.php +++ b/module/productplan/model.php @@ -151,7 +151,7 @@ class productplanModel extends model { $planID = $this->dao->lastInsertID(); $this->file->updateObjectID($this->post->uid, $planID, 'plan'); - $this->loadModel('score')->score('productplan', 'create', $planID); + $this->loadModel('score')->create('productplan', 'create', $planID); return $planID; } } diff --git a/module/project/model.php b/module/project/model.php index 709a63e87a..5471b83242 100644 --- a/module/project/model.php +++ b/module/project/model.php @@ -291,7 +291,7 @@ class projectModel extends model $lib->main = '1'; $lib->acl = $project->acl == 'open' ? 'open' : 'private'; $this->dao->insert(TABLE_DOCLIB)->data($lib)->exec(); - $this->loadModel('score')->score('project', 'create', $projectID); + $this->loadModel('score')->create('project', 'create', $projectID); return $projectID; } } @@ -537,7 +537,7 @@ class projectModel extends model ->autoCheck() ->where('id')->eq((int)$projectID) ->exec(); - $this->loadModel('score')->score('project', 'close', $oldProject); + $this->loadModel('score')->create('project', 'close', $oldProject); if(!dao::isError()) return common::createChanges($oldProject, $project); } diff --git a/module/release/model.php b/module/release/model.php index 4393038afa..ef6b28cd13 100644 --- a/module/release/model.php +++ b/module/release/model.php @@ -145,7 +145,7 @@ class releaseModel extends model $releaseID = $this->dao->lastInsertID(); $this->file->updateObjectID($this->post->uid, $releaseID, 'release'); $this->file->saveUpload('release', $releaseID); - $this->loadModel('score')->score('release', 'create', $releaseID); + $this->loadModel('score')->create('release', 'create', $releaseID); if(!dao::isError()) return $releaseID; } diff --git a/module/score/config.php b/module/score/config.php index 692a3e6697..7b5cad5650 100644 --- a/module/score/config.php +++ b/module/score/config.php @@ -1,55 +1,55 @@ score = new stdClass(); - -$config->score->model['user']['login'] = array('num' => 3, 'time' => 24, 'score' => 1, 'ext' => ''); -$config->score->model['user']['changePassword'] = array('num' => 1, 'time' => 0, 'score' => 10, 'ext' => array(1 => 2, 2 => 5)); -$config->score->model['user']['editProfile'] = array('num' => 1, 'time' => 0, 'score' => 10, 'ext' => ''); - -$config->score->model['tutorial']['keepAll'] = array('num' => 1, 'time' => 0, 'score' => 100, 'ext' => ''); - -$config->score->model['ajax']['selectTheme'] = array('num' => 1, 'time' => 0, 'score' => 10, 'ext' => ''); -$config->score->model['ajax']['selectLang'] = array('num' => 1, 'time' => 0, 'score' => 10, 'ext' => ''); -$config->score->model['ajax']['showSearchMenu'] = array('num' => 1, 'time' => 0, 'score' => 10, 'ext' => ''); -$config->score->model['ajax']['dragSelected'] = array('num' => 1, 'time' => 0, 'score' => 20, 'ext' => ''); -$config->score->model['ajax']['lastNext'] = array('num' => 1, 'time' => 0, 'score' => 20, 'ext' => ''); -$config->score->model['ajax']['switchToDataTable'] = array('num' => 1, 'time' => 0, 'score' => 1, 'ext' => ''); -$config->score->model['ajax']['submitPage'] = array('num' => 1, 'time' => 0, 'score' => 1, 'ext' => ''); -$config->score->model['ajax']['customMenu'] = array('num' => 1, 'time' => 0, 'score' => 1, 'ext' => ''); -$config->score->model['ajax']['quickDump'] = array('num' => 1, 'time' => 0, 'score' => 10, 'ext' => ''); -$config->score->model['ajax']['batchCreate'] = array('num' => 1, 'time' => 0, 'score' => 20, 'ext' => ''); -$config->score->model['ajax']['batchEdit'] = array('num' => 1, 'time' => 0, 'score' => 20, 'ext' => ''); - -$config->score->model['doc']['create'] = array('num' => 0, 'time' => 0, 'score' => 1, 'ext' => ''); - -$config->score->model['todo']['create'] = array('num' => 5, 'time' => 24, 'score' => 1, 'ext' => ''); - -$config->score->model['story']['create'] = array('num' => 0, 'time' => 0, 'score' => 1, 'ext' => ''); -$config->score->model['story']['close'] = array('num' => 0, 'time' => 0, 'score' => 1, 'ext' => array('createID' => 2));//每个需求被完成关闭,需求的创建者额外增加2分,关闭者增加1分 - -$config->score->model['task']['create'] = array('num' => 0, 'time' => 0, 'score' => 1, 'ext' => ''); -$config->score->model['task']['close'] = array('num' => 0, 'time' => 0, 'score' => 1, 'ext' => ''); -$config->score->model['task']['finish'] = array('num' => 0, 'time' => 0, 'score' => 1, 'ext' => array(1 => 2, 2 => 1, 3 => 0)); - -$config->score->model['bug']['create'] = array('num' => 0, 'time' => 0, 'score' => 1, 'ext' => ''); -$config->score->model['bug']['confirmBug'] = array('num' => 0, 'time' => 0, 'score' => 1, 'ext' => array(1 => 3, 2 => 2, 3 => 1)); -$config->score->model['bug']['createFormCase'] = array('num' => 0, 'time' => 0, 'score' => 1, 'ext' => ''); -$config->score->model['bug']['resolve'] = array('num' => 0, 'time' => 0, 'score' => 1, 'ext' => array(1 => 3, 2 => 2, 3 => 1)); -$config->score->model['bug']['saveTplModal'] = array('num' => 0, 'time' => 0, 'score' => 20, 'ext' => ''); - -$config->score->model['testTask']['runCase'] = array('num' => 0, 'time' => 0, 'score' => 1, 'ext' => ''); - -$config->score->model['testcase']['create'] = array('num' => 0, 'time' => 0, 'score' => 1, 'ext' => ''); - -$config->score->model['build']['create'] = array('num' => 0, 'time' => 0, 'score' => 10, 'ext' => ''); - -$config->score->model['project']['create'] = array('num' => 0, 'time' => 0, 'score' => 10, 'ext' => ''); -$config->score->model['project']['close'] = array('num' => 0, 'time' => 0, 'score' => 0, 'ext' => array('manager' => array(20, 10), 'member' => array(5, 5))); - -$config->score->model['productplan']['create'] = array('num' => 0, 'time' => 0, 'score' => 10, 'ext' => ''); - -$config->score->model['release']['create'] = array('num' => 0, 'time' => 0, 'score' => 10, 'ext' => ''); - -$config->score->model['block']['set'] = array('num' => 1, 'time' => 0, 'score' => 20, 'ext' => ''); - -$config->score->model['search']['saveQuery'] = array('num' => 1, 'time' => 0, 'score' => 1, 'ext' => ''); -$config->score->model['search']['saveQueryAdvanced'] = array('num' => 1, 'time' => 0, 'score' => 1, 'ext' => ''); +//user rule +$config->score->user->login = array('num' => 3, 'time' => 24, 'score' => 1, 'ext' => ''); +$config->score->user->changePassword = array('num' => 1, 'time' => 0, 'score' => 10, 'ext' => array(1 => 2, 2 => 5)); +$config->score->user->editProfile = array('num' => 1, 'time' => 0, 'score' => 10, 'ext' => ''); +//tutorial rule +$config->score->tutorial->keepAll = array('num' => 1, 'time' => 0, 'score' => 100, 'ext' => ''); +//javascript ajax rule +$config->score->ajax->selectTheme = array('num' => 1, 'time' => 0, 'score' => 10, 'ext' => ''); +$config->score->ajax->selectLang = array('num' => 1, 'time' => 0, 'score' => 10, 'ext' => ''); +$config->score->ajax->showSearchMenu = array('num' => 1, 'time' => 0, 'score' => 10, 'ext' => ''); +$config->score->ajax->dragSelected = array('num' => 1, 'time' => 0, 'score' => 20, 'ext' => ''); +$config->score->ajax->lastNext = array('num' => 1, 'time' => 0, 'score' => 20, 'ext' => ''); +$config->score->ajax->switchToDataTable = array('num' => 1, 'time' => 0, 'score' => 1, 'ext' => ''); +$config->score->ajax->submitPage = array('num' => 1, 'time' => 0, 'score' => 1, 'ext' => ''); +$config->score->ajax->customMenu = array('num' => 1, 'time' => 0, 'score' => 1, 'ext' => ''); +$config->score->ajax->quickDump = array('num' => 1, 'time' => 0, 'score' => 10, 'ext' => ''); +$config->score->ajax->batchCreate = array('num' => 1, 'time' => 0, 'score' => 20, 'ext' => ''); +$config->score->ajax->batchEdit = array('num' => 1, 'time' => 0, 'score' => 20, 'ext' => ''); +//doc rule +$config->score->doc->create = array('num' => 0, 'time' => 0, 'score' => 1, 'ext' => ''); +//todo rule +$config->score->todo->create = array('num' => 5, 'time' => 24, 'score' => 1, 'ext' => ''); +//story rule +$config->score->story->create = array('num' => 0, 'time' => 0, 'score' => 1, 'ext' => ''); +$config->score->story->close = array('num' => 0, 'time' => 0, 'score' => 1, 'ext' => array('createID' => 2)); +//task rule +$config->score->task->create = array('num' => 0, 'time' => 0, 'score' => 1, 'ext' => ''); +$config->score->task->close = array('num' => 0, 'time' => 0, 'score' => 1, 'ext' => ''); +$config->score->task->finish = array('num' => 0, 'time' => 0, 'score' => 1, 'ext' => array(1 => 2, 2 => 1, 3 => 0)); +//bug rule +$config->score->bug->create = array('num' => 0, 'time' => 0, 'score' => 1, 'ext' => ''); +$config->score->bug->confirmBug = array('num' => 0, 'time' => 0, 'score' => 1, 'ext' => array(1 => 3, 2 => 2, 3 => 1)); +$config->score->bug->createFormCase = array('num' => 0, 'time' => 0, 'score' => 1, 'ext' => ''); +$config->score->bug->resolve = array('num' => 0, 'time' => 0, 'score' => 1, 'ext' => array(1 => 3, 2 => 2, 3 => 1)); +$config->score->bug->saveTplModal = array('num' => 0, 'time' => 0, 'score' => 20, 'ext' => ''); +//testTask rule +$config->score->testTask->runCase = array('num' => 0, 'time' => 0, 'score' => 1, 'ext' => ''); +//testcase rule +$config->score->testcase->create = array('num' => 0, 'time' => 0, 'score' => 1, 'ext' => ''); +//bulid rule +$config->score->build->create = array('num' => 0, 'time' => 0, 'score' => 10, 'ext' => ''); +//project rule +$config->score->project->create = array('num' => 0, 'time' => 0, 'score' => 10, 'ext' => ''); +$config->score->project->close = array('num' => 0, 'time' => 0, 'score' => 0, 'ext' => array('manager' => array(20, 10), 'member' => array(5, 5))); +//productplan rule +$config->score->productplan->create = array('num' => 0, 'time' => 0, 'score' => 10, 'ext' => ''); +//release rule +$config->score->release->create = array('num' => 0, 'time' => 0, 'score' => 10, 'ext' => ''); +//block rule +$config->score->block->set = array('num' => 1, 'time' => 0, 'score' => 20, 'ext' => ''); +//search rule +$config->score->search->saveQuery = array('num' => 1, 'time' => 0, 'score' => 1, 'ext' => ''); +$config->score->search->saveQueryAdvanced = array('num' => 1, 'time' => 0, 'score' => 1, 'ext' => ''); diff --git a/module/score/control.php b/module/score/control.php index cec152cb98..a139c2574e 100644 --- a/module/score/control.php +++ b/module/score/control.php @@ -11,17 +11,26 @@ class score extends control { /** * Ajax action score + * javascript use : $.get(createLink('score', 'ajax', "method=method")); * - * @param string $method $.get(createLink('score', 'ajax', "method=selectLang")); + * @param string $method * * @access public * @return void */ public function ajax($method = '') { - $this->loadModel('score')->score('ajax', $method); + $this->loadModel('score')->create('ajax', $method); } + /** + * initialization score + * + * @param int $lastID + * + * @access public + * @return void + */ public function init($lastID = 0) { if(helper::isAjaxRequest()) @@ -40,19 +49,27 @@ class score extends control $this->display(); } - public function refresh($lastID = 0) + /** + * reset all score + * + * @param int $lastID + * + * @access public + * @return void + */ + public function reset($lastID = 0) { if(helper::isAjaxRequest()) { - $result = $this->score->refresh($lastID); + $result = $this->score->reset($lastID); if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError())); if($result['status'] == 'finish') { - $this->send(array('result' => 'finished', 'message' => $this->lang->score->refreshFinish)); + $this->send(array('result' => 'finished', 'message' => $this->lang->score->resetFinish)); } else { - $this->send(array('result' => 'unfinished', 'message' => $this->lang->score->refreshLoading, 'lastID' => $result['lastID'])); + $this->send(array('result' => 'unfinished', 'message' => $this->lang->score->resetLoading, 'lastID' => $result['lastID'])); } } $this->display(); diff --git a/module/score/lang/zh-cn.php b/module/score/lang/zh-cn.php index 76dbc60e99..dacb4aa435 100644 --- a/module/score/lang/zh-cn.php +++ b/module/score/lang/zh-cn.php @@ -8,17 +8,17 @@ $lang->score->initTips = '初始化将根据历史记录计算,执行时 $lang->score->initStart = '开始初始化'; $lang->score->initLoading = '正在初始化...'; $lang->score->initFinish = '初始化完成'; -$lang->score->refresh = '重置积分'; -$lang->score->refreshTips = '重置积分将对所有用户积分清零,执行时间可能会比较长.
    请勿在未完成前关闭窗口'; -$lang->score->refreshStart = '开始重置所有积分'; -$lang->score->refreshLoading = '积分重置中...'; -$lang->score->refreshFinish = '重置完成'; +$lang->score->reset = '重置积分'; +$lang->score->resetTips = '重置积分将对所有用户积分清零,执行时间可能会比较长.
    请勿在未完成前关闭窗口'; +$lang->score->resetStart = '开始重置所有积分'; +$lang->score->resetLoading = '积分重置中...'; +$lang->score->resetFinish = '重置完成'; $lang->score->processed = '正在处理中...'; $lang->score->id = '编号'; $lang->score->userID = '用户ID'; $lang->score->account = '用户'; -$lang->score->model = '模块'; +$lang->score->module = '模块'; $lang->score->method = '动作'; $lang->score->before = '之前'; $lang->score->score = '分值'; diff --git a/module/score/model.php b/module/score/model.php index b558d4dfdb..783f8ffd89 100644 --- a/module/score/model.php +++ b/module/score/model.php @@ -12,23 +12,23 @@ class scoreModel extends model public static $num = 0; /** - * get user score logs + * get user score list * + * @param $account * @param $pager * * @access public * @return array|bool */ - public function getScores($pager) + public function getListByAccount($account, $pager) { - $scores = $this->dao->select('*')->from(TABLE_SCORE)->where('account')->eq($this->app->user->account)->orderBy('time_desc,id_desc')->page($pager)->fetchAll(); - return empty($scores) ? array() : $scores; + return $this->dao->select('*')->from(TABLE_SCORE)->where('account')->eq($account)->orderBy('time_desc,id_desc')->page($pager)->fetchAll(); } /** * add score logs * - * @param string $model + * @param string $module * @param string $method * @param string $param * @param string $account @@ -37,22 +37,25 @@ class scoreModel extends model * @access public * @return bool */ - public function score($model = '', $method = '', $param = '', $account = '', $time = '') + public function create($module = '', $method = '', $param = '', $account = '', $time = '') { - if(!isset($this->config->score->model[$model][$method]) || empty($this->config->score->model[$model][$method])) return true; - $rule = $this->config->score->model[$model][$method]; - $desc = $this->lang->score->models[$model]; + if(!isset($this->config->score->$module->$method) || empty($this->config->score->$module->$method)) return true; + + $rule = $this->config->score->$module->$method; + $desc = $this->lang->score->models[$module]; $user = empty($account) ? $this->app->user->account : $account; $time = empty($time) ? helper::now() : $time; $objectID = is_numeric($param) ? $param : 0; - switch($model) + + switch($module) { case 'user': - if($method == 'login') $desc = $this->lang->score->methods[$model][$method]; + if($method == 'login') $desc = $this->lang->score->methods[$module][$method]; + if($method == 'changePassword') { if(!empty($rule['ext'][$param])) $rule['score'] = $rule['score'] + $rule['ext'][$param]; - $desc = $this->lang->score->methods[$model][$method]; + $desc = $this->lang->score->methods[$module][$method]; } break; case 'doc': @@ -63,6 +66,7 @@ class scoreModel extends model break; case 'story': $desc .= 'ID:' . $param; + if($method == 'close') { $createUser = $this->dao->findById($param)->from(TABLE_STORY)->fetch(); @@ -70,17 +74,17 @@ class scoreModel extends model { $newRule = $rule; $newRule['score'] = $rule['ext']['createID']; - $this->saveScore($createUser->openedBy, $newRule, $model, $method, $desc, $objectID, $time); + $this->saveScore($createUser->openedBy, $newRule, $module, $method, $desc, $objectID, $time); unset($newRule); } } break; case 'task': $desc .= 'ID:' . $param; + if($method == 'finish') { - $desc = $this->lang->score->methods[$model][$method] . 'ID:' . $param; - //每完成一个任务,增加初始积分1 + 工时积分round(工时 /10 * 预计 / 消耗) + 优先级积分(p1 2, p2, 1) 如果任务取消了,没有积分。 + $desc = $this->lang->score->methods[$module][$method] . 'ID:' . $param; $task = $this->loadModel('task')->getById($param); if(!empty($rule['ext'][$task->pri])) $rule['score'] = $rule['score'] + $rule['ext'][$task->pri]; if(!empty($task->estimate)) $rule['score'] = $rule['score'] + round(($task->consumed / 10 * $task->estimate / $task->consumed), 1); @@ -88,6 +92,7 @@ class scoreModel extends model break; case 'bug': if(is_numeric($param)) $desc .= 'ID:' . $param; + if($method == 'createFormCase') { $desc = $this->lang->score->models['testcase'] . 'ID:' . $param; @@ -97,7 +102,9 @@ class scoreModel extends model $user = $caseUser->openedBy; } } - if($method == 'saveTplModal') $desc = $this->lang->score->methods[$model][$method] . 'ID:' . $param; + + if($method == 'saveTplModal') $desc = $this->lang->score->methods[$module][$method] . 'ID:' . $param; + if($method == 'confirmBug') { $objectID = $param->id; @@ -105,6 +112,7 @@ class scoreModel extends model $desc .= 'ID:' . $param->id; if(!empty($rule['ext'][$param->severity])) $rule['score'] = $rule['score'] + $rule['ext'][$param->severity]; } + if($method == 'resolve' && !empty($rule['ext'][$param->severity])) { $objectID = $param->id; @@ -112,7 +120,7 @@ class scoreModel extends model } break; case 'testTask': - if($method == 'runCase') $desc = $this->lang->score->methods[$model][$method] . 'ID:' . $param; + if($method == 'runCase') $desc = $this->lang->score->methods[$module][$method] . 'ID:' . $param; break; case 'build': if($method == 'create') $desc .= 'ID:' . $param; @@ -121,13 +129,15 @@ class scoreModel extends model if($method == 'create') $desc .= 'ID:' . $param; if($method == 'close') { - $desc = $this->lang->score->methods[$model][$method] . ',' . $desc . 'ID:' . $param->id; + $desc = $this->lang->score->methods[$module][$method] . ',' . $desc . 'ID:' . $param->id; $objectID = $param->id; + if(!empty($param->PM)) { $rule['score'] = $param->end > date('Y-m-d', $time) ? $rule['ext']['manager'][0] + $rule['ext']['manager'][1] : $rule['ext']['manager'][0]; - $this->saveScore($param->PM, $rule, $model, $method, $desc, $objectID, $time); + $this->saveScore($param->PM, $rule, $module, $method, $desc, $objectID, $time); } + $teams = $this->dao->select('account')->from(TABLE_TEAM)->where('project')->eq($param->id)->fetchGroup('account'); if(!empty($teams)) { @@ -135,7 +145,7 @@ class scoreModel extends model $rule['score'] = $param->end > date('Y-m-d', $time) ? $rule['ext']['member'][0] + $rule['ext']['member'][1] : $rule['ext']['member'][0]; foreach($users as $user) { - if($user != $param->PM) $this->saveScore($user, $rule, $model, $method, $desc, $objectID, $time); + if($user != $param->PM) $this->saveScore($user, $rule, $module, $method, $desc, $objectID, $time); } } } @@ -152,13 +162,13 @@ class scoreModel extends model break; case 'search': if($method == 'saveQuery') $desc .= 'ID:' . $param; - if($method == 'saveQueryAdvanced') $desc = $this->lang->score->methods[$model][$method]; + if($method == 'saveQueryAdvanced') $desc = $this->lang->score->methods[$module][$method]; break; case 'ajax': - $desc = $this->lang->score->methods[$model][$method]; + $desc = $this->lang->score->methods[$module][$method]; break; } - $this->saveScore($user, $rule, $model, $method, $desc, $objectID, $time); + $this->saveScore($user, $rule, $module, $method, $desc, $objectID, $time); } /** @@ -166,7 +176,7 @@ class scoreModel extends model * * @param string $account * @param array $rule - * @param string $model + * @param string $module * @param string $method * @param string $desc * @param int $objectID @@ -175,19 +185,19 @@ class scoreModel extends model * @access private * @return bool */ - private function saveScore($account = '', $rule = array(), $model = '', $method = '', $desc = '', $objectID = 0, $time = '') + private function saveScore($account = '', $rule = array(), $module = '', $method = '', $desc = '', $objectID = 0, $time = '') { if(!empty($rule['num']) || !empty($rule['time'])) { if(empty($rule['time'])) { - $count = $this->dao->select('id')->from(TABLE_SCORE)->where('account')->eq($account)->andWhere('model')->eq($model)->andWhere('method')->eq($method)->count(); + $count = $this->dao->select('id')->from(TABLE_SCORE)->where('account')->eq($account)->andWhere('model')->eq($module)->andWhere('method')->eq($method)->count(); if($count >= $rule['num']) return true; } else { $timestamp = empty($time) ? time() : strtotime($time); - $count = $this->dao->select('id')->from(TABLE_SCORE)->where('account')->eq($account)->andWhere('time')->between(date('Y-m-d 0:0:0', $timestamp), date('Y-m-d 23:59:59', $timestamp))->andWhere('model')->eq($model)->andWhere('method')->eq($method)->count(); + $count = $this->dao->select('id')->from(TABLE_SCORE)->where('account')->eq($account)->andWhere('time')->between(date('Y-m-d 0:0:0', $timestamp), date('Y-m-d 23:59:59', $timestamp))->andWhere('model')->eq($module)->andWhere('method')->eq($method)->count(); if($count >= $rule['num']) return true; } } @@ -199,7 +209,7 @@ class scoreModel extends model $data = new stdClass(); $data->account = $account; - $data->model = $model; + $data->module = $module; $data->method = $method; $data->desc = $desc; $data->objectID = $objectID; @@ -207,8 +217,10 @@ class scoreModel extends model $data->score = $rule['score']; $data->after = $user->score + $rule['score']; $data->time = empty($time) ? helper::now() : $time; + $this->dao->insert(TABLE_SCORE)->data($data)->exec(); $this->dao->query("UPDATE " . TABLE_USER . " SET `score`=`score` + " . $rule['score'] . ",`scoreLevel`=`scoreLevel` + " . $rule['score'] . " WHERE `account`='" . $account . "'"); + $this->dao->commit(); } catch(ErrorException $e) @@ -218,14 +230,14 @@ class scoreModel extends model } /** - * refresh all user score and level score + * reset all user score and scoreLevel * * @param int $lastID * * @access public * @return void */ - public function refresh($lastID = 0) + public function reset($lastID = 0) { if($lastID == 0) { @@ -234,8 +246,11 @@ class scoreModel extends model $this->dao->query("CREATE TABLE " . TABLE_SCORE . ' LIKE score_bak'); $this->dao->query("UPDATE " . TABLE_USER . " SET `score`=0,`scoreLevel`=0"); } + $actions = $this->dao->select('*')->from('score_bak')->where('id')->gt($lastID)->orderBy('id_asc')->limit(100)->fetchAll('id'); + if(empty($actions)) return array('num' => 0, 'status' => 'finish'); + foreach($actions as $action) { $param = $action->objectID; @@ -243,6 +258,7 @@ class scoreModel extends model if($action->model == 'bug' && ($action->method == 'confirmBug' || $action->method == 'resolve')) $param = $this->dao->findById($action->objectID)->from(TABLE_BUG)->fetch(); $this->score($action->model, $action->method, $param, $action->account, $action->time); } + return array('status' => 'more', 'lastID' => max(array_keys($actions))); } @@ -261,19 +277,23 @@ class scoreModel extends model $this->dao->query("UPDATE " . TABLE_USER . " SET `score`=0,`scoreLevel`=0"); $this->dao->query("TRUNCATE TABLE " . TABLE_SCORE); } + $actions = $this->dao->select('*')->from(TABLE_ACTION)->where('id')->gt($lastID)->orderBy('id_asc')->limit(100)->fetchAll('id'); + if(empty($actions)) { $this->loadModel('setting')->setItem('system.common.global.scoreInit', 1); return array('num' => 0, 'status' => 'finish'); } + foreach($actions as $action) { $param = $action->objectID; if($action->objectType == 'project' && $action->action == 'closed') $param = $this->dao->findById($action->objectID)->from(TABLE_PROJECT)->fetch(); if($action->objectType == 'bug' && ($action->action == 'bugconfirmed' || $action->action == 'resolved')) $param = $this->dao->findById($action->objectID)->from(TABLE_BUG)->fetch(); - $this->score($action->objectType, $this->fix_key($action->action), $param, $action->actor, $action->date); + $this->score($action->objectType, $this->fixKey($action->action), $param, $action->actor, $action->date); } + return array('status' => 'more', 'lastID' => max(array_keys($actions))); } @@ -285,7 +305,7 @@ class scoreModel extends model * @access private * @return mixed */ - private function fix_key($string) + private function fixKey($string) { $strings = array('created' => 'create', 'closed' => 'close', 'finished' => 'finish', 'bugconfirmed' => 'confirmBug', 'resolved' => 'resolve'); return isset($strings[$string]) ? $strings[$string] : $string; diff --git a/module/score/view/refresh.html.php b/module/score/view/refresh.html.php index b986358fa9..9afa211468 100644 --- a/module/score/view/refresh.html.php +++ b/module/score/view/refresh.html.php @@ -10,53 +10,53 @@ */ ?> -
    +
    -

    score->refresh; ?>

    +

    score->reset; ?>


    -

    score->refreshTips; ?>

    +

    score->resetTips; ?>

    - +

    -