Browse code

Add device showcase module

Benjamin Roth authored on05/01/2016 15:52:24
Showing1 changed files
... ...
@@ -26,164 +26,219 @@ namespace eSM_clients;
26 26
  */
27 27
 class ModuleClientsShowcase extends \Module
28 28
 {
29
-	/**
30
-	 * Template
31
-	 * @var string
32
-	 */
33
-	protected $strTemplate = 'mod_clientsShowcase';
34
-
35
-	/**
36
-	 * URL
37
-	 * @var string
38
-	 */
39
-	protected $strLink;
40
-
41
-
42
-	public function generate()
43
-	{
44
-		if (TL_MODE == 'BE')
45
-		{
46
-			$objTemplate = new \BackendTemplate('be_wildcard');
47
-
48
-			$objTemplate->wildcard = '### ' . utf8_strtoupper($GLOBALS['TL_LANG']['FMD']['clientsShowcase'][0]) . ' ###';
49
-			$objTemplate->title = $this->headline;
50
-			$objTemplate->id = $this->id;
51
-			$objTemplate->link = $this->name;
52
-			$objTemplate->href = 'contao/main.php?do=themes&table=tl_module&act=edit&id=' . $this->id;
53
-
54
-			return $objTemplate->parse();
55
-		}
56
-
57
-		$this->strUrl = preg_replace('/\?.*$/', '', \Environment::get('request'));
58
-		$this->strLink = $this->strUrl;
59
-
60
-		return parent::generate();
61
-	}
62
-
63
-	/**
64
-	 * Compile the current element
65
-	 */
66
-	protected function compile()
67
-	{
68
-		global $objPage;
69
-
70
-		$Clients = EsmClientsModel::getReferenceClients();
71
-
72
-		$strItems = '';
73
-
74
-		foreach ($Clients as $client)
75
-		{
76
-//			dump($client);
77
-			// Load client template
78
-			$objClientTemplate = new \FrontendTemplate($this->esm_clientsShowcase_template);
79
-
80
-			// Set template data
81
-			$objClientTemplate->title = $client->title;
82
-			$objClientTemplate->text = $client->text;
83
-			$objClientTemplate->color = deserialize($client->basecolor);
84
-			$objClientTemplate->branchId = $client->branch;
85
-
86
-			// Branche
87
-			$Branch = $client->getRelated('branch');
88
-			if (!is_null($Branch))
89
-			{
90
-				$objClientTemplate->branch = $Branch->title;
91
-			}
92
-
93
-			// Neutral logo
94
-			$objNeutralLogo = \FilesModel::findByUuid($client->logo_neutral);
95
-
96
-			if (is_file(TL_ROOT . '/' . $objNeutralLogo->path))
97
-			{
98
-				$objFile = new \File($objNeutralLogo->path, true);
99
-				$arrSize = $objFile->imageSize;
100
-				$arrMeta = $this->getMetaData($objNeutralLogo->meta, $objPage->language);
101
-				if (empty($arrMeta))
102
-				{
103
-					if ($objPage->rootFallbackLanguage !== null)
104
-					{
105
-						$arrMeta = $this->getMetaData($objNeutralLogo->meta, $objPage->rootFallbackLanguage);
106
-					}
107
-				}
108
-				if ($arrMeta['title'] == '')
109
-				{
110
-					$arrMeta['title'] = specialchars($objFile->basename);
111
-				}
112
-				$objClientTemplate->logo_neutral = array
113
-				(
114
-					'src'         => $objNeutralLogo->path,
115
-					'width'       => $arrSize[0],
116
-					'height'      => $arrSize[1],
117
-					'attributes'  => $arrSize[3] . ' alt="' . $arrMeta['title'] . '"',
118
-					'meta'        => $arrMeta
119
-				);
120
-
121
-			}
122
-
123
-			// Original logo
124
-			$objOriginalLogo = \FilesModel::findByUuid($client->logo_original);
125
-
126
-			if (is_file(TL_ROOT . '/' . $objOriginalLogo->path))
127
-			{
128
-				$objFile = new \File($objOriginalLogo->path, true);
129
-				$arrSize = $objFile->imageSize;
130
-				$arrMeta = $this->getMetaData($objOriginalLogo->meta, $objPage->language);
131
-				if (empty($arrMeta))
132
-				{
133
-					if ($objPage->rootFallbackLanguage !== null)
134
-					{
135
-						$arrMeta = $this->getMetaData($objOriginalLogo->meta, $objPage->rootFallbackLanguage);
136
-					}
137
-				}
138
-				if ($arrMeta['title'] == '')
139
-				{
140
-					$arrMeta['title'] = specialchars($objFile->basename);
141
-				}
142
-				$objClientTemplate->logo_original = array
143
-				(
144
-					'src'         => $objOriginalLogo->path,
145
-					'width'       => $arrSize[0],
146
-					'height'      => $arrSize[1],
147
-					'attributes'  => $arrSize[3] . ' alt="' . $arrMeta['title'] . '"',
148
-					'meta'        => $arrMeta
149
-				);
150
-
151
-			}
152
-
153
-			// Get client projects
154
-			$Projects = $client->getProjects();
155
-
156
-			$arrProjects = array();
157
-			foreach($Projects as $project)
158
-			{
159
-
160
-				$arrRow = $project->row();
161
-
162
-				if ($this->jumpTo > 0)
163
-				{
164
-					$objTarget = \PageModel::findByPk($this->jumpTo);
165
-
166
-					if ($objTarget !== null)
167
-					{
168
-						$strJumpTo = ampersand($this->generateFrontendUrl($objTarget->row(), ((\Config::get('useAutoItem') && !\Config::get('disableAlias')) ?  '/%s' : '/items/%s')));
169
-						$strJumpTo = sprintf($strJumpTo,(!\Config::get('disableAlias') && $project->alias != '') ? $project->alias : $project->id);
170
-
171
-						$arrRow['link'] = $strJumpTo;
172
-					}
173
-				}
174
-
175
-				$arrProjects[] = $arrRow;
176
-			}
177
-
178
-			$objClientTemplate->projects = $arrProjects;
179
-
180
-
181
-			// Render Template
182
-			$strItems .= $objClientTemplate->parse();
183
-		}
184
-
185
-		$this->Template->items = $strItems;
186
-	}
29
+    /**
30
+     * Template
31
+     * @var string
32
+     */
33
+    protected $strTemplate = 'mod_clientsShowcase';
34
+
35
+    /**
36
+     * URL
37
+     * @var string
38
+     */
39
+    protected $strLink;
40
+
41
+
42
+    public function generate()
43
+    {
44
+        if (TL_MODE == 'BE')
45
+        {
46
+            $objTemplate = new \BackendTemplate('be_wildcard');
47
+
48
+            $objTemplate->wildcard = '### ' . utf8_strtoupper($GLOBALS['TL_LANG']['FMD']['clientsShowcase'][0]) . ' ###';
49
+            $objTemplate->title = $this->headline;
50
+            $objTemplate->id = $this->id;
51
+            $objTemplate->link = $this->name;
52
+            $objTemplate->href = 'contao/main.php?do=themes&table=tl_module&act=edit&id=' . $this->id;
53
+
54
+            return $objTemplate->parse();
55
+        }
56
+
57
+        $this->strUrl = preg_replace('/\?.*$/', '', \Environment::get('request'));
58
+        $this->strLink = $this->strUrl;
59
+
60
+        return parent::generate();
61
+    }
62
+
63
+    /**
64
+     * Compile the current element
65
+     */
66
+    protected function compile()
67
+    {
68
+        /** @var \PageModel $objPage */
69
+        global $objPage;
70
+
71
+        $limit = null;
72
+        $offset = 0;
73
+
74
+        // Maximum number of items
75
+        if ($this->esm_numberOfItems > 0)
76
+        {
77
+            $limit = $this->esm_numberOfItems;
78
+        }
79
+
80
+        // Get the total number of items
81
+        $intTotal = EsmClientsModel::countReferenceClients();
82
+
83
+        if ($intTotal < 1)
84
+        {
85
+            return;
86
+        }
87
+
88
+        $total = $intTotal - $offset;
89
+
90
+        // Split the results
91
+        if ($this->perPage > 0 && (!isset($limit) || $this->esm_numberOfItems > $this->perPage))
92
+        {
93
+            // Adjust the overall limit
94
+            if (isset($limit))
95
+            {
96
+                $total = min($limit, $total);
97
+            }
98
+
99
+            // Get the current page
100
+            $id = 'page_cs' . $this->id;
101
+            $page = (\Input::get($id) !== null) ? \Input::get($id) : 1;
102
+
103
+            // Do not index or cache the page if the page number is outside the range
104
+            if ($page < 1 || $page > max(ceil($total/$this->perPage), 1))
105
+            {
106
+                /** @var \PageError404 $objHandler */
107
+                $objHandler = new $GLOBALS['TL_PTY']['error_404']();
108
+                $objHandler->generate($objPage->id);
109
+            }
110
+
111
+            // Set limit and offset
112
+            $limit = $this->perPage;
113
+            $offset += (max($page, 1) - 1) * $this->perPage;
114
+
115
+            // Overall limit
116
+            if ($offset + $limit > $total)
117
+            {
118
+                $limit = $total - $offset;
119
+            }
120
+
121
+            // Add the pagination menu
122
+            $objPagination = new \Pagination($total, $this->perPage, \Config::get('maxPaginationLinks'), $id);
123
+            $this->Template->pagination = $objPagination->generate("\n  ");
124
+        }
125
+
126
+        $Clients = EsmClientsModel::getReferenceClients(($limit ?: 0), $offset);
127
+
128
+        $strItems = '';
129
+
130
+        foreach ($Clients as $client)
131
+        {
132
+            // Load client template
133
+            $objClientTemplate = new \FrontendTemplate($this->esm_clientsShowcase_template);
134
+
135
+            // Set template data
136
+            $objClientTemplate->title = $client->title;
137
+            $objClientTemplate->text = $client->text;
138
+            $objClientTemplate->color = deserialize($client->basecolor);
139
+            $objClientTemplate->branchId = $client->branch;
140
+
141
+            // Branche
142
+            $Branch = $client->getRelated('branch');
143
+            if (!is_null($Branch))
144
+            {
145
+                $objClientTemplate->branch = $Branch->title;
146
+            }
147
+
148
+            // Neutral logo
149
+            $objNeutralLogo = \FilesModel::findByUuid($client->logo_neutral);
150
+
151
+            if (is_file(TL_ROOT . '/' . $objNeutralLogo->path))
152
+            {
153
+                $objFile = new \File($objNeutralLogo->path, true);
154
+                $arrSize = $objFile->imageSize;
155
+                $arrMeta = $this->getMetaData($objNeutralLogo->meta, $objPage->language);
156
+                if (empty($arrMeta))
157
+                {
158
+                    if ($objPage->rootFallbackLanguage !== null)
159
+                    {
160
+                        $arrMeta = $this->getMetaData($objNeutralLogo->meta, $objPage->rootFallbackLanguage);
161
+                    }
162
+                }
163
+                if ($arrMeta['title'] == '')
164
+                {
165
+                    $arrMeta['title'] = specialchars($objFile->basename);
166
+                }
167
+                $objClientTemplate->logo_neutral = array
168
+                (
169
+                    'src'         => $objNeutralLogo->path,
170
+                    'width'       => $arrSize[0],
171
+                    'height'      => $arrSize[1],
172
+                    'attributes'  => $arrSize[3] . ' alt="' . $arrMeta['title'] . '"',
173
+                    'meta'        => $arrMeta
174
+                );
175
+
176
+            }
177
+
178
+            // Original logo
179
+            $objOriginalLogo = \FilesModel::findByUuid($client->logo_original);
180
+
181
+            if (is_file(TL_ROOT . '/' . $objOriginalLogo->path))
182
+            {
183
+                $objFile = new \File($objOriginalLogo->path, true);
184
+                $arrSize = $objFile->imageSize;
185
+                $arrMeta = $this->getMetaData($objOriginalLogo->meta, $objPage->language);
186
+                if (empty($arrMeta))
187
+                {
188
+                    if ($objPage->rootFallbackLanguage !== null)
189
+                    {
190
+                        $arrMeta = $this->getMetaData($objOriginalLogo->meta, $objPage->rootFallbackLanguage);
191
+                    }
192
+                }
193
+                if ($arrMeta['title'] == '')
194
+                {
195
+                    $arrMeta['title'] = specialchars($objFile->basename);
196
+                }
197
+                $objClientTemplate->logo_original = array
198
+                (
199
+                    'src'         => $objOriginalLogo->path,
200
+                    'width'       => $arrSize[0],
201
+                    'height'      => $arrSize[1],
202
+                    'attributes'  => $arrSize[3] . ' alt="' . $arrMeta['title'] . '"',
203
+                    'meta'        => $arrMeta
204
+                );
205
+
206
+            }
207
+
208
+            // Get client projects
209
+            $Projects = $client->getProjects();
210
+
211
+            $arrProjects = array();
212
+            foreach($Projects as $project)
213
+            {
214
+
215
+                $arrRow = $project->row();
216
+
217
+                if ($this->jumpTo > 0)
218
+                {
219
+                    $objTarget = \PageModel::findByPk($this->jumpTo);
220
+
221
+                    if ($objTarget !== null)
222
+                    {
223
+                        $strJumpTo = ampersand($this->generateFrontendUrl($objTarget->row(), ((\Config::get('useAutoItem') && !\Config::get('disableAlias')) ?  '/%s' : '/items/%s')));
224
+                        $strJumpTo = sprintf($strJumpTo,(!\Config::get('disableAlias') && $project->alias != '') ? $project->alias : $project->id);
225
+
226
+                        $arrRow['link'] = $strJumpTo;
227
+                    }
228
+                }
229
+
230
+                $arrProjects[] = $arrRow;
231
+            }
232
+
233
+            $objClientTemplate->projects = $arrProjects;
234
+
235
+
236
+            // Render Template
237
+            $strItems .= $objClientTemplate->parse();
238
+        }
239
+
240
+        $this->Template->items = $strItems;
241
+    }
187 242
 
188 243
 
189 244
 }
