Browse Source

adding #12

develop
HerrHase 3 years ago
parent
commit
f7e411f865
5 changed files with 126 additions and 3 deletions
  1. +66
    -0
      app/Repositories/MenuRepository.php
  2. +4
    -2
      app/Repositories/SiteRepository.php
  3. +46
    -0
      app/Repositories/SnippetRepository.php
  4. +10
    -1
      public/index.php
  5. +0
    -0
      storage/.gitkeep

+ 66
- 0
app/Repositories/MenuRepository.php View File

@ -0,0 +1,66 @@
<?php
namespace App\Repositories;
use App\Repositories\RepositoryAbstract;
/**
* request menu items from a menu
*
* @author Björn Hase, Tentakelfabrik
* @license http://opensource.org/licenses/MIT The MIT License
* @link https://gitea.tentakelfabrik.de/Tentakelfabrik/super-gear-directus
*
*/
class MenuRepository extends RepositoryAbstract
{
/** endpoint */
protected $endpoint = 'menu_items';
/**
* find menu_items by name of menu
* menu must be published
*
* @param string $slug
* @return array
*/
public function findOneByName($name)
{
$results = $this->queryBuilder
->fields([
'title',
'target',
'url',
'page.title',
'page.status',
'page.slug',
'menus.sort',
'menus.menus_id.name'
])
->aliases('page[title]', 'page_title')
->aliases('page[status]', 'page_status')
->aliases('page[slug]', 'page_slug')
->filter([
'page' => [
'status' => 'published'
],
'menus' => [
'menus_id' => [
'name' => $name,
'status' => 'published'
]
]
])
->find();
// @TODO Workaround sort functions seems have problems with relationals fields
if (count($results['data'])) {
usort($results['data'], function($a, $b) {
return ($a['menus'][0]['sort'] > $b['menus'][0]['sort']);
});
}
return $results;
}
}

+ 4
- 2
app/Repositories/SiteRepository.php View File

@ -5,7 +5,7 @@ namespace App\Repositories;
use App\Repositories\RepositoryAbstract; use App\Repositories\RepositoryAbstract;
/** /**
* request pages items from directus
* request site singleton
* *
* @author Björn Hase, Tentakelfabrik * @author Björn Hase, Tentakelfabrik
* @license http://opensource.org/licenses/MIT The MIT License * @license http://opensource.org/licenses/MIT The MIT License
@ -29,7 +29,9 @@ class SiteRepository extends RepositoryAbstract
{ {
return $this->queryBuilder return $this->queryBuilder
->fields([ ->fields([
'title', 'description', 'logo'
'title',
'description',
'logo'
]) ])
->aliases('logo[id]', 'logo') ->aliases('logo[id]', 'logo')
->findOne(); ->findOne();


+ 46
- 0
app/Repositories/SnippetRepository.php View File

@ -0,0 +1,46 @@
<?php
namespace App\Repositories;
use App\Repositories\RepositoryAbstract;
/**
* request pages items from directus
*
* @author Björn Hase, Tentakelfabrik
* @license http://opensource.org/licenses/MIT The MIT License
* @link https://gitea.tentakelfabrik.de/Tentakelfabrik/super-gear-directus
*
*/
class SnippetRepository extends RepositoryAbstract
{
/** endpoint */
protected $endpoint = 'snippets';
/**
* find single page with a slug,
* page must be published
*
* @param string $slug
* @return array
*/
public function findByType($type)
{
$results = $this->queryBuilder
->fields([
'title',
'content',
'view',
'blocks',
'files.directus_files_id'
])
->aliases('template', 'view')
->filter([
'type' => $type
])
->find();
return $results;
}
}

+ 10
- 1
public/index.php View File

@ -3,7 +3,16 @@
require __DIR__.'/../vendor/autoload.php'; require __DIR__.'/../vendor/autoload.php';
require __DIR__.'/../app/bootstrap.php'; require __DIR__.'/../app/bootstrap.php';
// default routes
// make sure that all routes with a slug and ending with a "/" redirect to a route without
$flight->route('GET /@slug:[a-z0-9\-]+/$', function() use ($flight) {
// getting position and build route
$position = strlen($flight->request()->url) - 1;
$route = substr_replace($flight->request()->url, '', $position, 1);
$flight->redirect($route);
});
$flight->route('GET /404', array(new App\Controllers\PageController, 'notFoundAction')); $flight->route('GET /404', array(new App\Controllers\PageController, 'notFoundAction'));
$flight->route('GET /(@slug:[a-z0-9\-]+$)', array(new App\Controllers\PageController, 'getAction')); $flight->route('GET /(@slug:[a-z0-9\-]+$)', array(new App\Controllers\PageController, 'getAction'));


+ 0
- 0
storage/.gitkeep View File


Loading…
Cancel
Save