|
| 1 | +<?php |
| 2 | +/* |
| 3 | + * Fusio - Self-Hosted API Management for Builders. |
| 4 | + * For the current version and information visit <https://www.fusio-project.org/> |
| 5 | + * |
| 6 | + * Copyright (c) Christoph Kappestein <christoph.kappestein@gmail.com> |
| 7 | + * |
| 8 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 | + * you may not use this file except in compliance with the License. |
| 10 | + * You may obtain a copy of the License at |
| 11 | + * |
| 12 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | + * |
| 14 | + * Unless required by applicable law or agreed to in writing, software |
| 15 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | + * See the License for the specific language governing permissions and |
| 18 | + * limitations under the License. |
| 19 | + */ |
| 20 | + |
| 21 | +namespace Fusio\Impl\Backend\View; |
| 22 | + |
| 23 | +use Fusio\Engine\ContextInterface; |
| 24 | +use Fusio\Impl\Backend\Filter\QueryFilter; |
| 25 | +use Fusio\Impl\Table; |
| 26 | +use PSX\Nested\Builder; |
| 27 | +use PSX\Sql\OrderBy; |
| 28 | +use PSX\Sql\ViewAbstract; |
| 29 | + |
| 30 | +/** |
| 31 | + * Taxonomy |
| 32 | + * |
| 33 | + * @author Christoph Kappestein <christoph.kappestein@gmail.com> |
| 34 | + * @license http://www.apache.org/licenses/LICENSE-2.0 |
| 35 | + * @link https://www.fusio-project.org |
| 36 | + */ |
| 37 | +class Taxonomy extends ViewAbstract |
| 38 | +{ |
| 39 | + public function getCollection(QueryFilter $filter, ContextInterface $context) |
| 40 | + { |
| 41 | + $startIndex = $filter->getStartIndex(); |
| 42 | + $count = $filter->getCount(); |
| 43 | + $sortBy = Table\Generated\TaxonomyColumn::tryFrom($filter->getSortBy(Table\Generated\TaxonomyTable::COLUMN_NAME) ?? ''); |
| 44 | + $sortOrder = $filter->getSortOrder(OrderBy::ASC); |
| 45 | + |
| 46 | + $condition = $filter->getCondition([QueryFilter::COLUMN_SEARCH => Table\Generated\TaxonomyTable::COLUMN_NAME]); |
| 47 | + $condition->equals(Table\Generated\TaxonomyTable::COLUMN_TENANT_ID, $context->getTenantId()); |
| 48 | + $condition->in(Table\Generated\TaxonomyTable::COLUMN_STATUS, [Table\Taxonomy::STATUS_ACTIVE]); |
| 49 | + |
| 50 | + $builder = new Builder($this->connection); |
| 51 | + |
| 52 | + $definition = [ |
| 53 | + 'totalResults' => $this->getTable(Table\Taxonomy::class)->getCount($condition), |
| 54 | + 'startIndex' => $startIndex, |
| 55 | + 'itemsPerPage' => $count, |
| 56 | + 'entry' => $builder->doCollection([$this->getTable(Table\Taxonomy::class), 'findAll'], [$condition, $startIndex, $count, $sortBy, $sortOrder], [ |
| 57 | + 'id' => $builder->fieldInteger(Table\Generated\TaxonomyTable::COLUMN_ID), |
| 58 | + 'parentId' => $builder->fieldInteger(Table\Generated\TaxonomyTable::COLUMN_PARENT_ID), |
| 59 | + 'status' => $builder->fieldInteger(Table\Generated\TaxonomyTable::COLUMN_STATUS), |
| 60 | + 'name' => Table\Generated\TaxonomyTable::COLUMN_NAME, |
| 61 | + ]), |
| 62 | + ]; |
| 63 | + |
| 64 | + return $builder->build($definition); |
| 65 | + } |
| 66 | + |
| 67 | + public function getEntity(string $id, ContextInterface $context) |
| 68 | + { |
| 69 | + $builder = new Builder($this->connection); |
| 70 | + |
| 71 | + $definition = $builder->doEntity([$this->getTable(Table\Taxonomy::class), 'findOneByIdentifier'], [$context->getTenantId(), $id], [ |
| 72 | + 'id' => $builder->fieldInteger(Table\Generated\TaxonomyTable::COLUMN_ID), |
| 73 | + 'parentId' => $builder->fieldInteger(Table\Generated\TaxonomyTable::COLUMN_PARENT_ID), |
| 74 | + 'status' => $builder->fieldInteger(Table\Generated\TaxonomyTable::COLUMN_STATUS), |
| 75 | + 'name' => Table\Generated\TaxonomyTable::COLUMN_NAME, |
| 76 | + ]); |
| 77 | + |
| 78 | + return $builder->build($definition); |
| 79 | + } |
| 80 | +} |
0 commit comments