20-02-2026

This commit is contained in:
Kevin Adametz 2026-02-20 17:55:06 +01:00
parent a8b395e20d
commit a00c42e770
252 changed files with 28785 additions and 8907 deletions

View file

@ -2,140 +2,153 @@
namespace App\Repositories\DC;
use Request;
use App\Models\DcTag;
use App\Models\DcCategory;
use App\Models\DcTag;
use App\Repositories\BaseRepository;
use Request;
class TagRepository extends BaseRepository {
public function __construct()
{
}
class TagRepository extends BaseRepository
{
public function __construct() {}
public function storeItem($obj, $data)
{
if($obj === 'category' && isset($data['dc_category_name'])){
if ($obj === 'category' && isset($data['dc_category_name'])) {
$category = new DcCategory;
$category->name = $data['dc_category_name'];
$category->pos = 0 ;
$category->pos = 0;
$category->save();
\Session()->flash('alert-success', 'Kategorie erstellt');
return redirect(route('admin_downloadcenter_tags'));
}
if($obj === 'tag' && isset($data['dc_tag_name'])){
if ($obj === 'tag' && isset($data['dc_tag_name'])) {
$data = Request::all();
$tag = new DcTag;
$tag->name = $data['dc_tag_name'];
$tag->pos = 0;
$tag->save();
\Session()->flash('alert-success', 'Tag erstellt');
return redirect(route('admin_downloadcenter_tags'));
}
if($obj === 'structure' && isset($data['nestable'])){
if ($obj === 'structure' && isset($data['nestable'])) {
$bool = $this->updateStructure($data);
if(Request::ajax()){
if (Request::ajax()) {
return response()->json([
'success' => $bool,
'redirect' => route('admin_downloadcenter_tags', ['flash' => true])
]);
'success' => $bool,
'redirect' => route('admin_downloadcenter_tags', ['flash' => true]),
]);
}
}
if($obj === 'update_ajax' && isset($data['action'])){
if ($obj === 'update_ajax' && isset($data['action'])) {
$active = $this->updateAjax($data);
if(Request::ajax()){
if (Request::ajax()) {
return response()->json([
'success' => $data['action'],
'active' => $active,
]);
'success' => $data['action'],
'active' => $active,
]);
}
}
return true;
}
}
protected function updateAjax($data){
protected function updateAjax($data)
{
if($data['action'] == 'update-tag-active' && isset($data['id'])){
if ($data['action'] == 'update-tag-active' && isset($data['id'])) {
$tag = DcTag::findOrFail($data['id']);
$tag->active = $tag->active ? 0 : 1;
$tag->save();
return $tag->active;
}
if($data['action'] == 'update-category-active' && isset($data['id'])){
return $tag->active;
}
if ($data['action'] == 'update-category-active' && isset($data['id'])) {
$category = DcCategory::findOrFail($data['id']);
$category->active = $category->active ? 0 : 1;
$category->save();
return $category->active;
}
return false;
}
protected function updateStructure($data)
{
if(empty($data['nestable']) || !is_array($data['nestable'])){
if (empty($data['nestable']) || ! is_array($data['nestable'])) {
return false;
}
$tags = DcTag::all();
foreach ($tags as $value) {
$value->category_id = null;
$value->pos = NULL;
$value->pos = null;
$value->save();
}
$this->saveStructureLevel($data['nestable']);
return true;
}
protected function saveStructureLevel($nestable, $deep = 0, $category_id = false){
protected function saveStructureLevel($nestable, $deep = 0, $category_id = false)
{
foreach ($nestable as $key => $value) {
if($value['id'] == 0){
if ($value['id'] == 0) {
continue;
}
if($deep == 0){
$cat = DcCategory::findOrFail($value['id']);
$cat->pos = $key;
$cat->save();
if ($deep == 0) {
$cat = DcCategory::find($value['id']);
if (! $cat) {
// Kategorie existiert nicht mehr, überspringen
continue;
}
$cat->pos = $key;
$cat->save();
}
if($deep == 1){
$tag = DcTag::findOrFail($value['id']);
if ($deep == 1) {
$tag = DcTag::find($value['id']);
if (! $tag) {
// Tag existiert nicht mehr, überspringen
continue;
}
$tag->category_id = $category_id;
$tag->pos = $key;
$tag->save();
}
if(!empty($value['children'])){
$this->saveStructureLevel($value['children'], $deep+1, $value['id']);
if (! empty($value['children'])) {
$this->saveStructureLevel($value['children'], $deep + 1, $value['id']);
}
}
}
public function deleteItem($obj, $id){
if($obj == 'category'){
public function deleteItem($obj, $id)
{
if ($obj == 'category') {
$this->deleteCategory($id);
}
if($obj == 'tag'){
$this->deleteTag($id);
if ($obj == 'tag') {
$this->deleteTag($id);
}
}
public function deleteCategory($id){
public function deleteCategory($id)
{
$cat = DcCategory::findOrFail($id);
$tags = DcTag::where('category_id', $cat->id)->get();
foreach ($tags as $tag) {
$this->deleteTag($tag->id);
$this->deleteTag($tag->id);
}
$cat->delete();
}
}
public function deleteTag($id){
public function deleteTag($id)
{
$tag = DcTag::findOrFail($id);
$tag->delete();
}
}
}
}