Subversion-Projekte lars-tiefland.laravel_shop

Revision

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

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