Exemple #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);
     }
 }
Exemple #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);
     }
 }
Exemple #3
0
 /**
  * Get the currently indexed files for a particular document, returns the total count, and a subset of files.
  *
  * @param document $document
  * @param int      $start The row to start the results on. Zero indexed.
  * @param int      $rows The number of rows to fetch
  * @return array   A two element array, the first is the total number of availble results, the second is an array
  *                 of documents for the current request.
  */
 protected function get_indexed_files($document, $start = 0, $rows = 500)
 {
     // Build a custom query that will get any document files that are in our solr_filegroupingid.
     $query = new \SolrQuery();
     // We want to get all file records tied to a document.
     // For efficiency, we are building our own, stripped down, query.
     $query->setQuery('*');
     $query->setRows($rows);
     $query->setStart($start);
     // We want a consistent sorting.
     $query->addSortField('id');
     // We only want the bare minimum of fields.
     $query->addField('id');
     $query->addField('modified');
     $query->addField('title');
     $query->addField('solr_fileid');
     $query->addField('solr_filecontenthash');
     $query->addField('solr_fileindexstatus');
     $query->addFilterQuery('{!cache=false}solr_filegroupingid:(' . $document->get('id') . ')');
     $query->addFilterQuery('type:' . \core_search\manager::TYPE_FILE);
     $response = $this->get_query_response($query);
     if (empty($response->response->numFound)) {
         return array(0, array());
     }
     return array($response->response->numFound, $this->convert_file_results($response));
 }
Exemple #4
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);
     }
 }