Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 1692 | Revision 1694 | Zur aktuellen Revision | Ganze Datei anzeigen | Leerzeichen ignorieren | Details | Blame | Letzte Änderung | Log anzeigen | RSS feed

Revision 1692 Revision 1693
Zeile 1... Zeile 1...
1
<?php
1
<?php
Zeile 2... Zeile 2...
2
 
2
 
Zeile 3... Zeile 3...
3
namespace App\Http\Controllers;
3
namespace App\Http\Controllers;
-
 
4
 
Zeile 4... Zeile 5...
4
 
5
use Illuminate\Http\Request;
5
use Illuminate\Http\Request;
6
use Illuminate\Support\Collection;
6
 
7
 
7
class DirectoryController extends Controller
8
class DirectoryController extends Controller
Zeile 59... Zeile 60...
59
        return view( $template, [
60
        return view( $template, [
60
            "subdir"          => $subdir,
61
            "subdir"          => $subdir,
61
            "artstaemmeItems" => $artstaemmeItems,
62
            "artstaemmeItems" => $artstaemmeItems,
62
        ] );
63
        ] );
63
    }
64
    }
-
 
65
 
-
 
66
    public function navigation( $root, $override = false, $rootInfo = false, $cnt = 0 ): array
-
 
67
    {
-
 
68
        if ( !isset( $GLOBALS["count"][__function__ . "_" . $root] ) )
-
 
69
        {
-
 
70
            $GLOBALS["count"][__function__ . "_" . $root] = 0;
-
 
71
            $GLOBALS["zeit"][__function__ . "_" . $root] = 0;
-
 
72
        }
-
 
73
        $nav = array();
-
 
74
        $GLOBALS["count"][__function__ . "_" . $root]++;
-
 
75
        $time = microtime( true );
-
 
76
        $showArtikelstamm = false;
-
 
77
 
-
 
78
        if ( isset( $GLOBALS["INI"]["Navigation"]["showArtikelstamm"] ) )
-
 
79
        {
-
 
80
            $showArtikelstamm = true;
-
 
81
        }
-
 
82
 
-
 
83
        $treebuffer = $this->with( 'directory' )->orderBy( "kennung" )->orderBy( "name" )->whereIn( "status", [ 0, 99 ] )->where( "directory_id", "=", $root )->where( 'articlemaster', '=', 0 )->get();
-
 
84
 
-
 
85
 
-
 
86
        /*if (is_array($treebuffer) && is_array($linkDirs)) {
-
 
87
            $treebuffer = array_merge($treebuffer, $linkDirs);
-
 
88
        }*/
-
 
89
 
-
 
90
        $treebufferCount = 0;
-
 
91
        if ( is_countable( $treebuffer ) )
-
 
92
        {
-
 
93
            $treebufferCount = count( $treebuffer ) - 1;
-
 
94
        }
-
 
95
 
-
 
96
        $i = 0;
-
 
97
        if ( is_countable( $treebuffer ) )
-
 
98
        {
-
 
99
            foreach ( $treebuffer as $counter => $zeile )
-
 
100
            {
-
 
101
                $k = $i % 2;
-
 
102
                $i++;
-
 
103
 
-
 
104
                /* ######################################################################## */ /* Link entsprechend der Alias-Definition generieren.                        */
-
 
105
                /* ######################################################################## */
-
 
106
                // Pfad ermitteln
-
 
107
                $buffer = array();
-
 
108
 
-
 
109
                $dirLink = "/directory/" . $zeile['id'] . "-" . $zeile["slug"] . "/";
-
 
110
 
-
 
111
 
-
 
112
                // dirLink
-
 
113
                //$zeile['dirLink']=$GLOBALS["INI"]["absoluteURL"]."/".implode("/",$buffer)."/";
-
 
114
                $zeile['dirLink'] = $dirLink;
-
 
115
 
-
 
116
                /* ######################################################################## */ /* Ausgabe der Unterverzeichnisse                                            */ /* ######################################################################## */
-
 
117
                // Container-Kopf
-
 
118
                $_SESSION['navigation']['nav-zebra'] = $k;
-
 
119
 
-
 
120
                $subdirC = $this->with( 'directory' )->orderBy( "kennung" )->orderBy( "name" )->whereIn( "status", [ 0, 99 ] )->where( "directory_id", "=", $zeile["id"] )->where( 'articlemaster', '=', 0 )->get();
-
 
121
                $subdirs = array();
-
 
122
                foreach ( $subdirC as $subdir )
-
 
123
                {
-
 
124
                    $subdirs[] = array(
-
 
125
                        "id"   => $subdir["id"],
-
 
126
                        "link" => "/directory/" . $subdir["id"] . "-" . $subdir['slug'] . "/",
-
 
127
                        "name" => $subdir["name"],
-
 
128
                    );
-
 
129
                }
-
 
130
                $nav["sub"][] = array(
-
 
131
                    "id"   => $zeile["id"],
-
 
132
                    "link" => $zeile['dirLink'],
-
 
133
                    "name" => $zeile["name"],
-
 
134
                    "sub2" => $subdirs,
-
 
135
 
-
 
136
                );
-
 
137
 
-
 
138
            }
-
 
139
        }
-
 
140
        $anzahl_spalten = 3;
-
 
141
 
-
 
142
        if ( isset( $GLOBALS["INI"]["navigation"]["anzahl_spalten"] ) && is_numeric( $GLOBALS["INI"]["navigation"]["anzahl_spalten"] ) )
-
 
143
        {
-
 
144
            $anzahl_spalten = $GLOBALS["INI"]["navigation"]["anzahl_spalten"];
-
 
145
        }
-
 
146
 
-
 
147
        if ( isset( $nav["sub"] ) && is_array( $nav["sub"] ) )
-
 
148
        {
-
 
149
            $nav["sub"]['elemsPerRow'] = floor( count( $nav["sub"] ) / $anzahl_spalten );
-
 
150
            $nav["sub"]['elemsPerRowRest'] = count( $treebuffer ) - ( $nav["sub"]['elemsPerRow'] * $anzahl_spalten );
-
 
151
        }
-
 
152
 
-
 
153
        $time2 = microtime( true );
-
 
154
        $diff = $time2 - $time;
-
 
155
        $GLOBALS["zeit"][__function__ . "_" . $root] += $diff;
-
 
156
        return $nav;
-
 
157
    }
