- Anmeldeformular für Kinderfeuerwehr fertiggestellt - Fehlerbehebung wegen Umstellung auf https - Navigationsleiste wird in der Kategorie "Wir über uns" dynamisch erstellt
155 lines
3.7 KiB
PHP
155 lines
3.7 KiB
PHP
<?php
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: Marco Glietsch
|
|
* Date: 11.07.2018
|
|
* Time: 14:26
|
|
*/
|
|
|
|
namespace App\Helpers;
|
|
|
|
use App\Models\Tag;
|
|
use App\Models\User;
|
|
use App\Models\Post;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class MenuHelper
|
|
{
|
|
static function getDepartments()
|
|
{
|
|
$model = new Tag();
|
|
$departments = $model->isType('abteilung')
|
|
->orderBy('order', 'ASC')
|
|
->get();
|
|
|
|
return $departments;
|
|
}
|
|
|
|
static function getInstances($departmentId)
|
|
{
|
|
$model = new Tag();
|
|
$instances = $model->isType('instanz')
|
|
->where('name', '!=', 'Gesamtwehr')
|
|
->whereHas('tags2', function ($query) use ($departmentId) {
|
|
$query->where('parent_id', $departmentId);
|
|
})
|
|
->orderBy('name', 'ASC')
|
|
->get();
|
|
|
|
return $instances;
|
|
}
|
|
|
|
static function hasDepartmentMembers($department)
|
|
{
|
|
$members = User::select('tags1.name as membertype')
|
|
->join('user_tag as user_tag1', function($join){
|
|
$join->on('user_tag1.user_id', 'users.id');
|
|
})
|
|
->join('tags as tags1', function($join) use($department){
|
|
$join->on('user_tag1.tag_id', 'tags1.id');
|
|
if($department->name == 'Gesamtwehr')
|
|
{
|
|
$join = $join->where('tags1.type', 'mitgliedsart-gesamtwehr');
|
|
}
|
|
else
|
|
{
|
|
$join = $join->where('tags1.type', 'mitgliedsart-abteilung');
|
|
}
|
|
});
|
|
if($department->name != 'Gesamtwehr')
|
|
{
|
|
$members = $members
|
|
->addSelect('tags2.name as department')
|
|
->join('user_tag as user_tag2', function($join){
|
|
$join->on('user_tag2.user_id', 'users.id');
|
|
})
|
|
->join('tags as tags2', function($join) use($department){
|
|
$join->on('user_tag2.tag_id', 'tags2.id')
|
|
->where('tags2.id', $department->id);
|
|
});
|
|
}
|
|
$members = $members->get();
|
|
|
|
return count($members) ? true : false;
|
|
}
|
|
|
|
static function getDepartmentPages($department)
|
|
{
|
|
$pages = Post::select('posts.*')
|
|
->where('posts.type', 'seite')
|
|
->where('posts.published', true)
|
|
->join('post_tag as post_tag1', function($join){
|
|
$join->on('post_tag1.post_id', 'posts.id');
|
|
})
|
|
->join('tags as tags1', function($join) use($department){
|
|
$join->on('post_tag1.tag_id', 'tags1.id')
|
|
->where('tags1.type', 'seitenkategorie')
|
|
->where('tags1.name', $department->name);
|
|
})
|
|
->get();
|
|
|
|
return $pages;
|
|
}
|
|
|
|
static function getCategoryPages($category, $sites = array())
|
|
{
|
|
$pages = Post::select('posts.*')
|
|
->where('posts.type', 'seite')
|
|
->where('posts.published', true)
|
|
->join('post_tag as post_tag1', function($join){
|
|
$join->on('post_tag1.post_id', 'posts.id');
|
|
})
|
|
->join('tags as tags1', function($join) use($category){
|
|
$join->on('post_tag1.tag_id', 'tags1.id')
|
|
->where('tags1.type', 'seitenkategorie')
|
|
->where('tags1.name', $category);
|
|
});
|
|
if(count($sites) > 0)
|
|
{
|
|
$pages = $pages->whereIn('posts.slug', $sites);
|
|
}
|
|
$pages = $pages->get();
|
|
|
|
return $pages;
|
|
}
|
|
|
|
static function getPageCategories($mainCategory)
|
|
{
|
|
$parent = Tag::select('tags.*')
|
|
->where('type', 'seitenkategorie')
|
|
->where('name', $mainCategory)
|
|
->first();
|
|
if($parent)
|
|
{
|
|
$categories = Tag::select('tags.*')
|
|
->where('tags.type', 'seitenkategorie')
|
|
->join('tag_tag', function($join) use ($parent){
|
|
$join->on('tag_tag.parent_id', 'tags.id')
|
|
->where('tag_tag.tag_id', $parent->id);
|
|
})
|
|
->orderBy('tags.order', 'DESC');
|
|
|
|
$categories = $categories->get();
|
|
for($i = 0; $i < count($categories); $i++)
|
|
{
|
|
$pages = self::getCategoryPages($categories[$i]->name);
|
|
if($pages->count())
|
|
{
|
|
$categories[$i]->hasPages = true;
|
|
$categories[$i]->pages = $pages;
|
|
}
|
|
else
|
|
{
|
|
$categories[$i]->hasPages = false;
|
|
}
|
|
|
|
}
|
|
|
|
return $categories;
|
|
}
|
|
else
|
|
{
|
|
return [];
|
|
}
|
|
}
|
|
} |