Gets a stored file for the backup section filearea directory

@param int $itemid item ID
@param string $filepath file path
@param string $filename file name
@return file_info|null file_info instance or null if not found or access not allowed
186758
protected function get_area_backup_section($itemid, $filepath, $filename) {
        global $CFG, $DB;

        if (!has_capability('moodle/backup:backupcourse', $this->context) and !has_capability('moodle/restore:restorecourse', $this->context)) {
            return null;
        }

        if (empty($itemid)) {
            // list all sections
            return new file_info_area_backup_section($this->browser, $this->context, $this->course, $this);
        }

        if (!$section = $DB->get_record('course_sections', array('course'=>$this->course->id, 'id'=>$itemid))) {
            return null; // does not exist
        }

        $fs = get_file_storage();

        $filepath = is_null($filepath) ? '/' : $filepath;
        $filename = is_null($filename) ? '.' : $filename;
        if (!$storedfile = $fs->get_file($this->context->id, 'backup', 'section', $itemid, $filepath, $filename)) {
            if ($filepath === '/' and $filename === '.') {
                $storedfile = new virtual_root_file($this->context->id, 'backup', 'section', $itemid);
            } else {
                // not found
                return null;
            }
        }

        $downloadable = has_capability('moodle/backup:downloadfile', $this->context);
        $uploadable   = has_capability('moodle/restore:uploadfile', $this->context);

        $urlbase = $CFG->wwwroot.'/pluginfile.php';
        return new file_info_stored($this->browser, $this->context, $storedfile, $urlbase, $section->id, true, $downloadable, $uploadable, false);
    }
566649
private function search($itemName, $type = null)
    {
        if (null === $type) {
            $searchArray = $this->getItems();
        } elseif (self::TYPE_FILE == $type) {
            $searchArray = $this->getFiles();
        } else {
            $searchArray = $this->getFolders();
        }

        foreach ($searchArray as $id => $cloudItem) {
            if ($itemName === $cloudItem->getName()) {
                return $cloudItem;
            }
        }

        return null;
    }
507174
public function getFile($sha, $filepath)
    {
        return $this->client->repositories()->getFile($this->id, $filepath, $sha);
    }
177433
public function rename($filepath, $filename) {
        if ($this->fs->file_exists($this->get_contextid(), $this->get_component(), $this->get_filearea(), $this->get_itemid(), $filepath, $filename)) {
            $a = new stdClass();
            $a->contextid = $this->get_contextid();
            $a->component = $this->get_component();
            $a->filearea  = $this->get_filearea();
            $a->itemid    = $this->get_itemid();
            $a->filepath  = $filepath;
            $a->filename  = $filename;
            throw new file_exception('storedfilenotcreated', $a, 'file exists, cannot rename');
        }
        $filerecord = new stdClass;
        $filerecord->filepath = $filepath;
        $filerecord->filename = $filename;
        // populate the pathname hash
        $filerecord->pathnamehash = $this->fs->get_pathname_hash($this->file_record->contextid, $this->file_record->component, $this->file_record->filearea, $this->file_record->itemid, $filepath, $filename);
        $this->update($filerecord);
    }
376106
public function getPath($relativePath, $fileName = null, $ext = '.php')
    {
        $path = Path::join($this->dir, $relativePath);

        return is_null($fileName) ? $path : Path::join($path, $fileName . $ext);
    }
1256569
public function get_file_info($component, $filearea, $itemid, $filepath, $filename) {
        global $DB;

        if (!core_course_category::can_view_category($this->category)) {
            if (empty($component)) {
                // we can not list the category contents, so try parent, or top system
                if ($this->category->parent and $pc = $DB->get_record('course_categories', array('id'=>$this->category->parent))) {
                    $parent = context_coursecat::instance($pc->id, IGNORE_MISSING);
                    return $this->browser->get_file_info($parent);
                } else {
                    return $this->browser->get_file_info();
                }
            }
            return null;
        }

        if (empty($component)) {
            return $this;
        }

        $methodname = "get_area_{$component}_{$filearea}";
        if (method_exists($this, $methodname)) {
            return $this->$methodname($itemid, $filepath, $filename);
        }

        return null;
    }
181846
protected function download(string $filePath, ?string $filename = null): Response
    {
        return ResponseFactory::getInstance()->buildDownload($filePath, $filename);
    }
37023
protected function getMethodObject(string $filePath, string $methodName)
    {
        $statements = $this->parseFile($filePath);
        if (empty($statements)) {
            return null;
        }
        $method = $this->getFunction($methodName, $statements);
        if (empty($method)) {
            return null;
        }

        return $method;
    }
