Conditions | 10 |
Paths | 25 |
Total Lines | 126 |
Code Lines | 85 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
77 | public function getConfiguration() |
||
78 | { |
||
79 | if ($this->allow()) { |
||
80 | //$translator = $this->connector->translator; |
||
81 | //$code = $this->connector->course->getCode(); |
||
82 | $courseCode = $this->connector->course['code']; |
||
83 | $alias = $courseCode.' '.get_lang('Documents'); |
||
84 | $userId = api_get_user_id(); |
||
85 | $config = [ |
||
86 | 'driver' => 'CourseDriver', |
||
87 | 'path' => $this->getCourseDocumentSysPath(), |
||
88 | 'URL' => $this->getCourseDocumentRelativeWebPath(), |
||
89 | 'accessControl' => [$this, 'access'], |
||
90 | 'alias' => $alias, |
||
91 | 'attributes' => [ |
||
92 | // Hide shared_folder |
||
93 | [ |
||
94 | 'pattern' => '/shared_folder/', |
||
95 | 'read' => false, |
||
96 | 'write' => false, |
||
97 | 'hidden' => true, |
||
98 | 'locked' => false, |
||
99 | ], |
||
100 | [ |
||
101 | 'pattern' => '/^\/index.html$/', |
||
102 | 'read' => false, |
||
103 | 'write' => false, |
||
104 | 'hidden' => true, |
||
105 | 'locked' => false, |
||
106 | ], |
||
107 | ], |
||
108 | ]; |
||
109 | |||
110 | // admin/teachers can create dirs from ckeditor |
||
111 | if ($this->allowToEdit()) { |
||
112 | $config['attributes'][] = [ |
||
113 | 'pattern' => '/^\/learning_path$/', // block delete learning_path |
||
114 | 'read' => true, |
||
115 | 'write' => false, |
||
116 | 'hidden' => false, |
||
117 | 'locked' => true, |
||
118 | ]; |
||
119 | $config['attributes'][] = [ |
||
120 | 'pattern' => '/learning_path\/(.*)/', // allow edit/delete inside learning_path |
||
121 | 'read' => true, |
||
122 | 'write' => true, |
||
123 | 'hidden' => false, |
||
124 | 'locked' => false, |
||
125 | ]; |
||
126 | |||
127 | $defaultDisabled = $this->connector->getDefaultDriverSettings()['disabled']; |
||
128 | $defaultDisabled = array_flip($defaultDisabled); |
||
129 | unset($defaultDisabled['mkdir']); |
||
130 | $defaultDisabled = array_flip($defaultDisabled); |
||
131 | $config['disabled'] = $defaultDisabled; |
||
132 | } else { |
||
133 | $protectedFolders = \DocumentManager::getProtectedFolderFromStudent(); |
||
134 | foreach ($protectedFolders as $folder) { |
||
135 | $config['attributes'][] = [ |
||
136 | 'pattern' => $folder.'/', |
||
137 | 'read' => false, |
||
138 | 'write' => false, |
||
139 | 'hidden' => true, |
||
140 | 'locked' => false, |
||
141 | ]; |
||
142 | } |
||
143 | } |
||
144 | |||
145 | $foldersToHide = \DocumentManager::get_all_document_folders( |
||
146 | $this->connector->course, |
||
147 | null, |
||
148 | false, |
||
149 | true |
||
150 | ); |
||
151 | |||
152 | // Teachers can see all files and folders see #1425 |
||
153 | if ($this->allowToEdit()) { |
||
154 | $foldersToHide = []; |
||
155 | } |
||
156 | |||
157 | if (!empty($foldersToHide)) { |
||
158 | foreach ($foldersToHide as $folder) { |
||
159 | $config['attributes'][] = [ |
||
160 | 'pattern' => '!'.$folder.'!', |
||
161 | 'read' => false, |
||
162 | 'write' => false, |
||
163 | 'hidden' => true, |
||
164 | 'locked' => false, |
||
165 | ]; |
||
166 | } |
||
167 | } |
||
168 | |||
169 | // Hide all groups folders |
||
170 | $config['attributes'][] = [ |
||
171 | 'pattern' => '!_groupdocs_!', |
||
172 | 'read' => false, |
||
173 | 'write' => false, |
||
174 | 'hidden' => true, |
||
175 | 'locked' => false, |
||
176 | ]; |
||
177 | |||
178 | // Allow only the groups I have access |
||
179 | $allGroups = \GroupManager::getAllGroupPerUserSubscription($userId); |
||
180 | if (!empty($allGroups)) { |
||
181 | foreach ($allGroups as $groupInfo) { |
||
182 | $groupId = $groupInfo['iid']; |
||
183 | if (\GroupManager::user_has_access( |
||
184 | $userId, |
||
185 | $groupId, |
||
186 | \GroupManager::GROUP_TOOL_DOCUMENTS |
||
187 | )) { |
||
188 | $config['attributes'][] = [ |
||
189 | 'pattern' => '!'.$groupInfo['secret_directory'].'!', |
||
190 | 'read' => true, |
||
191 | 'write' => false, |
||
192 | 'hidden' => false, |
||
193 | 'locked' => false, |
||
194 | ]; |
||
195 | } |
||
196 | } |
||
197 | } |
||
198 | |||
199 | return $config; |
||
200 | } |
||
201 | |||
202 | return []; |
||
203 | } |
||
472 |