diff --git a/main/calendar/exportEventMembers.php b/main/calendar/exportEventMembers.php index 948db38fb1..f4d689b2e7 100644 --- a/main/calendar/exportEventMembers.php +++ b/main/calendar/exportEventMembers.php @@ -21,20 +21,19 @@ if (empty($id)) { $agenda = new Agenda($type); switch ($action) { - case 'export_invitees' : + case 'export_invitees': if (!$agenda->getIsAllowedToEdit()) { break; } $data = $agenda->exportEventMembersToCsv($id, "Invitee"); Export::arrayToCsv($data); break; - case 'export_subscribers' : + case 'export_subscribers': if (!$agenda->getIsAllowedToEdit()) { break; } $data = $agenda->exportEventMembersToCsv($id, "Subscriber"); Export::arrayToCsv($data); - break; + break; } exit; - diff --git a/main/exercise/fill_blanks.class.php b/main/exercise/fill_blanks.class.php index 008f9074ad..0993dfc929 100755 --- a/main/exercise/fill_blanks.class.php +++ b/main/exercise/fill_blanks.class.php @@ -1384,7 +1384,6 @@ class FillBlanks extends Question $resultsDisabled = false, $showTotalScoreAndUserChoices = false ) { - return self::getHtmlAnswer( $answer, $correct, diff --git a/main/group/group_overview.php b/main/group/group_overview.php index 8fa8151b43..1ee1e0a107 100755 --- a/main/group/group_overview.php +++ b/main/group/group_overview.php @@ -100,7 +100,7 @@ if (isset($_GET['action'])) { exit; } break; - } + } break; case 'export_users': $data = GroupManager::exportStudentsToArray($groupId, true); diff --git a/main/inc/lib/agenda.lib.php b/main/inc/lib/agenda.lib.php index 31c289dfe6..8da328d871 100644 --- a/main/inc/lib/agenda.lib.php +++ b/main/inc/lib/agenda.lib.php @@ -1414,7 +1414,7 @@ class Agenda break; } } - + public function exportEventMembersToCsv(int $id, $type = "Invitee") { if (false === api_get_configuration_value('agenda_event_subscriptions') && false === api_get_configuration_value('agenda_collective_invitations')) { @@ -1444,6 +1444,7 @@ class Agenda $data[$count][] = $user['email']; $count++; } + return $data; } diff --git a/main/inc/lib/extra_field.lib.php b/main/inc/lib/extra_field.lib.php index 2083ce4fb2..2e26f196e4 100755 --- a/main/inc/lib/extra_field.lib.php +++ b/main/inc/lib/extra_field.lib.php @@ -2279,7 +2279,7 @@ class ExtraField extends Model 'variable', [ get_lang('SysId'), - get_lang('ExtraFieldIdComment') + get_lang('ExtraFieldIdComment'), ] ); $form->addElement( diff --git a/main/inc/lib/groupmanager.lib.php b/main/inc/lib/groupmanager.lib.php index be8dce6714..5bf0485d15 100755 --- a/main/inc/lib/groupmanager.lib.php +++ b/main/inc/lib/groupmanager.lib.php @@ -2762,7 +2762,7 @@ class GroupManager * Export all students from a group to an array. * This function works only in a context of a course. * - * @param int $groupId + * @param int $groupId * * @return array */ @@ -2788,6 +2788,7 @@ class GroupManager $data[$count][] = $user['email']; $count++; } + return $data; } diff --git a/main/inc/lib/message.lib.php b/main/inc/lib/message.lib.php index a9c3cd29de..0cb1f863b1 100755 --- a/main/inc/lib/message.lib.php +++ b/main/inc/lib/message.lib.php @@ -3404,6 +3404,25 @@ class MessageManager ); } + /** + * Reports whether the given user is sender or receiver of the given message. + * + * @return bool + */ + public static function isUserOwner(int $userId, int $messageId) + { + $table = Database::get_main_table(TABLE_MESSAGE); + $sql = "SELECT id FROM $table + WHERE id = $messageId + AND (user_receiver_id = $userId OR user_sender_id = $userId)"; + $res = Database::query($sql); + if (Database::num_rows($res) === 1) { + return true; + } + + return false; + } + private static function addTagsFormToInbox(): string { if (false === api_get_configuration_value('enable_message_tags')) { @@ -3486,24 +3505,4 @@ class MessageManager ->setMultiple(true) ; } - - /** - * Reports whether the given user is sender or receiver of the given message - * @param int $userId - * @param int $messageId - * @return bool - */ - public static function isUserOwner(int $userId, int $messageId) - { - $table = Database::get_main_table(TABLE_MESSAGE); - $sql = "SELECT id FROM $table - WHERE id = $messageId - AND (user_receiver_id = $userId OR user_sender_id = $userId)"; - $res = Database::query($sql); - if (Database::num_rows($res) === 1) { - return true; - } - - return false; - } } diff --git a/main/inc/lib/usergroup.lib.php b/main/inc/lib/usergroup.lib.php index d786132216..38122404d5 100755 --- a/main/inc/lib/usergroup.lib.php +++ b/main/inc/lib/usergroup.lib.php @@ -719,7 +719,7 @@ class UserGroup extends Model /** * Gets a list of session ids by user group. * - * @param int $id group id + * @param int $id group id * @param bool $returnSessionData Whether to return an array with info (true) or just the session ID (false) * * @return array @@ -1007,6 +1007,7 @@ class UserGroup extends Model api_get_user_id() ); } + return $sessions; } @@ -1043,7 +1044,6 @@ class UserGroup extends Model $this->unsubscribe_courses_from_usergroup($usergroup_id, $delete_items); } - $courses = []; // Adding new relationships if (!empty($new_items)) { @@ -1124,7 +1124,8 @@ class UserGroup extends Model } /** - * Unsubscribe a usergroup from a list of courses + * Unsubscribe a usergroup from a list of courses. + * * @param int $usergroup_id * @param array $delete_items */ @@ -1173,9 +1174,11 @@ class UserGroup extends Model } /** - * Unsubscribe a usergroup from a list of sessions + * Unsubscribe a usergroup from a list of sessions. + * * @param int $groupId - * @param array $items Session IDs to remove from the group + * @param array $items Session IDs to remove from the group + * * @return array The list of session IDs that have been unsubscribed from the group */ public function unsubscribeSessionsFromUserGroup($groupId, $items) @@ -1414,7 +1417,7 @@ class UserGroup extends Model } /** - * Returns whether teachers can access the classes, as per 'allow_teachers_to_classes' setting + * Returns whether teachers can access the classes, as per 'allow_teachers_to_classes' setting. * * @return bool */ @@ -1932,6 +1935,7 @@ class UserGroup extends Model api_get_user_id() ); } + return $res; } @@ -2443,7 +2447,7 @@ class UserGroup extends Model } /** - * Deletes the subscription of a user to a usergroup + * Deletes the subscription of a user to a usergroup. * * @author Julio Montoya * diff --git a/main/inc/lib/webservices/Rest.php b/main/inc/lib/webservices/Rest.php index a5dbb47f79..7e8ae21123 100644 --- a/main/inc/lib/webservices/Rest.php +++ b/main/inc/lib/webservices/Rest.php @@ -1856,7 +1856,6 @@ class Rest extends WebService /** * @param $userParam * - * @return array * @throws Exception */ public function addUser($userParam): array @@ -2116,7 +2115,8 @@ class Rest extends WebService } /** - * Add a group + * Add a group. + * * @param array Params */ public function createGroup($params) @@ -2125,8 +2125,6 @@ class Rest extends WebService $name = $params['name']; $description = $params['description']; - - } /** @@ -2780,6 +2778,7 @@ class Rest extends WebService public function groupExists($name) { $userGroup = new UserGroup(); + return false !== $userGroup->usergroup_exists($name); } @@ -3984,52 +3983,11 @@ class Rest extends WebService exit; } - protected static function generateApiKeyForUser(int $userId): string - { - UserManager::add_api_key($userId, self::SERVICE_NAME); - - $apiKeys = UserManager::get_api_keys($userId, self::SERVICE_NAME); - - return current($apiKeys); - } - - /** - * @param array $additionalParams Optional - * - * @return string - */ - private function encodeParams(array $additionalParams = []) - { - $params = array_merge( - $additionalParams, - [ - 'api_key' => $this->apiKey, - 'username' => $this->user->getUsername(), - ] - ); - - return json_encode($params); - } - - private function generateUrl(array $additionalParams = []): string - { - $queryParams = [ - 'course' => $this->course ? $this->course->getId() : null, - 'session' => $this->session ? $this->session->getId() : null, - 'api_key' => $this->apiKey, - 'username' => $this->user->getUsername(), - ]; - - return api_get_self().'?' - .http_build_query(array_merge($queryParams, $additionalParams)); - } - /** - * Create a group/class + * Create a group/class. * * @param $params * - * @return array * @throws Exception */ public function addGroup($params): array @@ -4056,12 +4014,11 @@ class Rest extends WebService } /** - * Delete a group/class + * Delete a group/class. * - * @param int $id + * @throws Exception * * @return bool - * @throws Exception */ public function deleteGroup(int $id): array { @@ -4081,8 +4038,8 @@ class Rest extends WebService } /** - * Get the list of users subscribed to the given group/class - * @param int $groupId + * Get the list of users subscribed to the given group/class. + * * @return array The list of users (userID => [firstname, lastname, relation_type] */ public function getGroupSubscribedUsers(int $groupId): array @@ -4093,8 +4050,8 @@ class Rest extends WebService } /** - * Get the list of courses to which the given group/class is subscribed - * @param int $groupId + * Get the list of courses to which the given group/class is subscribed. + * * @return array The list of courses (ID => [title] */ public function getGroupSubscribedCourses(int $groupId): array @@ -4104,9 +4061,9 @@ class Rest extends WebService return $userGroup->get_courses_by_usergroup($groupId, true); } - /** - * Get the list of sessions to which the given group/class is subscribed - * @param int $groupId + /** + * Get the list of sessions to which the given group/class is subscribed. + * * @return array The list of courses (ID => [title] */ public function getGroupSubscribedSessions(int $groupId): array @@ -4117,9 +4074,8 @@ class Rest extends WebService } /** - * Add a new user to the given group/class - * @param int $groupId - * @param int $userId + * Add a new user to the given group/class. + * * @param int $relationType (1:admin, 2:reader, etc. See GROUP_USER_PERMISSION_ constants in api.lib.php) * * @return array One item array containing true on success, false otherwise @@ -4132,9 +4088,8 @@ class Rest extends WebService } /** - * Add a new course to which the given group/class is subscribed - * @param int $groupId - * @param int $courseId + * Add a new course to which the given group/class is subscribed. + * * @return array One item array containing the ID of the course on success, nothing on failure */ public function addGroupSubscribedCourse(int $groupId, int $courseId): array @@ -4145,22 +4100,19 @@ class Rest extends WebService } /** - * Add a new session to which the given group/class is subscribed - * @param int $groupId - * @param int $sessionId + * Add a new session to which the given group/class is subscribed. + * * @return array One item array containing the ID of the session on success, nothing on failure */ public function addGroupSubscribedSession(int $groupId, int $sessionId): array { $userGroup = new UserGroup(); - return [$userGroup->subscribe_sessions_to_usergroup($groupId, [$sessionId] ,false)]; + return [$userGroup->subscribe_sessions_to_usergroup($groupId, [$sessionId], false)]; } /** - * Remove a user from the given group/class - * @param int $groupId - * @param int $userId + * Remove a user from the given group/class. * * @return array One item array containing true on success, false otherwise */ @@ -4172,9 +4124,8 @@ class Rest extends WebService } /** - * Remove a course to which the given group/class is subscribed - * @param int $groupId - * @param int $courseId + * Remove a course to which the given group/class is subscribed. + * * @return array One item array containing true on success, false otherwise */ public function deleteGroupSubscribedCourse(int $groupId, int $courseId): array @@ -4185,15 +4136,54 @@ class Rest extends WebService } /** - * Remove a session to which the given group/class is subscribed - * @param int $groupId - * @param int $sessionId + * Remove a session to which the given group/class is subscribed. + * * @return array One item array containing true on success, false otherwise */ public function deleteGroupSubscribedSession(int $groupId, int $sessionId): array { $userGroup = new UserGroup(); - return [$userGroup->unsubscribeSessionsFromUserGroup($groupId, [$sessionId] ,false)]; + return [$userGroup->unsubscribeSessionsFromUserGroup($groupId, [$sessionId], false)]; + } + + protected static function generateApiKeyForUser(int $userId): string + { + UserManager::add_api_key($userId, self::SERVICE_NAME); + + $apiKeys = UserManager::get_api_keys($userId, self::SERVICE_NAME); + + return current($apiKeys); + } + + /** + * @param array $additionalParams Optional + * + * @return string + */ + private function encodeParams(array $additionalParams = []) + { + $params = array_merge( + $additionalParams, + [ + 'api_key' => $this->apiKey, + 'username' => $this->user->getUsername(), + ] + ); + + return json_encode($params); + } + + private function generateUrl(array $additionalParams = []): string + { + $queryParams = [ + 'course' => $this->course ? $this->course->getId() : null, + 'session' => $this->session ? $this->session->getId() : null, + 'api_key' => $this->apiKey, + 'username' => $this->user->getUsername(), + ]; + + return api_get_self().'?' + .http_build_query(array_merge($queryParams, $additionalParams)); } }