| Conditions | 5 |
| Paths | 12 |
| Total Lines | 67 |
| Code Lines | 40 |
| 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 |
||
| 37 | function getUsers( |
||
| 38 | $from, |
||
| 39 | $numberItems, |
||
| 40 | $column, |
||
| 41 | $direction, |
||
| 42 | $getCount = false |
||
| 43 | ) { |
||
| 44 | $sessionId = api_get_session_id(); |
||
| 45 | $from = (int) $from; |
||
| 46 | $numberItems = (int) $numberItems; |
||
| 47 | |||
| 48 | $urlCondition = ''; |
||
| 49 | $urlJoin = ''; |
||
| 50 | if (api_is_multiple_url_enabled()) { |
||
| 51 | $accessUrlUser = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); |
||
| 52 | $urlId = api_get_current_access_url_id(); |
||
| 53 | $urlJoin = " INNER JOIN $accessUrlUser a ON (a.user_id = user.id) "; |
||
| 54 | $urlCondition = " AND a.access_url_id = $urlId "; |
||
| 55 | } |
||
| 56 | |||
| 57 | if (empty($time_limit)) { |
||
|
|
|||
| 58 | $time_limit = api_get_setting('time_limit_whosonline'); |
||
| 59 | } else { |
||
| 60 | $time_limit = 60; |
||
| 61 | } |
||
| 62 | |||
| 63 | $online_time = time() - $time_limit * 60; |
||
| 64 | $current_date = api_get_utc_datetime($online_time); |
||
| 65 | |||
| 66 | if ($getCount) { |
||
| 67 | $sql = "SELECT |
||
| 68 | count(DISTINCT last_access.login_user_id) count |
||
| 69 | FROM ".Database::get_main_table(TABLE_STATISTIC_TRACK_E_ONLINE)." AS last_access |
||
| 70 | INNER JOIN ".Database::get_main_table(TABLE_MAIN_USER)." AS user |
||
| 71 | ON user.id = last_access.login_user_id |
||
| 72 | $urlJoin |
||
| 73 | WHERE |
||
| 74 | session_id ='".$sessionId."' AND |
||
| 75 | login_date >= '$current_date' |
||
| 76 | $urlCondition"; |
||
| 77 | $result = Database::query($sql); |
||
| 78 | $result = Database::fetch_array($result); |
||
| 79 | |||
| 80 | return $result['count']; |
||
| 81 | } |
||
| 82 | |||
| 83 | $sql = "SELECT DISTINCT |
||
| 84 | last_access.login_user_id, |
||
| 85 | last_access.c_id |
||
| 86 | FROM ".Database::get_main_table(TABLE_STATISTIC_TRACK_E_ONLINE)." AS last_access |
||
| 87 | INNER JOIN ".Database::get_main_table(TABLE_MAIN_USER)." AS user |
||
| 88 | ON user.id = last_access.login_user_id |
||
| 89 | $urlJoin |
||
| 90 | WHERE |
||
| 91 | session_id ='".$sessionId."' AND |
||
| 92 | login_date >= '$current_date' |
||
| 93 | $urlCondition |
||
| 94 | GROUP BY login_user_id |
||
| 95 | LIMIT $from, $numberItems"; |
||
| 96 | |||
| 97 | $studentsOnline = []; |
||
| 98 | $result = Database::query($sql); |
||
| 99 | while ($user_list = Database::fetch_array($result)) { |
||
| 100 | $studentsOnline[$user_list['login_user_id']] = $user_list; |
||
| 101 | } |
||
| 102 | |||
| 103 | return $studentsOnline; |
||
| 104 | } |
||
| 151 |