... | ... |
@@ -33,16 +33,35 @@ class EsmClientsModel extends \Model |
33 | 33 |
*/ |
34 | 34 |
protected static $strTable = 'tl_esm_clients'; |
35 | 35 |
|
36 |
+ /** |
|
37 |
+ * @return \Model\Collection|null |
|
38 |
+ */ |
|
39 |
+ public static function countReferenceClients() |
|
40 |
+ { |
|
41 |
+ $t1 = static::$strTable; |
|
42 |
+ $t2 = $t1.'_projects'; |
|
43 |
+ |
|
44 |
+ $Result = \Database::getInstance()->execute("SELECT COUNT($t1.id) AS 'totalcount' FROM $t1 WHERE invisible='' AND EXISTS (SELECT 1 FROM $t2 WHERE $t2.pid = $t1.id AND invisible = '' GROUP BY $t2.pid)"); |
|
45 |
+ |
|
46 |
+ if ($Result->numRows) |
|
47 |
+ { |
|
48 |
+ return $Result->totalcount; |
|
49 |
+ } |
|
50 |
+ |
|
51 |
+ return 0; |
|
52 |
+ } |
|
36 | 53 |
|
37 | 54 |
/** |
38 | 55 |
* @return \Model\Collection|null |
39 | 56 |
*/ |
40 |
- public static function getReferenceClients() |
|
57 |
+ public static function getReferenceClients($intLimit=0, $intOffset=0) |
|
41 | 58 |
{ |
42 | 59 |
$t1 = static::$strTable; |
43 | 60 |
$t2 = $t1.'_projects'; |
44 | 61 |
|
45 |
- $Result = \Database::getInstance()->execute("SELECT $t1.id FROM $t1 WHERE invisible='' AND EXISTS (SELECT 1 FROM $t2 WHERE $t2.pid = $t1.id AND invisible = '' GROUP BY $t2.pid) ORDER BY $t1.sorting"); |
|
62 |
+ $Result = \Database::getInstance()->prepare("SELECT $t1.id FROM $t1 WHERE invisible='' AND EXISTS (SELECT 1 FROM $t2 WHERE $t2.pid = $t1.id AND invisible = '' GROUP BY $t2.pid) ORDER BY $t1.sorting") |
|
63 |
+ ->limit($intLimit,$intOffset) |
|
64 |
+ ->execute(); |
|
46 | 65 |
|
47 | 66 |
$arrIds = $Result->fetchEach('id'); |
48 | 67 |
|
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,69 @@ |
1 |
+<?php |
|
2 |
+ |
|
3 |
+/** |
|
4 |
+ * References 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 |
+ * Reads and writes reference clients |
|
22 |
+ * |
|
23 |
+ * @package Models |
|
24 |
+ * @author Benjamin Roth <http://www.esales-media.de> |
|
25 |
+ * @copyright eSales Media 2014 |
|
26 |
+ */ |
|
27 |
+class EsmClientsModel extends \Model |
|
28 |
+{ |
|
29 |
+ |
|
30 |
+ /** |
|
31 |
+ * Table name |
|
32 |
+ * @var string |
|
33 |
+ */ |
|
34 |
+ protected static $strTable = 'tl_esm_clients'; |
|
35 |
+ |
|
36 |
+ |
|
37 |
+ /** |
|
38 |
+ * @return \Model\Collection|null |
|
39 |
+ */ |
|
40 |
+ public static function getReferenceClients() |
|
41 |
+ { |
|
42 |
+ $t1 = static::$strTable; |
|
43 |
+ $t2 = $t1.'_projects'; |
|
44 |
+ |
|
45 |
+ $Result = \Database::getInstance()->execute("SELECT $t1.id FROM $t1 WHERE invisible='' AND EXISTS (SELECT 1 FROM $t2 WHERE $t2.pid = $t1.id AND invisible = '' GROUP BY $t2.pid) ORDER BY $t1.sorting"); |
|
46 |
+ |
|
47 |
+ $arrIds = $Result->fetchEach('id'); |
|
48 |
+ |
|
49 |
+ return static::findMultipleByIds($arrIds); |
|
50 |
+ } |
|
51 |
+ |
|
52 |
+ /** |
|
53 |
+ * @param bool $blnIncludeInvisible |
|
54 |
+ * @return \Model\Collection|null |
|
55 |
+ */ |
|
56 |
+ public function getProjects($blnIncludeInvisible=false) |
|
57 |
+ { |
|
58 |
+ $arrConditions = array('pid = ?'); |
|
59 |
+ $arrValues = array($this->id); |
|
60 |
+ |
|
61 |
+ if ($blnIncludeInvisible) |
|
62 |
+ { |
|
63 |
+ $arrConditions[] = 'invisible = ?'; |
|
64 |
+ $arrValues[] = '1'; |
|
65 |
+ } |
|
66 |
+ |
|
67 |
+ return EsmClientsProjectsModel::findBy($arrConditions,$arrValues,array('order'=>'sorting')); |
|
68 |
+ } |
|
69 |
+} |