Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 195 | Revision 197 | Zur aktuellen Revision | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
2 lars 1
<?php
2
 
3
namespace App\Models;
4
 
5
use Illuminate\Database\Eloquent\Factories\HasFactory;
6
use Illuminate\Database\Eloquent\Model;
169 lars 7
use Spatie\Sluggable\HasSlug;
8
use Spatie\Sluggable\SlugOptions;
181 lars 9
 
2 lars 10
class Directory extends Model
11
{
169 lars 12
    use HasFactory, HasSlug;
13
 
14
    /**
15
     * Get the options for generating the slug.
16
     */
17
    public function getSlugOptions(): SlugOptions
18
    {
19
        return SlugOptions::create()
20
            ->generateSlugsFrom('name')
21
            ->saveSlugsTo('slug')
22
            ->usingLanguage('de')
23
            ->doNotGenerateSlugsOnUpdate()
181 lars 24
            ->skipGenerateWhen(fn() => $this->id < 0);
169 lars 25
    }
181 lars 26
 
27
    public function navigation($root, $override = false, $rootInfo = false, $cnt = 0)
176 lars 28
    {
181 lars 29
        if (!isset($GLOBALS["count"][__function__ . "_" . $root])) {
30
            $GLOBALS["count"][__function__ . "_" . $root] = 0;
31
            $GLOBALS["zeit"][__function__ . "_" . $root] = 0;
176 lars 32
        }
193 lars 33
        $nav = array();
181 lars 34
        $GLOBALS["count"][__function__ . "_" . $root]++;
35
        $time = microtime(true);
176 lars 36
        $showArtikelstamm = false;
37
 
181 lars 38
        if (isset($GLOBALS["INI"]["Navigation"]["showArtikelstamm"])) {
176 lars 39
            $showArtikelstamm = true;
40
        }
41
 
181 lars 42
        $treebuffer = $this->where("directory_id", "=", $root)->get();
176 lars 43
 
44
 
181 lars 45
        if (is_array($treebuffer) && is_array($linkDirs)) {
46
            $treebuffer = array_merge($treebuffer, $linkDirs);
176 lars 47
        }
48
 
49
        $treebufferCount = 0;
181 lars 50
        if (is_countable($treebuffer)) {
51
            $treebufferCount = count($treebuffer) - 1;
176 lars 52
        }
53
 
54
        $i = 0;
196 lars 55
        if (is_countable($treebuffer)) {
181 lars 56
            foreach ($treebuffer as $counter => $zeile) {
176 lars 57
                $k = $i % 2;
58
                $i++;
59
 
60
                /* ######################################################################## */ /* Link entsprechend der Alias-Definition generieren.                        */
61
                /* ######################################################################## */
188 lars 62
                // Pfad ermitteln
63
                $buffer = array();
176 lars 64
 
188 lars 65
                $dirLink = "/directory/" . $zeile['id'] . "-" . $zeile["slug"] . "/";
176 lars 66
 
67
 
195 lars 68
                // dirLink
69
                //$zeile['dirLink']=$GLOBALS["INI"]["absoluteURL"]."/".implode("/",$buffer)."/";
70
                $zeile['dirLink'] = $dirLink;
176 lars 71
 
195 lars 72
                /* ######################################################################## */ /* Ausgabe der Unterverzeichnisse                                            */ /* ######################################################################## */
73
                // Container-Kopf
74
                $_SESSION['navigation']['nav-zebra'] = $k;
176 lars 75
 
196 lars 76
                $subdirs = $this->where("directory_id", "=", $zeile["id"])->get();
195 lars 77
                $nav["sub"][] = array(
196 lars 78
                    "id" => $zeile["id"],
79
                    "dirLink" => $zeile['dirLink'],
80
                    "name" => $zeile["name"],
195 lars 81
                    "sub2" => $subdirs,
176 lars 82
 
195 lars 83
                );
176 lars 84
 
195 lars 85
            }
176 lars 86
        }
87
        $anzahl_spalten = 3;
88
 
191 lars 89
        if (isset($GLOBALS["INI"]["navigation"]["anzahl_spalten"]) && is_numeric($GLOBALS["INI"]["navigation"]["anzahl_spalten"])) {
176 lars 90
            $anzahl_spalten = $GLOBALS["INI"]["navigation"]["anzahl_spalten"];
91
        }
92
 
192 lars 93
        if (isset($nav["sub"]) && is_array($nav["sub"])) {
181 lars 94
            $nav["sub"]['elemsPerRow'] = floor(count($nav["sub"]) / $anzahl_spalten);
95
            $nav["sub"]['elemsPerRowRest'] = count($treebuffer) - ($nav["sub"]['elemsPerRow'] * $anzahl_spalten);
176 lars 96
        }
97
 
181 lars 98
        $time2 = microtime(true);
196 lars 99
	$diff = $time2 - $time;
100
	dump($nav);
181 lars 101
        $GLOBALS["zeit"][__function__ . "_" . $root] += $diff;
176 lars 102
        return $nav;
103
    }
104
 
105
    /**
106
     * Wenn in der Config der Wert 'showNavigation' in der Kategorie 'Navigation' gleich "1" ist,
107
     * dann zeige die Navigation an.
108
     */
109
 
188 lars 110
    public
111
    function nav_menu($father = -1)
176 lars 112
    {
113
        $navigation = null;
181 lars 114
        if (!isset($GLOBALS["count"][__function__ . "_" . $father])) {
115
            $GLOBALS["count"][__function__ . "_" . $father] = 0;
116
            $GLOBALS["zeit"][__function__ . "_" . $father] = 0;
176 lars 117
        }
181 lars 118
        $GLOBALS["count"][__function__ . "_" . $father]++;
119
        $time = microtime(true);
120
        if ($GLOBALS['INI']['navigation']['cache_type'] == "2") {
176 lars 121
            $fName = $_SERVER["DOCUMENT_ROOT"] . "/menu_serialized.txt";
181 lars 122
            if (isset($GLOBALS["INI"]["treeRootMainNav"]) && $father == $GLOBALS["INI"]["treeRootMainNav"]) {
176 lars 123
                $fName = $_SERVER["DOCUMENT_ROOT"] . "/mainnav_serialized.txt";
124
            }
181 lars 125
            if (isset($GLOBALS["INI"]["treeRooSecondNav"]) && $father == $GLOBALS["INI"]["treeRootSecondNav"]) {
176 lars 126
                $fName = $_SERVER["DOCUMENT_ROOT"] . "/secondnav_serialized.txt";
127
            }
128
 
181 lars 129
            if (file_exists($fName)) {
130
                $content = file_get_contents($fName);
131
                $navigation = unserialize($content);
176 lars 132
            }
181 lars 133
        } elseif ($GLOBALS["INI"]["navigation"]["cache_type"] == "1") {
176 lars 134
            $fName = $_SERVER["DOCUMENT_ROOT"] . "/menu.xml";
135
 
181 lars 136
            if (file_exists($fName)) {
176 lars 137
                $confArr = array(
181 lars 138
                    "root" => "menu",
176 lars 139
                    "encoding" => "UTF-8",
140
                );
141
                $nav = new Config();
181 lars 142
                $nav = $nav->parseConfig($fName, "XML", $confArr);
176 lars 143
                $nav = $nav->toArray();
144
                $navigation = $nav["root"];
145
            }
146
        }
147
 
181 lars 148
        if (!$navigation) {
149
            $navigation = $this->getMenuFromDB($father);
176 lars 150
        }
151
 
181 lars 152
        $time2 = microtime(true);
176 lars 153
        $diff = $time2 - $time;
181 lars 154
        $GLOBALS["zeit"][__function__ . "_" . $father] += $diff;
176 lars 155
        return $navigation;
156
    }
157
 
188 lars 158
    private
159
    function getMenuFromDB($father)
176 lars 160
    {
181 lars 161
        if (!isset($GLOBALS["count"][__function__ . "_" . $father])) {
162
            $GLOBALS["count"][__function__ . "_" . $father] = 0;
163
            $GLOBALS["zeit"][__function__ . "_" . $father] = 0;
176 lars 164
        }
181 lars 165
        $GLOBALS["count"][__function__ . "_" . $father]++;
176 lars 166
        $navigation = array();
181 lars 167
        $time = microtime(true);
189 lars 168
        $order_by = array("kennung", "name");
178 lars 169
        $sql_erw = "AND artikelstamm = 0";
181 lars 170
        if (isset($GLOBALS['INI']['navigation']['order_by'])) {
176 lars 171
            $order_by = $GLOBALS['INI']['navigation']['order_by'];
172
        }
173
 
174
        //Sollen Artikelstämme in der Navigation rauskommen, dann hole auch Artikelstämme
181 lars 175
        if (isset($GLOBALS["INI"]["Navigation"]["showArtikelstamm"])) {
176 lars 176
            $sql_erw = "";
177
        }
181 lars 178
        if (isset($GLOBALS["INI"]["navigation"]["sqlErweiterung"])) {
176 lars 179
            $sql_erw .= " " . $GLOBALS["INI"]["navigation"]["sqlErweiterung"];
180
        }
181
 
190 lars 182
        $dirs = self::with('directory')->whereIn("status", [0, 2, 99])->where("directory_id", "=", $father)->get();
182 lars 183
        foreach ($dirs as $cnt => $dir) {
187 lars 184
            $dirLink = "/directory/" . $dir["id"] . "-" . $dir["slug"] . "/";
185 lars 185
            if ($dir["url"]) {
186
                $dirLink = $dir["url"];
187
            }
188
            $navigation[$cnt]["top"][] = array("id" => $dir["id"], "name" => $dir["name"], "dirLink" => $dirLink, "beschreibung" => $dir["description"],);
188 lars 189
            $nav = $this->navigation($dir["id"], false, true, $cnt);
194 lars 190
            if (isset($nav["sub"])) {
191
                $navigation[$cnt]["sub"] = $nav["sub"];
192
            }
181 lars 193
        }
194
        $time2 = microtime(true);
176 lars 195
        $diff = $time2 - $time;
181 lars 196
        $GLOBALS["zeit"][__function__ . "_" . $father] += $diff;
176 lars 197
        return $navigation;
198
    }
181 lars 199
 
180 lars 200
    public function directory()
201
    {
181 lars 202
        return $this->belongsTo(Directory::class);
180 lars 203
    }
2 lars 204
}