Subversion-Projekte lars-tiefland.laravel_shop

Revision

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

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