<?php
namespace Modules\Orders\Amadeus\Collector\Model\Filters;

class FileParsed extends \ModulesAbstract\ImportedOrdersFileManager\Model\Filters\FileParsedAbstract
{

 	/**
 	 * Get files list from database. The search can be recursevely
 	 * @param String $basePath
 	 * @throws \DBException
 	 * @return Array
 	 */
 	protected function getFilesFromDatabase($basePath)
 	{

 		global $DBTAmadeusParsedFiles;

 		$layoutHandlerSettings = $this->layoutHandler->getSettings();

 		if ($basePath == '/') {
 			$basePath = '';
 		}

 		// search recursevely
 		if ($layoutHandlerSettings['recurse']) {
 			$sql = sprintf("SELECT `filePath` FROM `{$DBTAmadeusParsedFiles}` WHERE `filePath` LIKE '%s%%'", $this->sqlEscapeForRegexpString($basePath));
 		}
 		else {
 			$sql = sprintf("SELECT `filePath` FROM `{$DBTAmadeusParsedFiles}` WHERE `filePath` REGEXP '^%s[^\/]+$'", $this->sqlEscapeForRegexpString($basePath));
 		}

 		$db = \DB::getInstance();

 		$amadeusFiles = $db->GetCol($sql);

 		if ($db->ErrorNo()) {
 			throw new \DBException("Cannot get Amadeus parsed files from database");
 		}

 		return $amadeusFiles;

 	}
}