Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:gopeak/masterlab into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
colder-winter committed Mar 20, 2020
2 parents 6abc2fe + 1ce7f92 commit ab11d31
Show file tree
Hide file tree
Showing 29 changed files with 1,058 additions and 285 deletions.
12 changes: 10 additions & 2 deletions app/classes/ProjectGantt.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public function initGanttSetting($projectId)
}
$addArr['is_display_backlog'] = '0';
$addArr['hide_issue_types'] = '';
$addArr['work_dates'] = '[1,2,3,4,5]';

$projectGanttModel->insertByProjectId($addArr, $projectId);
}
}
Expand Down Expand Up @@ -299,6 +301,9 @@ public function getIssuesGroupBySprint($projectId, $isDisplayBacklog='0')
$sprints[] = ['id' => '0', 'name' => '待办事项', 'order_weight' => 0, 'description' => '', 'start_date' => '', 'end_date' => '', 'status' => '1'];
}

$ganttSetting = (new ProjectGanttSettingModel())->getByProject($projectId);
$workDates = json_decode($ganttSetting['work_dates'], true);

$finalArr = [];
$sprintRows = [];
foreach ($sprints as $sprint) {
Expand All @@ -320,7 +325,7 @@ public function getIssuesGroupBySprint($projectId, $isDisplayBacklog='0')
// 计算迭代的用时
$holidays = (new HolidayModel())->getDays($projectId);
$extraWorkerDays = (new ExtraWorkerDayModel())->getDays($projectId);
$sprintDuration = getWorkingDays($sprint['start_date'], $sprint['end_date'], $holidays, $extraWorkerDays);
$sprintDuration = getWorkingDays($sprint['start_date'], $sprint['end_date'], $workDates, $holidays, $extraWorkerDays);
$treeArr = [];
if (!empty($sprintRows[$sprint['id']])) {
foreach ($sprintRows[$sprint['id']] as $k => &$row) {
Expand Down Expand Up @@ -424,6 +429,9 @@ public function getIssuesGroupByActiveSprint($projectId, $isDisplayBacklog='0')
$sprints[] = ['id' => '0', 'name' => '待办事项', 'order_weight' => 0, 'description' => '', 'start_date' => '', 'end_date' => '', 'status' => '1'];
}

$ganttSetting = (new ProjectGanttSettingModel())->getByProject($projectId);
$workDates = json_decode($ganttSetting['work_dates'], true);

$finalArr = [];
$sprintRows = [];
foreach ($sprints as $sprint) {
Expand All @@ -445,7 +453,7 @@ public function getIssuesGroupByActiveSprint($projectId, $isDisplayBacklog='0')
// 计算迭代的用时
$holidays = (new HolidayModel())->getDays($projectId);
$extraWorkerDays = (new ExtraWorkerDayModel())->getDays($projectId);
$sprintDuration = getWorkingDays($sprint['start_date'], $sprint['end_date'], $holidays, $extraWorkerDays);
$sprintDuration = getWorkingDays($sprint['start_date'], $sprint['end_date'], $workDates, $holidays, $extraWorkerDays);

if (!empty($sprintRows[$sprint['id']])) {
foreach ($sprintRows[$sprint['id']] as $k => &$row) {
Expand Down
17 changes: 17 additions & 0 deletions app/classes/UserLogic.php
Original file line number Diff line number Diff line change
Expand Up @@ -586,4 +586,21 @@ public static function getAllUserNameAndId()
$avatarMap = array_column($originalRes, 'avatar', 'uid');
return [$usernameMap, $displayNameMap, $avatarMap];
}

/**
* 判断两个用户是否在一个团队的
* @param $userId1
* @param $userId2
* @return bool
* @throws \Exception
*/
public static function checkUserIsTeam($userId1 ,$userId2)
{
$model = new ProjectUserRoleModel();
$rows1 = $model->getRows('DISTINCT `project_id` as project_id ',['user_id'=>$userId1]);
$user1ProjectIdArr = array_column($rows1, 'project_id');
$rows2 = $model->getRows('DISTINCT `project_id` as project_id ',['user_id'=>$userId2]);
$user2ProjectIdArr = array_column($rows2, 'project_id');
return count(array_intersect($user1ProjectIdArr, $user2ProjectIdArr))>0;
}
}
1 change: 1 addition & 0 deletions app/ctrl/BaseUserCtrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public function __construct()
if (isset($_GET['project_id'])) {
$projectId = (int)$_GET['project_id'];
}

if (!empty($projectId)) {
$this->projectPermArr = PermissionLogic::getUserHaveProjectPermissions(UserAuth::getId(), $projectId, false);
}
Expand Down
160 changes: 98 additions & 62 deletions app/ctrl/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use main\app\classes\WidgetLogic;
use main\app\model\issue\IssueFilterModel;
use main\app\model\issue\IssueModel;
use main\app\model\user\UserMessageModel;
use main\app\model\user\UserModel;
use main\app\model\user\UserTokenModel;
use main\app\model\user\UserSettingModel;
Expand All @@ -33,10 +34,30 @@ class User extends BaseUserCtrl

public $allowSettingFields = ['scheme_style' => 'left', 'layout' => 'aa','page_layout' => 'fixed', 'project_view' => 'issues', 'issue_view' => 'list'];

/**
*
* @var bool
*/
public $isInSameTeam = true;

public $isCurrentUser = true;

public function __construct()
{
parent::__construct();
parent::addGVar('top_menu_active', 'user');
if (isset($_GET['_target'][2])) {
$userId = $_GET['_target'][2];
if($userId==UserAuth::getId()){
$this->isCurrentUser = true;
}else{
$this->isCurrentUser = false;
// 判断指定的用户是否在同一项目中
$this->isInSameTeam = UserLogic::checkUserIsTeam(UserAuth::getId(),$userId);
}
}
parent::addGVar('is_in_same_team', $this->isInSameTeam);
parent::addGVar('is_current_user', $this->isCurrentUser);
}

/**
Expand All @@ -47,27 +68,8 @@ public function pageProfile()
$data = [];
$data['title'] = '个人资料';
$data['nav'] = 'profile';
$userId = '';
if (isset($_GET['_target'][2])) {
$userId = $_GET['_target'][2];
}
$data['other_user'] = [];

if ($userId != '' && $userId != UserAuth::getInstance()->getId()) {
$user = UserModel::getInstance($userId)->getUser();
if (isset($user['create_time'])) {
$user['create_time_text'] = format_unix_time($user['create_time']);
}
if (isset($user['password'])) {
unset($user['password']);
}
$user = UserLogic::format($user);
$data['other_user'] = $user;
}
if (empty($userId)) {
$userId = UserAuth::getInstance()->getId();
}
$data['user_id'] = $userId;
$this->getUserInfoByArg($data);
//print_r($data);
$this->render('gitlab/user/profile.php', $data);
}

Expand All @@ -76,25 +78,7 @@ public function pageLogOperation()
$data = [];
$data['title'] = '操作日志';
$data['nav'] = 'log_operation';
$userId = '';
if (isset($_GET['_target'][2])) {
$userId = $_GET['_target'][2];
}

$data['other_user'] = [];
$data['user_id'] = $userId;
if ($userId != '' && $userId != UserAuth::getInstance()->getId()) {
$user = UserModel::getInstance($userId)->getUser();
if (isset($user['create_time'])) {
$user['create_time_text'] = format_unix_time($user['create_time']);
}
if (isset($user['password'])) {
unset($user['password']);
}
$user = UserLogic::format($user);
$data['other_user'] = $user;
}
$data['user_id'] = $userId;
$this->getCurrentUserInfo($data);
$this->render('gitlab/user/log_operation.php', $data);
}

Expand All @@ -103,23 +87,7 @@ public function pageHaveJoinProjects()
$data = [];
$data['title'] = '参与的项目';
$data['nav'] = 'profile';
$userId = '';
if (isset($_GET['_target'][2])) {
$userId = $_GET['_target'][2];
}
$data['other_user'] = [];
if ($userId != '' && $userId != UserAuth::getInstance()->getId()) {
$user = UserModel::getInstance($userId)->getUser();
if (isset($user['create_time'])) {
$user['create_time_text'] = format_unix_time($user['create_time']);
}
if (isset($user['password'])) {
unset($user['password']);
}
$user = UserLogic::format($user);
$data['other_user'] = $user;
}
$data['user_id'] = $userId;
$this->getCurrentUserInfo($data);
$this->render('gitlab/user/have_join_projects.php', $data);
}

Expand All @@ -128,12 +96,20 @@ public function pageFollowedIssues()
$data = [];
$data['title'] = '关注的事项';
$data['nav'] = 'followed_issues';
$this->getCurrentUserInfo($data);

ConfigLogic::getAllConfigs($data);
$this->render('gitlab/user/follow_issues.php', $data);
}

private function getUserInfoByArg(&$data){
$userId = '';
if (isset($_GET['_target'][2])) {
$userId = $_GET['_target'][2];
}
$data['other_user'] = [];
if ($userId != '' && $userId != UserAuth::getInstance()->getId()) {
$data['profile'] = [];
$data['user_id'] = $userId;
if ($userId != '' && $userId != UserAuth::getId()) {
$user = UserModel::getInstance($userId)->getUser();
if (isset($user['create_time'])) {
$user['create_time_text'] = format_unix_time($user['create_time']);
Expand All @@ -142,12 +118,25 @@ public function pageFollowedIssues()
unset($user['password']);
}
$user = UserLogic::format($user);
$data['other_user'] = $user;
$data['profile'] = $user;
}
$data['user_id'] = $userId;
}

ConfigLogic::getAllConfigs($data);
$this->render('gitlab/user/follow_issues.php', $data);
private function getCurrentUserInfo(&$data){

$userId = UserAuth::getId();
$data['profile'] = [];
$user = UserModel::getInstance($userId)->getUser();
if (isset($user['create_time'])) {
$user['create_time_text'] = format_unix_time($user['create_time']);
}
if (isset($user['password'])) {
unset($user['password']);
}
$user = UserLogic::format($user);
$data['profile'] = $user;
$data['user_id'] = $userId;
}

public function pagePreferences()
Expand All @@ -167,6 +156,53 @@ public function pageFilters()
$this->render('gitlab/user/user_filters.php', $data);
}

public function pageMsgSystem()
{
$data = [];
$data['title'] = '系统消息';
$data['nav'] = 'msg_system';
$this->getCurrentUserInfo($data);
$this->render('twig/user/msg_system.twig', $data);
}

public function fetchMsgSystems()
{
$userId = UserAuth::getInstance()->getId();
$conditionArr = [];
$conditionArr['receiver_uid'] = $userId;
$range = 'all';
if(isset($_GET['range'])){
$range = $_GET['range'];
}
if($range=='unreaded'){
$conditionArr['readed'] = '0';
}
if($range=='readed'){
$conditionArr['readed'] = '1';
}
$orderBy = 'id';
$sort = 'desc';
$pageSize = 20;
$page = 1;
if(isset($_GET['page'])){
$page = (int)$_GET['page'];
}

$model = new UserMessageModel();
$ret = $model->filter($conditionArr, $page, $pageSize, $orderBy, $sort);
list($total, $totalPages, $msgs) = $ret;
$data['msgs'] = $msgs;
$data['total'] = $total;
$data['pages'] = $totalPages;
$data['page_size'] = $pageSize;
$data['page'] = $page;
$data['cur_range'] = $range;
$this->ajaxSuccess('ok', $data);


$this->ajaxSuccess('ok', $data);
}

public function fetchFollowIssues()
{
$userId = UserAuth::getInstance()->getId();
Expand Down
12 changes: 9 additions & 3 deletions app/ctrl/issue/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,9 @@ public function getDuration()
$extraWorkerDays = (new ExtraWorkerDayModel())->getDays($projectId);
$startDate = $_GET['start_date'];
$dueDate = $_GET['due_date'];
$duration = getWorkingDays($startDate, $dueDate, $holidays, $extraWorkerDays);
$ganttSetting = (new ProjectGanttSettingModel())->getByProject($projectId);
$workDates = json_decode($ganttSetting['work_dates'], true);
$duration = getWorkingDays($startDate, $dueDate, $workDates, $holidays, $extraWorkerDays);

$this->ajaxSuccess('ok', $duration);
}
Expand Down Expand Up @@ -1314,7 +1316,9 @@ private function getAddFormInfo(&$params = [])
if(!empty($params['start_date']) && !empty($params['due_date'])){
$holidays = (new HolidayModel())->getDays($params['project_id']);
$extraWorkerDays = (new ExtraWorkerDayModel())->getDays($params['project_id']);
$info['duration'] = getWorkingDays($params['start_date'], $params['due_date'], $holidays, $extraWorkerDays);
$ganttSetting = (new ProjectGanttSettingModel())->getByProject($params['project_id']);
$workDates = json_decode($ganttSetting['work_dates'], true);
$info['duration'] = getWorkingDays($params['start_date'], $params['due_date'], $workDates, $holidays, $extraWorkerDays);
}

$this->initAddGanttWeight($params, $info);
Expand Down Expand Up @@ -1574,7 +1578,9 @@ public function update($params)
$extraWorkerDays = (new ExtraWorkerDayModel())->getDays($issue['project_id']);
$updatedIssue = $issueModel->getById($issueId);
$updateDurationArr = [];
$updateDurationArr['duration'] = getWorkingDays($updatedIssue['start_date'], $updatedIssue['due_date'], $holidays, $extraWorkerDays);
$ganttSetting = (new ProjectGanttSettingModel())->getByProject($issue['project_id']);
$workDates = json_decode($ganttSetting['work_dates'], true);
$updateDurationArr['duration'] = getWorkingDays($updatedIssue['start_date'], $updatedIssue['due_date'], $workDates, $holidays, $extraWorkerDays);
// print_r($updateDurationArr);
list($ret) = $issueModel->updateById($issueId, $updateDurationArr);
if($ret){
Expand Down
Loading

0 comments on commit ab11d31

Please sign in to comment.