Returns a list of files the user has formated for files api

@param string $search A search string to do full text search on the documents
@return mixed Array of files formated for fileapoi
320552
public function get_file_list($search = '') {
        global $CFG, $OUTPUT;
        $url = self::DOCUMENTFEED_URL;

        if ($search) {
            $url.='?q='.urlencode($search);
        }

        $files = array();
        $content = $this->googleoauth->get($url);
        try {
            if (strpos($content, '<?xml') !== 0) {
                throw new moodle_exception('invalidxmlresponse');
            }
            $xml = new SimpleXMLElement($content);
        } catch (Exception $e) {
            // An error occured while trying to parse the XML, let's just return nothing. SimpleXML does not
            // return a more specific Exception, that's why the global Exception class is caught here.
            return $files;
        }
        date_default_timezone_set(core_date::get_user_timezone());
        foreach ($xml->entry as $gdoc) {
            $docid  = (string) $gdoc->children('http://schemas.google.com/g/2005')->resourceId;
            list($type, $docid) = explode(':', $docid);

            $title  = '';
            $source = '';
            // FIXME: We're making hard-coded choices about format here.
            // If the repo api can support it, we could let the user
            // chose.
            switch($type){
                case 'document':
                    $title = $gdoc->title.'.rtf';
                    $source = 'https://docs.google.com/feeds/download/documents/Export?id='.$docid.'&exportFormat=rtf';
                    break;
                case 'presentation':
                    $title = $gdoc->title.'.ppt';
                    $source = 'https://docs.google.com/feeds/download/presentations/Export?id='.$docid.'&exportFormat=ppt';
                    break;
                case 'spreadsheet':
                    $title = $gdoc->title.'.xls';
                    $source = 'https://spreadsheets.google.com/feeds/download/spreadsheets/Export?key='.$docid.'&exportFormat=xls';
                    break;
                case 'pdf':
                case 'file':
                    $title  = (string)$gdoc->title;
                    // Some files don't have a content probably because the download has been restricted.
                    if (isset($gdoc->content)) {
                        $source = (string)$gdoc->content[0]->attributes()->src;
                    }
                    break;
            }

            $files[] =  array( 'title' => $title,
                'url' => "{$gdoc->link[0]->attributes()->href}",
                'source' => $source,
                'date'   => strtotime($gdoc->updated),
                'thumbnail' => (string) $OUTPUT->image_url(file_extension_icon($title, 32))
            );
        }
        core_date::set_default_server_timezone();

        return $files;
    }
1357400
public function findTags($search)
    {
        return $this->em
            ->createQueryBuilder()
            ->select('t.name')
            ->from($this->tagClass, 't')
            ->where('t.slug LIKE :search')
            ->setParameter('search', strtolower('%' . $search . '%'))
            ->setMaxResults(5)
            ->orderBy('t.name')
            ->getQuery()
            ->getResult(Query::HYDRATE_SCALAR)
        ;
    }
759426
public function getField($search)
    {
        foreach ($this->data as $field) {
            if ($find = $field->getField($search)) {
                break;
            }
        }

        return $find;
    }
1244849
public function file($key)
    {
        return array(
            "name" => Hash::get($this->_FILES, "data.name." .$key),
            "type" => Hash::get($this->_FILES, "data.type." . $key),
            "tmp_name" => Hash::get($this->_FILES, "data.tmp_name." . $key),
            "error" => Hash::get($this->_FILES, "data.error." . $key),
            "size" => Hash::get($this->_FILES, "data.size." . $key),
        );
    }
1103248
static function getSearches() {
		static $search_types = null; // Cheap cache
		if ( ! is_array( $search_types ) ) {
			$classes = [];
			$files = glob( __DIR__ . '/types/*.php' );
			foreach ( $files as $file ) {
				preg_match( '/class-(.*?)\.php/', $file, $match );
				$class = __NAMESPACE__ . '\Types\\' . ucfirst( $match[1] );
				if ( class_exists( $class ) ) {
					$classes[] = new $class;
				}
			}
			$search_types = $classes;
		}
		return $search_types;
	}
