original_string: public static function get_popup_notifications($useridto, $newestfirst, $limit, $offset) {
          global $USER, $PAGE;
  
          $params = self::validate_parameters(
              self::get_popup_notifications_parameters(),
              array(
                  'useridto' => $useridto,
                  'newestfirst' => $newestfirst,
                  'limit' => $limit,
                  'offset' => $offset,
              )
          );
  
          $context = context_system::instance();
          self::validate_context($context);
  
          $useridto = $params['useridto'];
          $newestfirst = $params['newestfirst'];
          $limit = $params['limit'];
          $offset = $params['offset'];
          $issuperuser = has_capability('moodle/site:readallmessages', $context);
          $renderer = $PAGE->get_renderer('core_message');
  
          if (empty($useridto)) {
              $useridto = $USER->id;
          }
  
          // Check if the current user is the sender/receiver or just a privileged user.
          if ($useridto != $USER->id and !$issuperuser) {
              throw new moodle_exception('accessdenied', 'admin');
          }
  
          if (!empty($useridto)) {
              if (!core_user::is_real_user($useridto)) {
                  throw new moodle_exception('invaliduser');
              }
          }
  
          $sort = $newestfirst ? 'DESC' : 'ASC';
          $notifications = \message_popup\api::get_popup_notifications($useridto, $sort, $limit, $offset);
          $notificationcontexts = [];
  
          if ($notifications) {
              foreach ($notifications as $notification) {
  
                  $notificationoutput = new \message_popup\output\popup_notification($notification);
  
                  $notificationcontext = $notificationoutput->export_for_template($renderer);
  
                  // Keep this for BC.
                  $notificationcontext->deleted = false;
                  $notificationcontexts[] = $notificationcontext;
              }
          }
  
          return array(
              'notifications' => $notificationcontexts,
              'unreadcount' => \message_popup\api::count_unread_popup_notifications($useridto),
          );
      }
code: public static function get_popup_notifications($useridto, $newestfirst, $limit, $offset) {
          global $USER, $PAGE;
  
          $params = self::validate_parameters(
              self::get_popup_notifications_parameters(),
              array(
                  'useridto' => $useridto,
                  'newestfirst' => $newestfirst,
                  'limit' => $limit,
                  'offset' => $offset,
              )
          );
  
          $context = context_system::instance();
          self::validate_context($context);
  
          $useridto = $params['useridto'];
          $newestfirst = $params['newestfirst'];
          $limit = $params['limit'];
          $offset = $params['offset'];
          $issuperuser = has_capability('moodle/site:readallmessages', $context);
          $renderer = $PAGE->get_renderer('core_message');
  
          if (empty($useridto)) {
              $useridto = $USER->id;
          }
  
          // Check if the current user is the sender/receiver or just a privileged user.
          if ($useridto != $USER->id and !$issuperuser) {
              throw new moodle_exception('accessdenied', 'admin');
          }
  
          if (!empty($useridto)) {
              if (!core_user::is_real_user($useridto)) {
                  throw new moodle_exception('invaliduser');
              }
          }
  
          $sort = $newestfirst ? 'DESC' : 'ASC';
          $notifications = \message_popup\api::get_popup_notifications($useridto, $sort, $limit, $offset);
          $notificationcontexts = [];
  
          if ($notifications) {
              foreach ($notifications as $notification) {
  
                  $notificationoutput = new \message_popup\output\popup_notification($notification);
  
                  $notificationcontext = $notificationoutput->export_for_template($renderer);
  
                  // Keep this for BC.
                  $notificationcontext->deleted = false;
                  $notificationcontexts[] = $notificationcontext;
              }
          }
  
          return array(
              'notifications' => $notificationcontexts,
              'unreadcount' => \message_popup\api::count_unread_popup_notifications($useridto),
          );
      }
code_tokens: public static function get_popup_notifications ( $ useridto , $ newestfirst , $ limit , $ offset ) { global $ USER , $ PAGE ; $ params = self :: validate_parameters ( self :: get_popup_notifications_parameters ( ) , array ( 'useridto' => $ useridto , 'newestfirst' => $ newestfirst , 'limit' => $ limit , 'offset' => $ offset , ) ) ; $ context = context_system :: instance ( ) ; self :: validate_context ( $ context ) ; $ useridto = $ params [ 'useridto' ] ; $ newestfirst = $ params [ 'newestfirst' ] ; $ limit = $ params [ 'limit' ] ; $ offset = $ params [ 'offset' ] ; $ issuperuser = has_capability ( 'moodle/site:readallmessages' , $ context ) ; $ renderer = $ PAGE -> get_renderer ( 'core_message' ) ; if ( empty ( $ useridto ) ) { $ useridto = $ USER -> id ; } // Check if the current user is the sender/receiver or just a privileged user. if ( $ useridto != $ USER -> id and ! $ issuperuser ) { throw new moodle_exception ( 'accessdenied' , 'admin' ) ; } if ( ! empty ( $ useridto ) ) { if ( ! core_user :: is_real_user ( $ useridto ) ) { throw new moodle_exception ( 'invaliduser' ) ; } } $ sort = $ newestfirst ? 'DESC' : 'ASC' ; $ notifications = \ message_popup \ api :: get_popup_notifications ( $ useridto , $ sort , $ limit , $ offset ) ; $ notificationcontexts = [ ] ; if ( $ notifications ) { foreach ( $ notifications as $ notification ) { $ notificationoutput = new \ message_popup \ output \ popup_notification ( $ notification ) ; $ notificationcontext = $ notificationoutput -> export_for_template ( $ renderer ) ; // Keep this for BC. $ notificationcontext -> deleted = false ; $ notificationcontexts [ ] = $ notificationcontext ; } } return array ( 'notifications' => $ notificationcontexts , 'unreadcount' => \ message_popup \ api :: count_unread_popup_notifications ( $ useridto ) , ) ; }
docstring: Get notifications function.
  
  @since  3.2
  @throws invalid_parameter_exception
  @throws moodle_exception
  @param  int      $useridto           the user id who received the message
  @param  bool     $newestfirst        true for ordering by newest first, false for oldest first
  @param  int      $limit              the number of results to return
  @param  int      $offset             offset the result set by a given amount
  @return external_description
docstring_tokens: Get notifications function .