1132463
public function getNextPage($filepath, $entityBase)
    {
        $grabNext = false;
        $fallback = null;

        foreach ($this->getPages() as $url => $page) {
            if ($grabNext && strpos($page['filepath'], $entityBase) !== false) {
                return new ArrayData(
                    array(
                    'Link' => $this->buildUrl($url),
                    'Title' => $page['title']
                    )
                );
            }

            if ($filepath == $page['filepath']) {
                $grabNext = true;
            } elseif (!$fallback && strpos($page['filepath'], $filepath) !== false) {
                $fallback = new ArrayData(
                    array(
                    'Link' => $this->buildUrl($url),
                    'Title' => $page['title'],
                    'Fallback' => true
                    )
                );
            }
        }

        if (!$grabNext) {
            return $fallback;
        }

        return null;
    }
226943
public function store(string $filePath = null, string $disk = null, string $writerType = null, $diskOptions = [])
    {
        $filePath = $filePath ?? $this->filePath ?? null;

        if (null === $filePath) {
            throw NoFilePathGivenException::export();
        }

        return $this->getExporter()->store(
            $this,
            $filePath,
            $disk ?? $this->disk ?? null,
            $writerType ?? $this->writerType ?? null,
            $diskOptions ?? $this->diskOptions ?? []
        );
    }
736818
public function getRelist($itemId)
    {
        $item = Item::findOrFail($itemId);

        Session::forget('photos');

        foreach ($item->photos as $photo) {
            Session::push('photos', [
                'real_path' => $photo->getPath(),
                'filename'  => $photo->photoId,
            ]);
        }

        $categories = Category::leaves()->orderBy('category_id')->get();

        return view('mustard::item.new', [
            'item'       => $item,
            'categories' => $categories,
        ]);
    }
415811
public function parseFile($filePath, array $vars = [])
    {
        if (is_file($filePath)) {
            return $this->parseString(file_get_contents($filePath), $vars);
        }

        // Try to find from filePaths
        if (count($this->filePaths)) {
            foreach ($this->filePaths as $fileDirectory) {
                if (is_file($fileDirectory . $filePath)) {
                    return $this->parseString(file_get_contents($fileDirectory . $filePath), $vars);
                    break;
                }
            }
        }

        return null;
    }
326284
public function getDataItem($itemname)
    {
        if (isset($this->data[$itemname])) {
            return $this->data[$itemname];
        }

        return null;
    }
875912
final public function createFile($filePath = null)
    {
        if (isset($filePath)) {
            $this->filePath = $filePath;
        }

        if (pathinfo($this->filePath, PATHINFO_EXTENSION) === '') {
            $this->filePath .= $this->fileExtension;
        }

        return $this;
    }
733219
public function createFile($filePath, $folderId)
    {
        $fileHandler = $this->container->get('kunstmaan_media.media_handlers.file');

        // Get file from FilePath.
        $data = new File($filePath, true);

        /** @var $media Media */
        $media = $fileHandler->createNew($data);
        /** @var $folder Folder */
        $folder = $this->folderRepository->getFolder($folderId);

        $media->setFolder($folder);

        $fileHandler->prepareMedia($media);
        $fileHandler->updateMedia($media);
        $fileHandler->saveMedia($media);

        $this->em->persist($media);
        $this->em->flush();

        return $media;
    }
144814
public function getCopyRecordByItemNumber ($itemNumber)
    {
        foreach ($this->_records as $record) {
            if ($record->getItemNumber() === $itemNumber) {
                return $record;
            }
        }
        return null;
    }
746316
public static function getListItems($filepath,$ext = "json") {

		// set-up the dispatcher
		$dispatcherInstance = Dispatcher::getInstance();

		// dispatch that the data gather has started
		$dispatcherInstance->dispatch("data.getListItemsStart");

		// default vars
		$sourceDir     = Config::getOption("sourceDir");
		$listItems     = array();
		$listItemsData = array();

		// add list item data, makes 'listItems' a reserved word
		if (file_exists($sourceDir."/".$filepath)) {

			$file = file_get_contents($sourceDir."/".$filepath);

			if ($ext == "json") {
				$listItemsData = json_decode($file, true);
				if ($jsonErrorMessage = JSON::hasError()) {
					JSON::lastErrorMsg($filepath,$jsonErrorMessage,$listItems);
				}
			} else {

				try {
					$listItemsData = YAML::parse($file);
				} catch (ParseException $e) {
					printf("unable to parse ".$pathNameClean.": %s..\n", $e->getMessage());
				}

				// single line of text won't throw a YAML error. returns as string
				if (gettype($listItemsData) == "string") {
					$listItemsData = array();
				}

			}


			$numbers = array("one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve");

			$i = 0;
			$k = 1;
			$c = count($listItemsData)+1;

			while ($k < $c) {

				shuffle($listItemsData);
				$itemsArray = array();

				while ($i < $k) {
					$itemsArray[] = $listItemsData[$i];
					$i++;
				}

				$listItems[$numbers[$k-1]] = $itemsArray;

				$i = 0;
				$k++;

			}

		}

		$dispatcherInstance->dispatch("data.getListItemsEnd");

		return $listItems;

	}