Subversion-Projekte lars-tiefland.laravel_shop

Revision

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