original_string: protected static function get_linked_conversation_extra_fields(array $conversations) : array {
          global $DB, $PAGE;
  
          $renderer = $PAGE->get_renderer('core');
  
          $linkedconversations = [];
          foreach ($conversations as $conversation) {
              if (!is_null($conversation->component) && !is_null($conversation->itemtype)) {
                  $linkedconversations[$conversation->component][$conversation->itemtype][$conversation->id]
                      = $conversation->itemid;
              }
          }
          if (empty($linkedconversations)) {
              return [];
          }
  
          // TODO: MDL-63814: Working out the subname for linked conversations should be done in a generic way.
          // Get the itemid, but only for course group linked conversation for now.
          $extrafields = [];
          if (!empty($linkeditems = $linkedconversations['core_group']['groups'])) { // Format: [conversationid => itemid].
              // Get the name of the course to which the group belongs.
              list ($groupidsql, $groupidparams) = $DB->get_in_or_equal(array_values($linkeditems), SQL_PARAMS_NAMED, 'groupid');
              $sql = "SELECT g.*, c.shortname as courseshortname
                        FROM {groups} g
                        JOIN {course} c
                          ON g.courseid = c.id
                       WHERE g.id $groupidsql";
              $courseinfo = $DB->get_records_sql($sql, $groupidparams);
              foreach ($linkeditems as $convid => $groupid) {
                  if (array_key_exists($groupid, $courseinfo)) {
                      $group = $courseinfo[$groupid];
                      // Subname.
                      $extrafields[$convid]['subname'] = format_string($courseinfo[$groupid]->courseshortname);
  
                      // Imageurl.
                      $extrafields[$convid]['imageurl'] = $renderer->image_url('g/g1')->out(false); // default image.
                      if ($url = get_group_picture_url($group, $group->courseid, true)) {
                          $extrafields[$convid]['imageurl'] = $url->out(false);
                      }
                  }
              }
          }
          return $extrafields;
      }
code: protected static function get_linked_conversation_extra_fields(array $conversations) : array {
          global $DB, $PAGE;
  
          $renderer = $PAGE->get_renderer('core');
  
          $linkedconversations = [];
          foreach ($conversations as $conversation) {
              if (!is_null($conversation->component) && !is_null($conversation->itemtype)) {
                  $linkedconversations[$conversation->component][$conversation->itemtype][$conversation->id]
                      = $conversation->itemid;
              }
          }
          if (empty($linkedconversations)) {
              return [];
          }
  
          // TODO: MDL-63814: Working out the subname for linked conversations should be done in a generic way.
          // Get the itemid, but only for course group linked conversation for now.
          $extrafields = [];
          if (!empty($linkeditems = $linkedconversations['core_group']['groups'])) { // Format: [conversationid => itemid].
              // Get the name of the course to which the group belongs.
              list ($groupidsql, $groupidparams) = $DB->get_in_or_equal(array_values($linkeditems), SQL_PARAMS_NAMED, 'groupid');
              $sql = "SELECT g.*, c.shortname as courseshortname
                        FROM {groups} g
                        JOIN {course} c
                          ON g.courseid = c.id
                       WHERE g.id $groupidsql";
              $courseinfo = $DB->get_records_sql($sql, $groupidparams);
              foreach ($linkeditems as $convid => $groupid) {
                  if (array_key_exists($groupid, $courseinfo)) {
                      $group = $courseinfo[$groupid];
                      // Subname.
                      $extrafields[$convid]['subname'] = format_string($courseinfo[$groupid]->courseshortname);
  
                      // Imageurl.
                      $extrafields[$convid]['imageurl'] = $renderer->image_url('g/g1')->out(false); // default image.
                      if ($url = get_group_picture_url($group, $group->courseid, true)) {
                          $extrafields[$convid]['imageurl'] = $url->out(false);
                      }
                  }
              }
          }
          return $extrafields;
      }
code_tokens: protected static function get_linked_conversation_extra_fields ( array $ conversations ) : array { global $ DB , $ PAGE ; $ renderer = $ PAGE -> get_renderer ( 'core' ) ; $ linkedconversations = [ ] ; foreach ( $ conversations as $ conversation ) { if ( ! is_null ( $ conversation -> component ) && ! is_null ( $ conversation -> itemtype ) ) { $ linkedconversations [ $ conversation -> component ] [ $ conversation -> itemtype ] [ $ conversation -> id ] = $ conversation -> itemid ; } } if ( empty ( $ linkedconversations ) ) { return [ ] ; } // TODO: MDL-63814: Working out the subname for linked conversations should be done in a generic way. // Get the itemid, but only for course group linked conversation for now. $ extrafields = [ ] ; if ( ! empty ( $ linkeditems = $ linkedconversations [ 'core_group' ] [ 'groups' ] ) ) { // Format: [conversationid => itemid]. // Get the name of the course to which the group belongs. list ( $ groupidsql , $ groupidparams ) = $ DB -> get_in_or_equal ( array_values ( $ linkeditems ) , SQL_PARAMS_NAMED , 'groupid' ) ; $ sql = "SELECT g.*, c.shortname as courseshortname
                        FROM {groups} g
                        JOIN {course} c
                          ON g.courseid = c.id
                       WHERE g.id $groupidsql" ; $ courseinfo = $ DB -> get_records_sql ( $ sql , $ groupidparams ) ; foreach ( $ linkeditems as $ convid => $ groupid ) { if ( array_key_exists ( $ groupid , $ courseinfo ) ) { $ group = $ courseinfo [ $ groupid ] ; // Subname. $ extrafields [ $ convid ] [ 'subname' ] = format_string ( $ courseinfo [ $ groupid ] -> courseshortname ) ; // Imageurl. $ extrafields [ $ convid ] [ 'imageurl' ] = $ renderer -> image_url ( 'g/g1' ) -> out ( false ) ; // default image. if ( $ url = get_group_picture_url ( $ group , $ group -> courseid , true ) ) { $ extrafields [ $ convid ] [ 'imageurl' ] = $ url -> out ( false ) ; } } } } return $ extrafields ; }
docstring: Gets extra fields, like image url and subname for any conversations linked to components.
  
  The subname is like a subtitle for the conversation, to compliment it's name.
  The imageurl is the location of the image for the conversation, as might be seen on a listing of conversations for a user.
  
  @param array $conversations a list of conversations records.
  @return array the array of subnames, index by conversation id.
  @throws \coding_exception
  @throws \dml_exception
docstring_tokens: Gets extra fields like image url and subname for any conversations linked to components .