Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 182 | Revision 184 | 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
        }
181 lars 33
        $GLOBALS["count"][__function__ . "_" . $root]++;
34
        $time = microtime(true);
176 lars 35
        $showArtikelstamm = false;
36
 
181 lars 37
        if (isset($GLOBALS["INI"]["Navigation"]["showArtikelstamm"])) {
176 lars 38
            $showArtikelstamm = true;
39
        }
40
 
181 lars 41
        $treebuffer = $this->where("directory_id", "=", $root)->get();
176 lars 42
 
43
 
181 lars 44
        if (is_array($treebuffer) && is_array($linkDirs)) {
45
            $treebuffer = array_merge($treebuffer, $linkDirs);
176 lars 46
        }
47
 
48
        $treebufferCount = 0;
181 lars 49
        if (is_countable($treebuffer)) {
50
            $treebufferCount = count($treebuffer) - 1;
176 lars 51
        }
52
 
53
        $i = 0;
181 lars 54
        if (is_array($treebuffer)) {
55
            foreach ($treebuffer as $counter => $zeile) {
176 lars 56
                $k = $i % 2;
57
                $i++;
58
 
59
                /* ######################################################################## */ /* Link entsprechend der Alias-Definition generieren.                        */
60
                /* ######################################################################## */
181 lars 61
                if ($GLOBALS["INI"]['alias'] == 0) {
176 lars 62
                    // dirLink
63
                    //$zeile['dirLink']=$GLOBALS["INI"]["absoluteURL"]."/?navigation=".$zeile['ID'];
64
                    $zeile['dirLink'] = "/?navigation=" . $zeile['ID'];
181 lars 65
                } else {
176 lars 66
 
67
                    // Pfad ermitteln
68
                    $buffer = array();
69
 
181 lars 70
                    $path = getPath_New($zeile['ID']);
176 lars 71
 
181 lars 72
                    foreach ($path as $elem) {
176 lars 73
                        //Muss hier gemacht werden, weil durch die UTF8 Kodierung die Umlaute für die str2url funktion nicht richtig übergeben werden
74
                        //Wenn man hier die Dateikodierung ändert funktioniert es auch nicht weil der Shop UTF8 ist
75
 
76
                        $name = $elem['Name'];
77
                        $umlaute = array(
78
                            "Ä",
79
                            "ä",
80
                            "Ö",
81
                            "ö",
82
                            "Ü",
83
                            "ü",
84
                        );
85
                        $umlauteErsetzen = array(
86
                            "Ae",
87
                            "ae",
88
                            "Oe",
89
                            "oe",
90
                            "Üe",
91
                            "ue",
92
                        );
181 lars 93
                        $name = str_replace($umlaute, $umlauteErsetzen, $name);
176 lars 94
 
95
                        //$buffer[]=preg_replace("/[\W]+/", "", $elem['ID']."_".$elem['Name']);
181 lars 96
                        $buffer[] = $elem['ID'] . "-" . str2url($name);
176 lars 97
 
98
                    }
99
 
100
                    // dirLink
101
                    //$zeile['dirLink']=$GLOBALS["INI"]["absoluteURL"]."/".implode("/",$buffer)."/";
181 lars 102
                    $zeile['dirLink'] = "/" . implode("/", $buffer) . "/";
176 lars 103
 
104
                }
105
 
106
                /* ######################################################################## */ /* Ausgabe der Unterverzeichnisse                                            */ /* ######################################################################## */
107
                // Container-Kopf
108
                $_SESSION['navigation']['nav-zebra'] = $k;
109
 
181 lars 110
                $subdirs = $this->where("direcotry_id", "=", $zeile["ID"])->get();
176 lars 111
                $nav["sub"][] = array(
181 lars 112
                    "id" => $zeile["ID"],
176 lars 113
                    "link" => $zeile['dirLink'],
114
                    "name" => $zeile["Name"],
115
                    "sub2" => $subdirs,
116
 
117
                );
118
 
119
            }
120
        }
121
        $anzahl_spalten = 3;
122
 
181 lars 123
        if (is_numeric($GLOBALS["INI"]["navigation"]["anzahl_spalten"])) {
176 lars 124
            $anzahl_spalten = $GLOBALS["INI"]["navigation"]["anzahl_spalten"];
125
        }
126
 