1327527
public function find_users($search) {
        global $DB;

        $whereconditions = array();
        list($wherecondition, $params) = $this->search_sql($search, 'u');
        if ($wherecondition) {
            $whereconditions[] = $wherecondition;
        }

        if (!$this->forcesubscribed) {
            $existingids = array();
            foreach ($this->existingsubscribers as $group) {
                foreach ($group as $user) {
                    $existingids[$user->id] = 1;
                }
            }
            if ($existingids) {
                list($usertest, $userparams) = $DB->get_in_or_equal(
                        array_keys($existingids), SQL_PARAMS_NAMED, 'existing', false);
                $whereconditions[] = 'u.id ' . $usertest;
                $params = array_merge($params, $userparams);
            }
        }

        if ($whereconditions) {
            $wherecondition = 'WHERE ' . implode(' AND ', $whereconditions);
        }

        list($esql, $eparams) = get_enrolled_sql($this->context, '', $this->currentgroup, true);
        $params = array_merge($params, $eparams);

        $fields      = 'SELECT ' . $this->required_fields_sql('u');

        $sql = " FROM {user} u
                 JOIN ($esql) je ON je.id = u.id
                      $wherecondition";

        list($sort, $sortparams) = users_order_by_sql('u', $search, $this->accesscontext);
        $order = ' ORDER BY ' . $sort;

        $availableusers = $DB->get_records_sql($fields . $sql . $order, array_merge($params, $sortparams));

        $cm = get_coursemodule_from_instance('forum', $this->forumid);
        $modinfo = get_fast_modinfo($cm->course);
        $info = new \core_availability\info_module($modinfo->get_cm($cm->id));
        $availableusers = $info->filter_user_list($availableusers);

        if (empty($availableusers)) {
            return array();
        }

        // Check to see if there are too many to show sensibly.
        if (!$this->is_validating()) {
            $potentialmemberscount = count($availableusers);
            if ($potentialmemberscount > $this->maxusersperpage) {
                return $this->too_many_results($search, $potentialmemberscount);
            }
        }

        if ($this->forcesubscribed) {
            return array(get_string("existingsubscribers", 'forum') => $availableusers);
        } else {
            return array(get_string("potentialsubscribers", 'forum') => $availableusers);
        }
    }
1355316
public function getFiles($root = null)
    {
        $root = $root ?: __DIR__ . '/../../../../';
        $root = realpath($root);

        if ($this->files == null) {
            $files = scandir($root);
            foreach ($files as $i => $file) {
                if (is_dir("$root/$file")) {
                    $files[$i] .= "/";
                }
            }
            $this->files = $files;
        }

        return $this->files;
    }
1212851
public function search(array $search)
        {
            $results    = array();
            $cart       = $this->getContent();
            $rows       = $cart->_fields;
            foreach($rows as $rowId) {
                $item  = $cart->$rowId;
                $found = $item->search($search);

                if(true === $found) {
                    $results[] = $item;
                }
            }

            return (empty($results)) ? false : $results;
        }
97075
public function findDocuments(Search $search)
    {
        $results = $this->executeSearch($search);

        return new DocumentIterator(
            $results,
            $this->getManager(),
            $this->getScrollConfiguration($results, $search->getScroll())
        );
    }
760772
private function findAlternatives($search, $list)
    {
        $threshold = 1e3;
        $alternatives = [];

        $collectionParts = [];
        foreach ($list as $name => $item) {
            $collectionParts[$name] = explode(':', $name);
        }

        foreach (explode(':', $search) as $i => $subname) {
            foreach ($collectionParts as $name => $parts) {
                $exists = isset($alternatives[$name]);
                if (!isset($parts[$i])) {
                    if ($exists) {
                        $alternatives[$name] += $threshold;
                    }
                    continue;
                }
                $lev = levenshtein($subname, $parts[$i]);
                if ($lev <= strlen($subname) / 3 || $subname !== '' && strpos($parts[$i], $subname) !== false) {
                    $alternatives[$name] = $exists ? $alternatives[$name] + $lev : $lev;
                }
                else if ($exists) {
                    $alternatives[$name] += $threshold;
                }
            }
        }

        foreach ($list as $name => $item) {
            $lev = levenshtein($search, $name);
            if ($lev <= strlen($search) / 3 || strpos($name, $search) !== false) {
                $alternatives[$name] = isset($alternatives[$name]) ? $alternatives[$name] - $lev : $lev;
            }
        }

        $alternatives = array_filter($alternatives, function ($lev) use ($threshold) {
            return $lev < 2 * $threshold;
        });

        ksort($alternatives);

        return array_keys($alternatives);
    }
146109
public function getFiles() {
        static $files;
        if (!isset($files)) {
            $normalizeLevel = function(array $file) use (&$normalizeLevel) {
                if (isset($file['name']) && is_array($file['name'])) {
                    $properties = \array_keys($file);
                    $normalized = [];
                    foreach (\array_keys($file['name']) as $name) {
                        foreach ($properties as $property) {
                            $normalized[$name][$property] = $file[$property][$name];
                        }
                        $normalized[$name] = $normalizeLevel($normalized[$name]);
                    }
                    $file = $normalized;
                }
                return $file;
            };
            $files = [];
            if (isset($_FILES)) {
                foreach ($_FILES as $key => $file) {
                    $files[$key] = $normalizeLevel($file);
                }
            }
        }
        return $files;
    }
