public function isVisible()
 {
     // Is user enroled in the course the folder is in?
     if (($error = $this->isCourseVisible($this->row->course)) !== true) {
         return $error;
     }
     if (DataManager::canUserSeeModule($this->row->course, $this->tableName, $this->row->id)) {
         return true;
     } else {
         return 'notvisible';
     }
 }
 public function path()
 {
     //Get all info for the course this resource is in
     $course = DataManager::getCourse($this->row->courseid);
     $path = $this->getCategoryPath($course->category);
     if (function_exists('\\course_get_icon')) {
         $courseIcon = \course_get_icon($course->id);
     } else {
         $courseIcon = false;
     }
     $path[] = array('title' => 'Course', 'name' => $course->fullname, 'url' => new moodle_url('/course/view.php', array('id' => $course->id)), 'icon' => !empty($courseIcon) ? 'fa fa-' . $courseIcon : 'fa fa-archive');
     //Get all info for the course section this resource is in
     $section = DataManager::getResoureSectionFromCourseModuleID($this->row->moduleid);
     if ($section->name) {
         $path[] = array('title' => 'Section', 'name' => $section->name, 'url' => new moodle_url('/course/view.php', array('id' => $course->id, 'sectionid' => $section->id)), 'icon' => 'fa fa-th');
     }
     $path[] = array('title' => 'Folder', 'name' => $this->row->foldername, 'url' => new moodle_url('/mod/folder/view.php', array('id' => $this->row->folderid)), 'icon' => 'fa fa-folder');
     foreach (explode('/', $this->row->filepath) as $folder) {
         if ($folder) {
             $path[] = array('title' => 'Folder', 'name' => $folder, 'url' => $this->url(), 'icon' => 'fa fa-folder');
         }
     }
     return $path;
 }
 public function showResults($results, $pageNum = 0, $currentTable = false)
 {
     $startTime = DataManager::getDebugTime();
     $results = $this->sliceResultsForPage($results, $pageNum);
     $r = '';
     foreach ($results as $result) {
         if ($currentTable === false || $result->tableName != $currentTable) {
             //Start of a new section in results
             if ($currentTable !== false) {
                 //Close the previous section
                 $r .= html_writer::end_tag('ul');
             }
             //Section header in results
             $sectionDetails = $this->tableName($result->tableName);
             $r .= html_writer::tag('h3', $sectionDetails['icon'] . ' ' . $sectionDetails['title'], array('id' => 'searchresults-' . $result->tableName));
             //Show results from this table
             $r .= html_writer::start_tag('ul', array('class' => 'results'));
             $currentTable = $result->tableName;
         }
         $r .= $this->showResult($result->tableName, $result, $sectionDetails['icon']);
     }
     $r .= html_writer::end_tag('ul');
     $this->displayTime = DataManager::debugTimeTaken($startTime);
     return $r;
 }
Esempio n. 4
0
 /**
  * Go through the array of results and remove those the user doesn't have permission to see
  */
 public function filterResults($removeHiddenResults = true)
 {
     //Site admin can see everything so don't bother filtering
     if (is_siteadmin()) {
         return;
     }
     $this->results['filtered'] = time();
     $startTime = DataManager::getDebugTime();
     //Check if each result is visible
     foreach ($this->results['results'] as $i => &$result) {
         $visible = $result->isVisible();
         if ($visible === null) {
             //null means it should never be displayed
             unset($this->results['results'][$i]);
         } elseif ($visible !== true) {
             if ($removeHiddenResults) {
                 unset($this->results['results'][$i]);
             } else {
                 $result->hiddenReason = $visible;
                 $result->hidden = true;
             }
         }
     }
     //Unset hanging references
     unset($result);
     $this->addTableInfoToResults($this->results);
     if (!$removeHiddenResults) {
         // Hidden results are included, but we want them to go to the bottom
         // Sort the results by 'tableName' then by 'hidden'
         $this->results['results'] = Utils::sortMultidimensionalArray($this->results['results'], "tableName ASC, hidden ASC");
     }
     $this->results['filterTime'] = DataManager::debugTimeTaken($startTime);
 }
<?php

/**
 * Admin settings page for search block
 *
 * @package    block_search
 * @copyright  Anthony Kuske <www.anthonykuske.com>
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
defined('MOODLE_INTERNAL') || die;
require_once $CFG->dirroot . '/blocks/search/classes/DataManager.php';
/*
 * Tables to search
 */
$possibleTables = \block_search\DataManager::getTablesPossibleToSearch();
$settings->add(new admin_setting_configmulticheckbox('block_search/search_tables', get_string('settings_search_tables_name', 'block_search'), get_string('settings_search_tables_desc', 'block_search') . ' <a href="#" onclick=" ' . 'Y.all(\'#admin-search_tables input[type=checkbox]\').set(\'checked\', true); return false;">' . get_string('selectall', 'block_search') . '</a>', '', $possibleTables));
/*
 * Search files in folders?
 */
$settings->add(new admin_setting_configcheckbox('block_search/search_files_in_folders', get_string('settings_search_files_in_folders_name', 'block_search'), get_string('settings_search_files_in_folders_desc', 'block_search'), 1));
/*
 * Pagination
 */
$settings->add(new admin_setting_configtext('block_search/results_per_page', get_string('settings_results_per_page_name', 'block_search'), get_string('settings_results_per_page_desc', 'block_search'), 100, PARAM_INT));
/*
 * Cache
 */
$settings->add(new admin_setting_configtext('block_search/cache_results', get_string('settings_cache_results_name', 'block_search'), get_string('settings_cache_results_desc', 'block_search'), 86400, PARAM_INT));
$settings->add(new admin_setting_configtext('block_search/cache_results_per_user', get_string('settings_cache_results_per_user_name', 'block_search'), get_string('settings_cache_results_per_user_desc', 'block_search'), 900, PARAM_INT));
/*
 * Logging