181 lars 127
        if (is_array($nav["sub"])) {
128
            $nav["sub"]['elemsPerRow'] = floor(count($nav["sub"]) / $anzahl_spalten);
129
            $nav["sub"]['elemsPerRowRest'] = count($treebuffer) - ($nav["sub"]['elemsPerRow'] * $anzahl_spalten);
176 lars 130
        }
131
 
181 lars 132
        $time2 = microtime(true);
176 lars 133
        $diff = $time2 - $time;
181 lars 134
        $GLOBALS["zeit"][__function__ . "_" . $root] += $diff;
176 lars 135
        return $nav;
136
    }
137
 
138
    /**
139
     * Wenn in der Config der Wert 'showNavigation' in der Kategorie 'Navigation' gleich "1" ist,
140
     * dann zeige die Navigation an.
141
     */
142
 
181 lars 143
    public function nav_menu($father = -1)
176 lars 144
    {
145
        $navigation = null;
181 lars 146
        if (!isset($GLOBALS["count"][__function__ . "_" . $father])) {
147
            $GLOBALS["count"][__function__ . "_" . $father] = 0;
148
            $GLOBALS["zeit"][__function__ . "_" . $father] = 0;
176 lars 149
        }
181 lars 150
        $GLOBALS["count"][__function__ . "_" . $father]++;
151
        $time = microtime(true);
152
        if ($GLOBALS['INI']['navigation']['cache_type'] == "2") {
176 lars 153
            $fName = $_SERVER["DOCUMENT_ROOT"] . "/menu_serialized.txt";
181 lars 154
            if (isset($GLOBALS["INI"]["treeRootMainNav"]) && $father == $GLOBALS["INI"]["treeRootMainNav"]) {
176 lars 155
                $fName = $_SERVER["DOCUMENT_ROOT"] . "/mainnav_serialized.txt";
156
            }
181 lars 157
            if (isset($GLOBALS["INI"]["treeRooSecondNav"]) && $father == $GLOBALS["INI"]["treeRootSecondNav"]) {
176 lars 158
                $fName = $_SERVER["DOCUMENT_ROOT"] . "/secondnav_serialized.txt";
159
            }
160
 
181 lars 161
            if (file_exists($fName)) {
162
                $content = file_get_contents($fName);
163
                $navigation = unserialize($content);
176 lars 164
            }
181 lars 165
        } elseif ($GLOBALS["INI"]["navigation"]["cache_type"] == "1") {
176 lars 166
            $fName = $_SERVER["DOCUMENT_ROOT"] . "/menu.xml";
167
 
181 lars 168
            if (file_exists($fName)) {
176 lars 169
                $confArr = array(
181 lars 170
                    "root" => "menu",
176 lars 171
                    "encoding" => "UTF-8",
172
                );
173
                $nav = new Config();
181 lars 174
                $nav = $nav->parseConfig($fName, "XML", $confArr);
176 lars 175
                $nav = $nav->toArray();
176
                $navigation = $nav["root"];
177
            }
178
        }
179
 
181 lars 180
        if (!$navigation) {
181
            $navigation = $this->getMenuFromDB($father);
176 lars 182
        }
183
 
181 lars 184
        $time2 = microtime(true);
176 lars 185
        $diff = $time2 - $time;
181 lars 186
        $GLOBALS["zeit"][__function__ . "_" . $father] += $diff;
176 lars 187
        return $navigation;
188
    }
189
 
181 lars 190
    private function getMenuFromDB($father)
