From c4a005a69a854682f064016d428d23e50c6e9dee Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Sat, 15 Dec 2018 16:23:19 +0100 Subject: Flywheel extension and custom json formatter --- app/class/modeldb.php | 10 ++++++---- app/class/wflywheel/formatter/json.php | 20 ++++++++++++++++++++ app/class/wflywheel/predicate.php | 11 +++++++++++ app/class/wflywheel/query.php | 16 ++++++++++++++++ app/class/wflywheel/repository.php | 30 ++++++++++++++++++++++++++++++ 5 files changed, 83 insertions(+), 4 deletions(-) create mode 100644 app/class/wflywheel/formatter/json.php create mode 100644 app/class/wflywheel/predicate.php create mode 100644 app/class/wflywheel/query.php create mode 100644 app/class/wflywheel/repository.php diff --git a/app/class/modeldb.php b/app/class/modeldb.php index 94ed084..bc2a0c7 100644 --- a/app/class/modeldb.php +++ b/app/class/modeldb.php @@ -1,10 +1,9 @@ database = new \JamesMoss\Flywheel\Config(Model::DATABASE_DIR); - $this->artstore = new \JamesMoss\Flywheel\Repository(Config::arttable(), $this->database); + $this->database = new \JamesMoss\Flywheel\Config(Model::DATABASE_DIR, [ + 'query_class' => "\WFlywheel\Query", + 'formatter' => new \WFlywheel\Formatter\JSON, + ]); + $this->artstore = new \WFlywheel\Repository(Config::arttable(), $this->database); } diff --git a/app/class/wflywheel/formatter/json.php b/app/class/wflywheel/formatter/json.php new file mode 100644 index 0000000..8583802 --- /dev/null +++ b/app/class/wflywheel/formatter/json.php @@ -0,0 +1,20 @@ +operators = array( + '>', '>=', '<', '<=', '==', '===', '!=', '!==', 'IN' + ); + } +} diff --git a/app/class/wflywheel/query.php b/app/class/wflywheel/query.php new file mode 100644 index 0000000..49aff16 --- /dev/null +++ b/app/class/wflywheel/query.php @@ -0,0 +1,16 @@ +predicate = new Predicate(); + } +} diff --git a/app/class/wflywheel/repository.php b/app/class/wflywheel/repository.php new file mode 100644 index 0000000..baad42e --- /dev/null +++ b/app/class/wflywheel/repository.php @@ -0,0 +1,30 @@ +formatter->getFileExtension(); + $files = glob($this->path . DIRECTORY_SEPARATOR . '*.' . $ext); + return $files; + } + + /** + * Get an array containing the id of all files in this repository + * + * @return array An array, item is a id + */ + public function getAllIds() + { + $ext = $this->formatter->getFileExtension(); + return array_map(function($path) use ($ext) { + return $this->getIdFromPath($path, $ext); + }, $this->getAllFiles()); + } +} -- cgit v1.2.3