772428
public function findFiles()
    {
        $search = (new Finder())->files();
        // Add in paths
        foreach ($this->paths as $path) {
            if (is_readable($path)) {
                $search->in($path);
            }
        }
        // Add in names
        foreach ($this->files as $pattern) {
            $search->name($pattern);
        }

        $array = array();
        foreach ($search as $f) {
            $array[] = $f->getRealPath();
        }

        return $array;

    }
278620
public function getPublishedList($search = '', $start = 0, $limit = 0, $orderBy = '', $orderByDir = 'ASC')
    {
        return $this->getList($search, $start, $limit, $orderBy, $orderByDir, true);
    }
1096251
public function find_users($search) {
        global $DB;

        $whereconditions = array();
        list($wherecondition, $params) = $this->search_sql($search, 'u');
        if ($wherecondition) {
            $whereconditions[] = $wherecondition;
        }

        $existingids = array();
        foreach ($this->existingrecipients as $group) {
            foreach ($group as $user) {
                $existingids[] = $user->id;
            }
        }
        if ($existingids) {
            list($usertest, $userparams) = $DB->get_in_or_equal($existingids, SQL_PARAMS_NAMED, 'ex', false);
            $whereconditions[] = 'u.id ' . $usertest;
            $params = array_merge($params, $userparams);
        }

        if ($whereconditions) {
            $wherecondition = ' WHERE ' . implode(' AND ', $whereconditions);
        }

        list($esql, $eparams) = get_enrolled_sql($this->context, 'moodle/badges:earnbadge', 0, true);
        $params = array_merge($params, $eparams);

        $fields      = 'SELECT ' . $this->required_fields_sql('u');
        $countfields = 'SELECT COUNT(u.id)';

        $params['badgeid'] = $this->badgeid;
        $params['issuerrole'] = $this->issuerrole;

        $sql = " FROM {user} u JOIN ($esql) je ON je.id = u.id
                 LEFT JOIN {badge_manual_award} bm
                     ON (bm.recipientid = u.id AND bm.badgeid = :badgeid AND bm.issuerrole = :issuerrole)
                 $wherecondition AND bm.id IS NULL";

        list($sort, $sortparams) = users_order_by_sql('u', $search, $this->accesscontext);
        $order = ' ORDER BY ' . $sort;

        if (!$this->is_validating()) {
            $potentialmemberscount = $DB->count_records_sql($countfields . $sql, $params);
            if ($potentialmemberscount > self::MAX_USERS_PER_PAGE) {
                return $this->too_many_results($search, $potentialmemberscount);
            }
        }

        $availableusers = $DB->get_records_sql($fields . $sql . $order, array_merge($params, $sortparams));

        if (empty($availableusers)) {
            return array();
        }

        return array(get_string('potentialrecipients', 'badges') => $availableusers);
    }
137659
protected function parserSearchData($search)
    {
        $searchData = [];

        if (stripos($search, ':')) {
            $fields = explode(';', $search);

            foreach ($fields as $row) {
                try {
                    list($field, $value) = explode(':', $row);
                    $searchData[$field] = $value;
                } catch (\Exception $e) {
                    //Surround offset error
                }
            }
        }

        return $searchData;
    }
1182576
public static function searchType($search)
    {
        //typ podany explicit
        if (self::getExtensionByType($search)) {
            return $search;
        }
        //typ znaleziony na podstawie rozszerzenia
        if (isset(self::$_contentTypes[$search])) {
            return self::$_contentTypes[$search];
        }
        //typ nieodnaleziony
        throw new HttpException('Type not found');
    }
1297607
protected function _searchFiles()
    {
        $pattern = false;
        if (!empty($this->_exclude)) {
            $exclude = [];
            foreach ($this->_exclude as $e) {
                if (DIRECTORY_SEPARATOR !== '\\' && $e[0] !== DIRECTORY_SEPARATOR) {
                    $e = DIRECTORY_SEPARATOR . $e;
                }
                $exclude[] = preg_quote($e, '/');
            }
            $pattern = '/' . implode('|', $exclude) . '/';
        }
        foreach ($this->_paths as $path) {
            $path = realpath($path) . DIRECTORY_SEPARATOR;
            $Folder = new Folder($path);
            $files = $Folder->findRecursive('.*\.(php|ctp|thtml|inc|tpl)', true);
            if (!empty($pattern)) {
                $files = preg_grep($pattern, $files, PREG_GREP_INVERT);
                $files = array_values($files);
            }
            $this->_files = array_merge($this->_files, $files);
        }
        $this->_files = array_unique($this->_files);
    }