From 85cc21cf7744c708239d644577a099f520987b5e Mon Sep 17 00:00:00 2001 From: liugang Date: Wed, 22 Nov 2023 16:11:36 +0800 Subject: [PATCH] * user: refactor the dynamic method. --- module/user/control.php | 32 +++++++++++++++----------------- module/user/ui/dynamic.html.php | 12 ++++++------ 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/module/user/control.php b/module/user/control.php index c7521dab36..0e90e9d49d 100755 --- a/module/user/control.php +++ b/module/user/control.php @@ -1132,25 +1132,23 @@ class user extends control } /** - * User dynamic. + * 查看某个用户的动态。 + * View dynamic of a user. * * @param int $userID * @param string $period * @param int $recTotal - * @param string $date - * @param string $direction next|pre + * @param int $date + * @param string $direction next|pre * @access public * @return void */ - public function dynamic($userID = '', $period = 'today', $recTotal = 0, $date = '', $direction = 'next') + public function dynamic(int $userID, string $period = 'today', int $recTotal = 0, int $date = 0, string $direction = 'next') { - $user = $this->user->getById($userID, 'id'); - $account = $user->account; - $deptID = $this->app->user->admin ? 0 : $this->app->user->dept; - $users = $this->loadModel('dept')->getDeptUserPairs($deptID, 'id'); - - /* set menus. */ - $this->view->userList = $this->user->setUserList($users, $userID); + $user = $this->user->getById($userID, 'id'); + $deptID = $this->app->user->admin ? 0 : $this->app->user->dept; + $users = $this->loadModel('dept')->getDeptUserPairs($deptID, 'id'); + if(!isset($users[$userID])) $users[$userID] = $user->realname; /* Save session. */ $uri = $this->app->getURI(true); @@ -1168,19 +1166,19 @@ class user extends control /* Append id for second sort. */ $orderBy = $direction == 'next' ? 'date_desc' : 'date_asc'; - $date = empty($date) ? '' : date('Y-m-d', $date); - $actions = $this->loadModel('action')->getDynamic($account, $period, $orderBy, 50, 'all', 'all', 'all', $date, $direction); + $date = $date ? date('Y-m-d', $date) : ''; + $actions = $this->loadModel('action')->getDynamic($user->account, $period, $orderBy, 50, 'all', 'all', 'all', $date, $direction); $dateGroups = $this->action->buildDateGroup($actions, $direction); if(empty($recTotal)) $recTotal = count($dateGroups) < 2 ? count($dateGroups, 1) - count($dateGroups) : $this->action->getDynamicCount(); /* Assign. */ $this->view->title = $this->lang->user->common . $this->lang->colon . $this->lang->user->dynamic; - $this->view->type = $period; $this->view->users = $this->loadModel('user')->getPairs('noletter'); - $this->view->recTotal = $recTotal; - $this->view->user = $user; $this->view->dateGroups = $dateGroups; - $this->view->direction = $direction; + $this->view->deptUsers = $users; + $this->view->user = $user; + $this->view->period = $period; + $this->view->recTotal = $recTotal; $this->display(); } diff --git a/module/user/ui/dynamic.html.php b/module/user/ui/dynamic.html.php index 0ee517336b..2f5d852560 100644 --- a/module/user/ui/dynamic.html.php +++ b/module/user/ui/dynamic.html.php @@ -14,11 +14,11 @@ include './featurebar.html.php'; /* zin: Define the feature bar on main menu. */ $dynamicNavs = array(); -foreach($lang->user->featureBar['dynamic'] as $period => $label) +foreach($lang->user->featureBar['dynamic'] as $key => $label) { - $dynamicNavs[$period] = array('text' => $label, 'url' => inlink('dynamic', "userID={$user->id}&type={$period}")); + $dynamicNavs[$key] = array('text' => $label, 'url' => inlink('dynamic', "userID={$user->id}&period={$key}")); } -if(isset($dynamicNavs[$type])) $dynamicNavs[$type]['active'] = true; +if(isset($dynamicNavs[$period])) $dynamicNavs[$period]['active'] = true; $content = null; if(empty($dateGroups)) @@ -64,7 +64,7 @@ else div ( setClass('flex-auto px-4 alert actions-box'), - setClass($type == 'today' ? 'border-secondary' : ''), + setClass($period == 'today' ? 'border-secondary' : ''), dynamic ( set::dynamics($actions), @@ -97,8 +97,8 @@ if(!empty($firstAction)) $lastDate = substr($lastAction->originalDate, 0, 10); $hasPre = $this->action->hasPreOrNext($firstDate, 'pre'); $hasNext = $this->action->hasPreOrNext($lastDate, 'next'); - $preLink = $hasPre ? inlink('dynamic', "useID={$user->id}&type={$type}&recTotal={$recTotal}&date=" . strtotime($firstDate) . '&direction=pre') : 'javascript:;'; - $nextLink = $hasNext ? inlink('dynamic', "useID={$user->id}&type={$type}&recTotal={$recTotal}&date=" . strtotime($lastDate) . '&direction=next') : 'javascript:;'; + $preLink = $hasPre ? inlink('dynamic', "userID={$user->id}&period={$period}&recTotal={$recTotal}&date=" . strtotime($firstDate) . '&direction=pre') : 'javascript:;'; + $nextLink = $hasNext ? inlink('dynamic', "userID={$user->id}&period={$period}&recTotal={$recTotal}&date=" . strtotime($lastDate) . '&direction=next') : 'javascript:;'; if($hasPre || $hasNext) {