176 lars 191
    {
181 lars 192
        if (!isset($GLOBALS["count"][__function__ . "_" . $father])) {
193
            $GLOBALS["count"][__function__ . "_" . $father] = 0;
194
            $GLOBALS["zeit"][__function__ . "_" . $father] = 0;
176 lars 195
        }
181 lars 196
        $GLOBALS["count"][__function__ . "_" . $father]++;
176 lars 197
        $navigation = array();
181 lars 198
        $time = microtime(true);
178 lars 199
        $order_by = "kennung, name";
200
        $sql_erw = "AND artikelstamm = 0";
181 lars 201
        if (isset($GLOBALS['INI']['navigation']['order_by'])) {
176 lars 202
            $order_by = $GLOBALS['INI']['navigation']['order_by'];
203
        }
204
 
205
        //Sollen Artikelstämme in der Navigation rauskommen, dann hole auch Artikelstämme
181 lars 206
        if (isset($GLOBALS["INI"]["Navigation"]["showArtikelstamm"])) {
176 lars 207
            $sql_erw = "";
208
        }
181 lars 209
        if (isset($GLOBALS["INI"]["navigation"]["sqlErweiterung"])) {
176 lars 210
            $sql_erw .= " " . $GLOBALS["INI"]["navigation"]["sqlErweiterung"];
211
        }
212
 
213
        $sel = "";
214
 
215
        //if ( !$_SESSION['mainNavigation'] )
216
        {
180 lars 217
            /*$sql = 'SELECT
178 lars 218
                    id,
176 lars 219
                    name,
220
                    status,
178 lars 221
                    slug,
176 lars 222
                    url,
178 lars 223
                    description,
176 lars 224
                    short_line_1
225
                    ' . $sel . '
226
                FROM
227
                    directory
228
                WHERE
178 lars 229
                    directory_id = ' . $father . '
176 lars 230
                    ' . $sql_erw . '
231
 
232
                ORDER BY
233
                    ' . $order_by . '
234
            ';
235
 
236
            if ( $result = $GLOBALS["shopDB"]->query( $sql ) )
237
            {
238
                while ( $row = $result->fetch_assoc() )
239
                {
240
                    $row["medien"] = directory_medien::liste( $row["id"] );
241
 
242
                    if ( $row["status"] == 99 )
243
                    {
244
                        $row["dirLink"] = $row["url"];
245
                    }
246
                    else
247
                    {
178 lars 248
                        $row["dirLink"] = "/" . $row['id'] . "-" . $row['slug'] . "/";
176 lars 249
                    }
250
                    $topLvl_arr[] = $row;
251
                    $topLvl = $row["id"];
252
                    //$specialItems['specialItems'][$row['id']] = getItems( $row['id'] );
253
 
254
                }
255
                if ( is_array( $specialItems ) )
256
                {
257
                    $GLOBALS["ui"]->assign( "specialItems", $specialItems );
258
                }
259
            }
260
            else
261
            {
262
                admin_debug( $GLOBALS["shopDB"]->error . "<br>" . $sql );
263
            }
264
 
265
            $_SESSION['Fathers'] = @implode( ",", $topLvl );
266
 
267
            $cnt = 0;
268
 
269
            if ( is_array( $topLvl_arr ) )
270
            {
271
                foreach ( $topLvl_arr as $elem )
272
                {
273
                    $navigation[ $cnt ]["top"][] = array(
274
                        "id"           => $elem["id"],
275
                        "name"         => $elem["name"],
276
                        "dirLink"      => $elem["dirLink"],
277
                        "beschreibung" => $elem["Beschreibung"],
278
                        "medien"       => $elem["medien"],
279
                        "specialItem"  => $elem["specialItem"],
280
                        "short_line_1" => $elem["short_line_1"],
281
                    );
282
                    if ( $elem['Alternativer_Titel'] )
283
                    {
284
                        $navigation[ $cnt ]["top"][0]["Alternativer_Titel"] = $elem['Alternativer_Titel'];
285
                    }
286
                    if ( !( $_REQUEST["buy"] == true || $_REQUEST["basket"] == true ) )
287
                    {
288
                        $nav = $this->navigation( $elem["id"], false, true, $cnt );
289
                        $navigation[ $cnt ]["sub"] = $nav["sub"];
290
                    }
291
                    $cnt++;
292
                }
180 lars 293
	    }*/
181 lars 294
        }
295
        $dirs = self::with('directory')->whereIn("status", [0, 2, 99])->where("directory_id", "=", $father)->get();
182 lars 296
        foreach ($dirs as $cnt => $dir) {
183 lars 297
            $navigation[$cnt]["top"][] = array("id" => $dir["id"], "name" => $dir["name"],);
181 lars 298
        }
182 lars 299
        var_dump($navigation);
181 lars 300
        $time2 = microtime(true);
176 lars 301
        $diff = $time2 - $time;
181 lars 302
        $GLOBALS["zeit"][__function__ . "_" . $father] += $diff;
176 lars 303
        return $navigation;
304
    }
181 lars 305
 
180 lars 306
    public function directory()
307
    {
181 lars 308
        return $this->belongsTo(Directory::class);
180 lars 309
    }
2 lars 310
}