Пример #1
0
 /**
  * Add the attached description files.
  *
  * @param document $document The current document
  * @return null
  */
 public function attach_files($document)
 {
     $fs = get_file_storage();
     $cm = $this->get_cm($this->get_module_name(), $document->get('itemid'), $document->get('courseid'));
     $context = \context_module::instance($cm->id);
     $files = $fs->get_area_files($context->id, 'mod_assign', ASSIGN_INTROATTACHMENT_FILEAREA, 0, 'sortorder DESC, id ASC', false);
     foreach ($files as $file) {
         $document->add_stored_file($file);
     }
 }
Пример #2
0
 /**
  * Add the main file to the index.
  *
  * @param document $document The current document
  * @return null
  */
 public function attach_files($document)
 {
     $fs = get_file_storage();
     $cm = $this->get_cm($this->get_module_name(), $document->get('itemid'), $document->get('courseid'));
     $context = \context_module::instance($cm->id);
     // Order by sortorder desc, the first is consided the main file.
     $files = $fs->get_area_files($context->id, 'mod_resource', 'content', 0, 'sortorder DESC, id ASC', false);
     $mainfile = $files ? reset($files) : null;
     if ($mainfile && $mainfile->get_sortorder() > 0) {
         $document->add_stored_file($mainfile);
     }
 }
Пример #3
0
 /**
  * Add the forum post attachments.
  *
  * @param document $document The current document
  * @return null
  */
 public function attach_files($document)
 {
     global $DB;
     $postid = $document->get('itemid');
     try {
         $post = $this->get_post($postid);
     } catch (\dml_missing_record_exception $e) {
         unset($this->postsdata[$postid]);
         debugging('Could not get record to attach files to ' . $document->get('id'), DEBUG_DEVELOPER);
         return;
     }
     // Because this is used during indexing, we don't want to cache posts. Would result in memory leak.
     unset($this->postsdata[$postid]);
     $cm = $this->get_cm('forum', $post->forum, $document->get('courseid'));
     $context = \context_module::instance($cm->id);
     // Get the files and attach them.
     $fs = get_file_storage();
     $files = $fs->get_area_files($context->id, 'mod_forum', 'attachment', $postid, "filename", false);
     foreach ($files as $file) {
         $document->add_stored_file($file);
     }
 }