예제 #1
0
 /**
  * Export the document data to be used as a template context.
  *
  * Adding more info than the required one as people might be interested in extending the template.
  *
  * Although content is a required field when setting up the document, it accepts '' (empty) values
  * as they may be the result of striping out HTML.
  *
  * SECURITY NOTE: It is the responsibility of the document to properly escape any text to be displayed.
  * The renderer will output the content without any further cleaning.
  *
  * @param renderer_base $output The renderer.
  * @return array
  */
 public function export_for_template(\renderer_base $output)
 {
     list($componentname, $areaname) = \core_search\manager::extract_areaid_parts($this->get('areaid'));
     $title = $this->is_set('title') ? $this->format_text($this->get('title')) : '';
     $data = ['componentname' => $componentname, 'areaname' => $areaname, 'courseurl' => course_get_url($this->get('courseid')), 'coursefullname' => format_string($this->get('coursefullname'), true, array('context' => $this->get('contextid'))), 'modified' => userdate($this->get('modified')), 'title' => $title !== '' ? $title : get_string('notitle', 'search'), 'docurl' => $this->get_doc_url(), 'content' => $this->is_set('content') ? $this->format_text($this->get('content')) : null, 'contexturl' => $this->get_context_url(), 'description1' => $this->is_set('description1') ? $this->format_text($this->get('description1')) : null, 'description2' => $this->is_set('description2') ? $this->format_text($this->get('description2')) : null];
     // Now take any attached any files.
     $files = $this->get_files();
     if (!empty($files)) {
         if (count($files) > 1) {
             $filenames = array();
             foreach ($files as $file) {
                 $filenames[] = format_string($file->get_filename(), true, array('context' => $this->get('contextid')));
             }
             $data['multiplefiles'] = true;
             $data['filenames'] = $filenames;
         } else {
             $file = reset($files);
             $data['filename'] = format_string($file->get_filename(), true, array('context' => $this->get('contextid')));
         }
     }
     if ($this->is_set('userid')) {
         $data['userurl'] = new \moodle_url('/user/view.php', array('id' => $this->get('userid'), 'course' => $this->get('courseid')));
         $data['userfullname'] = format_string($this->get('userfullname'), true, array('context' => $this->get('contextid')));
     }
     return $data;
 }
예제 #2
0
 /**
  * Returns a document instance prepared to be rendered.
  *
  * @param \core_search\area\base $searcharea
  * @param array $docdata
  * @return \core_search\document
  */
 protected function to_document(\core_search\area\base $searcharea, $docdata)
 {
     list($componentname, $areaname) = \core_search\manager::extract_areaid_parts($docdata['areaid']);
     $doc = \core_search\document_factory::instance($docdata['itemid'], $componentname, $areaname, $this);
     $doc->set_data_from_engine($docdata);
     $doc->set_doc_url($searcharea->get_doc_url($doc));
     $doc->set_context_url($searcharea->get_context_url($doc));
     // Uses the internal caches to get required data needed to render the document later.
     $course = $this->get_course($doc->get('courseid'));
     $doc->set_extra('coursefullname', $course->fullname);
     if ($doc->is_set('userid')) {
         $user = $this->get_user($doc->get('userid'));
         $doc->set_extra('userfullname', fullname($user));
     }
     return $doc;
 }
예제 #3
0
 /**
  * Export the document data to be used as a template context.
  *
  * Adding more info than the required one as people might be interested in extending the template.
  *
  * Although content is a required field when setting up the document, it accepts '' (empty) values
  * as they may be the result of striping out HTML.
  *
  * @param renderer_base $output The renderer.
  * @return array
  */
 public function export_for_template(\renderer_base $output)
 {
     list($componentname, $areaname) = \core_search\manager::extract_areaid_parts($this->get('areaid'));
     $data = ['courseurl' => new \moodle_url('/course/view.php?id=' . $this->get('courseid')), 'coursefullname' => format_string($this->get('coursefullname'), true, array('context' => $this->get('contextid'))), 'modified' => userdate($this->get('modified')), 'title' => format_string($this->get('title'), true, array('context' => $this->get('contextid'))), 'docurl' => $this->get_doc_url(), 'content' => $this->is_set('content') ? $this->format_text($this->get('content')) : null, 'contexturl' => $this->get_context_url(), 'description1' => $this->is_set('description1') ? $this->format_text($this->get('description1')) : null, 'description2' => $this->is_set('description2') ? $this->format_text($this->get('description2')) : null];
     if ($this->is_set('userid')) {
         $data['userurl'] = new \moodle_url('/user/view.php', array('id' => $this->get('userid'), 'course' => $this->get('courseid')));
         $data['userfullname'] = format_string($this->get('userfullname'), true, array('context' => $this->get('contextid')));
     }
     return $data;
 }
예제 #4
0
파일: base.php 프로젝트: IFPBMoodle/moodle
 /**
  * Returns the config var name.
  *
  * It depends on whether it is a moodle subsystem or a plugin as plugin-related config should remain in their own scope.
  *
  * @access private
  * @return string Config var path including the plugin (or component) and the varname
  */
 public function get_config_var_name()
 {
     if ($this->componenttype === 'core') {
         // Core subsystems config in core_search and setting name using only [a-zA-Z0-9_]+.
         $parts = \core_search\manager::extract_areaid_parts($this->areaid);
         return array('core_search', $parts[0] . '_' . $parts[1]);
     }
     // Plugins config in the plugin scope.
     return array($this->componentname, 'search_' . $this->areaname);
 }