-
 
158
 
-
 
159
    /**
-
 
160
     * Wenn in der Config der Wert 'showNavigation' in der Kategorie 'Navigation' gleich "1" ist,
-
 
161
     * dann zeige die Navigation an.
-
 
162
     */
-
 
163
 
-
 
164
    public function nav_menu( $father = -1 )
-
 
165
    {
-
 
166
        $navigation = null;
-
 
167
        if ( !isset( $GLOBALS["count"][__function__ . "_" . $father] ) )
-
 
168
        {
-
 
169
            $GLOBALS["count"][__function__ . "_" . $father] = 0;
-
 
170
            $GLOBALS["zeit"][__function__ . "_" . $father] = 0;
-
 
171
        }
-
 
172
        $GLOBALS["count"][__function__ . "_" . $father]++;
-
 
173
        $time = microtime( true );
-
 
174
        if ( $GLOBALS['INI']['navigation']['cache_type'] == "2" )
-
 
175
        {
-
 
176
            $fName = $_SERVER["DOCUMENT_ROOT"] . "/menu_serialized.txt";
-
 
177
            if ( isset( $GLOBALS["INI"]["treeRootMainNav"] ) && $father == $GLOBALS["INI"]["treeRootMainNav"] )
-
 
178
            {
-
 
179
                $fName = $_SERVER["DOCUMENT_ROOT"] . "/mainnav_serialized.txt";
-
 
180
            }
-
 
181
            if ( isset( $GLOBALS["INI"]["treeRooSecondNav"] ) && $father == $GLOBALS["INI"]["treeRootSecondNav"] )
-
 
182
            {
-
 
183
                $fName = $_SERVER["DOCUMENT_ROOT"] . "/secondnav_serialized.txt";
-
 
184
            }
-
 
185
 
-
 
186
            if ( file_exists( $fName ) )
-
 
187
            {
-
 
188
                $content = file_get_contents( $fName );
-
 
189
                $navigation = unserialize( $content );
-
 
190
            }
-
 
191
        }
-
 
192
        elseif ( $GLOBALS["INI"]["navigation"]["cache_type"] == "1" )
-
 
193
        {
-
 
194
            $fName = $_SERVER["DOCUMENT_ROOT"] . "/menu.xml";
-
 
195
 
-
 
196
            if ( file_exists( $fName ) )
-
 
197
            {
-
 
198
                $confArr = array(
-
 
199
                    "root"     => "menu",
-
 
200
                    "encoding" => "UTF-8",
-
 
201
                );
-
 
202
                $nav = new Config();
-
 
203
                $nav = $nav->parseConfig( $fName, "XML", $confArr );
-
 
204
                $nav = $nav->toArray();
-
 
205
                $navigation = $nav["root"];
-
 
206
            }
-
 
207
        }
-
 
208
 
-
 
209
        if ( !$navigation )
-
 
210
        {
-
 
211
            $navigation = $this->getMenuFromDB( $father );
-
 
212
        }
-
 
213
 
-
 
214
        $time2 = microtime( true );
-
 
215
        $diff = $time2 - $time;
-
 
216
        $GLOBALS["zeit"][__function__ . "_" . $father] += $diff;
-
 
217
        return $navigation;
-
 
218
    }
