Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 1692 | Revision 1694 | 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
 
5
use Illuminate\Http\Request;
1693 lars 6
use Illuminate\Support\Collection;
108 lars 7
 
728 lars 8
class DirectoryController extends Controller
108 lars 9
{
10
    //
1692 lars 11
    public function index($id)
12
    {
13
        $_SESSION["navigation"]["position"] = $id;
14
        $subdir = Directory::with( 'medium.medium', 'template.template', 'manufacturer' )->where( "id", $id )->firstOrFail();
15
        $dirs = Directory::with( 'medium.medium','manufacturer' )->where( "directory_id", $id )->whereIn( 'status', [
16
            0,
17
            99
18
        ] )->orderBy( 'kennung' )->orderBy( 'name' )->get();
19
        $items = Item::with( 'price', 'medium.medium', 'manufacturer' )->where( "directory_id", $id )->where( 'status', '=', 0 )->get();
20
        $subdir["subdirs"] = $dirs->reject( function ( $value )
21
        {
22
            return $value->articlemaster == 1;
23
        } );
24
        $subdir["items"] = $items;
25
        $template = 'subdir';
26
        if ( $subdir->articlemaster == 1 )
27
        {
28
            $template = 'artstamm';
29
        }
30
        $artstaemmeItems = array();
31
        if ( is_countable( $subdir->template ) && isset( $subdir->template[0] ) )
32
        {
33
            $template = substr( $subdir->template[0]->template->template_value, strpos( $subdir->template[0]->template->template_value, "=" ) + 1 );
34
        }
35
        foreach ( $dirs as $dir )
36
        {
37
            if ( $dir->articlemaster == 1 )
38
            {
39
                $preise = array();
40
                $items = Item::with( 'price' )->where( "directory_id", $dir->id )->whereIn( "status", [ 0, 2 ] )->get();
41
                $dir->anz = count( $items );
42
                foreach ( $items as $item )
43
                {
44
                    $preise[] = $item->price[0]->preis;
45
                }
46
                if ( $preise )
47
                {
48
                    $startPrice = min( $preise );
49
                    $dir->mehrerePreise = count( array_unique( $preise ) ) > 1;
50
                    $dir->startpreis_tpl = $startPrice;
51
                }
52
                $subdir["items"] = $dirs->filter( function ( $value )
53
                {
54
                    return $value->articlemaster == 1 && $value->anz > 0;
55
                } );
56
                /*$artstaemmeItems[$dir->id] = $dir;
57
                $artstaemmeItems[$dir->id]["items"] = Item::with( 'medium.medium', 'price', 'manufacturer' )->where( 'directory_id', '=', $dir->id )->where( 'status', '=', 0 )->get();*/
58
            }
59
        }
60
        return view( $template, [
61
            "subdir"          => $subdir,
62
            "artstaemmeItems" => $artstaemmeItems,
63
        ] );
64
    }
1693 lars 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
    }
108 lars 279
}