Completed
Pull Request — master (#141)
by Maxence
02:40
created

CircleProviderRequest::isAccessibleResult()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 3
eloc 5
nc 3
nop 1
1
<?php
2
/**
3
 * Circles - Bring cloud-users closer together.
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the COPYING file.
7
 *
8
 * @author Maxence Lange <[email protected]>
9
 * @copyright 2017
10
 * @license GNU AGPL version 3 or any later version
11
 *
12
 * This program is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU Affero General Public License as
14
 * published by the Free Software Foundation, either version 3 of the
15
 * License, or (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU Affero General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU Affero General Public License
23
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
24
 *
25
 */
26
27
28
namespace OCA\Circles\Db;
29
30
31
use OCA\Circles\Model\Member;
32
33
class CircleProviderRequest extends CircleProviderRequestBuilder {
34
35
36
	/**
37
	 * @param $userId
38
	 * @param $circleUniqueIds
39
	 * @param $limit
40
	 * @param $offset
41
	 *
42
	 * @return array
43
	 */
44
	public function getFilesForCircles($userId, $circleUniqueIds, $limit, $offset) {
45
46
		$qb = $this->getCompleteSelectSql();
47
		$this->linkToFileCache($qb, $userId);
48
		$this->limitToPage($qb, $limit, $offset);
49
		$this->limitToCircles($qb, $circleUniqueIds);
50
51
		$this->linkToMember($qb, $userId, $this->configService->isLinkedGroupsAllowed());
52
53
		$this->leftJoinShareInitiator($qb);
54
		$cursor = $qb->execute();
55
56
		$object_ids = [];
57 View Code Duplication
		while ($data = $cursor->fetch()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
58
59
			if ($data['initiator_circle_level'] < Member::LEVEL_MEMBER
60
				&& ($data['initiator_group_level'] < Member::LEVEL_MEMBER
61
					|| !$this->configService->isLinkedGroupsAllowed())
62
			) {
63
				continue;
64
			}
65
66
			self::editShareFromParentEntry($data);
67
			if (self::isAccessibleResult($data)) {
68
				$object_ids[] = $data['file_source'];
69
			}
70
		}
71
		$cursor->closeCursor();
72
73
		return $object_ids;
74
	}
75
76
77
	/**
78
	 * Returns whether the given database result can be interpreted as
79
	 * a share with accessible file (not trashed, not deleted)
80
	 *
81
	 * @param $data
82
	 *F
83
	 *
84
	 * @return bool
85
	 */
86
	protected static function isAccessibleResult($data) {
87
		if ($data['fileid'] === null) {
88
			return false;
89
		}
90
91
		return (!(explode('/', $data['path'], 2)[0] !== 'files'
92
				  && explode(':', $data['storage_string_id'], 2)[0] === 'home'));
93
	}
94
95
96
	/**
97
	 * @param $data
98
	 */
99
	protected static function editShareFromParentEntry(&$data) {
100
		if ($data['parent_id'] > 0) {
101
			$data['permissions'] = $data['parent_perms'];
102
			$data['file_target'] = $data['parent_target'];
103
		}
104
	}
105
106
}