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