-
 
219
 
-
 
220
    private function getMenuFromDB( $father ): array
-
 
221
    {
-
 
222
        if ( !isset( $GLOBALS["count"][__function__ . "_" . $father] ) )
-
 
223
        {
-
 
224
            $GLOBALS["count"][__function__ . "_" . $father] = 0;
-
 
225
            $GLOBALS["zeit"][__function__ . "_" . $father] = 0;
-
 
226
        }
-
 
227
        $GLOBALS["count"][__function__ . "_" . $father]++;
-
 
228
        $navigation = array();
-
 
229
        $time = microtime( true );
-
 
230
        $order_by = array( "kennung", "name" );
-
 
231
        $sql_erw = "AND artikelstamm = 0";
-
 
232
        if ( isset( $GLOBALS['INI']['navigation']['order_by'] ) )
-
 
233
        {
-
 
234
            $order_by = $GLOBALS['INI']['navigation']['order_by'];
-
 
235
        }
-
 
236
 
-
 
237
        //Sollen Artikelstämme in der Navigation rauskommen, dann hole auch Artikelstämme
-
 
238
        if ( isset( $GLOBALS["INI"]["Navigation"]["showArtikelstamm"] ) )
-
 
239
        {
-
 
240
            $sql_erw = "";
-
 
241
        }
-
 
242
        if ( isset( $GLOBALS["INI"]["navigation"]["sqlErweiterung"] ) )
-
 
243
        {
-
 
244
            $sql_erw .= " " . $GLOBALS["INI"]["navigation"]["sqlErweiterung"];
-
 
245
        }
-
 
246
 
-
 
247
        $dirs = self::with( 'directory' )->orderBy( "kennung" )->orderBy( "name" )->whereIn( "status", [ 0, 99 ] )->where( "directory_id", "=", $father )->where( 'articlemaster', '=', 0 )->get();
-
 
248
        foreach ( $dirs as $cnt => $dir )
-
 
249
        {
-
 
250
            $dirLink = "/directory/" . $dir["id"] . "-" . $dir["slug"] . "/";
-
 
251
            if ( $dir["url"] )
-
 
252
            {
-
 
253
                $dirLink = $dir["url"];
-
 
254
            }
-
 
255
            $navigation[$cnt]["top"][] = array( "id" => $dir["id"], "name" => $dir["name"], "dirLink" => $dirLink, "beschreibung" => $dir["description"], );
-
 
256
            $nav = $this->navigation( $dir["id"], false, true, $cnt );
-
 
257
            if ( isset( $nav["sub"] ) )
-
 
258
            {
-
 
259
                $navigation[$cnt]["sub"] = $nav["sub"];
-
 
260
            }
-
 
261
        }
-
 
262
        $time2 = microtime( true );
-
 
263
        $diff = $time2 - $time;
-
 
264
        $GLOBALS["zeit"][__function__ . "_" . $father] += $diff;
-
 
265
        return $navigation;
-
 
266
    }
-
 
267
 
-
 
268
    public function shopPosition(): Collection
-
 
269
    {
-
 
270
        $pos = collect(); //$pos = "Sie sind hier: <a href=\"/\">Startseite</a> <span class='breadcrumb-trenner'> &raquo; </span>";
-
 
271
        $path = getPath( $_SESSION['navigation']['position'] )->reverse();
-
 
272
        foreach ( $path as $dir )
-
 
273
        {
-
 
274
            $pos[] = $dir;
-
 
275
        }
-
 
276
 
-
 
277
        return $pos;
-
 
278
    }
64
}
279
}