| ... | ... |
@@ -98,6 +98,12 @@ class WeinanlieferungSlotsModel extends Model |
| 98 | 98 |
$arrOptions['order'] = "$t.time ASC"; |
| 99 | 99 |
} |
| 100 | 100 |
|
| 101 |
+ if (isset($arrOptions['column'])) |
|
| 102 |
+ {
|
|
| 103 |
+ $arrColumns = array_merge($arrColumns,$arrOptions['column']); |
|
| 104 |
+ $arrOptions = array_diff_key($arrOptions,['column'=>true]); |
|
| 105 |
+ } |
|
| 106 |
+ |
|
| 101 | 107 |
return static::findBy($arrColumns,null,$arrOptions); |
| 102 | 108 |
} |
| 103 | 109 |
|
| ... | ... |
@@ -35,8 +35,9 @@ class WeinanlieferungSlotsModel extends Model |
| 35 | 35 |
|
| 36 | 36 |
// Skip unsaved elements (see #2708) |
| 37 | 37 |
$arrColumns[] = "$t.tstamp!=0"; |
| 38 |
+ $arrColumns[] = "$t.published='1'"; |
|
| 38 | 39 |
|
| 39 |
- $arrColumns[] = "$t.buchbar='1' AND $t.buchbar_bis>$time"; |
|
| 40 |
+ $arrColumns[] = "($t.buchbar_ab<=$time OR $t.buchbar_ab = 0 OR $t.buchbar_ab IS NULL) AND $t.buchbar_bis>$time"; |
|
| 40 | 41 |
|
| 41 | 42 |
if (!isset($arrOptions['order'])) |
| 42 | 43 |
{
|
| ... | ... |
@@ -54,8 +55,9 @@ class WeinanlieferungSlotsModel extends Model |
| 54 | 55 |
|
| 55 | 56 |
// Skip unsaved elements (see #2708) |
| 56 | 57 |
$arrColumns[] = "$t.tstamp!=0"; |
| 58 |
+ $arrColumns[] = "$t.published='1'"; |
|
| 57 | 59 |
|
| 58 |
- $arrColumns[] = "$t.buchbar='1' AND $t.buchbar_bis>$time"; |
|
| 60 |
+ $arrColumns[] = "($t.buchbar_ab<=$time OR $t.buchbar_ab = 0 OR $t.buchbar_ab IS NULL) AND $t.buchbar_bis>$time"; |
|
| 59 | 61 |
|
| 60 | 62 |
if (!isset($arrOptions['order'])) |
| 61 | 63 |
{
|
| ... | ... |
@@ -87,8 +89,9 @@ class WeinanlieferungSlotsModel extends Model |
| 87 | 89 |
|
| 88 | 90 |
// Skip unsaved elements (see #2708) |
| 89 | 91 |
$arrColumns[] = "$t.tstamp!=0"; |
| 92 |
+ $arrColumns[] = "$t.published='1'"; |
|
| 90 | 93 |
|
| 91 |
- $arrColumns[] = "$t.buchbar='1' AND $t.buchbar_bis>$time"; |
|
| 94 |
+ $arrColumns[] = "($t.buchbar_ab<=$time OR $t.buchbar_ab = 0 OR $t.buchbar_ab IS NULL) AND $t.buchbar_bis>$time"; |
|
| 92 | 95 |
|
| 93 | 96 |
if (!isset($arrOptions['order'])) |
| 94 | 97 |
{
|
| ... | ... |
@@ -108,7 +111,7 @@ class WeinanlieferungSlotsModel extends Model |
| 108 | 111 |
$arrOptions['order'] = "$t.time ASC"; |
| 109 | 112 |
} |
| 110 | 113 |
|
| 111 |
- return static::findBy(array("$t.time >= ?","$t.tstamp!=0","$t.buchbar='1' AND $t.buchbar_bis > ?"), [$time,$time], $arrOptions);
|
|
| 114 |
+ return static::findBy(array("$t.time >= ?","$t.tstamp!=0","$t.published='1' AND ($t.buchbar_ab<=$time OR $t.buchbar_ab = 0 OR $t.buchbar_ab IS NULL) AND $t.buchbar_bis > ?"), [$time,$time,$time], $arrOptions);
|
|
| 112 | 115 |
} |
| 113 | 116 |
|
| 114 | 117 |
public function getAvailableBehaelter(?int $intOffset=null) |
| ... | ... |
@@ -103,6 +103,11 @@ class WeinanlieferungSlotsModel extends Model |
| 103 | 103 |
$t = static::$strTable; |
| 104 | 104 |
$time = Date::floorToMinute(); |
| 105 | 105 |
|
| 106 |
+ if (!isset($arrOptions['order'])) |
|
| 107 |
+ {
|
|
| 108 |
+ $arrOptions['order'] = "$t.time ASC"; |
|
| 109 |
+ } |
|
| 110 |
+ |
|
| 106 | 111 |
return static::findBy(array("$t.time >= ?","$t.tstamp!=0","$t.buchbar='1' AND $t.buchbar_bis > ?"), [$time,$time], $arrOptions);
|
| 107 | 112 |
} |
| 108 | 113 |
|
| ... | ... |
@@ -14,6 +14,7 @@ namespace vonRotenberg\WeinanlieferungBundle\Model; |
| 14 | 14 |
|
| 15 | 15 |
use Contao\Controller; |
| 16 | 16 |
use Contao\Database; |
| 17 |
+use Contao\Date; |
|
| 17 | 18 |
use Contao\Model; |
| 18 | 19 |
use Contao\Model\Registry; |
| 19 | 20 |
use Doctrine\DBAL\Connection; |
| ... | ... |
@@ -97,6 +98,14 @@ class WeinanlieferungSlotsModel extends Model |
| 97 | 98 |
return static::findBy($arrColumns,null,$arrOptions); |
| 98 | 99 |
} |
| 99 | 100 |
|
| 101 |
+ public static function findAllFuturePublished(array $arrOptions=array()) |
|
| 102 |
+ {
|
|
| 103 |
+ $t = static::$strTable; |
|
| 104 |
+ $time = Date::floorToMinute(); |
|
| 105 |
+ |
|
| 106 |
+ return static::findBy(array("$t.time >= ?","$t.tstamp!=0","$t.buchbar='1' AND $t.buchbar_bis > ?"), [$time,$time], $arrOptions);
|
|
| 107 |
+ } |
|
| 108 |
+ |
|
| 100 | 109 |
public function getAvailableBehaelter(?int $intOffset=null) |
| 101 | 110 |
{
|
| 102 | 111 |
/** @var Connection $db */ |
| ... | ... |
@@ -97,7 +97,7 @@ class WeinanlieferungSlotsModel extends Model |
| 97 | 97 |
return static::findBy($arrColumns,null,$arrOptions); |
| 98 | 98 |
} |
| 99 | 99 |
|
| 100 |
- public function getAvailableBehaelter() |
|
| 100 |
+ public function getAvailableBehaelter(?int $intOffset=null) |
|
| 101 | 101 |
{
|
| 102 | 102 |
/** @var Connection $db */ |
| 103 | 103 |
$db = Controller::getContainer()->get('database_connection');
|
| ... | ... |
@@ -112,6 +112,11 @@ class WeinanlieferungSlotsModel extends Model |
| 112 | 112 |
$intReserved = 0; |
| 113 | 113 |
} |
| 114 | 114 |
|
| 115 |
+ if ($intOffset > 0) |
|
| 116 |
+ {
|
|
| 117 |
+ $intReserved += $intOffset; |
|
| 118 |
+ } |
|
| 119 |
+ |
|
| 115 | 120 |
return (int) $this->behaelter - $intReserved; |
| 116 | 121 |
} |
| 117 | 122 |
} |
| ... | ... |
@@ -12,9 +12,11 @@ declare(strict_types=1); |
| 12 | 12 |
|
| 13 | 13 |
namespace vonRotenberg\WeinanlieferungBundle\Model; |
| 14 | 14 |
|
| 15 |
+use Contao\Controller; |
|
| 15 | 16 |
use Contao\Database; |
| 16 | 17 |
use Contao\Model; |
| 17 | 18 |
use Contao\Model\Registry; |
| 19 |
+use Doctrine\DBAL\Connection; |
|
| 18 | 20 |
|
| 19 | 21 |
class WeinanlieferungSlotsModel extends Model |
| 20 | 22 |
{
|
| ... | ... |
@@ -40,7 +42,7 @@ class WeinanlieferungSlotsModel extends Model |
| 40 | 42 |
$arrOptions['order'] = "$t.time ASC"; |
| 41 | 43 |
} |
| 42 | 44 |
|
| 43 |
- return static::findBy($arrColumns, $intId, $arrOptions); |
|
| 45 |
+ return static::findOneBy($arrColumns, $intId, $arrOptions); |
|
| 44 | 46 |
} |
| 45 | 47 |
|
| 46 | 48 |
public static function findPublishedByPid($intPid, array $arrOptions=array()) |
| ... | ... |
@@ -94,4 +96,22 @@ class WeinanlieferungSlotsModel extends Model |
| 94 | 96 |
|
| 95 | 97 |
return static::findBy($arrColumns,null,$arrOptions); |
| 96 | 98 |
} |
| 99 |
+ |
|
| 100 |
+ public function getAvailableBehaelter() |
|
| 101 |
+ {
|
|
| 102 |
+ /** @var Connection $db */ |
|
| 103 |
+ $db = Controller::getContainer()->get('database_connection');
|
|
| 104 |
+ |
|
| 105 |
+ $ReservedBehaelter = $db->prepare("SELECT SUM(behaelter) FROM tl_vr_wa_reservation WHERE pid = ?")
|
|
| 106 |
+ ->executeQuery([$this->id]); |
|
| 107 |
+ |
|
| 108 |
+ $intReserved = $ReservedBehaelter->fetchOne(); |
|
| 109 |
+ |
|
| 110 |
+ if ($intReserved === null) |
|
| 111 |
+ {
|
|
| 112 |
+ $intReserved = 0; |
|
| 113 |
+ } |
|
| 114 |
+ |
|
| 115 |
+ return (int) $this->behaelter - $intReserved; |
|
| 116 |
+ } |
|
| 97 | 117 |
} |
| ... | ... |
@@ -24,6 +24,25 @@ class WeinanlieferungSlotsModel extends Model |
| 24 | 24 |
*/ |
| 25 | 25 |
protected static $strTable = 'tl_vr_wa_slot'; |
| 26 | 26 |
|
| 27 |
+ public static function findPublishedById($intId, array $arrOptions=array()) |
|
| 28 |
+ {
|
|
| 29 |
+ $time = time(); |
|
| 30 |
+ $t = static::$strTable; |
|
| 31 |
+ $arrColumns = array("$t.id=?");
|
|
| 32 |
+ |
|
| 33 |
+ // Skip unsaved elements (see #2708) |
|
| 34 |
+ $arrColumns[] = "$t.tstamp!=0"; |
|
| 35 |
+ |
|
| 36 |
+ $arrColumns[] = "$t.buchbar='1' AND $t.buchbar_bis>$time"; |
|
| 37 |
+ |
|
| 38 |
+ if (!isset($arrOptions['order'])) |
|
| 39 |
+ {
|
|
| 40 |
+ $arrOptions['order'] = "$t.time ASC"; |
|
| 41 |
+ } |
|
| 42 |
+ |
|
| 43 |
+ return static::findBy($arrColumns, $intId, $arrOptions); |
|
| 44 |
+ } |
|
| 45 |
+ |
|
| 27 | 46 |
public static function findPublishedByPid($intPid, array $arrOptions=array()) |
| 28 | 47 |
{
|
| 29 | 48 |
$time = time(); |
| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,78 @@ |
| 1 |
+<?php |
|
| 2 |
+ |
|
| 3 |
+declare(strict_types=1); |
|
| 4 |
+ |
|
| 5 |
+/* |
|
| 6 |
+ * This file is part of contao-weinanlieferung-bundle. |
|
| 7 |
+ * |
|
| 8 |
+ * (c) vonRotenberg |
|
| 9 |
+ * |
|
| 10 |
+ * @license commercial |
|
| 11 |
+ */ |
|
| 12 |
+ |
|
| 13 |
+namespace vonRotenberg\WeinanlieferungBundle\Model; |
|
| 14 |
+ |
|
| 15 |
+use Contao\Database; |
|
| 16 |
+use Contao\Model; |
|
| 17 |
+use Contao\Model\Registry; |
|
| 18 |
+ |
|
| 19 |
+class WeinanlieferungSlotsModel extends Model |
|
| 20 |
+{
|
|
| 21 |
+ /** |
|
| 22 |
+ * Table name |
|
| 23 |
+ * @var string |
|
| 24 |
+ */ |
|
| 25 |
+ protected static $strTable = 'tl_vr_wa_slot'; |
|
| 26 |
+ |
|
| 27 |
+ public static function findPublishedByPid($intPid, array $arrOptions=array()) |
|
| 28 |
+ {
|
|
| 29 |
+ $time = time(); |
|
| 30 |
+ $t = static::$strTable; |
|
| 31 |
+ $arrColumns = array("$t.pid=?");
|
|
| 32 |
+ |
|
| 33 |
+ // Skip unsaved elements (see #2708) |
|
| 34 |
+ $arrColumns[] = "$t.tstamp!=0"; |
|
| 35 |
+ |
|
| 36 |
+ $arrColumns[] = "$t.buchbar='1' AND $t.buchbar_bis>$time"; |
|
| 37 |
+ |
|
| 38 |
+ if (!isset($arrOptions['order'])) |
|
| 39 |
+ {
|
|
| 40 |
+ $arrOptions['order'] = "$t.time ASC"; |
|
| 41 |
+ } |
|
| 42 |
+ |
|
| 43 |
+ return static::findBy($arrColumns, $intPid, $arrOptions); |
|
| 44 |
+ } |
|
| 45 |
+ |
|
| 46 |
+ public static function findMultiplePublishedByPids(array $arrPids, array $arrOptions=array()) |
|
| 47 |
+ {
|
|
| 48 |
+ if (empty($arrPids) || !\is_array($arrPids)) |
|
| 49 |
+ {
|
|
| 50 |
+ return null; |
|
| 51 |
+ } |
|
| 52 |
+ |
|
| 53 |
+ $arrPids = array_filter($arrPids, function($var) {
|
|
| 54 |
+ return is_numeric($var); |
|
| 55 |
+ }); |
|
| 56 |
+ |
|
| 57 |
+ if (empty($arrPids)) |
|
| 58 |
+ {
|
|
| 59 |
+ return null; |
|
| 60 |
+ } |
|
| 61 |
+ |
|
| 62 |
+ $time = time(); |
|
| 63 |
+ $t = static::$strTable; |
|
| 64 |
+ $arrColumns = array("$t.pid IN (".implode(',',$arrPids).")");
|
|
| 65 |
+ |
|
| 66 |
+ // Skip unsaved elements (see #2708) |
|
| 67 |
+ $arrColumns[] = "$t.tstamp!=0"; |
|
| 68 |
+ |
|
| 69 |
+ $arrColumns[] = "$t.buchbar='1' AND $t.buchbar_bis>$time"; |
|
| 70 |
+ |
|
| 71 |
+ if (!isset($arrOptions['order'])) |
|
| 72 |
+ {
|
|
| 73 |
+ $arrOptions['order'] = "$t.time ASC"; |
|
| 74 |
+ } |
|
| 75 |
+ |
|
| 76 |
+ return static::findBy($arrColumns,null,$arrOptions); |
|
| 77 |
+ } |
|
| 78 |
+} |