Browse code

Initial commit

Benjamin Roth authored on26/03/2015 15:24:56
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,189 @@
1
+<?php
2
+
3
+/**
4
+ * Clients for Contao
5
+ *
6
+ * Copyright (c) 2014 Benjamin Roth [http://www.esales-media.de]
7
+ *
8
+ * @package eSM_clients
9
+ * @link    http://www.esales-media.de
10
+ * @license commercial
11
+*/
12
+
13
+
14
+/**
15
+ * Run in a custom namespace, so the class can be replaced
16
+ */
17
+namespace eSM_clients;
18
+
19
+
20
+/**
21
+ * Shows a list of clients which have active projects
22
+ *
23
+ * @package   Modules
24
+ * @author    Benjamin Roth <http://www.esales-media.de>
25
+ * @copyright eSales Media 2014
26
+ */
27
+class ModuleClientsShowcase extends \Module
28
+{
29
+	/**
30
+	 * Template
31
+	 * @var string
32
+	 */
33
+	protected $strTemplate = 'mod_clientsShowcase';
34
+
35
+	/**
36
+	 * URL
37
+	 * @var string
38
+	 */
39
+	protected $strLink;
40
+
41
+
42
+	public function generate()
43
+	{
44
+		if (TL_MODE == 'BE')
45
+		{
46
+			$objTemplate = new \BackendTemplate('be_wildcard');
47
+
48
+			$objTemplate->wildcard = '### ' . utf8_strtoupper($GLOBALS['TL_LANG']['FMD']['clientsShowcase'][0]) . ' ###';
49
+			$objTemplate->title = $this->headline;
50
+			$objTemplate->id = $this->id;
51
+			$objTemplate->link = $this->name;
52
+			$objTemplate->href = 'contao/main.php?do=themes&amp;table=tl_module&amp;act=edit&amp;id=' . $this->id;
53
+
54
+			return $objTemplate->parse();
55
+		}
56
+
57
+		$this->strUrl = preg_replace('/\?.*$/', '', \Environment::get('request'));
58
+		$this->strLink = $this->strUrl;
59
+
60
+		return parent::generate();
61
+	}
62
+
63
+	/**
64
+	 * Compile the current element
65
+	 */
66
+	protected function compile()
67
+	{
68
+		global $objPage;
69
+
70
+		$Clients = EsmClientsModel::getReferenceClients();
71
+
72
+		$strItems = '';
73
+
74
+		foreach ($Clients as $client)
75
+		{
76
+//			dump($client);
77
+			// Load client template
78
+			$objClientTemplate = new \FrontendTemplate($this->esm_clientsShowcase_template);
79
+
80
+			// Set template data
81
+			$objClientTemplate->title = $client->title;
82
+			$objClientTemplate->text = $client->text;
83
+			$objClientTemplate->color = deserialize($client->basecolor);
84
+			$objClientTemplate->branchId = $client->branch;
85
+
86
+			// Branche
87
+			$Branch = $client->getRelated('branch');
88
+			if (!is_null($Branch))
89
+			{
90
+				$objClientTemplate->branch = $Branch->title;
91
+			}
92
+
93
+			// Neutral logo
94
+			$objNeutralLogo = \FilesModel::findByUuid($client->logo_neutral);
95
+
96
+			if (is_file(TL_ROOT . '/' . $objNeutralLogo->path))
97
+			{
98
+				$objFile = new \File($objNeutralLogo->path, true);
99
+				$arrSize = $objFile->imageSize;
100
+				$arrMeta = $this->getMetaData($objNeutralLogo->meta, $objPage->language);
101
+				if (empty($arrMeta))
102
+				{
103
+					if ($objPage->rootFallbackLanguage !== null)
104
+					{
105
+						$arrMeta = $this->getMetaData($objNeutralLogo->meta, $objPage->rootFallbackLanguage);
106
+					}
107
+				}
108
+				if ($arrMeta['title'] == '')
109
+				{
110
+					$arrMeta['title'] = specialchars($objFile->basename);
111
+				}
112
+				$objClientTemplate->logo_neutral = array
113
+				(
114
+					'src'         => $objNeutralLogo->path,
115
+					'width'       => $arrSize[0],
116
+					'height'      => $arrSize[1],
117
+					'attributes'  => $arrSize[3] . ' alt="' . $arrMeta['title'] . '"',
118
+					'meta'        => $arrMeta
119
+				);
120
+
121
+			}
122
+
123
+			// Original logo
124
+			$objOriginalLogo = \FilesModel::findByUuid($client->logo_original);
125
+
126
+			if (is_file(TL_ROOT . '/' . $objOriginalLogo->path))
127
+			{
128
+				$objFile = new \File($objOriginalLogo->path, true);
129
+				$arrSize = $objFile->imageSize;
130
+				$arrMeta = $this->getMetaData($objOriginalLogo->meta, $objPage->language);
131
+				if (empty($arrMeta))
132
+				{
133
+					if ($objPage->rootFallbackLanguage !== null)
134
+					{
135
+						$arrMeta = $this->getMetaData($objOriginalLogo->meta, $objPage->rootFallbackLanguage);
136
+					}
137
+				}
138
+				if ($arrMeta['title'] == '')
139
+				{
140
+					$arrMeta['title'] = specialchars($objFile->basename);
141
+				}
142
+				$objClientTemplate->logo_original = array
143
+				(
144
+					'src'         => $objOriginalLogo->path,
145
+					'width'       => $arrSize[0],
146
+					'height'      => $arrSize[1],
147
+					'attributes'  => $arrSize[3] . ' alt="' . $arrMeta['title'] . '"',
148
+					'meta'        => $arrMeta
149
+				);
150
+
151
+			}
152
+
153
+			// Get client projects
154
+			$Projects = $client->getProjects();
155
+
156
+			$arrProjects = array();
157
+			foreach($Projects as $project)
158
+			{
159
+
160
+				$arrRow = $project->row();
161
+
162
+				if ($this->jumpTo > 0)
163
+				{
164
+					$objTarget = \PageModel::findByPk($this->jumpTo);
165
+
166
+					if ($objTarget !== null)
167
+					{
168
+						$strJumpTo = ampersand($this->generateFrontendUrl($objTarget->row(), ((\Config::get('useAutoItem') && !\Config::get('disableAlias')) ?  '/%s' : '/items/%s')));
169
+						$strJumpTo = sprintf($strJumpTo,(!\Config::get('disableAlias') && $project->alias != '') ? $project->alias : $project->id);
170
+
171
+						$arrRow['link'] = $strJumpTo;
172
+					}
173
+				}
174
+
175
+				$arrProjects[] = $arrRow;
176
+			}
177
+
178
+			$objClientTemplate->projects = $arrProjects;
179
+
180
+
181
+			// Render Template
182
+			$strItems .= $objClientTemplate->parse();
183
+		}
184
+
185
+		$this->Template->items = $strItems;
186
+	}
187
+
188
+
189
+}