Subversion-Projekte lars-tiefland.laravel_shop

Revision

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