| Conditions | 18 |
| Paths | 276 |
| 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 |
||
| 88 | public static function getPermissions($studentId, $currentUserId) |
||
| 89 | { |
||
| 90 | $params = ['variable = ? AND subkey = ?' => ['status', 'studentfollowup']]; |
||
| 91 | $result = api_get_settings_params_simple($params); |
||
| 92 | $installed = false; |
||
| 93 | if (!empty($result) && $result['selected_value'] === 'installed') { |
||
| 94 | $installed = true; |
||
| 95 | } |
||
| 96 | |||
| 97 | if ($installed == false) { |
||
| 98 | return [ |
||
| 99 | 'is_allow' => false, |
||
| 100 | 'show_private' => false, |
||
| 101 | ]; |
||
| 102 | } |
||
| 103 | |||
| 104 | if ($studentId === $currentUserId) { |
||
| 105 | $isAllow = true; |
||
| 106 | $showPrivate = true; |
||
| 107 | } else { |
||
| 108 | $isDrh = api_is_drh(); |
||
| 109 | $isCareTaker = false; |
||
| 110 | $isDrhRelatedViaPost = false; |
||
| 111 | $isCourseCoach = false; |
||
| 112 | $isDrhRelatedToSession = false; |
||
| 113 | |||
| 114 | // Only admins and DRH that follow the user |
||
| 115 | $isAdmin = api_is_platform_admin(); |
||
| 116 | |||
| 117 | // Check if user is care taker |
||
| 118 | if ($isDrh) { |
||
| 119 | $criteria = [ |
||
| 120 | 'user' => $studentId, |
||
| 121 | 'insertUser' => $currentUserId, |
||
| 122 | ]; |
||
| 123 | $repo = Database::getManager()->getRepository('ChamiloPluginBundle:StudentFollowUp\CarePost'); |
||
| 124 | $post = $repo->findOneBy($criteria); |
||
| 125 | if ($post) { |
||
| 126 | $isDrhRelatedViaPost = true; |
||
| 127 | } |
||
| 128 | |||
| 129 | // Check if course session coach |
||
| 130 | $sessions = SessionManager::get_sessions_by_user($studentId); |
||
| 131 | |||
| 132 | if (!empty($sessions)) { |
||
| 133 | foreach ($sessions as $session) { |
||
| 134 | $sessionId = $session['session_id']; |
||
| 135 | $sessionDrhInfo = SessionManager::getSessionFollowedByDrh( |
||
| 136 | $currentUserId, |
||
| 137 | $sessionId |
||
| 138 | ); |
||
| 139 | if (!empty($sessionDrhInfo)) { |
||
| 140 | $isDrhRelatedToSession = true; |
||
| 141 | break; |
||
| 142 | } |
||
| 143 | foreach ($session['courses'] as $course) { |
||
| 144 | //$isCourseCoach = api_is_coach($sessionId, $course['real_id']); |
||
| 145 | $coachList = SessionManager::getCoachesByCourseSession( |
||
| 146 | $sessionId, |
||
| 147 | $course['real_id'] |
||
| 148 | ); |
||
| 149 | if (!empty($coachList) && in_array($currentUserId, $coachList)) { |
||
| 150 | $isCourseCoach = true; |
||
| 151 | break(2); |
||
| 152 | } |
||
| 153 | } |
||
| 154 | } |
||
| 155 | } |
||
| 156 | |||
| 157 | $isCareTaker = $isDrhRelatedViaPost && $isDrhRelatedToSession; |
||
| 158 | } |
||
| 159 | |||
| 160 | $isAllow = $isAdmin || $isCareTaker || $isDrhRelatedToSession || $isCourseCoach; |
||
| 161 | $showPrivate = $isAdmin || $isCareTaker; |
||
| 162 | } |
||
| 163 | |||
| 164 | return [ |
||
| 165 | 'is_allow' => $isAllow, |
||
| 166 | 'show_private' => $showPrivate, |
||
| 167 | ]; |
||
| 168 | } |
||
| 169 | |||
| 240 |