Conditions | 19 |
Paths | 290 |
Total Lines | 81 |
Code Lines | 51 |
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 |
||
80 | public static function getPermissions($studentId, $currentUserId) |
||
81 | { |
||
82 | $installed = AppPlugin::getInstance()->isInstalled('studentfollowup'); |
||
83 | if ($installed === false) { |
||
84 | return [ |
||
85 | 'is_allow' => false, |
||
86 | 'show_private' => false, |
||
87 | ]; |
||
88 | } |
||
89 | |||
90 | if ($studentId === $currentUserId) { |
||
91 | $isAllow = true; |
||
92 | $showPrivate = true; |
||
93 | } else { |
||
94 | $isDrh = api_is_drh(); |
||
95 | $isDrhRelatedViaPost = false; |
||
96 | $isCourseCoach = false; |
||
97 | $isDrhRelatedToSession = false; |
||
98 | |||
99 | // Only admins and DRH that follow the user. |
||
100 | $isAdmin = api_is_platform_admin(); |
||
101 | |||
102 | // Check if user is care taker. |
||
103 | if ($isDrh) { |
||
104 | $criteria = [ |
||
105 | 'user' => $studentId, |
||
106 | 'insertUser' => $currentUserId, |
||
107 | ]; |
||
108 | $repo = Database::getManager()->getRepository('ChamiloPluginBundle:StudentFollowUp\CarePost'); |
||
109 | $post = $repo->findOneBy($criteria); |
||
110 | if ($post) { |
||
111 | $isDrhRelatedViaPost = true; |
||
112 | } |
||
113 | } |
||
114 | |||
115 | // Student sessions. |
||
116 | $sessions = SessionManager::get_sessions_by_user($studentId, true, true); |
||
117 | if (!empty($sessions)) { |
||
118 | foreach ($sessions as $session) { |
||
119 | $sessionId = $session['session_id']; |
||
120 | // Check if the current user is following that session. |
||
121 | $sessionDrhInfo = SessionManager::getSessionFollowedByDrh( |
||
122 | $currentUserId, |
||
123 | $sessionId |
||
124 | ); |
||
125 | if (!empty($sessionDrhInfo)) { |
||
126 | $isDrhRelatedToSession = true; |
||
127 | break; |
||
128 | } |
||
129 | |||
130 | // Check if teacher is coach between the date limits. |
||
131 | $visibility = api_get_session_visibility( |
||
132 | $sessionId, |
||
133 | null, |
||
134 | true, |
||
135 | $currentUserId |
||
136 | ); |
||
137 | |||
138 | if (SESSION_AVAILABLE === $visibility && isset($session['courses']) && !empty($session['courses'])) { |
||
139 | foreach ($session['courses'] as $course) { |
||
140 | $coachList = SessionManager::getCoachesByCourseSession( |
||
141 | $sessionId, |
||
142 | $course['real_id'] |
||
143 | ); |
||
144 | if (!empty($coachList) && in_array($currentUserId, $coachList)) { |
||
145 | $isCourseCoach = true; |
||
146 | break 2; |
||
147 | } |
||
148 | } |
||
149 | } |
||
150 | } |
||
151 | } |
||
152 | |||
153 | $isCareTaker = $isDrhRelatedViaPost && $isDrhRelatedToSession; |
||
154 | $isAllow = $isAdmin || $isCareTaker || $isDrhRelatedToSession || $isCourseCoach; |
||
155 | $showPrivate = $isAdmin || $isCareTaker; |
||
156 | } |
||
157 | |||
158 | return [ |
||
159 | 'is_allow' => $isAllow, |
||
160 | 'show_private' => $showPrivate, |
||
161 | ]; |
||
246 |