From 2f966a1d9db5b52e61c42a93020aa2e70b6fcb36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BB=94=E5=93=A5?= Date: Wed, 13 Dec 2017 21:29:58 +0800 Subject: [PATCH] * Task #3465 --- module/my/control.php | 23 +++++++++++---- module/my/view/managecontacts.html.php | 4 +++ module/user/model.php | 39 ++++++++++++++++++++++---- 3 files changed, 55 insertions(+), 11 deletions(-) diff --git a/module/my/control.php b/module/my/control.php index 622322f647..7013141438 100644 --- a/module/my/control.php +++ b/module/my/control.php @@ -418,8 +418,23 @@ class my extends control } } - $mode = empty($mode) ? 'edit' : $mode; - $lists = $this->user->getContactLists($this->app->user->account); + $mode = empty($mode) ? 'edit' : $mode; + $lists = $this->user->getContactLists($this->app->user->account); + + $globalContacts = isset($this->config->my->global->globalContacts) ? $this->config->my->global->globalContacts : ''; + $globalContacts = !empty($globalContacts) ? explode(',', $globalContacts) : array(); + + $myContacts = $this->user->getListByAccount($this->app->user->account); + $disabled = $globalContacts; + + if(!empty($myContacts) && !empty($globalContacts)) + { + foreach($globalContacts as $id) + { + if(in_array($id, array_keys($myContacts))) unset($disabled[array_search($id, $disabled)]); + } + } + $listID = $listID ? $listID : key($lists); if(!$listID) $mode = 'new'; @@ -436,13 +451,11 @@ class my extends control $this->view->list = $this->user->getContactListByID($listID); } - $globalContacts = isset($this->config->my->global->globalContact) ? $this->config->my->global->globalContact : ''; - if(!empty($globalContacts)) $globalContacts = explode(',', $globalContacts); - $this->view->mode = $mode; $this->view->lists = $lists; $this->view->listID = $listID; $this->view->users = $this->user->getPairs('noletter|noempty|noclosed|noclosed'); + $this->view->disabled = $disabled; $this->view->globalContacts = $globalContacts; $this->display(); } diff --git a/module/my/view/managecontacts.html.php b/module/my/view/managecontacts.html.php index 0a52c7ce66..bd8af46356 100644 --- a/module/my/view/managecontacts.html.php +++ b/module/my/view/managecontacts.html.php @@ -73,6 +73,7 @@ ?> + @@ -81,6 +82,8 @@ + + id, $disabled)):?> @@ -88,6 +91,7 @@ delete, 'hiddenwin', "class='btn btn-danger'");?> + diff --git a/module/user/model.php b/module/user/model.php index 36f5153f23..d124add45d 100644 --- a/module/user/model.php +++ b/module/user/model.php @@ -915,15 +915,29 @@ class userModel extends model /** * Get contact list of a user. * - * @param string $account - * @param string $params withempty|withnote + * @param string $account + * @param string $params withempty|withnote + * * @access public * @return object */ public function getContactLists($account, $params= '') { - $contacts = $this->dao->select('id, listName')->from(TABLE_USERCONTACT)->where('account')->eq($account)->fetchPairs(); - if(!$contacts) return array(); + $contacts = $this->getListByAccount($account); + $globalIDs = isset($this->config->my->global->globalContacts) ? $this->config->my->global->globalContacts : ''; + + if(!empty($globalIDs)) + { + $globalIDs = explode(',', $globalIDs); + $globalContacts = $this->dao->select('id, listName')->from(TABLE_USERCONTACT)->where('id')->in($globalIDs)->fetchPairs(); + foreach($globalContacts as $id => $contact) + { + if(in_array($id, array_keys($contacts))) unset($globalContacts[$id]); + } + if(!empty($globalContacts)) $contacts = $globalContacts + $contacts; + } + + if(empty($contacts)) return array(); if(strpos($params, 'withempty') !== false) $contacts = array('' => '') + $contacts; if(strpos($params, 'withnote') !== false) $contacts = array('' => $this->lang->user->contacts->common) + $contacts; @@ -931,6 +945,19 @@ class userModel extends model return $contacts; } + /** + * Get Contact List by account. + * + * @param string $account + * + * @access public + * @return array + */ + public function getListByAccount($account) + { + return $this->dao->select('id, listName')->from(TABLE_USERCONTACT)->where('account')->eq($account)->fetchPairs(); + } + /** * Get a contact list by id. * @@ -1022,7 +1049,7 @@ class userModel extends model */ public function setGlobalContacts($listID, $isPush = true) { - $contacts = $this->loadModel('setting')->getItem("owner=system&module=my§ion=global&key=globalContact"); + $contacts = $this->loadModel('setting')->getItem("owner=system&module=my§ion=global&key=globalContacts"); $contactsIDs = empty($contacts) ? array() : explode(',', $contacts); if($isPush) { @@ -1033,7 +1060,7 @@ class userModel extends model $key = array_search($listID, $contactsIDs); if($key !== false) array_splice($contactsIDs, $key, 1); } - $this->loadModel('setting')->setItem('system.my.global.globalContact', join(',', $contactsIDs)); + $this->loadModel('setting')->setItem('system.my.global.globalContacts', join(',', $contactsIDs)); } /**