Subversion-Projekte lars-tiefland.webanos.faltradxxs.de

Revision

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