@@ -29,76 +29,76 @@ |
||
29 | 29 | |
30 | 30 | class CommentersSorter implements ISorter { |
31 | 31 | |
32 | - /** @var ICommentsManager */ |
|
33 | - private $commentsManager; |
|
34 | - |
|
35 | - public function __construct(ICommentsManager $commentsManager) { |
|
36 | - $this->commentsManager = $commentsManager; |
|
37 | - } |
|
38 | - |
|
39 | - public function getId() { |
|
40 | - return 'commenters'; |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * Sorts people who commented on the given item atop (descelating) of the |
|
45 | - * others |
|
46 | - * |
|
47 | - * @param array $sortArray |
|
48 | - * @param array $context |
|
49 | - */ |
|
50 | - public function sort(array &$sortArray, array $context) { |
|
51 | - $commenters = $this->retrieveCommentsInformation($context['itemType'], $context['itemId']); |
|
52 | - if(count($commenters) === 0) { |
|
53 | - return; |
|
54 | - } |
|
55 | - |
|
56 | - foreach ($sortArray as $type => &$byType) { |
|
57 | - if(!isset($commenters[$type])) { |
|
58 | - continue; |
|
59 | - } |
|
60 | - |
|
61 | - // at least on PHP 5.6 usort turned out to be not stable. So we add |
|
62 | - // the current index to the value and compare it on a draw |
|
63 | - $i = 0; |
|
64 | - $workArray = array_map(function($element) use (&$i) { |
|
65 | - return [$i++, $element]; |
|
66 | - }, $byType); |
|
67 | - |
|
68 | - usort($workArray, function ($a, $b) use ($commenters, $type) { |
|
69 | - $r = $this->compare($a[1], $b[1], $commenters[$type]); |
|
70 | - if($r === 0) { |
|
71 | - $r = $a[0] - $b[0]; |
|
72 | - } |
|
73 | - return $r; |
|
74 | - }); |
|
75 | - |
|
76 | - // and remove the index values again |
|
77 | - $byType = array_column($workArray, 1); |
|
78 | - } |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * @param $type |
|
83 | - * @param $id |
|
84 | - * @return array |
|
85 | - */ |
|
86 | - protected function retrieveCommentsInformation($type, $id) { |
|
87 | - $comments = $this->commentsManager->getForObject($type, $id, 1); |
|
88 | - if(count($comments) === 0) { |
|
89 | - return []; |
|
90 | - } |
|
91 | - |
|
92 | - return $this->commentsManager->getActorsInTree($comments[0]->getTopmostParentId()); |
|
93 | - } |
|
94 | - |
|
95 | - protected function compare(array $a, array $b, array $commenters) { |
|
96 | - $a = $a['value']['shareWith']; |
|
97 | - $b = $b['value']['shareWith']; |
|
98 | - |
|
99 | - $valueA = isset($commenters[$a]) ? $commenters[$a] : 0; |
|
100 | - $valueB = isset($commenters[$b]) ? $commenters[$b] : 0; |
|
101 | - |
|
102 | - return $valueB - $valueA; |
|
103 | - } |
|
32 | + /** @var ICommentsManager */ |
|
33 | + private $commentsManager; |
|
34 | + |
|
35 | + public function __construct(ICommentsManager $commentsManager) { |
|
36 | + $this->commentsManager = $commentsManager; |
|
37 | + } |
|
38 | + |
|
39 | + public function getId() { |
|
40 | + return 'commenters'; |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * Sorts people who commented on the given item atop (descelating) of the |
|
45 | + * others |
|
46 | + * |
|
47 | + * @param array $sortArray |
|
48 | + * @param array $context |
|
49 | + */ |
|
50 | + public function sort(array &$sortArray, array $context) { |
|
51 | + $commenters = $this->retrieveCommentsInformation($context['itemType'], $context['itemId']); |
|
52 | + if(count($commenters) === 0) { |
|
53 | + return; |
|
54 | + } |
|
55 | + |
|
56 | + foreach ($sortArray as $type => &$byType) { |
|
57 | + if(!isset($commenters[$type])) { |
|
58 | + continue; |
|
59 | + } |
|
60 | + |
|
61 | + // at least on PHP 5.6 usort turned out to be not stable. So we add |
|
62 | + // the current index to the value and compare it on a draw |
|
63 | + $i = 0; |
|
64 | + $workArray = array_map(function($element) use (&$i) { |
|
65 | + return [$i++, $element]; |
|
66 | + }, $byType); |
|
67 | + |
|
68 | + usort($workArray, function ($a, $b) use ($commenters, $type) { |
|
69 | + $r = $this->compare($a[1], $b[1], $commenters[$type]); |
|
70 | + if($r === 0) { |
|
71 | + $r = $a[0] - $b[0]; |
|
72 | + } |
|
73 | + return $r; |
|
74 | + }); |
|
75 | + |
|
76 | + // and remove the index values again |
|
77 | + $byType = array_column($workArray, 1); |
|
78 | + } |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * @param $type |
|
83 | + * @param $id |
|
84 | + * @return array |
|
85 | + */ |
|
86 | + protected function retrieveCommentsInformation($type, $id) { |
|
87 | + $comments = $this->commentsManager->getForObject($type, $id, 1); |
|
88 | + if(count($comments) === 0) { |
|
89 | + return []; |
|
90 | + } |
|
91 | + |
|
92 | + return $this->commentsManager->getActorsInTree($comments[0]->getTopmostParentId()); |
|
93 | + } |
|
94 | + |
|
95 | + protected function compare(array $a, array $b, array $commenters) { |
|
96 | + $a = $a['value']['shareWith']; |
|
97 | + $b = $b['value']['shareWith']; |
|
98 | + |
|
99 | + $valueA = isset($commenters[$a]) ? $commenters[$a] : 0; |
|
100 | + $valueB = isset($commenters[$b]) ? $commenters[$b] : 0; |
|
101 | + |
|
102 | + return $valueB - $valueA; |
|
103 | + } |
|
104 | 104 | } |
@@ -31,70 +31,70 @@ |
||
31 | 31 | |
32 | 32 | class ShareRecipientSorter implements ISorter { |
33 | 33 | |
34 | - /** @var IManager */ |
|
35 | - private $shareManager; |
|
36 | - /** @var Folder */ |
|
37 | - private $userFolder; |
|
34 | + /** @var IManager */ |
|
35 | + private $shareManager; |
|
36 | + /** @var Folder */ |
|
37 | + private $userFolder; |
|
38 | 38 | |
39 | - public function __construct(IManager $shareManager, Folder $userFolder) { |
|
40 | - $this->shareManager = $shareManager; |
|
41 | - $this->userFolder = $userFolder; |
|
42 | - } |
|
39 | + public function __construct(IManager $shareManager, Folder $userFolder) { |
|
40 | + $this->shareManager = $shareManager; |
|
41 | + $this->userFolder = $userFolder; |
|
42 | + } |
|
43 | 43 | |
44 | - public function getId() { |
|
45 | - return 'share-recipients'; |
|
46 | - } |
|
44 | + public function getId() { |
|
45 | + return 'share-recipients'; |
|
46 | + } |
|
47 | 47 | |
48 | - public function sort(array &$sortArray, array $context) { |
|
49 | - // let's be tolerant. Comments uses "files" by default, other usages are often singular |
|
50 | - if($context['itemType'] !== 'files' && $context['itemType'] !== 'file') { |
|
51 | - return; |
|
52 | - } |
|
53 | - /** @var Node[] $nodes */ |
|
54 | - $nodes = $this->userFolder->getById((int)$context['itemId']); |
|
55 | - if(count($nodes) === 0) { |
|
56 | - return; |
|
57 | - } |
|
58 | - $al = $this->shareManager->getAccessList($nodes[0]); |
|
48 | + public function sort(array &$sortArray, array $context) { |
|
49 | + // let's be tolerant. Comments uses "files" by default, other usages are often singular |
|
50 | + if($context['itemType'] !== 'files' && $context['itemType'] !== 'file') { |
|
51 | + return; |
|
52 | + } |
|
53 | + /** @var Node[] $nodes */ |
|
54 | + $nodes = $this->userFolder->getById((int)$context['itemId']); |
|
55 | + if(count($nodes) === 0) { |
|
56 | + return; |
|
57 | + } |
|
58 | + $al = $this->shareManager->getAccessList($nodes[0]); |
|
59 | 59 | |
60 | - foreach ($sortArray as $type => &$byType) { |
|
61 | - if(!isset($al[$type]) || !is_array($al[$type])) { |
|
62 | - continue; |
|
63 | - } |
|
60 | + foreach ($sortArray as $type => &$byType) { |
|
61 | + if(!isset($al[$type]) || !is_array($al[$type])) { |
|
62 | + continue; |
|
63 | + } |
|
64 | 64 | |
65 | - // at least on PHP 5.6 usort turned out to be not stable. So we add |
|
66 | - // the current index to the value and compare it on a draw |
|
67 | - $i = 0; |
|
68 | - $workArray = array_map(function($element) use (&$i) { |
|
69 | - return [$i++, $element]; |
|
70 | - }, $byType); |
|
65 | + // at least on PHP 5.6 usort turned out to be not stable. So we add |
|
66 | + // the current index to the value and compare it on a draw |
|
67 | + $i = 0; |
|
68 | + $workArray = array_map(function($element) use (&$i) { |
|
69 | + return [$i++, $element]; |
|
70 | + }, $byType); |
|
71 | 71 | |
72 | - usort($workArray, function ($a, $b) use ($al, $type) { |
|
73 | - $result = $this->compare($a[1], $b[1], $al[$type]); |
|
74 | - if($result === 0) { |
|
75 | - $result = $a[0] - $b[0]; |
|
76 | - } |
|
77 | - return $result; |
|
78 | - }); |
|
72 | + usort($workArray, function ($a, $b) use ($al, $type) { |
|
73 | + $result = $this->compare($a[1], $b[1], $al[$type]); |
|
74 | + if($result === 0) { |
|
75 | + $result = $a[0] - $b[0]; |
|
76 | + } |
|
77 | + return $result; |
|
78 | + }); |
|
79 | 79 | |
80 | - // and remove the index values again |
|
81 | - $byType = array_column($workArray, 1); |
|
82 | - } |
|
83 | - } |
|
80 | + // and remove the index values again |
|
81 | + $byType = array_column($workArray, 1); |
|
82 | + } |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * @param array $a |
|
87 | - * @param array $b |
|
88 | - * @param array $al |
|
89 | - * @return int |
|
90 | - */ |
|
91 | - protected function compare(array $a, array $b, array $al) { |
|
92 | - $a = $a['value']['shareWith']; |
|
93 | - $b = $b['value']['shareWith']; |
|
85 | + /** |
|
86 | + * @param array $a |
|
87 | + * @param array $b |
|
88 | + * @param array $al |
|
89 | + * @return int |
|
90 | + */ |
|
91 | + protected function compare(array $a, array $b, array $al) { |
|
92 | + $a = $a['value']['shareWith']; |
|
93 | + $b = $b['value']['shareWith']; |
|
94 | 94 | |
95 | - $valueA = (int)in_array($a, $al, true); |
|
96 | - $valueB = (int)in_array($b, $al, true); |
|
95 | + $valueA = (int)in_array($a, $al, true); |
|
96 | + $valueB = (int)in_array($b, $al, true); |
|
97 | 97 | |
98 | - return $valueB - $valueA; |
|
99 | - } |
|
98 | + return $valueB - $valueA; |
|
99 | + } |
|
100 | 100 | } |